
Tuesday, January 30, 2007
Configuration management tool using C# 2.0 System.Configuration
So, I have been trying to write a tool to manage addition/updates to configuration file like SomeApp.exe.config. This involves reading and writing to configuration files. Using XML DOM is too low level when 2.0 provides System.Configuration namespace. Here is the outcome of that effort. Thought I will share in view of the lack of documentation from MS. Read/Write AppSettings wasnt hard. What I had problems with was read/write custom ConfigurationSection
Here are a bunch of gotchas from this effort
- If you are writing a configuration management app that wants to access random config files, you need to use ExeConfigurationFileMap and ConfigurationManager.OpenMappedExeConfiguration
- When you read a configuration section from a source file and move it into some target file, you get an error "Cannot add a ConfigurationSection that already belongs to the Configuration". I used reflection to get around this. I will show you how in a moment.
- You can get raw xml configuration from ConfigurationSection using section.SectionInformation.GetRawXml(). Likewise use SetRawXml to set this
- When you load a config file using OpenMappedExeConfiguration, you get an in memory configuration which is "merged" and has sections from machine.config. You can check if a section came from the file you provided using section.ElementInformation.Source.Equals(source.FilePath)
So having got through that, here is how I did what I did
First off, load the source and target configs
//Load Source ExeConfigurationFileMap map = new ExeConfigurationFileMap(); map.ExeConfigFilename = "source.config"; Configuration source = ConfigurationManager.OpenMappedExeConfiguration(map,ConfigurationUserLevel.None);
//Load Target map.ExeConfigFilename = "target.config"; Configuration target = ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None);
Now that we have the source and the target files we can start doing the real work
foreach (ConfigurationSection section in source.Sections) { //We want to ensure that this guy came from the file we provided.. and not from say machine config if (section.ElementInformation.Source !=null && section.ElementInformation.Source.Equals(source.FilePath)) { //Enumerator is on AppSettings. So we update the appSettings if (section is AppSettingsSection) { foreach (KeyValueConfigurationElement element in source.AppSettings.Settings) { target.AppSettings.Settings.Remove(element.Key); target.Save(ConfigurationSaveMode.Full, false); target.AppSettings.Settings.Add(element); } } //Enumerator is on a custom section else { //Remove from target and add from source. target.Sections.Remove(section.SectionInformation.SectionName); //Just paranoid. target.Save(ConfigurationSaveMode.Full, false); //Using reflection to instantiate since no public ctor and the instance we hold is tied to "Source" ConfigurationSection reflectedSection = Activator.CreateInstance(section.GetType()) as ConfigurationSection; reflectedSection.SectionInformation.SetRawXml(section.SectionInformation.GetRawXml()); //Bug/Feature in framework prevents target.Sections.Add(section.SectionInformation.Name, Section); target.Sections.Add(section.SectionInformation.Name, reflectedSection); } ConfigurationManager.RefreshSection(section.SectionInformation.SectionName); }
Here is what the source looks like. It has one custom section and one appsettings key value pair
<?xml version="1.0" ?> <configuration> <configSections> <section name="MyCustomConfiguration" type="Covarius.Configuration.MyCustomConfigurationSection, Covarius.Configuration, Version=1.0.0.0, Culture=neutral, PublicKeyToken=147be6ea50c5d416" /> </configSections> <MyCustomConfiguration ConfigValue="C:\Test2.ini" MyURL="http://webservices.covarius.dev/testservice.asmx"/> <appSettings> <add key="CustomConfig" value="c:\blahCon.config"/> </appSettings> </configuration>
That was easy wasnt it. I have attached a utility AppConfigUpdater.exe. So you can use it as a deployment tool to update config in say QA or PROD. Syntax is AppConfigUpdater <sourcefile> <targetfile>
Comments welcome.
Linus Joseph
Download AppConfiUpdater.exe (16 KB)
1/30/2007 2:21:21 PM (Eastern Standard Time, UTC-05:00)
|
|

Wednesday, October 11, 2006
AJAX with ASP.NET 1.1
AJAX stands for Asynchronous JavaScript and XML. AJAX allows data on a page to be dynamically updated by a javascript http method to send XML to server and get the response back from the server as XML without having to make the browser reload the page.
The following is an outline of the sequence of events happening when using AJAX with the sample project attached:
- Web page (Grid.aspx) is rendered with data on an xml/xslt grid using xml/xslt transformation.
- JavaScript function call is called from page (grid.js) on the event "onblur " to update the inline edited data to the database.
- JavaScript function calls an XML HTTP to a Callback remote page(CallbackManageGrid.aspx)
-
Remote Page update the database and return the result message in an xml format
NOTES: Run the sql script from the sql folder to create the database and populate the initial data. Update the web.config as needed to update the database connection string data.
Covarius_AJAX_100606.zip (41.32 KB)
10/11/2006 9:10:55 PM (Eastern Daylight Time, UTC-04:00)
|
|

Tuesday, October 03, 2006
Unzip commandline tool
I have been looking for a simple command line tool to unzip files for a long time. Put this together since I couldnt quite find one I liked. So here is the exe if you have been looking for one. I use it as a barebones unzipper with dos batch files etc. Its a shame windows xp/2003 doesnt have anything that can be called by and external tool. When I get time I also want to look in the windows APIs to see if there is a way to call an api to do unzip etc.
Accepts two parameters filename and target directory(optional)
Here is syntax "Funzip.exe zipfileName target_unzip_directory". Its free under GPL. I am too lazy to add readme and package it etc. If you need source code or additional features etc. let me know. Based on SharpZipLib by Mike Krueger. The sample code had some bug with directory creation etc so I fixed it.
Download Funzip (88 KB)
Disclaimer:- Use at your own risk. Covarius or author not liable for any damage arising from use or miuse of this tool (Funzip.exe)
10/3/2006 10:32:22 AM (Eastern Daylight Time, UTC-04:00)
|
|

Wednesday, August 30, 2006
Zombies in Biztalk 2006
You are familiar with the Zombie instances in Biztalk 2004. For a background on zombies try these articles http://msdn.microsoft.com/library/default.asp?url=/library/en-us/bts_2004wp/html/956fd4cb-aacc-43ee-99b6-f6137a5a2914.asp
http://blogs.msdn.com/biztalk_core_engine/archive/2004/06/30/169430.aspx
Zombies instances are created in Biztalk 2006 also under similar Sequencial Convoy scenarios. The error description is different.. "The instance completed without consuming all of its messages. The instance and its unconsumed messages have been suspended."
This time around you would think that failed message routing can be used to track down these failed zombies. Unfortunately, these are not handled by the failed message handling mechanism. Zombies are suspended as (not resumable). This leaves us with few options to handle them.. mostly older Biztalk 2004 style WMI event handlers and so forth
here is one from Darren Jefferd
http://blogs.msdn.com/darrenj/archive/2004/03/30/104135
8/30/2006 4:53:32 PM (Eastern Daylight Time, UTC-04:00)
|
|
Biztalk 2006 File Receive Location script
I had to write something up quickly the other day to speed up testing on one of our prod biztalk 2006 apps. Thought this might be useful to someone out there. This script creates File Receive Locations on Biztalk 2006 given Receive location name, port name, biztalk host name, pipeline name and url. I would say this is good cookie cutter to do more interesting things by modifying this script. RecvLoc.vbs (2.78 KB)
8/30/2006 9:59:17 AM (Eastern Daylight Time, UTC-04:00)
|
|
Core Duo and Virtual PC 2004 SP1 Performance
I havent been able to find any performance studies for Virtual PC 2004 on a Core Duo Processors. I am trying to spec out development boxes that run instances of Virtual PC with Biztalk 2006, SQL Server 2005 and Windows 2003 Domain Controller. I will be doing a performance study in the next couple of days. I am planning to run Biztalk 2006 Stress tests on core duo with 2Ghz processors and 2 Ghz RAM. Will try to use a resonably fast hard drive.. say 7200 RPM. The intention is to get a feel of how good this set up is as a decent but not too pricey dev box.
8/30/2006 7:58:07 AM (Eastern Daylight Time, UTC-04:00)
|
|

Tuesday, August 29, 2006
SQL Prompt
SQL Prompt by redgate software fits the bill if you are looking for a T-SQL editor that can do intellisense. I have been playing it for the past few hours and it does the job quite well. Best part is its free.. well atleast for the time being..
Check it out here.
http://http://www.red-gate.com/products/SQL_Prompt/index.htm
8/29/2006 2:39:54 PM (Eastern Daylight Time, UTC-04:00)
|
|

Wednesday, July 20, 2005
this is the root for 7/20
Test content dasBlog
7/20/2005 3:00:00 AM (Eastern Daylight Time, UTC-04:00)
|
|