Showing posts with label c#. Show all posts
Showing posts with label c#. Show all posts

Friday, March 6, 2015

Having fun with C# dynamic and reflection: create a class that let us to avoid access modifier

Yeah, the title says it all.

Have you ever get tired of manually call reflection methods to get a value of an hidden field? Yes I do!

In my spare time I found a funny solution to work around this problem.
I found a dummy way to avoid access modifier without losing 'deafult' syntax: thanks to c# dynamic object!
public class MyClass
{
    private int value = 1 ; 
}
private static void Main(string[] args)
{
    MyClass myInstance = new MyClass();

    //cannot access private field 'value' here
    //myInstance.value = 2;

    dynamic myInstance2 = myInstance.Expose();

    //can do it!
    myInstance2.value = 2;
}

Monday, July 28, 2014

Move ViewState out of the page

From this year I'm working on a ASP.NET Web Forms project. I'm currently tuning this project with some tweaks.
One of those tweaks is related to ViewState, IMHO the Achilles' heel of this framework.
Due to business decisions, budget etc... dev-team could not re-engineer the entire pages, so they decided to improve whatever possible.

Move ViewState out of the page... that means one thing: lighter pages!

ViewState, by default implementation,  is actually stored in a HiddenField, but you can move it everywhere: Session, Cache, Database...

Monday, July 1, 2013

Convert from jar to dll

Nowadays, development is very eased from community.
We can easily re-use our code between different platforms in so many ways, gaining time, money and above all... today have multiple skills is not so as useful as before.

By the way, I recently had necessity to bring some java code to .NET runtimes.
No difficulties with IKVM.NET !

If you follow these steps you can convert from JAR to DLL or even from Runnable JAR to EXE!

Friday, November 9, 2012

That damn NFC alert after tapping a tag on WP8

In these days I had the opportunity to develop a Windows Phone 8 application for my company.
The main reason we choose WP8 was the new Proximity API for reading NFC Tags.

I don't wanna write about how to read or write a NFC Tag but I just want to notify you an issue I encountered while developing.

When you tap a Tag over a device, a system dialog appears asking you if you want to view the content of the tag. A dialog is showed even if there aren't app that can manage a specified tag content.
So read a Tag brings an annoying system dialog.

I had to realize an app that reads tags during an event and does a check-in . So in a single page I want to read several nfc tags without any kind of interruptions.
Can I read a tag without seeing this damn alert that is literally ruining my UX? The answer is yes I can.

Monday, March 12, 2012

A month view calendar for WP7


We know that wp7 is a bit young but it has a good potential.
We also know that its youth means, for developers, poor os-controls, poor API etc...

Last week I had to demonstrate that WP7 is comparable to iOS and Android. 
I had to realize a sort of "accounting app" already done in iOS and Android.

I had no significant problems while working except for some limits of SDK.
SDK doesn't provide a datetime picker, a combo box or list picker not even a calendar.

I found on the web a Silverlight for Windows Phone Toolkit that brings some controls I've just mentioned.

No track of a calendar :(

I found only 1 calendar for wp7 on web but it didn't like me.... So..
I decided to make my own :)

Fixed layout for PhoneApplicationPage

As a beginner in WP7 I found some issues for my first applications.
One of those problems I had was the hated "fixed layout" of a page.

It's a topic already discussed (view the post for Android) but in this case, it's a bit different.

Suppose we want a "fixed header and footer" for every page, how do you do it?

Thursday, January 26, 2012

Getting started with Lamba Expressions

C# 3.0 brought so much news (for example var, extensions ,LINQ, lambda expressions etc...).
Sometime companies have its reason to don't update .NET framework in their applications.
For this, developers who grow parallely to those applications, never have time to upgrade their knowledges.

I know companies that use 2003's IDE in 2011!

For those who never had a chance to see what's new in latest framework, like me, I dedicate this post.

What is a lambda expression and what can I do with it?

It's "an anonymous function that can contain expressions and statements, and can be used to create delegates or expression tree types" (msdn).

Tuesday, January 17, 2012

Invoking a method from its name

A few weeks ago I showed how can work a simple Server.
My client sends a pre-formatted string with the method to call and the parameters, my server processes the string and calls the correct method.
But how it can be?

Thursday, January 5, 2012

Server Multi-client in C# .NET

Un altro progetto a scopo didattico che è sempre carino da affrontare è la comunicazione Client/Server via socket TCP.

E cosa schiarisce meglio le idee di un immagine?

Il progetto in questione si divide quindi in due parti. La prima è semplicemente un server, realizzato in c# .net, che:
-riceve in ingresso delle stringhe formattate in un certo modo,
-effettua un operazione a seconda di che stringa riceve,
-rimanda al client la risposta in formato stringa.

Questo tipo di progetto può avere numerosissimi tipi di applicazione: in teoria tutto quello che può fare un applicativo .Net è "attivabile/reperibile" via socket. Le più stupide modalità di utilizzo che mi vengono in mente ora possono essere: reperire dei dati da un database, lanciare procedure, controllare funzioni di sistema ecc... ecc... 

Vediamo un po' più nel dettaglio come funziona.

Tuesday, December 20, 2011

Interrogare un Web Service ASP.NET con Android

Abbiamo il nostro bel WS in ASMX o WCF e vogliamo renderlo raggiungibile dai nostri terminali Android senza troppe rogne? Le librerie ksoap2 ci stravengo incontro!

Scarichiamo il jar relativo qui , importiamolo nel nostro progetto e aggiungiamo le referenze nella nostra classe:

 import org.ksoap2.SoapEnvelope;  
 import org.ksoap2.serialization.SoapObject;  
 import org.ksoap2.serialization.SoapPrimitive;  
 import org.ksoap2.serialization.SoapSerializationEnvelope;  
 import org.ksoap2.transport.HttpTransportSE;  

Supponendo di avere un webservice con una pagina "Service1.asmx" la quale contiene questo metodo:

 [WebMethod]  
 public string HelloWorld(string valore)  
 {  
       return valore;  
 }  

Wednesday, December 14, 2011

Keylogger in .NET (parte1)

Un giorno vidi, su una nota webzine, un articolo sui tipi di malware esistenti nel campo informatico.
Mi balzò all'occhio il keylogger e mi domandai... che ci vorrà mai a farne uno?

Perchè fare ciò? Per passare in qualche modo il mio giorno di requiem ;)

________________________________________________________________________________

Per prima cosa vediamo che caratteristiche dovrà avere questo keylogger (da ora in poi KL):

-Il software dovrà essere in grado di catturare tutti i tasti digitati dall'utente, segnalando tutti i comandi speciali e hotkey
-Il software dovrà essere in grado di riconoscere le finestre in uso dall'utente
-Il software dovrà loggare tutte le informazioni sopracitate e poterle inviare tramite mail o socket
-Il software dovrà essere totalmente trasparente all'utilizzatore del computer e individuabile solamente come processo nel task manager

Questo dovrebbe bastare per far si che il programma possa essere un keylogger.