Software Development Skills Review Part 1: WCF, ASP.NET Web API

Recently I was asked multiple questions about WCF, Web API, actually I posted multiple blog articles which were about WCF, Web API, The relationships between WCF, WCF Web API and ASP.NET Web API etc. in 2010 ~ 2013. Let me review them first, and then I will add new content and changes

Continue reading “Software Development Skills Review Part 1: WCF, ASP.NET Web API”

Experienced Software Developer Still Faces to Code or Basic Acknowledge Test When Interview

As a IT guy, a Software Developer, a Microsoft technologies developer (from C++ to .NET ) with over 24 years development history, I still have to face to some awkward (embarrassed ? ) situations such as job interviews. I left school so many years, but some interviews still needed me to give correct answers for some basic computer and programming acknowledges, such as: What is C# ? What features does OO have ? or I was asked for writing code to give a good performance program to implement a scanning or searching case based on stack or queue ….

Continue reading “Experienced Software Developer Still Faces to Code or Basic Acknowledge Test When Interview”

An error occurred while signing with SignTool Error

When I opened an old .NET project in Visual Studio 2013, I got the following error when I tried to rebuild the project:

Error    1    An error occurred while signing: Failed to sign bin\Release\app.publish\xxxx.exe. SignTool Error: No certificates were found that met all the given criteria.    xxxx

image

The reason should caused by the old .NET framework platform about ClickOnce manifest certificate.

Continue reading “An error occurred while signing with SignTool Error”

Microsoft Announced .NET Open Source and Visual Studio Free

I missed a big event from Microsoft in passed 2 days since I was busy on our business project. I forgot the event date. so, I missed the big news from Microsoft. I just realized Microsoft took .NET open source, and released Visual Studio full feature edition.

Yes, .NET open-sourced to everybody, and Visual Studio is free to everybody now; Also, .NET will be running on Linux and Mac systems eventually! And, Programmers will be able to use Visual Studio to develop Android and Mac projects directly!

Continue reading “Microsoft Announced .NET Open Source and Visual Studio Free”

Visual Studio 2013 and .NET 4.5.1 Released

Microsoft just released the new development tool Visual Studio 2013 and .NET 4.5.1.

The Main New Features or Improvement in for Visual Studio 2013

One ASP.NET
– ASP.NET Scaffolding
– Browser Link
Windows Azure Web Sites Support in Visual Studio
– NuGet 2.7
ASP.NET MVC 5
ASP.NET Web API 2
ASP.NET SignalR 2
– ASP.NET Identity
– Entity Framework 6

Microsoft’s ScottGu’s blog and ASP.NET official website both announced the release information, but another Scott, hanselman has not yet released his idea about this.

About .NET Framework 4.5.1, it also a big release than we expected:

– X64 edit and continue (Improve x64 debugger so Edit and Continue works when running on Windows x64 o/s)
– Async-aware debugging
– Managed return value inspection
– ADO.NET idle connection resiliency
– Improvements in Windows Store app development
– ADO.NET connection resiliency
– ASP.NET app suspension
– Multi-core JIT improvements

see .NET Framework official site.

From the new features list, Visual Studio 2013 and .NET framework 4.5.1 bring us great new tech and big changes.

For Next Generation Apps – Visual Studio 2012 Released

Microsoft released Visual Studio 2012 and .NET Framework 4.5 in the last week (2012 August 15). That was really a big day for both of all .NET developers and Microsoft.

When I quickly viewed the introduction of Visual Studio 2012, I felt a new generation using Microsoft techs and tools was coming fast. If we thought the new generation was still some far before, now we have to say: we are in the new stage (generation) now.

image

The following are some important features which are NEW compared with old version of Visual Studio:

1: For Windows 8, for Windows Phone 8;
Yes, Everything for Microsoft now is the number 8: Windows 8 and Windows phone 8. they should be the most important products for Microsoft’s several of new coming years, definitely the Visual Studio 2012 should provide good support for them, this is the m

2: For new Web stuff:
Before Microsoft could only consider their Silverlight, but now all over the world turning to HTML5, also HTML & CSS, JavaScript. So VS 2012 provided support for them, including IntelliSense JavaScript editor, a new DOM explorer;

3: For cloud computing (Azure):
Cloud computing is also a big one part the next generation applications. Microsoft spent lots of budget on their cloud computing platform, the Azure;

4: For SharePoint:
Business Stuff.

5: For Game and 3D

There are other new features which I should not talk more here, because we need to read more professional articles and messages. the following are the important links which I suggest to read:

1: Jason Zander: Visual Studio 2012 and .NET Framework 4.5 released to the web!;
2: Scott Hanselman: Visual Studio 2012 and .NET Framework 4.5 is RELEASED – Here’s 5 minute videos to get you up to speed quick;
3: Jon Galloway: http://weblogs.asp.net/jgalloway/archive/2012/08/16/asp-net-4-5-asp-net-mvc-4-asp-net-web-pages-2-and-visual-studio-2012-web-developer-features.aspx

Finally, Yes, do not forget the Visual Studio official page and download:

http://www.microsoft.com/visualstudio/11/en-us

Wow!

Event, Custom Event and Generic Event in .NET

We often need to implement events in our own class. About how to implement events, Microsoft provides tutorials such as this one.

About the concepts of Event and Delegate, please read Microsoft site here.

I. Traditional Method :

Microsoft provides tutorials seems still in .NET 1.1 way even the web page is showing for .NET Framework 4, this is the traditional way to implement an event in custom class:

For event-specific data:

1: If for an event with event-specific data:

Create custom EventArgs, just like Microsoft’s sample:

public class MyEventArgs : EventArgs
{
    private string msg;

    public MyEventArgs( string messageData ) {
        msg = messageData;
    }
    public string Message { 
        get { return msg; } 
        set { msg = value; }
    }
}

2: like 1, this case is still if for an event with event-specific data:

Declare a delegate for the event, use the name like EventNameEventHandler;

public delegate void MyEventHandler(object sender, MyEventArgs e);

3: Define a public event in our class. Set the type of the event member to the event delegate type.

 public class MyClassIncludesDefinedEvent
{
    public event MyEventHandler MyEvent;
    ...
}

4: Define a protected method in our class that raises the event:

public class MyClassIncludesDefinedEvent
{
    public event MyEventHandler MyEvent;

    protected virtual void OnMyEvent(MyEventArgs e)
    {
      if (MyEvent != null) 
          MyEvent(this, e); 
    }
}

5: Since our raising event method is protected, we’d better define another method in the same class to “launch” our OnMyEvent, also, we need to initial our MyEventArgs:

public class MyClassIncludesDefinedEvent
{
    public event MyEventHandler MyEvent;

    protected virtual void OnMyEvent(MyEventArgs e)
    {
      if (MyEvent != null) 
          MyEvent(this, e); 
    }

    public void CallEvent(string newMsg)
    {
       OnMyEvent(new MyEventArgs(newMsg));
    }
}

6: Then, we can consumer our custom event just like below sample:

private void Form1_Load(object sender, EventArgs e)
{
    MyClassIncludeDefinedEvent myEventClass = new MyClassIncludeDefinedEvent();            

    myEventClass.MyEvent += new MyEventHandler(myEventClass_MyEvent);
    myEventClass.CallEvent("My Custome Event Test.");            
}

void myEventClass_MyEvent(object sender, MyEventArgs e)
{
    MessageBox.Show(e.Message);
}

When we run above sample, we can get the correct result successfully:

image

For Non-event-specific data:

If we do not need event-specific data, it means we do not need a custom EventArgs (above samle: MyEventArgs), we do not need to define a custom delegate but just use .NET’s pre defined  EventHandler.

Then we can skip the above step 1 and step 2, In Step 3, we use like below (for testing, we create a new class named MyClassIncludesDefinedEvent2):

 public class MyClassIncludesDefinedEvent2
{
    public EventHandler MyEvent;
    ...
 }

The next we put other methods like the following:

(Note: now the EventArgs changed to the default EventArgs too, which is defined by .NET too)

public class MyClassIncludesDefinedEvent2
{
    public event MyEventHandler MyEvent;

    protected virtual void OnMyEvent(EventArgs e)
    {
      if (MyEvent != null) 
          MyEvent(this, e); 
    }

    public void CallEvent()
    {
       OnMyEvent(new EventArgs());
    }
}

Then we can consumer our event using the following code:

private void Form1_Load(object sender, EventArgs e)
{
    MyClassIncludeDefinedEvent2 myEventClass2 = new MyClassIncludeDefinedEvent2();
    myEventClass2.MyEvent += new EventHandler(myEventClass2_MyEvent);
    myEventClass2.CallEvent();
}

void myEventClass2_MyEvent(object sender, EventArgs e)
{
    MessageBox.Show("This is Non-specific data event test.");
}

We also get event launched result:

image



II. New Method – Generic Event Method (Since .NET 2.0 )

From previous sample, we can see .NET provides a EventHandler which let us ignore delegate define, actually, .NET defined delegate for us automatically without need us define. But, for the event with specific data (generated data), we have to define delegate handler for each time. just like this:

public delegate void MyEventHandler(object sender, MyEventArgs e);

Most of cases, when we define delegate handler, only the second parameter is different, So why don’t .NET provide another style EventHandler to let us skip defining the delegate too for those specific data events ?

Yes, Since .NET 2.0, Microsoft provided the Generic EventHandler, which let us reduce some works.

Let’s go back to the sample 1 above (For event-specific data):

1: Step 1 keeps the same: define MyEventArgs

2: We do not need to define a delegate handler this time, but just use Generic EventHandler;

3: We create a new class to replace the first class MyClassIncludesDefinedEvent, The new class named MyGenericEventClass, its full content is the following:

public class MyGenericEventClass
{
    public event EventHandler MyEvent;

    protected virtual void OnMyEvent(MyEventArgs e)
    {
        // Copy to a temporary variable to be thread-safe.
        EventHandler tempEvent = MyEvent;
        if (tempEvent != null)
            tempEvent(this, e);
    }

    public void CallEvent(string newMsg)
    {
        OnMyEvent(new MyEventArgs(newMsg));
    }
}

Actually the last two methods in above class can be merged to the single method, just like the following:

public class MyGenericEventClass
{
    public event EventHandler MyEvent;

    public void CallEvent(string newMsg)
    {
        // Copy to a temporary variable to be thread-safe.
        EventHandler tempEvent = MyEvent;
        if (tempEvent != null)
            tempEvent(this, new MyEventArgs(newMsg));	
    }
}

Then we can consume the generic event like the following:

private void Form1_Load(object sender, EventArgs e)
{
    MyGenericEventClass  myGenericEventClass = new MyGenericEventClass();

    myGenericEventClass.MyEvent += new EventHandler(myGenericEventClass_MyEvent);
    myGenericEventClass.CallEvent("My Generic Event Test.");
}

void myGenericEventClass_MyEvent(object sender, MyEventArgs e)
{
    MessageBox.Show(e.Message); 
}

Also, we can get correct result:

image