Monday 30 June 2014

Advantages of Windows Store Apps

Windows Store apps are often called WinRT apps and were formerly known as Metro apps. These are applications that take advantage of new WinRT APIs and can only be distributed in the Windows 8 store. Microsoft has enabled a number of features and streamlined some of its touch and sensor APIs into a robust set of device APIs under WinRT. WinRT-based apps are developed using Visual Studio* 2012 and can be written in C++, C#, or web technologies like HTML5, JavaScript*, and CSS3, then packaged and distributed to the Windows Store from the Visual Studio IDE. We will look at each aspect in detail below.


Robust and Modern UI and Navigation 
In Windows Store apps more focus is given to the content, so you should expect to focus on your apps’ content. You can envision these apps as websites, where you know what data to highlight and how to navigate them. Every app will open in a single window and the window covers the whole screen. However, inside your app you have multiple views and layouts depending on app needs.

Active Tiles
Apps in Windows 8 are tiled instead of icons. “So what?,” They are something similar to widgets for Windows 7. They can provide live data even if the app is not running on the foreground. They can refresh themselves to show the latest content either by push or pull  notification mechanisms

Search and share content across apps 
In the past, sharing data between two applications was difficult due to the heterogeneous nature of data formats and/or processing mechanisms. However, Windows Store apps can talk to each other quite easily using a concept called “App Contracts.” These contracts eliminate the hassles of understanding each application’s APIs and data formats. You don’t need to know anything about the target app other than its declared support for the target contract. App contracts allow you to search and share content between different apps. 

Multi- Touch
Windows 8 supports Multi-Touch user interface events. There are three primary touch events provided by Windows Runtime Platform API to respond to user inputs: pointer, gesture, and manipulation events. 
Pointer events are focused more on surface (screen) “contact” from input devices. These devices could be mouse, pen/stylus, single finger, or multi-finger. 

Gesture events are primarily focused on capturing single finger events such as tapping and press-and-hold. 

Manipulation events trigger when actions such as pinching/stretching, panning/scrolling, zooming and rotating happens. 

Windows 8 provides a robust set of APIs for various sensors. Some of them give access directly to physical sensors data (using hardware drivers) and some by using virtual sensors through a concept called Sensor Fusion. For example, the Accelerometer invokes Inclinometer by using angular position; Accelerometer + Gyro meter gives raise to Compass. 

Geolocation data in Windows 8 is provided through Wi-Fi* triangulation and IP address data to determine the location. This sensor is called Windows Location Provider. This is not a true hardware sensor. However, if your device has a physical GPS sensor, then this location provider will make use of it and provide more accurate location information based on GPS sensor. 

NFC (Near Field Communication)
NFC has been in the mobile world for quite some time now. With Windows 8, it is now available in laptops and Ultrabooks as well. These Windows 8 APIs can be used for desktop or Windows Store apps. 

Programming Language and Platform
You can develop Windows Store apps with your choice of language. Currently, Windows Store apps can be developed using Visual Basic, C#, C++ and JavaScript along with HTML5 and CSS3. Tons of documentation and Samples can be found on each of these languages on every Windows Store API. You would use Visual Studio 2012 IDE to develop, package, and deploy these apps to Windows Store. You can get a free Express version of the IDE for your development. You will have to register yourself as a developer on each machine before you start developing any apps.

Distribution, Sales, and Installation from Windows Store 
You can develop apps if you have a developer license, however, for distribution you need to follow either of these two routes.

1.    Go through all the Microsoft Store validation process and publish it to Windows store. Your published apps will then be available in Windows Store. Users can download and install your apps. The process of installing and upgrades are handled by Windows Store.
2.    Publish without going through Microsoft Store. Generally you use this model to distribute the app within your enterprise or within your known circles. This concept is called side loading.

Notes : Windows Store apps are not backward compatible. You cannot deploy Store apps on Windows 7 or Windows 2012 servers.
For More Info Visit Here

Use Multiple HUBs in SignalR

At first install SignalR for your application


Tools  > Library Package Manager > Package Manager Console

Write following command in that console and all SignalR files will be added in your project

pm> Install-Package Microsoft.AspNet.SignalR -pre

Now, Create HUB for SingalR communication with server.

public class ChatHub : Hub
        public void TestMethod()
            Clients.Caller.Temp("Chat HUB");

public class TestHUB : Hub
        public void TestMethod()
            Clients.Caller.Temp("test HUB");

We have taken 2 HUBs, You have to inherit HUB class to make your class work like a HUB.

Now, In HTML
Add Referance of signalR files like below

<script src="Scripts/jquery-1.6.4.js" type="text/javascript"></script>
<script src="Scripts/jquery.signalR-1.0.0.js" type="text/javascript"></script>
<script type="text/javascript" src='<%= ResolveClientUrl("~/signalr/hubs") %>'></script>

Finally do your stuff in Javascript to communicate with server. E.g.

  var myHub = $.connection.chatHub;
  var TestHUB = $.connection.testHUB;

  $(function () {          
           TestHUB.client.Temp = function (e) {
                alert(e);  //  "test HUB"
            myHub.client.Temp = function (e) {
                alert(e); // "Chat HUB"

      // Start the HUB
            $.connection.hub.start().done(function (e) {
                $('#dvMsg').html("Hub Started");

                // call Server Method
            .fail(function () {
                $('#dvMsg').html("Hub failed to connect");


When HUB get started then you can call the server methods and HUB class can call client methods. signalR use connection ID to identify client.


Thursday 26 June 2014

Catch HTML Page Events in Web Browser Control

Hello,Here is simple example to catch HTML document's control's events in Web browser control in winform.

1. Add browser control in your form. and register its CodumentCompleted  Event in constructor of form.2. Add Html document url in browser control.3. Find HTML control in Webbrowser control's event and register HTMl control's event.4.  Now you can catch HTML control's Event in your winform

// Initialize control and its event
public Form1()
            brwWebBrowser.DocumentCompleted += WebBrowser1_DocumentCompleted;    

private void WebBrowser1_DocumentCompleted(System.Object sender, System.Windows.Forms.WebBrowserDocumentCompletedEventArgs e)
               // Get HTML Element from HTML document
                HtmlElement Elem_btn = brwWebBrowser.Document.GetElementById("btnSave");
                if (Elem_btn != null)
                    Elem_btn.Click += Elem_btn_Click;

            catch (Exception ex)

 void Elem_btn_Click(object sender, HtmlElementEventArgs e)
            HtmlElement Elem = brwWebBrowser.Document.GetElementById("txt");

            if ((Elem != null))
                // Get Value from control's attribute
                string Temp_Val = Elem.GetAttribute("value");
                string strVal = Elem.GetAttribute("value");


<!DOCTYPE html>
<html xmlns="">

    <input type="text" id="txt" />
    <input type="button" id="btnSave" value="Save" />



Get days list by Month in SQL

DECLARE @year INT = 2014
DECLARE @Month INT = 1

;WITH mths AS(

SELECT 1 AS mth, DATENAME(WEEKDAY, cast(@year*100+@Month AS VARCHAR) + '01')  as monthname,CONVERT(DATETIME, cast(@year*100+@Month AS VARCHAR) + '01') AS mnthDT


SELECT mth+1 AS mth, DATENAME(WEEKDAY, cast(@year*100+@Month AS VARCHAR) + (CASE LEN(CAST((1+mth) as VARCHAR))  WHEN 1 THEN '0'+ CAST((1+mth) as VARCHAR) ELSE CAST((1+mth) as VARCHAR) END) ) AS monthname,
CONVERT(DATETIME,cast(@year*100+@Month  AS VARCHAR) + (CASE LEN(CAST((1+mth) as VARCHAR))  WHEN 1 THEN '0'+ CAST((1+mth) as VARCHAR) ELSE CAST((1+mth) as VARCHAR) END)) AS mnthDT FROM mths WHERE mnthDT < (SELECT DATEADD(d, -1, DATEADD(m, DATEDIFF(m, 0, mnthDT) + 1, 0)))



Wednesday 11 June 2014

Enable / Disable Asp.Net Validation

<asp:TextBox ID="txt1" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfv1" runat="server" ControlToValidate="txt1" ErrorMessage="*" ValidationGroup="1"></asp:RequiredFieldValidator>

<asp:TextBox ID="txt2" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfv2" runat="server" ControlToValidate="txt2" ErrorMessage="*" ValidationGroup="1"></asp:RequiredFieldValidator>

<asp:TextBox ID="txt3" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfv3" runat="server" ControlToValidate="txt3" ErrorMessage="*" ValidationGroup="1"></asp:RequiredFieldValidator>
            <br />

<asp:Button ID="btn" runat="server" CssClass="btn" Text="Save" ValidationGroup="1" OnClientClick="ValidatorEnable(rfv2, false);" />

Use this function to disable/Enable validation

ValidatorEnable(Id of Validator, Enable or Disable (true/false))

 ValidatorEnable(rfv2, false)