RSS feed

New Version: Microsoft Silverlight 4 Tools for Visual Studio 2010 – Build 30319.352

By Nithin Mohan T K - Last updated: Friday, September 3, 2010

Microsoft Silverlight 4 Tools for Visual Studio 2010 is an Add-on and pre-requisite files for Visual Studio 2010 to develop Silverlight 4 and RIA Services applications.

Latest version of Microsoft Silverlight 4 Tools for Visual Studio 2010 has been released on 09/02/2010.

The quick file details are

File Name:  Silverlight4_Tools.exe

Version:      30319.352

Date Published: 9/2/2010

Language:   English

Download Size:  35.1 MB

This package is an add-on for Visual Studio 2010 to provide tooling for Microsoft Silverlight 4 and RIA Services. It can be installed on top of either Visual Studio 2010 or Visual Web Developer 2010 Express. It extends existing Silverlight 3 features and multitargeting capabilities in Visual Studio 2010 to also create applications for Silverlight 4 using C# or Visual Basic.

Download  Microsoft Silverlight 4 Tools for Visual Studio 2010 – Build 30319.352 ( Microsoft Download Center)

Filed in .NET, Add-In's, Microsoft, Silverlight, Updates, VS2010, VisualStudio

Released: Windows Phone 7 RTM

By Nithin Mohan T K - Last updated: Friday, September 3, 2010

On 1st September 2010 Microsoft has announced the Windows Phone 7 RTM(Released-To-Manufacture), the most awaited Mobile OS from Microsoft. Just like Windows 7 it has already won the hearts of millions. Hope to win more..

You can read the official Windows Phone 7 team blog  Windows Phone 7 – Released To Manufacturing.

Quoting from Paul’s blog at WinSuperSite

Windows Phone 7 RTM

Well, the day has finally arrived. I was told very early on that Windows Phone would most likely be released to manufacturing (RTM) in August, and they missed that mark by just a day, which isn’t so horrible for a completely new platform. Anyway, the Windows Phone 7 OS has been finalized and sent to Microsoft’s hardware and carrier partners so that they can integrate their own software and services solutions and ship new devices to customers later in the year. No word yet on the launch, but I don’t believe the October/November plans have changed.

There are, however, some changes to the RTM version of the Windows Phone 7 OS, which are fortunately not too bad considering I pretty much finished the Windows Phone 7 Secrets book recently:

  • Facebook contacts filtering in the People hub, which isn’t actually what people have been asking for (i.e. the ability to decide which Facebook contacts appear and which do not). Instead, it’s that those Facebook contacts who don’t have phone information will be automatically filtered out of the list for you.
  • Facebook “Like” capability from the People hub. You can now “Like” a Facebook post from within the People hub’s What’s New list and post messages directly to someone’s Facebook wall.
  • Various user interface updates, including a new Search button in the contacts list.

Note that those with Tech Preview prototype phones will not be getting upgraded to the RTM build.

Filed in Microsoft, Windows Mobile, Windows Phone

FileSystemWatcher to Monitor when External configuration file is changed (C#)

By Nithin Mohan T K - Last updated: Thursday, September 2, 2010

It is quite interesting thoughts and ideas i have, since I wrote my last post about using External Configuration files in .NET Applications.

This is a followup to my previous article. So I would n’t be discussing it again. If you need full understanding about using External config file in Windows/Console/Web applications please read my previous article.

The problem when we use external configuration file is that we wouldn’t get updated result/latest values from the config file whenever the external configuration file is modified. It’s because we are linking to an external file and applications can detect changes to the config file as long as the file is within the application base folder. So ideally ASP.NET or Windows Application or Console Application cannot automatically detect an external config it refering is changed. This we have to do it through custom implementation

I got an idea, which would be like I will write a FileSystemWatcher implementation to watch/monitor  for changes in external configuration file and reload the configuration settings the moment it found that file has changed.

This would ideally be cool, we don’t have to worry whether we get latest information or not. FileSystemWatcher will ideally capture if any changes occurred and our few lines of implementation code will refresh the configuration data in the application and we get the latest information from config.

To know more details about System.IO.FileSystemWatcher class, i would suggest reading the MSDN article here

I could give a brief introduction. System.IO.FileSystemManager class has the functionality to watch a file or a folder in the system for changes made to it or any other alteration to it.

File System Watcher will monitor the file or folder. When a new file is created or existing file is modified or deleted or renamed, it can capture that change and raise/notify through events.

There are generally 4 events we can talk about here

Created
Changed
Deleted
Renamed

I hope the naming of the events itself makes sense what it does.

My sample implementation utilizes the “Changed” event because my requirement is to get notified when config file content is modified.

Here is the code I made

External.config

<?xml version="1.0"?>

<appSettings>

  <add key="Web_App_Name" value="Dream Works India Tech-003-990"/>
  <add key="Web_App_ID" value="E1635BA6-0714-4496-A852-18868A0EB591"/>
</appSettings>


The main program.

Program.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

namespace DreamConsoleApp
{
    class Program
    {
        /// <summary>
        /// Mains the specified args.
        /// </summary>
        /// <param name="args">The args.</param>
        static void Main(string[] args)
        {

            string configFilePath = @"C:\Demo\External.config";

            //First Time initializing to the config file.
            ConfigFileMonitor.SetConfigFileAtRuntime(configFilePath);  

            string webAppName = ConfigurationManager.AppSettings["Web_App_Name"];
            string webAppId = ConfigurationManager.AppSettings["Web_App_ID"];

            //Initializing the config file monitor.
            ConfigFileMonitor.BeginConfigFilesMonitor(configFilePath);

            // Wait for the user to quit the program.
            Console.WriteLine("Press \'q\' to quit the Application.");
            while
                (
                Console.Read() != 'q'
                ) ;

            //Some way the application should continue running,
            //other wise the file system watcher would not continue watching.
            //To solve this the best way would be implementing in to a Windows service.

        }

    }
}


The File Watcher watches my external config file for changes.

Do not worry this is just a sample code, just a simple solution. You can implement it in your own way, as per your need.

One thing the application should continue running, other wise the file system watcher would not continue watching.

To solve this the best way would be implementing in to a Windows service.

ConfigFileMonitor.cs


using System;
using System.Collections.Generic;
using System.Configuration;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;

namespace DreamConsoleApp
{
    public class ConfigFileMonitor
    {
        private static FileSystemWatcher _watcher;
        private static string _configFilePath = "";
        private static string _configFileName = "";

        /// <summary>
        /// Texts the files surveillance.
        /// </summary>
       public static void BeginConfigFilesMonitor(string fileToMonitor)
        {

            if (fileToMonitor.Length == 0)
            {
                Console.WriteLine("Please specify a config file to watch");
                Console.Write("> "); // prompt
                //runtimeconfigfile = Console.ReadLine();
            }
            else
            {

                _configFileName = Path.GetFileName(fileToMonitor);
                _configFilePath = fileToMonitor.Substring(0, fileToMonitor.IndexOf(_configFileName));

            }

            // Use FileWatcher to check and update only modified text files.
            WatchConfigFiles(_configFilePath, _configFileName);

        }

        /// <summary>
        /// Watches the files.
        /// </summary>
        /// <param name="targetDir">The target dir.</param>
        /// <param name="filteredBy">The filtered by.</param>
       static void WatchConfigFiles(string targetDir, string filteredBy)
        {
            _watcher = new FileSystemWatcher();
            _watcher.Path = targetDir;
            _watcher.Filter = filteredBy;
            _watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite;
            _watcher.EnableRaisingEvents = true;

            _watcher.Changed += new FileSystemEventHandler(FileChanged);

            _watcher.WaitForChanged(WatcherChangeTypes.Changed, 24 * 60 * 60 * 1000);  //Wait for 24 hours ( 24 Hours * 60 Mins * 60 Sec * 1000 Milli second)

        }

        /// <summary>
        /// Handles the Changed event of the File control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.IO.FileSystemEventArgs"/> instance containing the event data.</param>
       protected static void FileChanged(object sender, FileSystemEventArgs e)
        {
            string filechange = e.FullPath;

            Console.WriteLine("Configuration File: " + filechange + "changed");

           //Since the file is changed - We have reload the configuration settings again.
           SetConfigFileAtRuntime(@"C:\Demo\External.config");

            string webAppName = ConfigurationManager.AppSettings["Web_App_Name"];
            string webAppId = ConfigurationManager.AppSettings["Web_App_ID"];

            Console.WriteLine("New Web App Name :: " + webAppName);
            Console.WriteLine("New Web App ID   :: " + webAppId);

        }

        /// <summary>
        /// Sets the config file at runtime.
        /// </summary>
        /// <param name="configFilePath"></param>
        public static void SetConfigFileAtRuntime(string configFilePath)
        {
            string runtimeconfigfile;

            if (configFilePath.Length == 0)
            {
                Console.WriteLine("Please specify a config file to read from ");
                Console.Write("> "); // prompt
                runtimeconfigfile = Console.ReadLine();
            }
            else
            {
                runtimeconfigfile = configFilePath;
                _configFileName = Path.GetFileName(configFilePath);
                _configFilePath = configFilePath.Substring(0,configFilePath.IndexOf(_configFileName));

            }

            // Specify config settings at runtime.
            System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

            //Similarly you can apply for other sections like SMTP/System.Net/System.Web etc..
            //But you have to set the File Path for each of these
            config.AppSettings.File = runtimeconfigfile;

            //This doesn't actually going to overwrite you Exe App.Config file.
            //Just refreshing the content in the memory.
            config.Save(ConfigurationSaveMode.Modified);

            //Refreshing Config Section
            ConfigurationManager.RefreshSection("appSettings");
        }

    }

}

Here is the result


I hope this helps to give a self explanatory solution which you can interpret from the code and comments on it.

This is just a Quick Thought.. I will test and update the code with much more perfection on later time.

That’s all for now. If any help needed, please leave a comment

Filed in .NET, .NET Framework, ASP.NET, C#.NET, CodeSnippets, Codes, Dev Community, KnowledgeBase, Microsoft, Resources, Samples, VS2010, VisualStudio, Web Services

Released: Microsoft® Silverlight™ 4 SDK – 4.0.50826.0 (September 2010)

By Nithin Mohan T K - Last updated: Thursday, September 2, 2010

Microsoft has today released the latest version of Microsoft® Silverlight™ 4 SDK – Version: 4.0.50826.0. This is the latest September 2010 released on 09/01/2010.

The Microsoft® Silverlight™ 4 SDK contains online documentation, online samples, libraries and tools for developing Silverlight 4 applications.

Usage of the SDK is subject to the SDK License (included in the package).

Download Microsoft® Silverlight™ 4 SDK – 4.0.50826.0

Filed in .NET, Expression, HotFixes, Microsoft, Silverlight, Updates, VS2010, VisualStudio

Using External Configuration Files in .NET Applications (C#)

By Nithin Mohan T K - Last updated: Tuesday, August 31, 2010

This post is about making a small code snippet which read from an external configuration file and get the custom configuration entries from it.

I went through the solutions. My target was to checkout how we can use the external configuration files in an ASP.NET Web.config. The idea is that there are more than one web application is there in my own Virtual Organization. I thought of keeping a common configuration file for all those web application. So that I have to change configuration only in one place, from time to time changes.

1. Scenario 1 :- ASP.NET Application

Here is the solution I came across.

External configuration file(External.config), which will have some set of AppSettings key value pairs.

<?xml version="1.0"?>

<appSettings>

  <add key="Web_App_Name" value="Dream Works India"/>
  <add key="Web_App_ID" value="E1635BA6-0714-4496-A852-18868A0EB591"/>
</appSettings>

ASP.NET Web.config (Which refering to an external config file with name “External.config”)

<?xml version="1.0"?>
<configuration>
	<appSettings configSource="External.config"> <!-- Refering to an External Config File, You should specify the relative path -->

	</appSettings>

	<system.web>
		<compilation debug="true"/>
  </system.web>

</configuration>

Note: One thing you should make sure is that, in ASP.NET you have to mention the External config file’s relative path. It will not accept if i keep like “C:\External.config”

ASP.NET – C# Code (for reading from external config file)


using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.Configuration;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace DreamWebSiteMain
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string Web_App_Name = WebConfigurationManager.AppSettings["Web_App_Name"];
            string Web_App_Id   = WebConfigurationManager.AppSettings["Web_App_ID"];

            string str = string.Empty;
        }
    }
}

That’s it. We are ready, here is the output i captured while debugging.

2. Scenario 2 :- Console/Windows Application

Here case is bit different from ASP.NET, you cannot simply specify in App.config file. Windows/Console Application would n’t work that way.

You will receive an exception if you try the same in console/windows application.

Error:- “Unable to initialize the configuration entries”
.

So what is other option we have. I came across a code-project article(link Specify a Configuration File at Runtime for a C# Console Application. That was really informative and thoughtful.

So i made slight changes to the code and implemented for my scenario.

External configuration file(C:\External.config), which will have some set of AppSettings key value pairs.

<?xml version="1.0"?>

<appSettings>

  <add key="Web_App_Name" value="Dream Works India"/>
  <add key="Web_App_ID" value="E1635BA6-0714-4496-A852-18868A0EB591"/>
</appSettings>

Console Executable App.config (Which will not refering to an external config file with name “External.config”, leave it empty)

<?xml version="1.0"?>
<configuration>
	<appSettings > <!-- forget about linking external config here -->

	</appSettings>

	<system.web>
		<compilation debug="true"/>
  </system.web>

</configuration>

Note: One thing you should make sure is that, in ASP.NET you have to mention the External config file’s relative path. It will not accept if i keep like “C:\External.config”

Console Application – C# Code (for reading from external config file)


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

namespace DreamConsoleApp
{
    class Program
    {
        /// <summary>
        /// Mains the specified args.
        /// </summary>
        /// <param name="args">The args.</param>
        static void Main(string[] args)
        {
            SetConfigFileAtRuntime(@"C:\External.config");  

            string Web_App_Name = ConfigurationManager.AppSettings["Web_App_Name"];
            string Web_App_Id = ConfigurationManager.AppSettings["Web_App_ID"];

            string str = string.Empty;
        }

        /// <summary>
        /// Sets the config file at runtime.
        /// </summary>
        /// <param name="configFilePath"></param>
        protected static void SetConfigFileAtRuntime(string configFilePath)
        {
            string runtimeconfigfile;

            if (configFilePath.Length == 0)
            {
                Console.WriteLine("Please specify a config file to read from ");
                Console.Write("> "); // prompt
                runtimeconfigfile = Console.ReadLine();
            }
            else
            {
                runtimeconfigfile = configFilePath;
            }

            // Specify config settings at runtime.
            System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

            //Similarly you can apply for other sections like SMTP/System.Net/System.Web etc..
            //But you have to set the File Path for each of these
            config.AppSettings.File = runtimeconfigfile;

            //This doesn't actually going to overwrite you Exe App.Config file.
            //Just refreshing the content in the memory.
            config.Save(ConfigurationSaveMode.Modified);

            //Refreshing Config Section
            ConfigurationManager.RefreshSection("appSettings");
        }

    }
}

That’s it. We are ready to go, here is the output i captured while debugging.

Voila!!!! Everything working as expected. I got the implementations for ASP.NET and Windows/Console App.

Hope this helps. I couldn’t get much time to do proper formatting. Hope you folks don’t mind the beauty of the code.

Happy Learning !!!!

Filed in .NET, .NET Framework, ASP.NET, C#.NET, CodeSnippets, Codes, KnowledgeBase, Microsoft, Samples, Snippets, VS2010, VisualStudio, WinForms
Get Adobe Flash playerPlugin by wpburn.com wordpress themes