Google Anlatics

Tuesday, August 23, 2011

Google Map API V3 with ASP .Net


Google Map API V3 with ASP .Net 4.0

This is the link for Google Map API Version 3


Google Geocoding API no longer requires a Maps API key!
Google Maps API Premier customers must additionally sign their URLs using a new cryptographic key. See the Premier documentation for more information.

For premium usage
is the link and by filing above link can buy the

Google API Map premium account.

Usage Limits

Use of the Google Geo coding API is subject to a query limit of 2,500 geo location requests per day. (User of Google Maps API Premier may perform up to 100,000 requests per day.) This limit is enforced to prevent abuse and/or repurposing of the Geo coding API, and this limit may be changed in the future without notice. Additionally, we enforce a request rate limit to prevent abuse of the service. If you exceed the 24-hour limit or otherwise abuse the service, the Geo coding API may stop working for you temporarily. If you continue to exceed this limit, your access to the Geo coding API may be blocked.
Note: the Geocoding API may only be used in conjunction with a Google map; geocoding results without displaying them on a map is prohibited. For complete details on allowed usage, consult the Maps API Terms of Service License Restrictions.

For XML version normal user

For XML version Premier user

gme-myclientID is Google premier ID

If the client id is not valid then following error message will displayed
Unable to authenticate the supplied URL. Please check your client and signature parameters.

Some coding examples with C# .NET

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Net;
using System.Xml;

namespace WebApp
{
    public class GeoCode
    {
        protected const string googleClientID = "googleClientID";
        public interface IGeoLocation
        {
            double latitude { get; set; }
            double longitude { get; set; }
            string geocodeurl { get; set; }
        }

        public struct GeoLocation : IGeoLocation
        {
            private double _latitude;
            private double _longitude;
            private string _geocodeurl;

            public GeoLocation(double latitude, double longitude, string geocodeurl)
            {
                _latitude = latitude;
                _longitude = longitude;
                _geocodeurl = geocodeurl;
            }

            public double latitude
            {
                get { return _latitude; }
                set { _latitude = value; }
            }

            public double longitude
            {
                get { return _longitude; }
                set { _longitude = value; }
            }

            public string geocodeurl
            {
                get { return _geocodeurl; }
                set { _geocodeurl = value; }
            }
        }
      
 public class GeoCode
 {
    const string _googleUri = "http://maps.googleapis.com/maps/api/geocode/xml?address=";

    private static Uri GetGeoCodeURI(string address)
    {
        address = HttpUtility.UrlEncode(address);
   

        string _googleJsapiUrl = System.Configuration.ConfigurationManager.AppSettings[googleClientID];

        string uri = String.Format("{0}{1}&client={2}&sensor=false", _googleUri, address, _googleJsapiUrl);               

                return new Uri(uri);
            }

            public static GeoLocation GetCoordinates(string address)
            {
                WebClient wc = new WebClient();
                Uri uri = GetGeoCodeURI(address);

                try
                {
                    string geoCodeInfo = wc.DownloadString(uri);
                    XmlDocument xmlDoc = new XmlDocument();
                    xmlDoc.LoadXml(geoCodeInfo);

                    string status = xmlDoc.DocumentElement.SelectSingleNode("status").InnerText;
                    double geolat = 0.0;
                    double geolong = 0.0;
                    XmlNodeList nodeCol = xmlDoc.DocumentElement.SelectNodes("result");
                    foreach (XmlNode node in nodeCol)
                    {
                        geolat = Convert.ToDouble(node.SelectSingleNode("geometry/location/lat").InnerText, System.Globalization.CultureInfo.InvariantCulture);
                        geolong = Convert.ToDouble(node.SelectSingleNode("geometry/location/lng").InnerText, System.Globalization.CultureInfo.InvariantCulture);
                    }
                    return new GeoLocation(geolat, geolong, uri.ToString());
                }
                catch
                {
                    return new GeoLocation(0.0, 0.0, "http://");
                }
            }
        }
    }
}

Creating object of Geo Code and passing address attribute will generate out form XML Version.

GeoCode.GeoLocation geolocation = GeoCode.GeoCode.GetCoordinates("1128 West Hastings Street " + ","+ "Vancouver" + "," + " British" + "," + "Columbia" + "canada");

JSon also support like XML for premier user.

Sunday, August 14, 2011

Google Maps v3 API and SSIS

This is the latest V3 API Version

http://code.google.com/apis/maps/documentation/geocoding/

And this is the link for Geocode Locations Using Google Maps v3 API and SSIS

http://www.sqlmusings.com/2011/03/25/geocode-locations-using-google-maps-v3-api-and-ssis/

To insert for SQL table these are more detail about SSIS script component
These are more step than above mention link step.pls refer above link and if need more details see below additional steps.

Create Data Flow













Go to the Data Flow and added ADO or OLDEDB Data Source and after that add Script Component


















ADO .NET link connection and Output Table can be set like below Image.






Edit the Script









Set the Inputs and Outputs


Set the Connection 




Little overview of the Main Code


















Like below code can be use stored procedure OR SQL Query for insert to table.
This code cannot be debugging and using Windows message can be set message to see the output and windows.Forms namespace has to import.
To use Google map refer above given link it is very easy to use Goggle Map with SSIS.

These are status code will be provide by the Google and can be customize code using it

Status Codes

The "status" field within the Geocoding response object contains the status of the request, and may contain debugging information to help you track down why Geocoding is not working. The "status" field may contain the following values:
• "OK" indicates that no errors occurred; the address was successfully parsed and at least one geocode was returned.
• "ZERO_RESULTS" indicates that the geocode was successful but returned no results. This may occur if the geocode was passed a non-existent address or a latlng in a remote location.
• "OVER_QUERY_LIMIT" indicates that you are over your quota.
• "REQUEST_DENIED" indicates that your request was denied, generally because of lack of a sensor parameter.
• "INVALID_REQUEST" generally indicates that the query (address or latlng) is missing.


Pls take to consider below Usage Limits othe wise you account will block by the google if you try use it for more data.


Usage Limits


Use of the Google Geocoding API is subject to a query limit of 2,500 geolocation requests per day. (User of Google Maps API Premier may perform up to 100,000 requests per day.) This limit is enforced to prevent abuse and/or repurposing of the Geocoding API, and this limit may be changed in the future without notice. Additionally, we enforce a request rate limit to prevent abuse of the service. If you exceed the 24-hour limit or otherwise abuse the service, the Geocoding API may stop working for you temporarily. If you continue to exceed this limit, your access to the Geocoding API may be blocked.

SSIS simple way to start

SSIS – simple way to start
These are the link you can find for easy way to start SSIS.
http://msdn.microsoft.com/en-us/library/ms170419.aspx
http://www.accelebrate.com/sql_training/ssis_2008_tutorial.htm
http://www.mssqltips.com/tutorial.asp?tutorial=200

How to Run a Package SQL Server 2008 R2

To run an Integration Services package, you can use one of the following tools:
• The dtexec command prompt utility (dtexec.exe).
• The Execute Package Utility (dtexecui.exe).
• A SQL Server Agent job.

http://msdn.microsoft.com/en-us/library/ms138023.aspx

Running an SSIS Package Programmatically on the Local Computer SQL Server 2008 R2
With only a few lines of managed code and the correct prerequisites on the local computer, you can run a package from a custom application. The custom application can be a Windows Forms application, a console application, an ASP.NET Web form or Web service, or a Windows service.

http://msdn.microsoft.com/en-us/library/ms136090.aspx#Y1954

I think this code will be useful
This can be run creating console application.

using System;
using Microsoft.SqlServer.Dts.Runtime;

namespace RunFromClientAppCS
{
  class Program
  {
    static void Main(string[] args)
    {
      string pkgLocation;
      Package pkg;
      Application app;
      DTSExecResult pkgResults; 

      pkgLocation =

        @"C:\Program Files\Microsoft SQL Server\100\Samples\Integration Services" +

        @"\Package Samples\CalculatedColumns Sample\CalculatedColumns\CalculatedColumns.dtsx";

      app = new Application();
      pkg = app.LoadPackage(pkgLocation, null);
      pkgResults = pkg.Execute();

      Console.WriteLine(pkgResults.ToString());
      Console.ReadKey();
    }
  }
}

Sunday, August 7, 2011

Import Email contact in asp.net 4

Import Email contact in asp.net 4

Previously there was third party tool called Octazen now it’s gone.

The best way for contact importing is API usage form email service providers.

These are the API links

There is c# .net code in below link and I have download and tested code in below link.
You can download the code form below link

But using AOL: http://dev.aol.com/article/2007/integrating_openauth_into_aspnet link I have tried to imports the contact but I couldn’t import the contact form above mention API.

There are only limited support from AOL API it is saying contact API is coming soon 2008 onwards.
It’s seems to be it will not be available.


AOL developer support is very less. ( Egg: http://dev.aol.com/user/83)

Although this very difficult find code from internet there are plenty of third party tool available for this those are paid one.

.Net 4 Smart Thread Pool With Windows Service

Smart tread pool is third part tool and hear is link for more information about it.

This is best alternative for customize tread which is better than .net tread pool.

http://www.codeproject.com/KB/threads/smartthreadpool.aspx

Keep Concurrent Threads in App Config.

<appSettings>

<add key="ConcurrentThreads" value="5"/>

appSettings>

Import Following Namespace including Imports Amib. Threading which is for Smart Thread Pool.

Imports System.Diagnostics

Imports System.Threading

Imports Amib.Threading

Imports System.ServiceProcess

Imports Microsoft.Practices.Unity

This is Little Sample Code


Partial Public Class Service

Inherits ServiceBase

Private _threadPool As SmartThreadPool

Private _trace As New TraceSource("Import")


Sub New()

InitializeComponent()

End Sub



Private Shared _allowLoop As Boolean = True

Public Shared Sub Main(ByVal args As String())

Dim service As New TestService()

If args.Contains("console") OrElse Environment.UserInteractive Then

' disallow loops if passed a param

If args.Length > 1 Then

_allowLoop = False

End If

service.OnStart(args)

service.OnStop()

Else

ServiceBase.Run(service)

End If

End Sub


Protected Overrides Sub OnStart(ByVal args() As String)

_trace.TraceInformation("Starting Test...")


With Service.ServiceLocator.Container

.RegisterType(Of Service.IService,

End With

AddHandler Test.Test, AddressOf OnTest


_threadPool = New SmartThreadPool

_threadPool.MaxThreads=System.Configuration.ConfigurationManager.AppSettings("ConcurrentThreads")

_threadPool.MinThreads = 1

_threadPool.Start()



_trace.TraceInformation("ThreadPool started with maxthreads = {0}.", _threadPool.MaxThreads)



Dim worker As New Thread(AddressOf DoWork)

worker.Start()

End Sub

Private Sub DoWork()

_trace.TraceInformation("Worker started.")

 While _allowLoop ' by default, this is an infinite loop

Try

Console.WriteLine("Loop!")

'Check if we need to run some import

Dim ofrImpId = ImportQueue.Dequeue()

If Not ofrImpId.Equals(Guid.Empty) Then

_threadPool.QueueWorkItem(AddressOf Import, ofrImpId)

End If

'put Job to queue if scheduled

JobSchedule()

Catch ex As Exception

_trace.TraceEvent(TraceEventType.Error, 0, "EXPLOSION: {0}", ex.ToString)

 End Try

Thread.Sleep(TimeSpan.FromSeconds(15))

 End While

_threadPool.Shutdown()

 _threadPool.Dispose()

 _trace.TraceInformation("Worker finished.")

End Sub

Private Sub JobSchedule ()

Code Hear………………………………………………………………………..

_trace.TraceInformation("{0} enqueued!", lImport.ofrImpUrl)

End Sub

 Private Sub Working Process(ByVal ofrImpId As Guid)

Try

Working Code Hear()

Try

ImportManager.ImportOffers(job)

Catch ex As Exception

_trace.TraceEvent(TraceEventType.Error, 0, "failed with exception", )

Finally

End Try

Catch ex As Exception

_trace.TraceEvent(TraceEventType.Error, 0, " failed with exception: {0}.")

End Try

End Sub


Different Language in Sitemap ASP.NET 4.0

Different Language with Sitemap ASP.NET 4.0
For Set up Custom Error Page these are the setup for it.
If you are using IIS 7.0 of Web server, these are link to how we can create custom error page for error 404.

<httpErrors errorMode="Custom" existingResponse="Auto">
<clear />
<error statusCode="404" prefixLanguageFilePath="" path="/error/errorsitemap.aspx?status=404" responseMode="ExecuteURL" />
<error statusCode="401" prefixLanguageFilePath="" path="/error/default.aspx?status=401" responseMode="ExecuteURL" />
<error statusCode="403" prefixLanguageFilePath="" path="/error/default.aspx?status=403" responseMode="ExecuteURL" />
<error statusCode="405" prefixLanguageFilePath="" path="/error/default.aspx?status=405" responseMode="ExecuteURL" />
<error statusCode="406" prefixLanguageFilePath="" path="/error/default.aspx?status=406" responseMode="ExecuteURL" />
<error statusCode="410" prefixLanguageFilePath="" path="/error/default.aspx?status=404" responseMode="ExecuteURL" />
<error statusCode="412" prefixLanguageFilePath="" path="/error/default.aspx?status=412" responseMode="ExecuteURL" />
<error statusCode="500" prefixLanguageFilePath="" path="/error/default.aspx?status=500" responseMode="ExecuteURL" />
<error statusCode="501" prefixLanguageFilePath="" path="/error/default.aspx?status=501" responseMode="ExecuteURL" />
<error statusCode="502" prefixLanguageFilePath="" path="/error/default.aspx?status=502" responseMode="ExecuteURL" />

httpErrors>
if you’re using Custom Error Mode

<customErrors defaultRedirect="/error/errorsitemap.aspx" mode="On" redirectMode="ResponseRewrite" >
<error statusCode="404" redirect="/error/errorsitemap.aspx?status=404" />
<error statusCode="500" redirect="/error/default.aspx?status=500" />

…… All the error code has to come here like above httpErrors section

customErrors>

If you are using Site map like flowing example
Web.CA.en-CA.sitemap
Web.CA.en-US.sitemap
Web.CA.fr-CA.sitemap

Then have to overwrite InitializeCulture() method of page.
Refer below link for more information
Protected override void InitializeCulture()
{
//Resetting the culture when the URL is contain fr
int rawLocalizeUrl = Request.RawUrl.IndexOf("/fr/");
if (rawLocalizeUrl >= 0)
{
UICulture = "fr-CA";
}
base.InitializeCulture();
}
Other wise
v Microsoft .NET Framework 4: What is New in Globalization Can be found in following links.
Localization with script
Sri Lanka .NET 
                Forum Member