Sunday, January 31, 2010
patterns & practices - Unity - Discussions - separate config file path issue
var assembly = Assembly.GetExecutingAssembly();
Uri uriPath = new Uri(assembly.CodeBase);
string path = Path.Combine(Path.GetDirectoryName(uriPath.AbsolutePath.Replace('%20',' ')), 'unity.config');
var map = new ExeConfigurationFileMap() { ExeConfigFilename = path };
var config = ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None);
var section = (UnityConfigurationSection)config.GetSection('unity');
var container = new UnityContainer();
section.Containers['container'].Configure(container);
return container;
A typical thing happened in my code. The uriPath.AbsolutePath returns following path which is the location of my machine
E:\Working%20Folder\IocUnity\IocUnity.Website\bin\
Now if I go with this path, the config file didn't load but if I replace %20 with a space, it worked fine. I could not sort why it is behaving like this. If you look at my code, you can see I used Replace function to get rid of this problem.
Any idea....."
Friday, November 13, 2009
Tail recursion
Another nice one could be found here.
Serializing Dictionary to/from XML
Published 09 November 09 04:08 by Michael LehmanI spent a bit of time searching for the magic of how to use XmlSerialize with the Dictionary type this morning and thought I’d share the easy-to-use result:
Assuming you have an object, let’s say it’s called “data” that is of type Dictionary
, you can save it to an XML file whose name is contained in the string “dataName” like this: XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
XmlWriter writer = XmlWriter.Create(dataName, settings);
DataContractSerializer serializer = new DataContractSerializer(typeof(Dictionary));
serializer.WriteObject(writer, data);
writer.Close();(XmlWriterSettings is used to cause the resulting XML come out on human-readable multiple lines instead of all on one very long line.)
and read it back like this:
XmlReader reader = XmlReader.Create(dataName);
DataContractSerializer serializer = new DataContractSerializer(typeof(Dictionary)); result = (Dictionary
)serializer.ReadObject(reader);
reader.Close();
Thursday, November 12, 2009
Update manger thoughts
I also discovered that WSS web-services could be used for file copy.
Wednesday, November 11, 2009
Lectures on Physics:Tuva
http://research.microsoft.com/apps/tools/tuva/
New Mock/Stub Framework as part of Pex
Pex - Downloads - Microsoft Research: "Stubs framework, lightweight test stubs and detours for .NET"
AOP:AspectF
CodeProject: AspectF Fluent Way to Add Aspects for Cleaner Maintainable Code. Free source code and programming help: "AspectF"
AspectF.Define
.Log(Logger.Writer, "Inserting customer the easy way")
.HowLong(Logger.Writer, "Starting customer insert",
"Inserted customer in {1} seconds")
.Retry()
.Do(() =>
{
CustomerData data = new CustomerData();
data.Insert(firstName, lastName, age, attributes);
});