this blog contains information for .net and sql stuffs. You can find various tips and tricks to overcome problem you may be facing in ...

Showing posts with label Configuration. Show all posts
Showing posts with label Configuration. Show all posts

Monday, October 1, 2012

Add Event/Appointment in Google Calendar with Google account credential.


Google calendar is one of the best free tool for tracking your day to day appointment and reminder for your rest of schedule. There are facilities for reminder with email and sms that will enable you for preparing your next meeting/appointment.
We can leverage this tool in our any of application, we can sync our event or appointment with google calendar so one may miss reminder from application but alternatively get from google calendar.
Doesn’t it seem cool? Even implementation is simpler than it seem.
Firstly, you will need to add reference of following files.

using Google.GData.Client;
using Google.GData.Extensions;
using Google.GData.Calendar;

You can find those files here.

Below is code block for adding event in google calendar.

public CalendarService GetService(string applicationName, string userName, string password)
        {
            CalendarService service = new CalendarService(applicationName);
            service.setUserCredentials(userName, password);
            return service;
        }

public static void AddEvent(CalendarService service, string title, string contents, string location, DateTime startTime, DateTime endTime)
        {
            Google.GData.Calendar.EventEntry entry = new Google.GData.Calendar.EventEntry();

            // Set the title
            entry.Title.Text = title;

            //Set event details.
            entry.Content.Content = contents;

            // Set a location for the event.
            Where eventLocation = new Where();
            eventLocation.ValueString = location;
            entry.Locations.Add(eventLocation);

            //Set starting time and end time for the event.
            When eventTime = new When(startTime, endTime);
            entry.Times.Add(eventTime);

            Uri postUri = new Uri("https://www.google.com/calendar/feeds/aslam.h.net@gmail.com/private/full");

            // Send the request and receive the response:
            AtomEntry insertedEntry = service.Insert(postUri, entry);
        }

Here, GetService method will take three parameters named application name, username and password.
Application name can be any name, you wish. Username is your google account name where you have configured your calendar and wish to sync with that calendar. Password is your google account password.
Method will return back calendar service object. We can use this service object anywhere for using any service associated with calendar.

Method AddEvent: this method will add event in any our calendar. Most of statements are formatted with comments.
There is one critical statement you need to take care.

Uri postUri = new Uri("https://www.google.com/calendar/feeds/shailesh@gmail.com/private/full");


Please note that one dynamic part, shailesh@gmail.com. It’s my calendar’s id. You can easily find your sync calendar id with following steps.

1)      Logon to your gmail account and click on calendar link at top bar, it will open up your calendar in new tab.
2)      On the right side, there will be section named “My Calendars”. It lists out calendars, you created. You can create more than one calendar in google calendar tool.
3)      Go to any of calendar, click on the arrow. It will show one menu. Click on “Calendar settings”.
4)      There will be one row with “Calendar Address”, most probably before last row. Just look around this row, there will be information like this.
(Calendar ID: shailesh @gmail.com)
This is the address for your calendar. No one can use this link unless you have made your calendar public

That’s it.

I hope this will enable to sync your important tasks, appointment and meeting with google calendar.

Happy scheduling appointment

Tuesday, June 5, 2012

Change default time out of strongly typed dataset table adapter command.


By default when every any command executed by table adapter, its time out is 30 second. Due to heavy load of data and traffic over the network, we require increasing this default time out.
It’s very straight forward when we use code for it. In case of strongly data set it’s a bit tricky.
Firstly, you will require extending your dataset existing name space and its table adapter. In data table adapter class, you can add one method for changing this time out.
//Extend existing data table adapter class created by strongly typed dataset.
Namespace MyTableAdapters
Partial Public Class MyTableAdapter

Public Sub SetCustomCommandTimeout()
Utility.SetCommandTimeout(CommandCollection)
End Sub

End Class
End Namespace
//Set Custom Timeout to underlying command.
Public Shared Sub SetCommandTimeout(ByVal commands As System.Data.SqlClient.SqlCommand(), Optional ByVal timeout As Integer = -1)

If (commands IsNot Nothing) Then

If (timeout < 0) Then timeout = GetConfigTimeout()

For Each cmd As System.Data.SqlClient.SqlCommand In commands
cmd.CommandTimeout = timeout
Next

End If

End Sub

//Get Custom time out from web.config.

Private Shared Function GetConfigTimeout() As Integer

Dim timeOut As Integer
If Not System.Configuration.ConfigurationManager.AppSettings("CommandExecutionTimeOut") Is Nothing Then
timeOut = CType(System.Configuration.ConfigurationManager.AppSettings("CommandExecutionTimeOut"), Integer)
Else
timeOut = 0
End If

Return timeOut

End Function

Hope this would be very helpful !!

Thursday, January 12, 2012

Prerequisites could not be found for bootstrapping (while upgrading from VS 2005, 2008 to VS 2010)

Latest IDE by Microsoft for .net application is VS 2010. Most of applications are upgraded to newer version of IDE, some are in the process and some are already done. The thing create problem during upgrade is that most of time targeted framework does not change, it just refer older version.

When you try to add prerequisites, you will be surprised that it will not find your older version any more. Many forums said that Microsoft has disabled it and you need to upgrade to higher version of prerequisites.

You can see that in the given below images that shows unavailability.


To resolve this issue you need to copy boots trapper files.

Older version of VS files can be found at

C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bootstrapper\Packages

You need to copy files from above location to below location and once you copy required folders, you will be able to access those in prerequisites.

C:\Program Files\Microsoft SDKs\Windows\v7.0A\Bootstrapper\Packages

Cheers!!

Monday, May 17, 2010

Configuration in .net

When ever .net application runs in any computer, it requires storing some user preference data, connection string if it’s interacting with database and setting for user’s custom control over application. To do so, user adds custom class that stores all information and retrieve when need arise. Usually system administrator wishes to change setting information.

If information is stored in XML file, its easy to store, edit and retrieve by application, with help of System.Configuration namespace that task can be fulfilled.

There are two types of configuration files exist. Machine.Config, it is one which stores information for all application running in a computer, that defines setting for machine. Application .cofing files which stores information for a particular application and which resides in executable folder of running assembly.

Some of the settings which are exists in Machine.Config can be overridden in application configuration but only whose setting allowDefination property set to MachineToApplication , whose property set to MachineOnly can’t be override in application configuration.

To play with setting files, System.Configuration require, we can add reference to it by selecting add reference to our project and once its added to our application, it can be used by Imports in vb.net and using in C#.

To edit Machine.Configue file following steps are useful.

Create instance of Configuration by calling ConfigurationMangaer.OpenMachineConfiguration();

Configuration machineConfig = ConfigurationManager.OpenMachineConfiguration();

There are different sections exist in it, let’s check ProtectedConfigurationSection.
ProtectedConfigurationSection pcs =
(ProtectedConfigurationSection)machineSettings.GetSection( "configProtectedData");

Its provider can be displayed as
MessageBox.Show(pcs.DefaultProvider);

Parameters of section can be accessed by.

MessageBox.Show(pcs.Providers[“DataProtectionConfigurationProvider”].Parameters[“description”]);


Configuration section has unique class, and that c

Each configuration section has a unique class. To determine which class a configuration section uses, call ConfigurationManager.OpenMachineConfiguration().GetSection(
"").ElementInformation.Type.ToString.

To edit application configuration file
Create instance of Configuration by method OpenExeConfiguration
Configuration config =
ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

Values can be added as
config.AppSettings.Settings.Add("MyKey", "MyValue");

Save new value to configuration file
config.Save(ConfigurationSaveMode.Modified);

After running above code check your configuration file, it should look like


Application settings can be read as ..
Configuration.AppSettings(“KeyName”);

Above code will return values of “KeyName” key.

Configuration.AppSettings return NameValueCollection, for database connection string we have ConnectionStringCollection.

The three most useful property of ConnectionStringClass are
Name -- defines name of connection string
ProviderName –type of database connection i.e sql servr, oracle, oledb etc
ConnectionString –defines a string how to connect with database.

We have following connection string in configuration file
Integrated Security=SSPI; AttachDBFilename=|DataDirectory|aspnetdb.mdf; User Instance=true"
providerName="System.Data.SqlClient" />

Though in above connections string split in many lines, in actual it can be placed in a single line.
We can access this connection as
ConfigurationManager.ConnectionStrings["mySqlServer"].ConnectionString

To create custom section in our application configuration there are two way to do that in first create a class that inherits from IConfigurationSectionHandler interface and create a class derived from ConfigurationSection class.