Vici Core Tip #1 - XML file based settings

13. October 2009

.NET offers quite an extensive configuration framework in which you can use XML files to configure your applications. The drawback is that most of these files need to be located in the applications directory or sub-directories. Thus excluding reuse throughout different applications. An example of this is using an app.config or web.config file to store all your config information. If you have different applications that use the same base assemblies you can either place them in the GAC or place them in the same application directory as you main applications. Which imply that you need to keep you config settings in sync across multiple files and apps.

You can off course design your own settings-framework to resolve the above issue or use one of the fancy features of Vici Core. Let's get started on how we implement this.

What you need to obtain first is a copy of the latest Vici.Core dll which you can download at http://viciproject.com/wiki/Projects/Mvc/Download (the core has not yet received its own download, so it comes together with the mvc binaries for now, just get it from that download).

After you downoaded Vici.Core.dll, reference it in your project and then let the fun begin. I will include some sample code to show you  how simple it is to load your settings in your application

Step 1 - Create your XML file

As you can see there is a version attribute in the XML file to tell the config framework that we updated the XML file and that a new version needs to be updated in the cache.

<?xml version="1.0" encoding="utf-8" ?><Config version="1">    <FileLocation>c:\files\</FileLocation>    <TempPath>c:\temp\</TempPath></Config>

Step 2 - Create a POCO to hold your settings

Property names map to the XML nodes in your config file.

 

public class ConfigSet{  public string FileLocation;  public string TempPath;}

 

Step 3 - Register your POCO with the Vici Core config framework

 

using Vici.Core.Config;  class Program  {    public static ConfigSet Config;    static void Main(string[] args)    {      // The path to the location of your config file      string configFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Config.xml");      // Register the provider with the xml file      ConfigManager.RegisterProvider(new ConfigurationProviderXmlConfig(configFilePath));      // Create a new instance of our POCO      Config = new ConfigSet();      // Register our POCO with the framework      ConfigManager.Register(Config);      // Update our manager to tell it that we registered a new config file      ConfigManager.Update();    }  }

 

 

Step 4 - Use it

/*  Your code here*/string filePath = Program.Config.FileLocation;/*  More of your code here*/

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Development, Featured

What's in a name ...

19. May 2009

kijker Once upon a time there was a young boy that was looking for a virtual outlet on the web. Together with a few colleagues they all started their own websites. But! Wait a second, it all stands with a good name right? Right! So of we went, searching for good names for our sites. And there it was, out of the blue, as a flash of lightning: B-Virtual! Why? Since the web is a virtual place on a cloud of its own and my name starts with a B there it was => B-Virtual. So, years past by, visitors enjoyed this website, postings were done under the name B-Virtual and all went well. I've been active on the web for about 14 years now, I've seen domains come and go, technologies rise and fall, experienced venture capital at its best thanks to HyperTrust and met many interesting people.

 

But here comes the interesting part of the story. A few months ago I was contacted by someone asking me if I was interested in selling my b-virtual.com domain. My first reaction was no, why should I, it's almost my second name. But they kept asking and I went thinking. Since I live in Belgium and I own both .com, .eu and .be domains I started thinking that I could miss the .com if the price was right. Ok, I here you thinking, here we go, he's going to take advantage of the situation. Not really actually, I made some calculations and found a reasonably low price including fees for new logo designs, email campaigns, branding, ... but the price was seen as to high. No problem for me, I'm not really looking to sell it anyway.

 

Since I'm into the web, I went looking for more information about the company wanting to buy my domain. I came up with B-Virtual, a Belgian, yes Belgian as in Belgium, company. So do the math with me, a Belgian company wanting my name for their company? It seems as if the people at A-Server weren't really in a creative mood. They just took my name. Maybe it's good marketing, take a name that has a good SEO rating a piggyback on it. Don't get me wrong, I'm not against their products, cloud services are the future for some virtual needs. It's just that they were to lazy to search for a fresh and creative name for their brand.

 

To proof that I'm in favor of them, I'll even advertise their website, since I'm still, at the time of writing, higher ranked in Google ;)

Here we go:

B-Virtual delivers ground breaking cloud storage solutions

I wish you all great success in your business since I'm also a through believer in virtual storage solutions.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Featured, Varia