IgorShare Weblog

Practical Engineering

Archive for the ‘C#’ Category

Now I have ALL of the Microsoft developer certifications – long journey is over!!!

Posted by igormoochnick on 09/09/2009

Now I own the full deck of the Microsoft certifications and I can sit back and relax (beer is in order ;-) . Unfortunately, in the startup world that I operate most of the time, it’s not very recognizable achievement, but it’s nice to put these logos on my presentation slide decks and, especially now, I have a very powerful bragging rights – I have ALL of the Microsoft developers certifications !!!

It was a lengthy path and, I should add, a very confusing one. It wasn’t very obvious what certification is a prerequisite to which one and, I must add, I’ve made a couple of mistakes on the road until I’ve discovered a developer’s certification map by Jorgen Thelin that put everything in order and cleared all the confusions.

ms-cert-path-mcpd_4[1]

Posted in .NET, ADO.Net, ASP.NET, C#, Community, Thoughts, WCF, WPF, Workflows | 6 Comments »

Building GWT web clients [Part 4.1] – How to create an Azure RESTful web service?

Posted by igormoochnick on 06/08/2009

Prerequisites: make sure that you have all the Azure SDK tools installed for your VS2008.

 

(1) Start by creating a new “Web Cloud Service” project in the Visual Studio. Give it a nice name.

(2) Add a new “WCF Service” to the WebRole project.

(3) Define a required contract:

The most important part here is to put attributes that will tell the WCF in what format to send/receive the message body (XML or JSON) …

[ServiceContract(Name = "service", Namespace = "http://www.igorshare.com")]
public interface IContactManagerService
{
    [OperationContract]
    [WebGet(UriTemplate = "/contacts", BodyStyle = WebMessageBodyStyle.Bare,
       ResponseFormat = WebMessageFormat.Json)]
    List<Contact> GetAllContacts();

    [OperationContract]
    [WebGet(UriTemplate = "/contacts/{filter}", BodyStyle = WebMessageBodyStyle.Bare,
       ResponseFormat = WebMessageFormat.Json)]
    List<Contact> GetContacts(string filter);
}

[DataContract]
public class Contact
{
    [DataMember]
    public string FirstName { get; set; }

    [DataMember]
    public string LastName { get; set; }

    [DataMember]
    public string Company { get; set; }
}

(4) Implement the service logic:

public class ContactManagerService : IContactManagerService
{
    private static readonly List<Contact> Contacts = new List<Contact>() { ... };

    public List<Contact> GetAllContacts()
    {
        return Contacts;
    }

    public List<Contact> GetContacts(string filter)
    {
        string f = filter.ToLower();

        var contacts = from contact in Contacts
                       where contact.FirstName.ToLower().Contains(f)
                            || contact.LastName.ToLower().Contains(f)
                            || contact.Company.ToLower().Contains(f)
                       select contact;

        return contacts.ToList();
    }
}

(5) Configure it to be exposed as a RESTful service:

To make it REALLY, REALLY simple for you, do this trick:

a) Comment out the system.serviceModel section in the Web.config file

b) Add the Factory attribute to the .svc file

<%@ ServiceHost Language="C#" Debug="true"
Service="ContactManagerCloudService_WebRole.ContactManagerService"
CodeBehind="ContactManagerService.svc.cs"
Factory="System.ServiceModel.Activation.WebServiceHostFactory" %>

(6) Build the service

 

You’re interested in 2 artifacts of the build:

  1. .cscfg file – configuration for the Cloud Service deployment
  2. .cspkg file – all the bits packaged (zipped)

 

At this moment you have 2 choices:

  1. Run your project in the local Development Fabric (for testing and debugging), or …
  2. Deploy it to the Azure Cloud (for staging or production)

 

To deploy your application to the cloud, do right-click on the CloudService project and select “Publish”.

Visual Studio will launch the Azure Service Developer Portal page. Log-in to your account, create a project and deploy your bits to the staging environment:

clip_image001

 

This is it!  You’re good to go.

BTW: make sure that your application works in the staging environment and then you can push it to Production by just switching it with the Staging.

 

 

Note: Check out a great explanation about the difference between the WCF REST Configuration for ASP.NET AJAX and plain REST Services by Rick Strahl.

Posted in .NET, Azure, C#, JSON, REST, S+S, Tutorials, WCF | Leave a Comment »

Data in the Cloud: Data Camp presentation in Waltham

Posted by igormoochnick on 01/30/2009

clip_image001

It was a lot of fun to present last Saturday at the very first Data Camp that was held in Waltham.

Almost every company I worked with needed some ways to store and process huge amounts of data on the cloud – that includes Intel, ICQ/AOL, Symantec and Broadserve. The latter was the worst case scenario – it was an online multimedia streaming on demand.

So, as you can guess, I’ve learned a great deal about this “trade” and, after release of Amazon AWS and, now, Azure, I’ve become a happy man – no more need in setting up and managing your own infrastructure.

In my view, the “DATA in the Cloud” is actually a mix of the following 3 main aspects (“pillars”):

  1. Data Storage
  2. Data Processing
  3. Data Delivery
  4. Access Control (Authentication + Authorization)

Yes, I know – it’s four, but where can you go without mentioning the last one? Nowhere – you’ll be eaten alive ;-)

In this presentation I’ve tried to distill all the different ways that Azure Fabric (Platform and Services) helps you to address all the (first) 3 aspects of working with the “Data in the Cloud”.

Enjoy the presentation!        (URL is here) 

While at this: I’d like to thank the organizers of the Waltham Data camp and Microsoft for providing support and the great location!!!

Posted in Azure, C#, Presentations, S+S, Thoughts, Tutorials | 1 Comment »

Hosted Prism (or how to host Prism in the old projects)

Posted by igormoochnick on 09/02/2008

Recently I’m playing a lot with Prism and Unity and was looking for a way to gradually bring Prism to the existing projects. If you have an existing GUI project and you’d like to start using Prism (without rewriting everything from scratch) stay with me – I’m going to show a way that worked for me.

In order to work with Prism you need a “root” window, or, how they call it, a “shell” window. But what if you already have a window? There is a solution to that.

First of all create a WPF user control that will become a “shell” window to Prism. The XAML rules for this control is not different from any other Prism “shell” window. Just the root element of it is a “UserControl” and not “Window”. Let’s call it “ShellContainer”.

Then you need to attach this control to your existing application. But first you need to tell the Bootstrapper about it, but you don’t need to activate it:

   1: protected override DependencyObject CreateShell()
   2: {
   3:     return Container.Resolve<ShellContainer>();
   4: }

If your project is Windows Forms-based, you’ll need to drop on your form an ElementHost control. This control is located on the toolbox in the WPF Interoperability group. This will allow you to host a WPF User control on you non-WPF form.

   1: // Get the ShellContainer from IOC
   2: IUnityContainer container = new UnityContainer();
   3: var shellElement = container.Resolve<myLib.ShellContainer>();
   4:
   5: // Attach the WPF control to the host
   6: hostControl.Child = shellElement;

If you have a WPF form you can add this WPF User Control either manually.

   1: // Get ShellContainer from IOC
   2: IUnityContainer container = new UnityContainer();
   3: var shellElement = container.Resolve<myLib.ShellContainer>();
   4:
   5: // Add the ShellContainer UserControl to the main window
   6: this.mainGrid.Children.Add(shellElement);

From this point on you are on a home run – just follow the rest of the Prism guidelines.

TIP: I found it convenient to put the ShellContainer with the Bootstrapper in the same class library with the rest of the configuration logic. This allows a clean separation of the infrastructure from the rest of the logic of the Prism modules.

Posted in C#, IOC/DI, Prism, Tutorials, WPF | 1 Comment »

CodeCamp #10 [InTENsity] – see you at my presentations

Posted by igormoochnick on 08/28/2008

Note: Please forward this information to anyone who is interested.

The next CodeCamp #10 will be held in Waltham, MA on weekend September 20th and 21st.

For more information check Chris Bowen’s post.

Currently there are 33 submitted (and growing number of) presentations.

I’ll be presenting the “Toolbox for Agile Projects and Developers” and will be covering the topics like:

  • Agile Development Practices
  • TDD ( Test Driven Development)
  • Unit Testing
  • Mocking
  • IOC / DI (Inversion of Control / Dependency Injection)
  • ORM (Object Relational Mapping)
  • Code Coverage
  • Source Control
  • etc …

It appears that the amount of information is enormous, so I’ve decided to split these topics into 2 separate presentations.

See you all there …

Posted in Alt.Net, C#, Community, IOC/DI, Mocking, NHibernate, ORM, Presentations, Refactoring, Tutorials, Unit Testing | Leave a Comment »

Toolbox for Agile Projects and Developers @ Hartford, CT

Posted by igormoochnick on 08/18/2008

image

It was Hartford’s first CodeCamp. I think it was a great success – way to go, Hartford! More to come!

My presentation had a solid attendance and people stayed until the very end. At the end I’ve ran out of time and haven’t had a time to cover in details the Inversion-of-Control and Dependency Injection tools, but, I think, I’ll prepare a separate talk only on this topic – it’s huge and requires a lot of detailed attention.

 

As I’ve promised, I’m publishing the slide deck as well as all the code iterations for you to have some fun:

 

Iteration Introduced Link
Slide deck link
0 Base solution link
1 Unit testing link
2 Source Control & Continuous Integration (CI) link
3 Mocking, Refactoring link
4 IOC (Inversion-of-Control) & DI (Dependency Injection) link

 

Please feel free to contact me for more information or leave your comments on the blog. I’m available to present this topic or any other portion of it in more details on your site – let me know.

Posted in Alt.Net, C#, Community, IOC/DI, Mocking, Presentations, Refactoring, Thoughts, Tutorials, Unit Testing, Visual Studio | Leave a Comment »

Pheww… Two more will not tip the bucket.

Posted by igormoochnick on 07/28/2008

MCTS: ADO.Net

MCTS: ASP.Net

This is how it looks like on the paper:

current_certifications

Posted in C#, Community, Thoughts, Visual Studio | Leave a Comment »

WPF Skin Factory – or how to skin your application

Posted by igormoochnick on 06/19/2008

Here are a couple of very simple steps to follow to make your WPF application skin-friendly.

  1. Create an empty WPF Windows Application (or use or old one)
  2. Create a Skins folder and a subfolder for each separate skin (you’ll need it later if your skins become more complex)
  3. Add a Resource dictionary (Add –> New Item –> Resource Dictionary) into each skin folder.
    1. In this example we’ll create a Black skin with BlackResources.xaml and
    2. Green skin with GreenResources.xaml
  4. In the App.xaml add the following code in the <Application.Resources> section:
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <!-- Use the Black skin by default -->
            <ResourceDictionary Source="Skins\Black\BlackResources.xaml"/>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>

  5. Let’s start (for simplicity) with skinning of the main window background only.
  6. In each skin resource dictionary create a Brush resource:
  7. <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
     
        <!-- The Background Brush is used as the background for the Main Window -->
        <LinearGradientBrush x:Key="MainBackgroundBrush" EndPoint="0.5,1" StartPoint="0.5,0">
            <GradientStop Color="#FF2C952C" Offset="0"/>
            <GradientStop Color="#FFFFFFFF" Offset="1"/>
        </LinearGradientBrush>
     
    </ResourceDictionary>

  8. In the window’s XAML bind the window’s background brush to the skin dynamic resource by it’s name (note that we have to use DynamicResource, since we’re planning to change it while the application is still running to let the customers to change the skin):
  9. <Window x:Class="SkinFactory.Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Window1" Height="300" Width="300"
        Background="{DynamicResource MainBackgroundBrush}">
        
        <Grid>
            <Button Width="100" Height="100" Content="Toggle Skin" />
        </Grid>
        
    </Window>

  10. Let’s wire the “Toggle Skin” button with the functionality that will toggle between these two (Black and Green) skins:
  11.    1: private void ToggleSkin_Click(object sender, RoutedEventArgs e)
       2: {
       3:     var rd = new ResourceDictionary();
       4:  
       5:     string uriSkin;
       6:     if (_bIsBlackSkin)
       7:     {
       8:         uriSkin = @"Skins\Green\GreenResources.xaml";
       9:     }
      10:     else
      11:     {
      12:         uriSkin = @"Skins\Black\BlackResources.xaml";
      13:     }
      14:     _bIsBlackSkin = !_bIsBlackSkin;
      15:  
      16:     rd.MergedDictionaries.Add(Application.LoadComponent(new Uri(uriSkin, UriKind.Relative)) as ResourceDictionary);
      17:     Application.Current.Resources = rd;
      18: }

  12. Note: try to avoid hardcoding the resource dictionary path in the code. You can replace it either with a configuration file or with a simple file discovery.
  13. You have to make sure that the resource files will be located in the output folder. To do so you need:
    1. On the resource file properties set Build Action to Content
    2. Set the “Copy to Output directory” to “Copy if newer”
  14. Start the application.

You can take the sample source code here:

If you’ll toggle the button you’ll see the window background colors are changing.

skin_factory

Posted in C#, Tutorials, WPF | 3 Comments »

TechValley CodeCamp, thank you!

Posted by igormoochnick on 04/21/2008

This Saturday I was talking about Workflows at TechValley CodeCamp. The organizers (Andrew Badera and Griffith Townsend) did a terrific job making this happen. It’s their first CodeCamp in TechValley and I’d like to wish them more success in the future and that they’ll finally fix the CodeCamp registration site.  [ BTW: The food was way better than at Waltham CodeCamp :lol: ]

Useful links:

Presentation slides – CodeCamp_Workflows.ppsx

Presentation code – CodeCamp_Workflows.zip

Posted in C#, Presentations, Thoughts, Tutorials, Workflows | Leave a Comment »

70-504 – Congratulations to … me again ?!!!

Posted by igormoochnick on 04/19/2008

MCTS_WF

Just got a confirmation that I’ve passed the 70-504 TS: Workflow Foundation.

And, you can guess, I’m heading to a bar for some beers :-) – this becomes a habit and, at this rate, I can become an alcoholic too :lol:

Posted in C#, Presentations, Thoughts, Tutorials, Visual Studio, Workflows | 2 Comments »