Friday, July 11, 2014

Free Source Version Control Facility from Microsoft for Small Teams

They have introduced Visual Studio Online with the capabilities of Team Foundation Server and additional cloud services, Where we can create our source code repository on the cloud and work in the same way as what we do now.

This online user plan includes everything from the hosted GIT repos, project tracking tools, and continuous integration tools. These user plans are described in
Visual Studio Online User Plans

The Visual Studio online basic is given free for up to five users. In this blog, I’ll elaborate on each and every step of how you can get your projects migrated to online TFS and work as a small team.

 ** You need Visual Studio 2013 Professional or Ultimate installation to use this feature.

Steps :
1. You must create a Live account, and verify the given email and phone number. Go to http://www.visualstudio.com/en-us/products/what-is-visual-studio-online-vs.aspx​ and logged in using your credentials.

 If all the validations and verification are completed, you must see your own name as below.

3. Then click on Create a free account now to create a Visual Studio online account.


4. Now you should be landed on this page.


5. Now type your project name, chose the version control system TFVC / Git, Process Control Template, and click on Create project. Read more on the SVC system supported by Microsoft Visual Studio : Use version control

6. Now you must see this page.


7. Now click on "Open with Visual Studio to connect". You might be asked for your credentials, please provide them. Then you will be connected to the online TFS account that you have just created.


8. Now you can add your solution to the online TFS.

Sunday, October 6, 2013

Type Sharing Issue with Multiple WCF Service References

I've encountered with a strange issue where the WCF test client could not generate the WSDL for the WCF service. No solutions have been available when googling with the error message we've got. So I split the service contract into three separate services depending on their functionality of them with the intention of adding them as 3 separate service references.

Then I've added the 3 service references to the front-end projects with the type-sharing option. But still had to re-factor a considerable number of lines of codes as the previous service client splits into 3 now. I've opened the files (except the xsds) generated by the service reference, then found this interesting behaviour in a file called "Reference.svcmap"


I've listed all my other mex endpoints as below and incremented the souceId, then I've regenerated the service reference.



Bingo..... Now using the ServiceAClient object I could invoke all the service methods available in ServiceB, ServiceC and ServiceD.

Wednesday, August 21, 2013

Fix : The "FindRibbons" task could not be loaded VSTO


I've recently encountered with an error in a VSTO development (an Excel Add-in) under Vs 2010 environment.   The error message I got when compiling the solution is as follows.

"The "FindRibbons" task could not be loaded from the assembly, Microsoft.VisualStudio.Tools.Office.BuildTasks, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a. Confirm that the <UsingTask> declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask"

I have installed the VS 2012 together with VS2010 recently and I did the following process to get this resolved.

1. Open "Microsoft.VisualStudio.Tools.Office.targets" File from below Location
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\OfficeTools
2.  Press Ctrl+H and replace all 10.0.0.0 text with 11.0.0.0
3. Save the file to the desktop with the same & extension.
4. Delete the original file
5. Cut and paste the saved file to the above location.
6. Close and restart VS 2010 (If Opened)

Saturday, April 13, 2013

WCF (Windows Communication Foundation) First Step

Prerequisite : Microsoft Visual Studio 2010 (.net 4.0)

The purpose of this WCF article is to give a basic idea about how to create a simple WCF service.


To begin this tutorial, First, open up Visual Studio 2010 and create an empty Visual Studio solution. In My case, "WCF All in One Place".

Then add a WCF Service Library Project as Follows.





Now, There should be 3 files appear in the WCFServiceLibray project. The basic purpose of those files is as follows.
- Service.cs : Contains the service implement ion code
- IService.cs : Contains the service contract/ Service Interface class
- App.config : Contains the service configurations


You should be able to build and run the solution. If you do, the WCF Test Client should automatically host your WCF service and show what are the methods in your service and will give you a chance to play with those methods. If you have noticed your service metadata is exposed via the following mex end point.

 "http://localhost:8732/Design_Time_Addresses/WcfServiceLibrary/Service1/mex" 



"The metadata that the mex endpoint exposes describes the service, the various operations it has, parameters the operations require, and the return types. In other words, the metadata exposes the contract. With this information, the client can create a proxy to interact with the service. Clients use the mex endpoint to access the metadata."

Let's customize the project as we need. I suggest you to detached (decouple) the Service from its service contact, since I'm going to deploy this solution in several ways.


So first add another class library project to the solution called "ServiceContract" and delete the automatically create class1.cs.


Then add a new Interface class called "IServiceContratc.cs" to the ServiceContract project and place the following code inside the interface class.



Then delete the IService1.cs and Service1.cs classes from the WcfServiceLibrary project and add a new class called SampleService.cs to the same project and place the following code.

 
 Change the following attributes in the app.config file located in the WcfServiceLibrary project as follows.

- service name="WcfServiceLibrary.SampleService"
- baseAddress = "http://localhost:8732/WcfServiceLibrary/SampleService/"
- contract="ServiceContract.IServiceContract"



Debug the WcfServiceLibrary project, and the WCF Test Client window should list your new methods. Click on the .. method and enter the two values for the required two parameters.



and click on the invoke button. A pop-up dialogue box may appear and click OK after clicking on the tick (Don't show this....).  Then observe the Response.

Click on the XML tab located in the bottom center of the window and observe the request message sent by the WCF Test Client.





Password is in the plain sight !!. This is why you are required to think of securing your WCF services. 

Thursday, March 28, 2013

Do the Right Thing in Behind the Splash Screen

Prerequisite : Microsoft Visual Studio, Microsoft SQL Server (Any version)

I have seen many novice developers/students using a splash screen in their applications to give a good impression to the user. They usually place a timer and inside the timer tick event update the progress bar value and the text of a label. When the cap value reached 100 they close the splash screen and prompt the Login screen (if you have). 

The real purpose of the Splash screen is clearly described in this Wikipedia article. 

This is how I've done it differently for a 3-layer application, where the presentation layer and the business logic layer are connected through a web/WCF service. If you are unfamiliar with the web services or WCF, consider the serviceClient class as a regular class that calls some functions in the business logic layer.

Steps :
1. Add a new Windows Form (Splash.cs) to the project.
2. Set the following Properties of the Splash screen to the given values.
    -   ControlBox : false
    -   FormBoarderStyle : none
    -   ShowIcon : false
    -   ShowInTaskBar : false
    -   StartPosition : CenterScreen
    -   Size : 450,250 (Change according to the size of your image, If you have prepared any)

   If you provide a background image, set these values
    -   BackroundImage : brows and set your image
    -   BackgroundImageLayout : Zoom
    -   Transparency Key : set the colour that should be displayed as transparent.
3. Place some labels add a progress bar to the Splash form, and give whatever text is appropriate.
    Set the label BackColor to transparent, otherwise, labels will be displayed with a gray colour.


 4. Define a boolean variable inside the Splash.cs as follows. 
 public bool IsValidationCompleted  
 {  
     get;  
     private set;  
 } 

 5. Now set splash screen as the first screen by placing the following code in the Program.cs file.
 Application.EnableVisualStyles();  
   Application.SetCompatibleTextRenderingDefault(false);  
      //---- Added Code ----------------  
   Splash splash = new Splash();  
   Application.Run(splash);  

6. Clear the text of the status message and initialize IsValidationCompleted to false inside the Splash screen window constructor,
  public Splash()  
  {  
     InitializeComponent();  
     IsValidationCompleted = false;  
     lbStatusMessage.Text = "";  
  }  

7. Add a new class named serviceClient and implement your initial validation logic, basic data download, or what ever process that should be executed before the main UI is shown to the user. For the demonstration purpose, I will create some dummy methods as follows.

 public bool PingToService()  
 {  
   try  
   {  
      /* Create a client object and call a method in the service   
       * and return the value. You may implement the Ping method in   
       * the web/wcf service as follows.  
       * public bool Ping()  
       * {  
       *  return true;  
       * }  
       */  
      //------ For the Demonstration Purpose ------------------------  
        System.Threading.Thread.Sleep(1000);  
        return true;  
        //-------------------------------------------------------------    
   }  
   catch   
   {  
      /* If you want to handle the exception exactly one   
       * at a time implement as follows   
       * try{ .... }  
       * catch (ServiceException ex)  
       * {}  
       * catch (XYZException ex)  
       * {}  
       * catch(Exception ex)  
       * {}  
      */  
      return false;  
   }  
 }

 public bool CheckDataBaseConnectivity()  
 {  
    //------ For the Demonstration Purpose ------------------------  
     System.Threading.Thread.Sleep(1000);  
     return true;  
    //-------------------------------------------------------------    
 }

 public bool DownloadSomeData()  
 {  
     //----- For the Demonstration Purpose ------------------------  
     System.Threading.Thread.Sleep(1000);  
     return true;  
     //------------------------------------------------------------    
 }   
  
8. Now implement a method called InitialValidation inside the Splash.cs file and call the validation methods implemented in the above step as follows
 private void InitialValidation()  
 {  
   try  
   {  
      // Invoke an UI update through a delegate  
       this.Invoke((MethodInvoker)delegate  
       {  
          lbStatusMessage.Text = " Connecting ....";  
          progressBar1.Value = 10;  
       });  
       ServiceClient oServiceClient = new ServiceClient();  
       if (oServiceClient.PingToService())  
       {  
          this.Invoke((MethodInvoker)delegate  
          {   
             lbStatusMessage.Text = "Service Connectivity is OK ....";  
             progressBar1.Value = 20;  
          });  
          if (oServiceClient.CheckDataBaseConnectivity())  
          {  
             this.Invoke((MethodInvoker)delegate  
             {  
                 lbStatusMessage.Text = "DB Connectivity is OK ...";  
                 progressBar1.Value = 50;  
             });  
          }   
          if (oServiceClient.DownloadSomeData())  
          {  
             this.Invoke((MethodInvoker)delegate  
             {  
                lbStatusMessage.Text = "Configuration has applied ....";  
                progressBar1.Value = 70;  
             });  
          }  
          this.Invoke((MethodInvoker)delegate  
          {  
              lbStatusMessage.Text = "Finalizing ....";  
              progressBar1.Value = 90;  
          });  
          //---------- For the Demonstration Purpose ------------------------  
          System.Threading.Thread.Sleep(1000);  
          //----------------------------------------------------------------  
         this.Invoke((MethodInvoker)delegate  
         {  
           lbStatusMessage.Text = "";  
           progressBar1.Value = 100;  
         });  
      }  
      IsValidationCompleted = true;  
      // Invoke UI update  
      this.Invoke((MethodInvoker)delegate  
      {  
         this.Dispose();  
      });  
    }  
    catch (Exception Ex)  
    {  
      MessageBox.Show(Ex.Message, "Stop", MessageBoxButtons.OK, MessageBoxIcon.Error);  
      IsValidationCompleted = false;  
      Application.Exit();  
     }
 }

Make sure you assign the correct value for the variable IsValidationCompleted at the end of this method.

9. Then go to the design view of the Splash screen window, and double-click on an empty area to generate the Load event. Place the following code inside the form load event.
 System.Threading.Thread thread = new System.Threading.Thread(  
                      () => InitialValidation());  
 thread.Start();  

10. Now, if you run your project, and must see the splash screen with an incrementally increasing progress bar. Once it reaches 100 splash screen will be closed and the focus to the Visual Studio, Now you can prompt the login screen, to do that place the following code inside the program.cs file and call your login screen 
 if (frmSplash.IsValidationCompleted)  
  {  
   //-------- Show the Login Screen -------------  
  }