Friday, October 31, 2014

Programming Stuff: SOME NEW TECHNOLOGIES FOR VISUAL STUDIO

Programming Stuff: SOME NEW TECHNOLOGIES FOR VISUAL STUDIO: NCrunch for VS This software provides an inbuilt ADDON for VS for automatically executing your defined unit tests on your code. How i...

SOME NEW TECHNOLOGIES FOR VISUAL STUDIO

  1. NCrunch for VS
This software provides an inbuilt ADDON for VS for automatically executing your defined unit tests on your code.
How it works:
  • You create your program
  • You create your unit tests
  • Ncrunch automatically detects unit test methods and keeps executing in memory
  • As soon as you modify something in your program and while you are writing the buggy code, ncrunch on that line itself will give you a prompt that, with this code change this unit test method is breaking
  1. Microsoft Pex
This is more intelligent version of ncrunch you can say. This is more interesting too J. It’s a VS add on kind of software from Microsoft that once you install, gives you an option in your code with any method as “create PEX possible unit tests for this method”. Once selected, intelligently it would create n number of all posibble unit test methods for your code with all possible combinations of parameters that you have defined for your method. Actually you can play around without installing anything on service URL they have given.
How it works:
  • You create your program
  • You right click on method name and select “create pex unit test methods”
  • Once selected, it will create all possible combination of unit test methods for your method with all possible variations and will also execute and will let you know the results

Friday, October 17, 2014

Introducing WCF :- Next-generation connected systems on Windows

Outline 

  1.  Connected systems overview 
  2.  The move towards "services" 
  3.  Service-orientation 
  4.  Introduction to WCF 
  5.  WCF programming model basics 
  6.  Common WCF questions 

1.What is a connected system? 

  • An application that is distributed across multiple computer nodes  

Building connected systems on Windows 

  • MS has shipped many communication frameworks over the years  

2.The move towards "services" 

  • Demand for technology freedom and interoperability is common now  Services expose units of functionality via messaging Interop achieved via standard protocols and message formats

Service design philosophies 


SOAP + WS-* services 

  •  The industry has defined a complete protocol stack for services Typically implemented with RPC-based toolkits, feels a lot like COM+.

RESTful services 

  •  RESTful services typically embrace HTTP, the "Web" transport 
    •  Services are modeled as "resources" with unique identifiers (URI's) 
    •  HTTP defines a uniform service contract: GET, POST, PUT, DELETE (CRUD)
    •  Resources can be represented as XML, RSS, JSON, etc
  •  HTTP provides numerous features for security and scalability
    •  A successful design pattern used throughout the Web today 

3. Service-orientation 

  • Service-orientation is a design paradigm for separation of concerns 
  •  Focused on autonomy, explicit boundaries, contracts & policies 
  •  Design principles help achieve a Service Oriented Architecture (SOA) 
  •  SOA says nothing about technology – room for both SOAP & REST 

      The ideal communication framework 


4. Introducing WCF 

       WCF is the new unified "communications" framework for Windows


Services and endpoints 


  • With WCF, you write services that expose endpoints to the world
    • Service implementation defines business logic
    • Endpoints define the communication options
    • Services can expose multiple endpoints for consumers

What is an endpoint? 

  •  Endpoints tell WCF how to build the runtime communication channels

Consuming services with WCF 


  • Clients need to know several things in order to consume a service 
    • Where to send the message (address) 
    • How to send the message, such as what transport/protocols to use (binding) 
    • What the messages should contain (contract)

WCF clients 

  • With WCF, you consume services via channels based on endpoints 
    •  Clients retrieve endpoint definitions from service metadata 

Summary 


  • WCF provides a unified model with flexibility in communications 
    •  Your choice of architecture, transport, message format, protocols, etc 
    •  Replaces the need for the preceding Windows frameworks 
  •  There are several good reasons to begin moving towards WCF 
    •  It provides a simpler model that will increase productivity/reach 
    •  Microsoft has positioned it as the "DCOM" of the next decade 

Basic about Fiddler

Overview

  1. HTTP 
  2. Requests 
  3. Responses 
  4. What is Fiddler? 
  5. Why Use Fiddler? 
  6. How does Fiddler Work? 
  7. Where to get Fiddler? 
  8. Basic Usage  

  1. HTTP 

  • HyperText Transfer Protocol
  • Protocol defined in RFC 2068 (Http 1.1), January 1997 
  • http://www.ietf.org/rfc/rfc2068.txt 
  • Request/response paradigm 
  • Header and body  

2.HTTP Request 

3.HTTP Response  

4.What is Fiddler? 

  •  Freeware HTTP tracing tool 
  •  Shows complete request and response (not packets)  
  •  Created by Eric Lawrence (@ericlaw) 
    •  Microsoft, Program Manager on IE team
    •  First version 0.8, October 2003
  • C# 

5. Why Use Fiddler? 

  • Troubleshoot problems 
  • Performance evaluation
  • Fiddle with requests and responses 
  • Security testing 
  • Visualize page requests (timeline) 
  • Periodic site reviews 

6.How Does Fiddler Work? 

  •  Proxy 
  •  Local 
  •  Remote (smart phones, tablets, non-Windows platforms) 
  •  Adjusts browser’s proxy configuration to intercept traffic 
    •  Many of the latest browsers work with localhost and 127.0.0.1 (automatically) 
    •  ipv4.fiddler or ipv6.fiddler 
  •  NOT a wire/network monitor! 

7.Where to Get Fiddler? 

  • http://fiddler2.com 

8.Basic Fiddler Usage 

  •  Capture traffic 
  •  Review “sessions” 
  •  Statistics 
    • Number of Requests 
    • Bytes received 
    • Chart  
  • Timeline 
  • Inspectors 
  • Save as .saz file  

Summary 

  •  HTTP protocol used to communicate between web browsers and web servers 
  •  Fiddler is a great freeware tool that shows web requests and responses 
  •  Fiddler acts as a proxy for browsers and even other platforms and devices 
  •  Reviewed basic common usage of Fiddler 

Coalescing operator - ??

How Coalescing operator works?
Note 
Here I am just going to show how coalescing operator replace ternary operator. i.e not comparing ternary operator with coalescing operator.
Ternary Operator
Syntax
?
1
Type variable = booleanCondition ? exp1 : exp2;

Ternary operator assign exp1 to variable if the booleanCondition return true or exp2 if booleanCondition return false.
Consider Case were I am coding with the nullable type using ternary opertor.

Example
?
1
2
3
Nullable<int> a = null;
Nullable<int> b = 10;
int c = a==null ? b.Value : a;

Coalescing operator
Coalescing operator work some what similar to ternary operator but it works only with the Nullable types only. so its sort hand operator to deal with Nullable types only.

Syntax
?
1
Type variable = nullalbeTypeVariable1.Value ?? nullableTypeVariable2.Value;

Operator its check value of nullalbeTypeVariable1 if its as real value rater tan null it assin value to variable else assign value of nullableTypeVariable2.

Example
?
1
2
3
Nullable<int> a = null;
Nullable<int> b = 10;
int c = a ?? b.Value;

Summary
Coalescing operator deals with Nullable type and its sort for long ternary operator expression.

Store data locally with HTML5 Web Storage

Now new version of HTML5 having number of new API one of the is Storage API, which allow you to store data of use locally. Here in following post I am going to describe Storage API.

Cookies vs. Storage
In previous version of HTML allows to store data locally with the help of Cookies but the
  •  issue with the cookies is its not allow to big object and which can be easily done. Storage allows 5M (most browsers) or 10M (IE) of memory at disposal. 
  • Another problem is cookies get sent to server with each HTTP request which in term increases traffic.
Storage 
Now lets start using the store in application 
?
1
2
3
4
5
6
7
8
if(typeof(Storage)!=="undefined")
{
  alert("storage is supported and you can store data in it");
}
else
{
 alert("Get new version of browser or use browser which support storage");
}
So here in above as you can see, first line of code check weather browser supports/have Storage object. It's good to check because most of the older browser is not supporting and as its new feature its mostly supported in new browsers.

After doing check for Storage support decide either you want to store data for given session only or want to store data which available even after session is over and when user come back. 
So there are two type of object which is explained below 
  • sessionStorage is used to store within the browser tab or window session. so it allows to store data in a single web page session.
  • localStorage is used to kept even between browser sessions. so it allows to access data after the browser is closed and reopened again, and also instantly between tabs and windows.
Note : Storage data created by one browser is not avaible in other browser. for example created in IE is not available in FireFox.

Following is the way you can use the localStorage and sessionStorage in your application. 
?
1
//sessionStorage
?
1
2
3
4
5
6
7
8
9
10
11
12
//set and get object
sessionStorage.setItem('myKey', 'myValue');
var myVar = sessionStorage.getItem('myKey');
//another way to set and get
sessionStorage.myKey = 'myValue';
var myVar = sessionStorage.myKey;
 
//remove item
sessionStorage.removeItem('myKey');
 
//clear storage
sessionStorage.clear();
?
1
2
3
4
5
6
7
8
9
10
11
12
13
//localStorage
//set and get object
localStorage.setItem('myKey', 'myValue');
var myVar = localStorage.getItem('myKey');
//another way to set and get
localStorage.myKey = 'myValue';
var myVar = localStorage.myKey;
 
//remove item
localStorage.removeItem('myKey');
 
//clear storage
localStorage.clear();
as in the above code both of the object support same set of methods to store and retrieve data.
  • setItem - allows to set value. 
  • getItem - allows to get value.
  • removeItem - allows to remove object from storage. Note: if it used like removeItem(), it removes all stored object , so be careful when removing -to remove specific object use removeItem("myKey"). 
  • clear - clear storage i.e. clear all stored data.
and as you can see storage store data in key value pair.

Conclusion
Web Storage simplify the storing of object in client and also have advantage over cookies, but its always good to not store sensitive information in the client side storage as storage is not provide that much security.

Thanks for reading and do post comment if you like it or something is missing or wrong.