Sunday, 25 January 2015

Windows Phone App Basics - 1

In this article we are going to see the basics of Windows Phone. Normally today Mobile phones are more widely used technology which is present in the  every person home. Mobile which means we can handle anything related to internet or computing process can be done with out the presence of computer. but all the things cant be done in the mobile, like we doing in computer. so now we start the basics of windows phone.

For create a successful app, First we have to understand the architect of a app.To develop a app, we need to knew that Windows Phone offers App in Two version 7 and 8,  now most of them stopped the developing the app for Version 7. It is recommended to develop a app for version 8, basically Both the versions are differs in many things.

Difference between the Windows Phone 7 and 8.
                                       

Windows Phone 7 Windows Phone 8
Screen size 800x480 800x480
1280x720
1280x768
orientation Portrait Portrait
Programming languages C#, Visual Basic, F# C#, Visual Basic
C++/CX
HTML5 + js  HTML5 + js 
APIs .NET .NET
XNA XNA 
DirectX (sans Direct2D)
WinRT 

Now there is a announcement soon about releasing Windows Phone 10.

Features in windows Phone 8.

1. Customize size of start screen
2. Location API
3. Maps
4. Wallet
5. Speech API
6. VoIP
7. Screen resolution

First we have to understand about the structure of Windows Phone Application.

Project structure:
********************
1. App.Xaml :  
             which is the entry point of application. contains global resources, events, Life cycle.
2. WMAppManifest.Xaml : 
              which contains application deployment information - capabilities, icon, Task etc.
3. MainPage.Xaml :  
              which is the Design of application.


Application Structure:
******************
Phone have two types of Views.
1. Panoramic 
2. Pivot

Panoramic:
**********
It is view which offers a unique way of views in Horizontal way, which extends beyond the windows phone screen.

Pivot:
********
It is a view which offers a view in Vertical Way, looks like Tab options.


Windows Phone have a system where we can place controls in the two way 
1. Application Bar
2. Menu Items

In Application bar we can add a 4 buttons up to as maximum, in Menu items we can add up to 5 menu items.



Above image explains the place of application bars and menu items in the windows phone.

Sensors:
**********
Windows Phone supports multiple sensors, which can determine the motion of a device and orientation.Compass, Accelerometer, Gryoscope

Launchers and Choosers of  windows phone
************************************
Launcher and chooser are used to access the common device functionality, which is used to access the services of phone to use for there need , but there is a small difference in that. Launchers doesnt return the data, choosers return the data to the invoker.

some of the Launchers & Choosers
*****************************
CameraCaptureTask
PhotoChooserTask
PhoneNumberChooserTask
EmailAddressChooserTask
BingMapsTask
PhoneCallTask
SearchTask
MediaPlayerLauncher
SavePhoneNumberTask
SaveEmailAddressTask
SmsComposeTask
WebBrowserTask
MapsTask
MapsDirectionTask
MapsDownloaderTask
ShareMediaTask

Now let we see some of them, First add the reference to the following namepsace.

 using Microsoft.Phone.Tasks;

Launch Media Player
*********************
Use the MediaPlayer use the MediaPlayer Launcher.


MediaPlayerLauncher mediaPlayer = new MediaPlayerLauncher();
mediaPlayer.Media = new Uri(@"http://s.com/test.mp4", UriKind.Absolute);
mediaPlayer.Show();



                                   


Launch  camera Capture:
*********************
For Take a Photo we have to use the CameraCaptureTask, to set the result of the data in the Image use the Callback completed event.


CameraCaptureTask cameraCapture = new CameraCaptureTask();
cameraCapture.Completed += new EventHandler<PhotoResult>(cameraCapture_Completed);
cameraCapture.Show();


                                           
             



        void cameraCapture_Completed(object sender, PhotoResult e)
        {
            if (e.TaskResult == TaskResult.OK)
            {              
                BitmapImage bmp = new BitmapImage();
                bmp.SetSource(e.ChosenPhoto);
                image1.Source = bmp; 
            }
        }


Chooser PhotoChooser
*******************
For browse a photo from the Phone and place inside the application we have to use the PhotoChooserTask and bind the result an image control.

PhotoChooserTask PhotoChoosernew PhotoChooserTask();
PhotoChooser.Completed += PhotoChooser_Completed;

PhotoChooser.Show();

                                                             


  void  PhotoChooser_Completed(object sender, PhotoResult e)
        {
            if (e.TaskResult == TaskResult.OK)
            {              
                BitmapImage bmp = new BitmapImage();
                bmp.SetSource(e.ChosenPhoto);
                image1.Source = bmp; 
            }
        }

After choosen the photo
                                             

From the above you can learn some of the basics things in the Windows Phone apps.



Sunday, 11 January 2015

Cookieless sessions in ASP.Net

In this article we are going to see the cookieless mode in Asp.net, normally each application is received in client browser by having a send and receive mode of Request and Response. For a every request from user, server maintain a session to identify whether same user is requesting the page or different user requesting the page in application. To identity the user maintain the session id for each user.

Normally the Session Id is stored in the Cookiess as in the name of ASP.NET_SessionId with a value of some random number. For the first request it will generate the number for the sessionid for the user, from the second request from the user it will maintain the same sessionId between the client and server. So to maintain the Session it is mandatory to enable the cookies in client side.

Sometimes there is a chance that the cookie's can be disabled in client Browser, Like block the application to set the data on client side , this means it is blocking the application to set the any data in client side. so now we cant able to store any cookies in client machine, so we cant able to handle the storing of session in the client machine.

We can understand this in a simple example.

Let we create a some Aspx pages from the Login screen, when the user entered the username and password save the credentials in the sessions, so we can access it any time in the application, so now each user have an session id based on that only, individual user information are segregated.

            Session["username"] = username.Text;
            Session["password"] = pwd.Text;

Later in some part of the code if we use to access the values from the session we can able to get it using the simple steps.

Session["username"].ToString();
Session["password"].ToString();

so now there is a scenario that the cookies in the client side is disabled, what will happen we cant able to get the values from Session instead we get a null value.

Below image shows the storing sessionid in cookie in the name of ASP.NET_SessionId



from the above we can see the variable name ASP.NET_SessionId

Now we going to see the state when the cookies disabled, we can do a simple  configuration steps make the session to maintain for user by specifying the web.config Cookieless="true" in sessionstate.

http://server/(session ID here)/sample.aspx

In Cookieless state session id is maintained in the Url of the application like below
session id : S(v4fzi2eitec02vnzmblvkwyu) in the url

http://localhost:17186/S(v4fzi2eitec02vnzmblvkwyu)/sample.aspx

 <sessionState cookieless="true" mode="InProc" customProvider="DefaultSessionProvider">

For every request the session id is maintained in the url with the unique value for the same user.

normally cookieless property have a six values

AutoDetect
UseDeviceProfile
UseCookies
UseUri
true
false

cookieless="AutoDetect" :
************************
 It will automatically detect the status of the cookies, whether cookies enabled in this browser or not. based on this it will decide to maintain the session value in url or in cookies.

For this it will use another cookie name and use some url concat with the application url to check whether cookies are enabled or not.

In the above u can see the cookie name AspxAutoDetectCookiesSupport in the browser, On the first load it will try to place the cookie in the browser in the name of AspxAutoDetectCookiesSupport and concat a query string in the url, to mention that this autodetect the cookies and tested by concat the following line. ?AspxAutoDetectCookieSupport=1 .with the url of application like this

http://localhost:176/(X(1)S(v4fzi2eitec02vnzmblvkwyu))/sample.aspx?AspxAutoDetectCookieSupport=1

The above url is the result url after check and redirect because , when it check for the cookie placed in the name AspxAutoDetectCookiesSupport  ,it doesnt find that so it place the session value in url

 and redirect to the same page again with result

Cookies not enabled resulted url :
http://localhost:17186/(X(1)S(v4fzi2eitec02vnzmblvkwyu))/sample.aspx?AspxAutoDetectCookieSupport=1

After a redirect to another page http://localhost:17186/(X(1)S(v4fzi2eitec02vnzmblvkwyu))/home.aspx

Cookies enabled resulted url :
http://localhost:17186/sample.aspx?AspxAutoDetectCookieSupport=1

After a redirect to another page
http://localhost:17186/home.aspx

cookieless="True":
********************
In this option we are forcing the application to use the cookieless mode and maintain the session in the Url.

cookiesless="false"
********************
In this options we are forcing the application to use the cookie based session mode.

remaining are the same one of the above we have mentioned.when we are using cookieless url based session, then we have to keep in mind that we have to maintain the session id to be passed in the url, otherwise for a new url it will generate a different session.

In Response.Redirect use the relative path to redirect with in the application, so now the session id automatically concat with the url like same below

Response.Redirect("~/home.aspx");

If you use the absolute path in the Response.Redirect then it will create a new one Response.Redirect("http;//localhost/home.aspx");

To avoid this use the uses the ApplyAppPathModifier method on the Response:

Response.ApplyAppPathModifier("/home.aspx");

Normally in this method stealing a session id possible, it gives a ways to session hijacking.

From the above information you can learn some of the information about session and cookieless sessions.



Saturday, 3 January 2015

Geometry present in the WPF

The Geometry classes is used to define a two dimensional shapes and paths.Geometry class is the base class for all Geometries. Geometry class are not derived from the UIElement.


The classes that are derived from the Geometry are 

Line Geometry           -  Draw a Line
Ellipse Geometry       -  Draw a Ellipse
Rectangle Geometry   - Draw a Rectangle
Path Geometry            - Draw a Geometry used by some given paths
Stream Geometry       - Light weight version of Geometry

And some of that are used to give collection of geometry in to one, which is derived from the the base class Geometry.

1. Geometry Group
2. Combined Geometry

normally we are using the Geometry to specify the shape of a diagram, to see this diagram in visual , we have to assign this Geometry in the Data of the Path ,Because the Geometry is not derived from the UIElement. Geometry is a definition for arbitrary shapes.

                        Path
                           |
                        Data  ------ Draw based on the arbitrary shapes given by the Geometry.

supply the geometry directly in to the Data property of the Path, if it is collection of geometry then supply it using the Geometry Group and combined Geometry, to form a single geometry finally.

Predefined geometry Classes:
***************************
Line Geometry: For line geometry we need to specify the startpoint and endpoint, if the startpoint is alone specified then it is referred as end point, from the initial position to draw a line.

<LineGeometry StartPoint="10,10" EndPoint="200,20"></LineGeometry>




Rectangle Geometry:Rectangle geometry is used to draw rectangle, specify the data in the rect.
<RectangleGeometry Rect="10,25,200,120"></RectangleGeometry> 



Ellipse Geometry: Ellipse Geometry is used to draw a ellipse we have to specify the center of the point. For specify the length and width of the ellipse using RadiusX, RadiusY




Arbitrary paths:
*****************
Path Geometry: Path geometry is used to draw a shape using the points or markup mention in the Figures. Every PathGeometry consists of Path Figures,Each Path Figure consists of Path segments.

If we use the element and attribute to render the shape, then it takes lot of code, to avoid this we have option called markup value for Figures.

<Path Fill="Pink" Stroke="SaddleBrown" StrokeThickness="5">
   <Path.Data>
       <PathGeometry Figures="M 10,20 L 20,40 40,50 60,20 80,40Z" FillRule="Nonzero" />
   </Path.Data>

 </Path>




Collections of Geometry:
**********************
Path.Data can only accepts a single Geometry, then how we can give the multiple geometry in the Data property to do this we have to specify the Geometry Group or combined Geometry elements.

GeometryGroup:


<Path.Data>
       <GeometryGroup>
            <LineGeometry StartPoint="10,10" EndPoint="200,20"></LineGeometry>
            <RectangleGeometry Rect="10,25,200,10"></RectangleGeometry>
        </GeometryGroup>

</Path.Data>





CombinedGeometry:
In combined Geometry we have a options called Geometry combined mode which changes the rendering of the View for the shape.

Following are the four options to specify the GeometryCombinedMode 
1. Union
2. Intersect
3. Exclude
4. Xor

GeometryCombineMode="Union"
****************************

<Path Fill="Pink" Stroke="SaddleBrown" StrokeThickness="5">
  <Path.Data>
      <CombinedGeometry GeometryCombineMode="Union">
         <CombinedGeometry.Geometry1>
           <RectangleGeometry Rect="20,25,100,100"></RectangleGeometry>
          </CombinedGeometry.Geometry1>                           
         <CombinedGeometry.Geometry2>
           <RectangleGeometry Rect="10,25,200,10"></RectangleGeometry>
         </CombinedGeometry.Geometry2>
       </CombinedGeometry>
    </Path.Data>
  </Path>


Output:
************



 GeometryCombineMode="Exclude"
********************************
<Path Fill="Pink" Stroke="SaddleBrown" StrokeThickness="5">
  <Path.Data>
      <CombinedGeometry GeometryCombineMode="Exclude">
         <CombinedGeometry.Geometry1>
           <RectangleGeometry Rect="20,25,100,100"></RectangleGeometry>
          </CombinedGeometry.Geometry1>                           
         <CombinedGeometry.Geometry2>
           <RectangleGeometry Rect="10,25,200,10"></RectangleGeometry>
         </CombinedGeometry.Geometry2>
       </CombinedGeometry>
    </Path.Data>
  </Path>

Output:
************



 GeometryCombineMode="Intersect"
************************************
<Path Fill="Pink" Stroke="SaddleBrown" StrokeThickness="5">
  <Path.Data>
      <CombinedGeometry GeometryCombineMode="Intersect">
         <CombinedGeometry.Geometry1>
           <RectangleGeometry Rect="20,25,100,100"></RectangleGeometry>
          </CombinedGeometry.Geometry1>                           
         <CombinedGeometry.Geometry2>
           <RectangleGeometry Rect="10,25,200,10"></RectangleGeometry>
         </CombinedGeometry.Geometry2>
       </CombinedGeometry>
    </Path.Data>
  </Path>

Output:
************



GeometryCombineMode="Xor"
*******************************
<Path Fill="Pink" Stroke="SaddleBrown" StrokeThickness="5">
  <Path.Data>
      <CombinedGeometry GeometryCombineMode="Xor">
         <CombinedGeometry.Geometry1>
           <RectangleGeometry Rect="20,25,100,100"></RectangleGeometry>
          </CombinedGeometry.Geometry1>                           
         <CombinedGeometry.Geometry2>
           <RectangleGeometry Rect="10,25,200,10"></RectangleGeometry>
         </CombinedGeometry.Geometry2>
       </CombinedGeometry>
    </Path.Data>
  </Path>




Output:
************



From the above details you can learn how to draw the geometry for a Path and different types of geometry present in the WPF