Sunday, April 8, 2012

My Second Android App on Google Play


My Second Android App on Google Play

Dear Friends, Today i have published the upgraded version of my vtracker android app on google play market. The main feature of this app is.

Download form Google Play Here


This is another version of v-tracke android based apps which enable you to locate your vehicle just by sending a SMS text.

You can use this app to locate your android device just by sending a SMS to this device from any other phone/device. In return the app will return you the location of your android device.

To locate your vehicle send a SMS with key word (in earlier version it is hard coded as .findmycar) with combination of your password. The SMS should be in form of <<your Password>>.findlocation. Please note command name to locate your phone is dotfindlocation(.findlocation). The application will automatically detect your current GPS location.

If GPS is not enabled the application will use Cell Tower Triangular calculation to detect your approximate location.

In replay you will receive the text containing your current longitude and Latitude information in Google map formatted like

http://maps.google.com/?q=xxx.xxxx,yy.yyyy

You can use this text to locate your vehicle/phone.

This is is initial release as this is my second app to android development.  The next version will have some more features. Please keep vesting.

Thanks
Bhargava Pandey
http://wwww.bhargavapandey.com
email: bhargava.pandey@gmail.com

Wednesday, December 21, 2011

.NET Web Application with SQL Azure

.NET Web Application with SQL Azure

Developing for Windows Azure is easy using Visual Studio 2010 and the free Windows Azure SDK for .NET. If you do not already have Visual Studio 2010, the SDK will automatically install Visual Web Developer 2010 Express, so you can start developing for Windows Azure entirely for free. This guide assumes you have no prior experience using Windows Azure. On completing this guide, you will have an application that uses multiple Windows Azure resources up and running in the cloud.
You will learn:
  • How to enable your machine for Windows Azure development with a single download and install
  • How to create and modify a Visual Studio ASP.NET MVC 3 project so it can run on Windows Azure
  • How to use a SQL Azure database to store data in the cloud
  • How to deploy and update your application to Windows Azure
You will build a to-do list web application that runs in Windows Azure and stores its data in SQL Azure. The application is hosted in an instance of a Web role that, when running in the cloud, is itself hosted in a dedicated virtual machine (VM). A screenshot of the completed application is below:

SETTING UP THE DEVELOPMENT ENVIRONMENT

Before you can begin developing your Windows Azure application, you need to get the tools and set-up your development environment.
  1. To install the Windows Azure SDK for .NET, click the button below:
    When prompted to run or save WindowsAzureSDKForNet.exe, click Run:
  2. Click on Install in the installer window and proceed with the installation:
  3. Once the installation is complete, you will have everything necessary to start developing. The SDK includes tools that let you easily develop Windows Azure applications in Visual Studio. If you do not have Visual Studio installed, it also installs the free Visual Web Developer Express.

CREATING AN ASP.NET MVC 3 APPLICATION

CREATING THE PROJECT

  1. Use administrator privileges launch either Microsoft Visual Studio 2010 or Microsoft Visual Web Developer Express 2010. To launch Visual Studio with administrator privileges, right-click Microsoft Visual Studio 2010 (or Microsoft Visual Web Developer Express 2010) and then click Run as administrator. The Windows Azure compute emulator, discussed later in this guide, requires that Visual Studio be launched with administrator privileges.
    In Visual Studio, on the File menu, click New, and then click Project.
  2. From Installed Templates, under Visual C#, click Web and then click ASP.NET MVC 3 Web Application.
  3. Name the application ToDoListApp and click OK:
  4. In the New ASP.NET MVC 3 Project dialog, select the Internet Application template and the Razor view engine. Click OK.

MODIFY UI TEXT WITHIN YOUR APPLICATION

  1. In Solution Explorer, under Views\Shared open the _Layout.cshtml file.
  2. Within the body tag, find the title of the page enclosed in h1 tags. Change the title text from My MVC Application to To Do List. Here is where you type this in:

RUN YOUR APPLICATION LOCALLY

Run the application to verify that it works.
  1. Within Visual Studio, press F5.
  2. Your application should appear running in a browser:

MAKING YOUR APPLICATION READY TO DEPLOY TO WINDOWS AZURE

Now, you will prepare your application to run in a Windows Azure hosted service. Your application needs to include a Windows Azure deployment project before it can be deployed to the cloud. The deployment project contains configuration information that is needed to properly run your application in the cloud.
  1. To make your app deployable to the cloud, right click on the ToDoListApp project in Solution Explorer and click Add Windows Azure Deployment Project:
  2. To enable the built-in membership provider you must use the ASP.NET Universal Providers. This provider enables the account management capabilities in your application. In Solution Explorer, right click on ToDoListApp and then click Manage NuGet Packages... (or Add Library Package Reference... in older versions of NuGet):
  3. In the ToDoListApp – Manage NuGet Packages dialog, in the top right corner within the Search Online field, write "universal providers":
  4. Select the "ASP.NET Universal Providers" and click Install. Close the ToDoListApp – Manage NuGet Packages dialog after installation is complete.
  5. In Solution Explorer, open the Web.config file in the root directory of the ToDoListApp project.
  6. Under the <configuration> / <connectionStrings> section replace theDefaultConnection connection stringas shown below.
        <add name="DefaultConnection" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=aspnet_ToDoListApp;Integrated Security=True;MultipleActiveResultSets=True"
          providerName="System.Data.SqlClient" />
  7. To test your application, press F5.
  8. This will start the Windows Azure compute emulator. The compute emulator uses the local computer to emulate your application running in Windows Azure. You can confirm the emulator has started by looking at the system tray:
  9. A browser will still display your application running locally, and it will look and function the same way it did when you ran it earlier as a regular ASP.NET MVC 3 application.

DEPLOYING YOUR APPLICATION TO WINDOWS AZURE

You can deploy your application to Windows Azure either through the portal or directly from within Visual Studio. This guide shows you how to deploy your application from within Visual Studio.
In order to deploy your application to Windows Azure, you need an account. If you do not have one you can create a free trial account. Once you are logged in with your account, you can download a Windows Azure publishing profile. The publishing profile will authorize your machine to publish packages to Windows Azure using Visual Studio.

CREATING A WINDOWS AZURE ACCOUNT

  1. Open a web browser, and browse to http://www.windowsazure.com.
    To get started with a free account, click free trial in the upper right corner and follow the steps.
  2. Your account is now created. You are ready to deploy your application to Windows Azure!

PUBLISHING THE APPLICATION

  1. Right click on the ToDoListApp project in Solution Explorer and click Publish to Windows Azure.
  2. The first time you publish, you will first have to download credentials via the provided link.
    1. Click Sign in to download credentials:
    2. Sign-in using your Live ID:
    3. Save the publish profile file to a location on your hard drive where you can retrieve it:
    4. Within the publish dialog, click on Import Profile:
    5. Browse for and select the file that you just downloaded, then click Next.
    6. Pick the Windows Azure subscription you would like to publish to:
    7. If your subscription doesn’t already contain any hosted services, you will be asked to create one. The hosted service acts as a container for your application within your Windows Azure subscription. Enter a name that identifies your application and choose the region for which the application should be optimized. (You can expect faster loading times for users accessing it from this region.)
    8. Select the hosted service you would like to publish your application to. Keep the defaults as shown below for the remaining settings. Click Next:
    9. On the last page, click Publish to start the deployment process:
      This will take approximately 5-7 minutes. Since this is the first time you are publishing, Windows Azure provisions a virtual machine (VM), performs security hardening, creates a Web role on the VM to host your application, deploys your code to that Web role, and finally configures the load balancer and networking so you application is available to the public.
    10. While publishing is in progress you will be able to monitor the activity in the Windows Azure Activity Log window, which is typically docked to the bottom of Visual Studio or Visual Web Developer:
    11. When deployment is complete, you can view your website by clicking the Website URL link in the monitoring window:

ADDING SQL DATABASE SUPPORT

The Windows Azure platform offers two primary storage options:
  • Windows Azure Storage Services provide non-relational data storage in the form of blobs and tables. It is fault-tolerant, highly available, and will scale automatically to provide practically unlimited storage.
  • SQL Azure provides a cloud-based relational database service that is built on SQL Server technologies. It is also fault-tolerant and highly available. It is designed so the tools and applications that work with SQL Server also work with SQL Azure. A SQL Azure database can be up to 100GB in size, and you can create any number of databases.
This guide uses a SQL Azure database to store data, however the application could also be constructed using Windows Azure Storage. For more information about SQL Azure and Windows Azure Storage, see Data Storage Offerings on the Windows Azure Platform.

CREATING CLASSES FOR THE DATA MODEL

You will use the Entity Framework Code First feature to create and set-up a database schema for your application. Code First lets you write standard classes that the Entity Framework will use to create your database and tables automatically.
  1. In Solution Explorer, right click on Models and click Add and then Class.
  2. In the Add New Item dialog, in the Name field type ToDoModels.cs, and then click Add.
  3. Replace the contents of the ToDoModels.cs file with the code below. This code defines the structure of your ToDoItem class, which will be mapped to a database table. It also creates a database context class that will allow you to perform operations on the ToDoItem class.
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Data.Entity;
    namespace ToDoListLib.Models
    {
        public class ToDoItem
        {
            public int ToDoItemId { get; set; }
            public string Name { get; set; }
            public bool IsComplete { get; set; }
        }
    
        public class ToDoDb : DbContext
        {
            public DbSet<ToDoItem> ToDoItemEntries { get; set; }
        }
    }
    That’s all the Entity Framework needs to create your database and a table called ToDoItem.
  4. In Solution Explorer, right click on ToDoListApp and select Build to build your project.

CREATING SCAFFOLDING TO CREATE/READ/UDPDATE/DELETE TO DO ITEMS

ASP.NET MVC makes it easy to build an application that performs the main database access operations. The scaffolding feature will generate code that uses the model and data context you created earlier to perform CRUD (create, read, update, delete) actions.
  1. In Solution Explorer, right-click on Controllers and click Add and then click Controller.
  2. In the Add Controller window, enter HomeController as your Controller name, and select the Controller with read/write actions and views, using Entity Framework template. Scaffolding will also write code that uses a model and a data context. Select ToDoItem as your model class and ToDoDb as your data context class, as shown in the screenshot below:
  3. Click Add.
  4. You will see a message indicating that HomeController.cs already exists. Select both the Overwrite HomeController.cs and Overwrite associated views checkboxes and click OK.
  5. This will create a controller and views for each of the four main database operations (create, read, update, delete) for ToDoItem objects.
  6. In Solution Explorer, open the Web.config file in the root directory of the ToDoListApp project.
  7. Under the <configuration> / <connectionStrings> section add the ToDoDb connection string as shown below.
        <add name="ToDoDb" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;Initial Catalog=ToDoDb;User Instance=true;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />
  8. To test your application at this stage, press F5 in Visual Studio to run the application in the compute emulator. When your application first runs, a database will be created in your local SQL Server Express instance, which was installed as part of the Windows Azure SDK.
  9. Clicking the Create New link on the web page that is displayed in the browser will create new entries in the database.

SET-UP SQL AZURE

  1. The next step is to configure your application to store data in the cloud. First, you must create a SQL Azure server. Login to the Windows Azure Platform Management Portal, http://windows.azure.com, and click on Database:
  2. On the top of the left pane, click the subscription associated with your SQL Azure account:
  3. From the top menu, click Create.
  4. In Create Server, select the region for which you want database access to be optimized, and then click Next:
    IMPORTANT: Pick the same region that you choose earlier when deploying your application. This will give you the best performance.
  5. Choose an administrator username and password.
    Note: These are the credentials for your administrative account and give you full access to all databases on the server.
  6. Click Next.
  7. The next dialog will prompt you to create firewall rules for the server. Firewall rules identify specific IP addresses or ranges of IP addresses that are able to communicate directly with your SQL Azure server. Add a new rule by clicking Add. In the Add Firewall Rule dialog, enter the values shown in the table below. This will enable your local application to communicate with SQL Azure, but will block other IP addresses from communicating directly with your server.
    NameValue
    Rule namelocal development environment
    IP range start(Type the IP address of the computer you are using. The IP address is listed at the bottom of the dialog.)
    IP range end(Type the IP address of the computer you are using.)
  8. Click OK.
  9. Select the Allow other Windows Azure services to access this server check box, Note: SQL Azure has two types of access control: firewall and SQL authentication. You must configure the SQL Azure firewall settings to allow connections from your computer(s).
  10. Important: In addition to configuring the SQL Azure server-side firewall, you must also configure your client-side environment to allow outbound TCP connections over TCP port 1433. For more information, see Security Guidelines for SQL Azure.
  11. Click Finish.
  12. You will now see an entry for your new server in the left menu. The fully qualified domain name of the server uses the following format:
    <ServerName>.database.windows.net
    Where <ServerName> identifies the server. Write down the server name; you will need it later in the tutorial.
You can use either SQL Server Management Studio or Windows Azure Platform Management Portal to manage your SQL Azure database. To connect to SQL Azure from SQL Server Management Studio, you must provide the fully qualified domain name of the server: <ServerName>.database.windows.net.

SET-UP YOUR APPLICATION TO USE THE DATABASE

Often times, you want to use a different database locally that you use in production. Visual Studio makes this easy. You can have your Web.config vary between your development machine and cloud deployment by creating a transform in Web.Release.config. In this guide, you will edit the Web.Release.config to use SQL Azure instead of your local SQL Server when deployed to the cloud:
  1. Back in Visual Studio or Visual Web Developer, in Solution Explorer, open the Web.Release.config file located under Web.config in the root directory of the ToDoListApp project.
  2. Under the <configuration> / <connectionStrings> section replace all items as shown below. Substitute the <serverName> placeholder with the name of the server you created. For <user> and <password>, enter the administrative user and password you created earlier.
    <connectionStrings>
      <add name="ToDoDb" connectionString="data source=<serverName>.database.windows.net;Initial Catalog=ToDoDb;User ID=<user>@<serverName>;Password=<password>;Encrypt=true;Trusted_Connection=false;MultipleActiveResultSets=True" providerName="System.Data.SqlClient"/>
      <add name="DefaultConnection" connectionString="data source=<serverName>.database.windows.net;Initial Catalog=ToDoDb;User ID=<user>@<serverName>;Password=<password>;Encrypt=true;Trusted_Connection=false;MultipleActiveResultSets=True" providerName="System.Data.SqlClient"/>
    </connectionStrings>
    Note: The administrative user has access to all the databases on the server. To create a SQL Azure user with more restricted pemissions, follow the steps in Adding Users to Your SQL Azure Database. Then, modify the above connection string to use the newly created user and password instead of the administrative user and password.

RUN YOUR APPLICATION IN THE CLOUD

Now, for the final step, you will test your app both living in the Windows Azure cloud and accessing the SQL Azure cloud database. You will redeploy your application to Windows Azure:
  1. Confirm that the correct publishing profile is still selected and click Publish. In particular, ensure that the Build Configuration is set to Release, so you pick up the SQL Azure connection string from the Web.Release.Config that you edited earlier.
    Clicking Publish will perform an in-place update, so this will complete faster than your initial deployment.
  2. When deployment completes, open the URL of your app from the deployment monitor
  3. Check that your application functions as expected:
  4. The application is now fully running in the cloud. It uses SQL Azure to store its data, and it is running on one small web role instance. One of the benefits the cloud provides over running this application under standard web hosting is the ability to dynamically scale the number of instances as demand changes. This scaling will require no changes to the application itself. Moreover, updates can be deployed without service interruptions as Azure ensures there is always a role instance handling user requests while another one is being updated.

STOP AND DELETE YOUR APPLICATION

After deploying your application, you may want to disable it so you can use build and deploy other applications within the free 750 hours/month (31 days/month) of server time.
Windows Azure bills web role instances per hour of server time consumed. Server time is consumed once your application is deployed, even if the instances are not running and are in the stopped state. A free account includes 750 hours/month (31 days/month) of dedicated virtual machine server time for hosting these web role instances.
The following steps show you how to stop and delete your application.
  1. Login to the Windows Azure Platform Management Portal, http://windows.azure.com, and click on Hosted Sevices, Storage Accounts & CDN, then Hosted Services:
  2. Click on Stop to temporarily suspend your application. You will be able to start it again just by clicking on Start. Click on Delete to completely remove your application from Windows Azure with no ability to restore it.
http://www.mkwebcy.com

Saturday, October 15, 2011

How to Resolve The name 'xxx' does not exist in the current context Issue

Yesterday I was working on a page which contains Ajax Toolkit Tab Container, and there were some control on the other tab.
   
When i build my ASP.NET (C#) project in Visual Studio 2010, i started getting this error message

"The name 'XXXX' does not exist in the current context"

Displayed and the problem is in my .aspx page. Most surprisingly I can access the control in Intellisens but while compile time it throw error. My code definitely has no problem.

After debugging and searching for a while, i noticed that problem is cause by the back up copy of the same aspx file (copy of xxxx.aspx) that i forget to exclude from the project.

The problem solved after i exclude the file from the project.

Sunday, September 25, 2011

Itrarting Bewteen Date Range using Foreach C#.

There are some situation when we want to itrate trough a range of date.
Hear is ample how you can itrates through the date range using foreach in C#

for itrating you will need to first create a function which will convert the date range in inumaration formate so that you can itrates.

For this i have created the follwing function.

public IEnumerable<DateTime> EachDay(DateTime from, DateTime thru)
{
for (var day = from.Date; day.Date <= thru.Date; day = day.AddDays(1)) yield return day;
}


Now you can use the code like this.

foreach (DateTime day in EachDay(strartDate, EndDate)
{
 //Do something

}
 

Tuesday, September 20, 2011

Hosting WCF Service in IIS

Create a WCF service


1. Create a blank solution and add a WCF Service Library project to it. For the purpose of this post, I am going to create a simple GreetingService that has a method Greet. This method accepts a single parameter name and returns a string “Hello “ appended to name


2. The following is the code for the GreetingService WCF service. We define a service contract, mark the operations in that contract that are going to be exposed to the external world and then implement the service.


using System;
using System.Collections.Generic;
using System.Text;
using System.ServiceModel;

namespace Wcf.Samples.ServiceLibrary
{
    [ServiceContract()]
    public interface IGreeting
     {
        [OperationContract()]
        string Greet(string name);
     }
}


GreetingService.cs


using System;
using System.Collections.Generic;
using System.Text;


namespace Wcf.Samples.ServiceLibrary
{
   public class GreetingService : IGreeting
    {
      #region IGreeting Members
      public string Greet(string name)
       {
         return "Hello - " + name;
       }
#endregion
}
}


3. Now that you added the service contract and its implementation (the GreetingService), build the project.




Host the service in IIS


1. Now we create a Web site that will host the WCF service that we created in the previous section. For this, right-click the solution in the solution explorer and from the context menu, select Add -> New Web site ->WCF Service as shown in the following figure.




2. This will create a WCF Service Web site into your solution along with the standard folders that get created for a Web site project (App_Code, App_Data etc). A new type of file called Service.svc will be generated and placed into the root of the Web site project, along with the corresponding code-behind file (Service.cs). The Service.cs is provided to implement a WCF service, which then can be referred in the Service.svc file. Since we already have created the WCF service in a separate assembly, we will refer to it in the Service.svc. As such we don’t need Service.cs and hence, it can be deleted.


3. Open Service.svc file and modify the single line in it like this:


4. In the above statement we point to the fully-qualified class name that implements the service that we want to host in IIS.


5. Add the reference of the Wcf.Samples.ServiceLibrary project to the web-site project and build the web-site.


6. This completes the creation of WCF service. Now, in order to let the service communicate with the external world, we need to define the communication behavior of the service. For defining this behavior, we will use the Service Configuration tool that comes along with Visual Studio 2005.


7. From the main menu of Visual Studio 2005, select Tools -> WCF Service Configuration Editor. The WCF Configuration Editor window will open up. Select File -> Open -> Config File… from the main menu. Browse and select the Web.config file of the WCF web-site.


8. Once selected, the screen will be displayed as follows. The Web.config already has the configuration for the default service MyService under the Services node in the left-panel. Select this service and deleted it. We are going to create a new configuration for our service.




9. Right-click the Services node and select “New service” from the context menu. A service with service type NewServiceType will be created. On the right-panel, select the property “Name” and click the ellipsis. Service Type Browser will open up. Browse the bin folder of the web-site and locate the service assembly Wcf.Samples.ServiceLibrary and double-click it. The Service Type Browser dialog now will list the service “Wcf.Samples.ServiceLibrary.GreetingService” service. Select this service and click Open. This will set the service-type that we are going to configure.


10. Now for the above service, we first need to specify the end-point. Right-click Endpoints node in the left-panel of the WCF Service Configuration Editor and select “New Endpoint”. This will create a default end-point with its properties being displayed in the right-panel.


11. Set the following properties:


Name
defaultEp


Address
http://localhost:28053/GreetingService/Service.svc


· Here 28053 is the port-number where the local web-server is running. You need to check your port number and enter it here appropriately.


Binding
basicHttpBinding


Contract
Wcf.Samples.ServiceLibrary.IGreeting


· You can click the ellipses to open the Contract Type Browser and select the appropriate assembly and contract from the bin directory of the web-site.


12. This sets the basic communication for our service. In order to enable the service for metadata exchange (thereby allowing us the browse its wsdl), we need to set the metadata exchange properties for the service. To do this, expand the Advanced node in the left-panel, right-click Service Behaviors and select “New Service Behavior Configuration”. This will add a new Behavior Configuration by the default name NewBehavior. Behavior is a collection of attributes (here, service attributes) that can be set and applied to the service together. Right now, we are going to define a behavior that allows the metadata exchange on the service. Set the Name property of the new behavior configuration to mexBehavior.


13. In the “Behavior element extension position” (lower part of the right-panel), click “Add” button. This opens up a dialog “Adding Behavior Element Extension Sections”. Select serviceMetadata from the list and click “Add” on the dialog. This adds the extension serviceMetadata to the grid in the right-panel. Double-click the extension to open up its property-page. Set the property HttpGetEnabled to true.







14. Now that we have defined the behavior separately, we need to associate the behavior with our service. To do this, select the Wcf.Samples.ServiceLibrary.GreetingService under the Services node in the left panel. The right-panel will display its properties. Select the BehaviorConfiguration property, and select “mexBehavior” from the drop-down.


15. This sets the service configuration and allows the service to communicate with the external world. Save the configuration by selecting the menu File->Save. Close the WCF Service Configuration Editor.


16. Test that the service is hosted by running the WCF Web Site application. The following screen should be displayed.