.NET Xpress

Microsoft Technology Xplicit

Standalone WPF Application VS XBAP

Posted by anandkumar2004 on May 13, 2009

Here are few important differences between standalone and XBAP

Standalone WPF Application

XAML Browser Applications

Installed via MSI or ClickOnce Not installed on the client’s computer
Available like other windows program in Start Menu & Add/Remove program Do not appear in the in Start Menu or Add/Remove Programs
Run in Full Trust unless modified by Administrator Are automatically deployed via ClickOnce
Runs in its own standard OS window Run in Internet Zone (sandbox)
Can be use as occasionally   connected application Security exception thrown if attempt made to access unauthorized areas
Auto update available throw ClickOnce deployment process Hosted in browser process , Only run in IE browsers and User must be online to use application

Posted in WPF | Leave a Comment »

How to build XBAP

Posted by anandkumar2004 on May 11, 2009

Windows Presentation Foundation is a new programming model to build rich windows smart client, media and document application . WPF support both Windows and Web based application .In this demo I am trying to build a web based  WPF application called  XBAP ( pronounced “ex-bap”) .XBAP stands for  XAML browser application the most interesting point about XBAP is the application is hosted inside your web browser ,XBAP is the aggregation of  web based and windows application . Initially I too got confuse between a standalone WPF application and a XBAP .In my next session I will cover the major differences between this two programming model  , in this demo I am trying to navigate between two XBAP pages programmatically   , I am using the NavigationService class to switch between two pages , here is the code snippet

 

 

        private void button1_Click(object sender, RoutedEventArgs e)

        {

            Uri uri = new Uri(“Page2.xaml”, UriKind.Relative);

            this.NavigationService.Navigate(uri);

        }

  

The output of the application is a exe  , yes compiler generates exe output .Now lets see what are the files are in debug/release folder

 NavigationDemo

 

  • An executable file. This contains the compiled code and has an .exe extension.
  • An application manifest. This contains metadata associated with the application and has a .manifest extension.
  • A deployment manifest. This file contains the information that ClickOnce uses to deploy the application and has an .xbap extension.

 To access the application  you need to You publish XBAPs to a Web server (Microsoft Internet Information Services (IIS) or later). You do not need to install .NET Framework on the Web server, but you do need to register the WPF Multipurpose Internet Mail Extensions (MIME) types and file extensions such as

Manifest application/manifest
.xaml application/xaml+xml
.application application/x-ms-application
.xbap application/x-ms-xbap
.deploy application/octet-stream
.xps application/vnd.ms-xpsdocument

 To prepare your XBAP for deployment, copy the .exe and the associated manifests to your Web server. Create a hyperlink on a Web page to navigate to the deployment manifest. When the user clicks the link and navigates to the .xbap file, ClickOnce automatically handles the mechanics of downloading and launching the application.

Click Here for sample code

 

Cheers

Anand

Posted in WPF | Leave a Comment »

WPF WPF WPF WPF…..

Posted by anandkumar2004 on May 8, 2009

Recently I have gone throw the WPF technology, I will share few of my experience on this .Keep watching my new posts on WPF….
 
 
Cheers
Anand

Posted in WPF | Leave a Comment »

SQLCE Demo

Posted by anandkumar2004 on May 7, 2009

There are several ways to setup SQLCE database in mobile device. I usually prefer SQL replication in this demo I am trying to create database and tables programmatically so when you launch the application it will create the database if it is not present in the device.

In order to make it more clear I have created a class called  SqlCeHelper. Primary objective of this class is
Create Database if not available
Establish connection on request
Insert data into table
Perform queries
Close database on request

I have also created two windows forms to add and view data. This is a very simple application, hope this will help to those who are trying to know how to work with SQLCE database

Click Here to down the source code

Cheers
Anand

Posted in Win Mobile | Leave a Comment »

Prevent Idle State

Posted by anandkumar2004 on May 6, 2009

Recently a mobile developer posted me a query how to prevent system idle time?  Indeed in some scenario you must consider this lets say stops the device from sleeping when its playing a video without manually adjust the power setting because most of the end users do not understand properly the power saver concept in win CE   . The point to be notice is  idle time is  60 seconds that means we need to awake the processer before elapse of 60 seconds .Here is the sample code  to Implement this I am using the PowerManagement class of OpenNETCF library

using System;
using OpenNETCF.WindowsCE;

public class SampleClass
{
//Timer thread
private static System.Threading.Timer preventIdleThread;

public SampleClass()
{
//call the delegate elapse of 59 seconds
preventIdleThread = new System.Threading.Timer(new TimerCallback(Reactivate),
null, 0, 59 * 1000);
}

private static void Reactivate()
{
//Powermanagement class of OpenNetCF
PowerManagement.ResetSystemIdleTimer();

}
}

HTH

Cheers
Anand

Posted in Win Mobile | Leave a Comment »

Excel and Exponential Value

Posted by anandkumar2004 on April 6, 2009

Recently I was working on MS Excel automation project, during development I was facing some serious problems like getting exponential value while reading a cell data such as 0.23485759606896689878794. Now the question is how to convert exponential value to the actual value?  The answer is

 

decimal originalVal = decimal.Parse(cellArray[2].Tostring(), System.Globalization.NumberStyles.Any);

 

Please be aware this kind of small issues can be a nightmare for you and your project.

 

 

Cheers

Anand

Posted in .NET | Leave a Comment »

April Fool on Computer Virus

Posted by anandkumar2004 on April 1, 2009

Yes its not a  JOKE..  its a high alert warning to all computer users

Symptoms of  Virus

  • It burrows deep into the code of a computer and blocks security updates which could remove it.
  • When activated, it can take control of a large number of PCs around the world.  This forms what is called a Botnet, in which PCs are controlled remotely to spread the virus or launch spam e-mail or even attack and shut down websites.

Microsoft has posted a $250,000 reward for the capture of the virus author so far no success .

 

 

Cheers

Anand

Posted in General | Leave a Comment »

Kill if Running

Posted by anandkumar2004 on March 31, 2009

Recently I got a query from a reader to know how to kill an application if it is running  in Windows Mobile 5.0, this is a very interesting question .To do this you need to capture the snapshot of current processes by calling  CreateToolhelp32Snapshot  API and then get each process name from the process list finally  kill the process if its matches with the application name passed as parameter

 

using System;

using System.Runtime.InteropServices;

using System.Collections.Generic;

 

 

public class Class1

{

    [DllImport("toolhelp.dll")]

    public static extern IntPtr CreateToolhelp32Snapshot(uint flags, uint processid);

    [DllImport("coredll.dll")]

    private static extern IntPtr OpenProcess(int flags, bool fInherit, int PID);

    private const int PROCESS_TERMINATE = 1;

    [DllImport("coredll.dll")]

    private static extern bool TerminateProcess(IntPtr hProcess, uint ExitCode);

    [DllImport("CoreDll.dll")]

    private extern static Int32 CloseHandle(IntPtr hProcess);

    private const int TH32CS_SNAPPROCESS = 0×00000002;

    private const int PROCESS_TERMINATE = 1;

    private const int INVALID_HANDLE_VALUE = -1;

    public Class1()

    {

    }

    public void ShutDownApp(string appName)

    {

 

        //get the sanpshot of the processlist

        IntPtr handle = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);

        if ((int)handle > 0)

        {

 

            byte[] data, tempBuffer;

            data = new byte[564];

            tempBuffer = BitConverter.GetBytes(564);

            Buffer.BlockCopy(tempBuffer, 0, data, 0, tempBuffer.Length);

            //initialize a empty buffer

            byte[] buffer = data;

            //get the snapshot of the process

            int sanpshotStatus = Process32First(handle, buffer);

            while (sanpshotStatus == 1)

            {

                //Retrive ProcessID,ProcessName

                uint ProcessID = BitConverter.ToUInt32(buffer, 8);

                //extract the process name

                string ProcessName = Encoding.Unicode.GetString(buffer, 36, 256);

                ProcessName = ProcessName.Substring(0, ProcessName.IndexOf());

                if (ProcessName == appName) //if application is running then kill the app

                {

                    IntPtr termProcess;

                    termProcess = OpenProcess(PROCESS_TERMINATE, false, (int)ProcessID);

                    if (termProcess != (IntPtr)INVALID_HANDLE_VALUE)

                    {

                        TerminateProcess(termProcess, 0);

                        CloseHandle(termProcess);

                        break;

                    }

                }

                sanpshotStatus = Process32Next(handle, buffer);

            }

            //Close handle

            CloseToolhelp32Snapshot(handle);

        }

    }

}

 

Cheers

Anand

Posted in Win Mobile | Leave a Comment »

Try without Installation

Posted by anandkumar2004 on March 13, 2009

Do you want to experience Microsoft’s latest product without installation and free of cost  .Here is the best option  MSDN Virtual Lab its highly recommend to all developer to leverage it .

MSDN Virtual Labs! Quickly evaluate or learn how to build great applications for Windows and the Web through a series of guided, hands-on labs which can be completed in 90 minutes or less. The best part is, the MSDN Virtual Labs don’t require any installation and are available to you immediately for FREE.

 

http://msdn.microsoft.com/en-us/virtuallabs/default.aspx

 

Enjoy ….

 

Cheers

Anand

Posted in General | Leave a Comment »

Activate VPN

Posted by anandkumar2004 on March 12, 2009

Most of the corporate mobile devices ship with VPN to connect to  corporate network  to access Email or shared folder  or even your application may need to call intranet web service .In this example I am demonstrating how to activate VPN programmatically user  ConnectionManager  class of openNetCF.Net library

 

using System;
using System.Collections.Generic;
using System.Text;
using OpenNETCF.Net;

namespace Demo
{
    public class SampleNetworkManager
    {
        private ConnectionManager conManager;
        public SampleNetworkManager()
        {
            conManager = new OpenNETCF.Net.ConnectionManager();
        }

        public void ConnectNetwork()
        {

            foreach (DestinationInfo destInfo in conManager.EnumDestinations())
            {
               //VPN name
                if (destInfo.Description == “My Work Network”)
                {

                    //wait till connection establish
                    conManager.Connect(destInfo.Guid, true, ConnectionMode.Synchronous);

                    if (conManager.Status == 1)
                    {
                        MessageBox.Show(“Connected”);
                        break;
                    }
                }
            }
        }
        public void DisconnectNetwork()
        {
            
                 conManager.RequestDisconnect();

            
        }

    }

}

Cheers

Anand

 

Posted in Win Mobile | Leave a Comment »