December 2003 - Posts
If the name of the post doesn't sum it all the way up, here's the question. Does anyone know of a way, in macro code, to programmatically add a reference to a project? That'd be swell, eh? Takers?
tim berners-lee is going to be knighted by the queen! how cool is that! does that make him the first geek knight? three cheers for our leader!
So i received an amazon.com gift certificate for Christmas, and i'm thinking of getting a few good .NET books for myself. Thing is, i've not had the time recently to read a lot of good stuff or to have even kept up with the new books that are out. So i'm asking for some reco's from everyone.
i've been interested in books on attribute-based programming, reflection, and more advanced topics. Perhaps a good one on server controls, but more along the lines of the more academic stuff. Nothing basic, nothing simple.
Comments anyone?
So this time i've taken the old example one step further. Let's say that you've got a plugin architecture that works with the Provider model, so that plugins can be snapped right in via the configuration file. Now think about this for a moment - what if you wanted to be able to snap in as many plugins as you want, but want to be able to reference the one you need at run-time with a key?
Without going into too long-winded a discussion like the last post on this topic (which ended up being something shy of an article), here's an example of how to do something like this.
First off, the configuration file itself.
<
configuration>
<configSections>
<sectionGroup name="SelectiveProvider">
<section name="Settings"
type="SelectingProviderViaXPath.SelectiveProviderReader,
SelectingProviderViaXPath"
/>
</sectionGroup>
</configSections>
<SelectiveProvider>
<Settings>
<provider key="helloWorld">
<typeName>SelectingProviderViaXPath.HelloWorld</typeName>
</provider>
<provider key="goodbyeWorld">
<typeName>SelectingProviderViaXPath.GoodbyeWorld</typeName>
</provider>
</Settings>
</SelectiveProvider>
</configuration>
Now, a quick look at the configuration reader and settings classes.
using
System;
using System.Configuration;
using System.Xml;
using cs = System.Configuration.ConfigurationSettings;
namespace SelectingProviderViaXPath
{
public class SelectiveProviderReader : IConfigurationSectionHandler
{
/// <summary>
/// Creates an instance of the GenericDal settings object
/// from the custom configuration settings.
/// </summary>
/// <returns></returns>
public object Create(object parent,
object context,
XmlNode section)
{
XmlNodeList lst = section.SelectNodes("provider");
return new SelectiveProviderSettings(lst);
}
}
/// <summary>
/// The settings class, which contains the type name to be loaded.
/// </summary>
public class SelectiveProviderSettings
{
const string section = "SelectiveProvider/Settings";
string typeName = String.Empty;
XmlNodeList providerList;
internal SelectiveProviderSettings(XmlNodeList installedProviders)
{
providerList = installedProviders;
}
public string TypeName
{
get { return typeName; }
}
/// <summary>
/// Set the provider according to what was asked for in the
/// GetSettings() parameter.
/// </summary>
/// <param name="key"></param>
void SetProvider(string key)
{
for(int i=0; i<providerList.Count; i++)
{
string j = providerList[i].Name;
string keyValue = providerList[i].Attributes["key"].Value;
XmlNode nodTypeName = providerList[i].SelectSingleNode("typeName");
if(keyValue == key)
{
typeName = nodTypeName.InnerText;
return;
}
}
}
/// <summary>
/// Return an instance of the Settings object.
/// </summary>
/// <param name="providerKey">The provider's key we want to instantiate.</param>
/// <returns></returns>
public static SelectiveProviderSettings GetSettings(string providerKey)
{
SelectiveProviderSettings b =
(SelectiveProviderSettings)cs.GetConfig(section);
b.SetProvider(providerKey);
return b;
}
}
}
Next, the IProvider interface and a few basic implementations of it.
using
System;
namespace SelectingProviderViaXPath
{
public interface IProvider
{
void WriteMessage();
}
public class HelloWorld : IProvider
{
public void WriteMessage()
{
Console.WriteLine("Hello World!");
}
}
public class GoodbyeWorld : IProvider
{
public void WriteMessage()
{
Console.WriteLine("Goodbye World!");
}
}
}
Finally, a little console client to exemplify the whole deal.
using System;
namespace
SelectingProviderViaXPath
class Client
{
static void Main(string[] args)
{
Client c = new Client("goodbyeWorld");
c.WriteMessage();
Console.ReadLine();
}
protected IProvider provider;
/// <summary>
/// Constructor which sets up the required provider.
/// </summary>
/// <param name="providerKey">Key of the provider in the config setting.</param>
public Client(string providerKey)
{
SelectiveProviderSettings settings =
SelectiveProviderSettings.GetSettings(providerKey);
Type t = Type.GetType(settings.TypeName);
object o = Activator.CreateInstance(t);
provider = o as IProvider;
}
void WriteMessage()
{
if(provider != null)
provider.WriteMessage();
else
Console.WriteLine("Provider does not implement IProvider");
}
}
}
There you have it - the Provider model, extended somewhat so that multiple plugins can coexist in harmony, only to be used when needed by an individual application at run-time. Deviation, variation, and extension, all through one little model.
I've seen hundreds of them - these RSS reader classes. Has anyone written one that basically does just that, for RSS 1.0, 2.0, and RDF documents? I'm basically looking for a customized reader implementation, completely compiled (as in no XSLT), managed code? Love a reco if you've got one.
They're about to do a little expose' on one of my least favorite topics - large companies outsourcing all of their US work!
You're a consultant. Your job is to help organizations build bridges. You have a new client who brings you a proposal that looks like this:
“We have this need for a bridge. We don't know what materials the bridge needs to be made of. We don't know how high the bridge needs to be. We don't know what the bridge will be stretched over. We aren't sure how long the bridge needs to be, and we definitely don't know the weather conditions at the spot where the bridge needs to be built. We'd like you to build the bridge, but we need it done by next month.”
What do you do?
What if they come to you and say “we need you to help us build a bridge and we will pay you well for it." You agree to do the job, and then they come to you and say, “We don't know what materials the bridge needs to be made of. We don't know how high the bridge needs to be. We don't know what the bridge will be stretched over. We aren't sure how long the bridge needs to be, and we definitely don't know the weather conditions at the spot where the bridge needs to be built. We'd like you to build the bridge, but we need it done by next month.”
Better yet, they start with “we need a bridge that's 2 miles long built by next month and we want you to help us.” You agree, and then they change the length of the bridge, tell you what you can and cannot use (because obviously they know better than you even though you're the stinkig bridgebuilder), and then say “we need it in two weeks.”
AH, such is the life of a programming contractor. Any advice?
i couldn't resist. who-in-the-heck's idea was this?
One of my clients is looking for a good ad-hoc, easy-to-use intranet tool that runs under ASP.NET for doing reporting. They tried Crystal and hated it, and want to stay within the HTML generated realm. i downloaded ezWebReports and it seems pretty nice. What's better is they love the price. i don't want to make a decision until i've evaluated a lot of packages, so if anyone has any advice on this front, drop a note.
Check out the cool stuff you can do (unless you just hate looking at yours truly) at typeorganism! Just resize or crop your own image to 60x50 pixels, upload, and try it out. Quite nifty!
(((<==szs=<+h+<<(<~<~=<+(~-+((<z+<<(~hDDDhs++zs==z<<=zshsz=s
<((=zszhss+ss<+((((<(=<=<z~(<~<z<((~~Dshhhzzs=zz+z<~=sszz=zz
<(<=szhss=zzs=+<<~<<+(z=<s<~+((+(<((~hhshhh=hzzhz=z<(+zs+zz=
<<<zzhzs=szhs==<z~+h++=s~=<~<~~+++<((+h=szhzshhhDhh=(++z<+sD
<(<hzhsszzhssz=+z(+z=++s(s<~(~(<+~(+=<hh+zs=zzhDhhzs(+++<~+s
(<<szszzhhzss=z+z<szs=s++s=-~--~<~~(<+zs===szzDhBhsh=(s+<~++
<<+szzsszzzszzz=s+=zzss<=s=-~-(~(~(s++hss~==zhhhDzz<s(+<<-(<
<<++zzszzzssszssss=zzhzzsz=~~-~~(~+<z=hsz(<=zhDDhhz<+<(<~<-s
<<<s=szhzz=zsz==ss=ssszzzzs-~'~~(~(<zzs=s+-=zzhhzzz=<+~<<((~
<<<=+zzDz===s==+ss=s=szssss((--~((<(zhsz=s-<zzshszhs<<~(s<<~
<<<hszsz=ss===+==ssz+==s+=+~(--(--(+<z====~~hs==++zs+<~==z<~
<<<szhzz===++=+===sz++=ss=(++~-~<(~+=szz==<(h=+=<+===+(=(zz~
<<<=hzz====+++++=ss=<<++=+(+<~-(<~<+==sz=s<(=<<+<<s=s=<=<ss<
<<<<zDhzs===++<+==ss<<++(++s+<-~+<<=sszhs=<(<<+<<<sss+<=<s=<
<<<<shDz+++<+<++==s+<<<<<++=+<~(++<==szhss<((<<+(<zsz++s(ss~
<<<<+DBD=++++++++<<<<<(<<<<==<(~++==zszhz=<<<(<<<+z=s=+s<+<<
<<<<<hDD+++<<<<<<<<(~~(<<<<+++<~(+==s=hhz+(<<<<((=h=h<+s<=~<
<<<<<=hh=++<<((<<<<<(((((((<==<(<+===szz+<<<(~(<<z==<+=s+((<
<<<<<<zh++<<<<((((((<<((((((<++<((<+=sz+<+<<((<<=s+=<<s=<<=z
<<<<<+zz+++<<(<((~~(~((<<(<((<<((((<++(((~~-~(<+<+~~(+szs+hh
<<<<<+zs+==++<((((~~~-~~((((<((<((~<(<((~(~~~~~(~-~-(=hzhDD(
<<<<<=z======+<((((---~~~~(~(((<((~~~~~~(--~----~~-~<=zzhhs~
<<<<<=z========+<(~~~~~-~~~--~(~~~~~-~~~(~~~~----~-~(+zzhz(-
<<<<<<z+++======<((~~-~--~----~~(--~-~-----------~~-~<=zh(-(
<<<<<+s+++<++=s==<((~~~---~~-~~~~~--~~--'--------~-~~(=z=~-(
<<<<<<==++<++=+===<((~--~----~~--~~---'---'-'----~~~((+=<~~~
<<+<<<++<++=zzhzss=+<((~-~~--(~~~~-~---''---------~~((=s<(~(
<<+<+<<+<++=sz=sDz==+(((~~~~~~~~~-~~---'------~~~(~~~(+s<(((
<<+<++<++++<==+shDBs=+<(~~~~-~~~~-~~--~~~~~((((<((((((=s<((~
<<+<++++<<<+=<<+hhzzs+=<~((~~~~~~~~~~(~~(<<(+<+<+<(~(<++(<(~
<++<+++++<<=<=+<++<(=z=+<(((~~(~((<(<<<+=+++<<(((((((<==<((~
<+++<+++<<<++++++(<<szs=+<(<((((((<+==++ss=++<(((~(~(<=<(((~
++++++==+<<<++++++++++=z=<<((((<<<+==shDB==+s++(((~~(+=<(<~(
+++<<<<<<<(<<+<<++<+=+===+<(((<<+<<+<(+zz=~~<<<<~~~~(=<<<~((
<+<<<<+++<<(<<<<<<<++++++=((~~(((((+<((<+(-(((((--~((<<(((((
<(<<<=<<+<<<(<<<<<++<<<+++(~~-~~((<(<+((((~<<~~~~~~(<((<<(<(
<<<<<+<<<<<<<<<<<<<<<<<<<+(---~~~~(<++<<<<((~(~~-~~(z<(<<((<
+++=sz<=++<<<<<<<((<<<<<<<(~--~---~((<<<((((~~-~-~((.(<<(<((
<(<<<<<s++<<<<<<<<<<<<<<<<~---~~~-~~((((<((~~---~((+~<<(<<((
(<<<<+<<<+<<<(((<<<<<<<<<(~---~~~~~(~((~~(~~~--~-(<<<~<<<(<(
((((<<<<<<++<<<(<<<<<++<+(~---~-~~--~~((~~~-~--~~<<<<<<<<(((
<((<<<(<<<++<<<<(<<<<<++<(~---~~~~~~~~~~~~~~-~~~~<<(<<<<<<((
(((<<<<<<<+<<<<<<<<<++++<(~----~~(~~~~~~~~~(~~~((<<<<<<<(<((
(((<((<<+<++<<<<<<<<+++<((~---~~((((~~-~~~~~~~((<((<<<<<<~~(
(((<((<<<<<<<<<<<<<<++<<((~-~-~-~(((~~~~~~~~~~((<(((++<<<<~~
((((((<<<<<+<<<<<+<<=+<<((~~--~~~~(((~~~~~~~((((<<(((+<<<<<(
(((((<(<<<<++<<+++++=+<(((---~-~~~((((~~~~~~((<<(+<(((++<<<(
((((((((<<<++<<++<<<=+<<((~---~~~~~((((~~~(~((<<~+((((~<+<<<
s<(((<((<<<+<<++++++==<<((-~-(-~(~~~(((((((~((<~-~~(((~~(+<<
zzhhhh<((<<<=++++<+++s+<((~~-~~~~~~~~~(((~~(<<+~--<(((~~~(<+
|
More Posts
Next page »