/// <summary>
/// Converts NULL values to String.Empty in any object
/// </summary>
/// <param name="o"></param>
public static void ConvertNullToEmptyString(object o) {
    Type stringType = typeof(String);

    var q = from n in o.GetType().GetProperties()
                    where n.PropertyType == stringType
                    select n;

    foreach (PropertyInfo p in q)
        if (p.GetValue(o, null) == null)
            p.SetValue(o, String.Empty, null);
}

The above code is a little function that I wrote that converts all NULL string references in an object to String.Empty.  Don’t forget to add in a Reflection using statement.

public myTestClass myTestClass() {
    myTestClass n = new myTestClass();
    //    ?Get from Database?
    n.string_1 = null;
    n.string_2 = "Hello";

    //    Convert null values
    ConvertNullToEmptyString(n);

    //    Return the new object
    return n;
}
/// <summary>
///    Simple class
/// </summary>
public class myTestClass {
    public string string_1 { get; set; }
    public string string_2 { get; set; }
}

This example shows how it could be used.  This way, when running a JSON based webservice, the data returned van be filtered through ConvertNullToEmptyString and that will make JavaScript much happier, rather than having to deal with … “string_1” : "null, … we get a : “”, which is then immediately usable.

- Matthew

ASP.NET, AJAX, and jQuery

| | Comments (0) | TrackBacks (0)

I’ve been doing a lot of ASP.NET work lately, and have in fact enjoyed it very much.  Since this is a new and “recent” development due to my past being in Classic ASP, then PHP I have had a lot of new things to learn.. also, for nearly the last two years, I have been doing WinForms only programming, and have forgotten a lot of the stuff I once knew!

The ASP.NET model is considerably different from the PHP 4 model.  Some things are far easier, and other things are just different.  I wanted to learn how to use an HTML/JavaScript/ASP.NET model [like I would do in PHP] and had a few things to figure out.  Fortunately, there exists a lot of places where people have pioneered this stuff before I did.

Here is how to use jQuery with ASP.NET 3.5.

Figure 1:  Create a new C# .NET 3.5 Web Service [SampleService.asmx]

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;

namespace admin {
    /// <summary>
    /// Summary description for CMSWebServices
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]    
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    [System.Web.Script.Services.ScriptService]
    public class WebServices : System.Web.Services.WebService {

        [WebMethod]
        public string HelloWorld() {
            return "Hello World";
        }
    }
}

Well, that was simple.  Most of the code as you can see, is already written for you by Visual Studio.

Figure 2:  Define an ASP.NET Page [SampleConsumer.aspx], add jQuery, and this script

<script language="javascript" type="text/javascript">
                function testme() {

                    $.ajax({
                        type: "POST",
                        url: "SampleService.asmx/HelloWorld",
                        data: "{}",
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        beforeSend: function(xhr) {
                            xhr.setRequestHeader("Content-type",
                         "application/json; charset=utf-8");
                        },
                        success: function(msg) {
                            alert(msg.d);
                        }
                    });

                }
</script>

Figure 3:  An HTML button in the ASP.NET page

<input id="Button1" type="button" value="button" onclick="testme();"/>

Well, that was easy, eh ?  Simply pushing the button will write HelloWorld in the Alert Box.

Figure 4:  Sources
http://encosia.com/2008/06/05/3-mistakes-to-avoid-when-using-jquery-with-aspnet-ajax/
http://encosia.com/2008/05/29/using-jquery-to-directly-call-aspnet-ajax-page-methods/
http://encosia.com/2008/03/27/using-jquery-to-consume-aspnet-json-web-services/

I found those series of articles to be extremely helpful in figuring all of this out.  Next time, I hope to write a little bit more about what I’m doing, but wanted to make sure this information was easy to find.  It took me a little while to dig up the exact ‘how-to’ and read through all of the information on the topic.

Note:  This is a little sloppy, sorry :)  I just don’t feel like going to indepth on this topic.  You can find additional resources using the links above. 

YMMV.

- Matthew

The Wonders of ASP.NET & C#

| | Comments (0) | TrackBacks (0)

Recently, I've been digging into Microsoft's ASP.NET platform.  As you know [or don't] I've been working with C# heavily for the last two years, but in a WinForms environment.  Before that, I was doing all of my programming using LAMP.. PHP, HTML, and JavaScript - by hand, no doubt.  I have spent countless hours coding JavaScript applications.  Once the "AJAX" revolution hit {I had been doing "AJAX" before the term "AJAX" was coined, using IFRAMES, and other nifty ways of getting data back-and-forth to the server, Prototype.js was a godsend though!} I moved most of my code to JavaScript, and used PHP as a simple backend for delivering JSON formatted packets of information to the client.  Instead of having a bunch of mixed code, I moved closer to the MVC model with a lot of separation.

Since there's a [business] need for me to move back into Web Development, I convinced the 'uppers' that it would be a wise investment to look into ASP.NET for creating our solutions.  There has been a lot of grief because of that, but in my opinion -- it's a better platform, and there is no doubt in my mind about that.  I am so incredibly impressed with how the .NET model works.. and if in practice, how it is in theory works out the way that I think it will, it will make us deliver better products, in a shorter amount of time.  I'm currently teaching our designer how the model works, and how to effectively use it.  He'll be able to produce me 'ready-designer-made' files and all I will have to do is plug in the functionality in the code-behind model, and make sure that things work.

Just simply writing an AJAX type-of function in ASP.NET is 100x easier than what I would have to do 'the old fashioned' way using PHP & JavaScript.  See below:

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
        <asp:ListBox AutoPostBack="true" ID="ListBox1" runat="server" onselectedindexchanged="ListBox1_SelectedIndexChanged" Width="343px"></asp:ListBox>
        <asp:TextBox ID="TextBox1" runat="server" AutoPostBack="true" ontextchanged="TextBox1_TextChanged" Width="242px"></asp:TextBox>
        <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" Width="102px" />
        <br />
        <br />
        <asp:Label ID="Label1" runat="server" Text="Label" BackColor="#FFFFCC"></asp:Label>
        <br />
    </ContentTemplate>
</asp:UpdatePanel>

Above is a sample of how AJAX is done is ASP.NET 3.5.  Everything just worked, and on the first try.  I'd type something in the search box, hit the button, and my listbox would be populated with data from the server.  That would have taken me quite a bit more time to do if I had to code everything manually.

However, I am not happy with this model.

There exists a far superior one.

It's called.

Gaia Ajax Widgets {Gaia Ajax Widgets}.

I've mentioned it before in my Dev Tools.  I work closely with the core developers, learning, working with, suggesting, and sometimes working on the product.  It turns the ASP.NET world upside down!!  Fortunately, I've had the opportunity to work with their controls from their as-yet unreleased version.  They are TERRIFIC.  In the above example, the JavaScript that is sent to the browser from the .NET engine is over 6,000 lines of code.  With Ajax Widgets, only about 200 or so.

To recreate the above example:

<gaia:ListBox .../>
<gaia:TextBox .../>
<gaia: Button.../>

Now, their controls are much richer as well.  Instead of having to rely on the user pressing the button to pass their results to the server, I am able to do something LIKE the following:

<gaia:TextBox InputTimeLimit="200" OnTimerTick="PopulateListBox"/>

The above is not exact, I'm paraphrasing because I do not have the parameters right in front of me.  Simply though, I am telling the control that 200ms after the user has last entered a key, fire off a server side event.  My Codebehind would look something like this:

protected void PopulateListBox() {

string input = TextBox1.Text;

// Do some sort of searching here

foreach(...) {

ListBox1.Items.Add(...);

}

}

The server would populate the listbox, and the results would be instantly transmitted to the client.

This is a much cleaner, and simpler than using Microsoft's AJAX model.  Less code, less confusion, faster development, better quality.  The data that is sent back to the listbox by the way.. instead of what Microsoft does which is send basically the .innerHTML to a control (<select..><option><option><option>...) this sends only the *data* and the JavaScript that AjaxWidgets wrote parses it and populates the listbox.  This could mean substantially less time for the client to wait while fulfilling a large request.

There are a million other controls, and they are all top-notch.  There is no way I could do in PHP/HTML/JS what I could do with ASP.NET/C#/Gaia Ajax Widgets in the same amount of time.  I would have a complete, simple, entire application done before I was even done coding a login page in PHP. 

In my opinion, ASP.NET is a better platform and with the right tools - can kick ass over any other development language, especially for rapid prototyping.

- Matthew

I just purchased a new hard drive for my laptop, a Seagate Momentus 7200.2 200GB drive.  Let me tell you - this thing is FAST.  Let me also mention that what I'm saying is no means scientific, and the environment in which I did the testing was not something I would consider "reliable" or "clean".  This is anecdotal evidence at best.

Seagate Momentus 7200.2 @ NewEgg

image

Above is a picture of HDTune showing the performance of the drive.  I am extremely happy with it, and it totally kicks ass over my slightly older Hitachi HITACHI Travelstar 7K100 HTS721010G9SA00.  Here is an ugly comparison shot of the Hitachi drive:

image

As you can see, the Seagate drive outperforms the Hitachi drive right from the start!

So, if you have a laptop and are looking for an inexpensive hard drive upgrade (@ time of purchase, $149 w/ free shipping from NewEgg) then I completely recommend the Seagate drive.  Also, the software available from Seagate's website to do the transfer was extremely easy to use.

I hooked up my new Seagate drive to a SATA->USB Converter.
I loaded up the backup software Seagate Disk Wizard.
I told the software that I wanted to clone my Hitachi drive to the Seagate drive.
It copied all 5 of my partitions to the new drive, including my Truecrypt partition.
The system rebooted, and then started doing the file transfer (Windows did not load, just the bootloader - i.e., where checkdisk and boot time defrag runs)
The system then let me know it was complete, and prompted to shutdown the computer.

Everything feels considerably faster now, and I am no longer waiting for the inevitable hard drive grind I usually get when I have a lot of programs active!  VMWare runs a lot faster as well, and everything just seems smoother and where it is supposed to be.  Additionally, the Seagate drive is Q-U-I-E-T (quiet) !!!  I could hear my Hitachi drive a mile away when it was busy.. I can not hear this drive at all.  Some people on the NewEgg message board mentioned vibration and other noises of which I have had no issues with.

I whole heartedly recommend this drive to anyone.  It was inexpensive, easy to hook up, easy to transfer the data (I usually use RIP & NTFSClone/Partimage/etc.), and boat loads faster.  As always, YMMV, but I am extremely happy/impressed with the new drive.  All is right in Matthew land. :)

- Matthew

My Favorite Tools List for Developers

| | Comments (0) | TrackBacks (0)

Everyone else is doing it, and so should I :)  It's a good idea as well, because I may have to go looking to find out what I need to install on my machine the next time I decide to reinstall it.  Fortunately, I have a few things I use that I think are unique to me, that I haven't seen elsewhere.. so that makes me extra-cool in my book.

  • Webdrive - Webdrive is such a fantastic tool.  It allows you to connect to remote sites via FTP, SFTP[SSH], WebDAV, and a few other protocols.. the kicker is this:  It maps them as drives on your machine.  So for instance, I can have "Z:" mapped to ftp://www.csharpbydesign.com.  How utterly cool is that ?!
  • Pidgin - Everyone needs a cross platform, multi protocol IM client.  Pidgin is by far the best, and I think is better than all the rest.  Source code available.
  • SpeedSwitchXP - Because being able to change your CPU power from "mobile/battery/dynamic" to "max performance" in a click is nice.  Source code available.
  • KeePass (2.05Alpha)- I just recently discovered this gem (see my previous post Password Protection Utility) and I absolutely love it.  It's my new second brain.  Source code available.  A note on the source code - this has got to be the best looking source code I've ever seen in an Open Source application.  While there are very few code comments, it is almost self explanatory and extremely clean and concise.  I downloaded the source, opened it up in VS '08 and it just *worked*.  I could immediately run it and open up my password database.. not a lot of products work just "out of the box" like that.  I was impressed.  The author is old-school C++ so the code is full of m_'s, but that's not so bad.  You can tell he is a top-notch expert programmer.
  • RSSBandit - This is by far the best RSS reader that I have tried.  While I might like to try others, I'm sort of locked in at this point.. too much data to lose!  It downloads all of the posts and saves them locally which is a great feature.  I am a data collection junkie, and I would hate to lose the last 6-8 months worth of blog posts I've collected.  Source code available.
  • LogMeIn Ignition - I have a lot of remote sites that I need to control the machines of, and I use their Free version of LogMeIn, but pay for Ignition because it keeps everything in one place in a desktop app.. single click remote connect.
  • Developer Express Enterprise - Because these are some of the best .NET development tools I have ever used.  I've seen the competition and was just nowhere near as impressed with their products as I was with DevEx.  They are quick to fix bugs, update versions and add new functionality, send you daily builds if they have to, and have top-notch support.  The price is fair, and updates are included for a year.  Source code available ($).
  • Firefox 3 - Because it kicks ass over Firefox 2.  I was a die-hard Opera user for years, but Firefox 3 has taken the lead in my opinion and I've nearly stopped using Opera.  I was using the latest Beta version [9.50] and they haven't made any updates in months, and I was having some issues with it.. so I decided to try out the new Firefox and was pleasantly surprised.  Source code available.
  • Visual Studio 2008 - 'nuff said.
  • Putty - I have my own Linux server and there's nothing like opening up an SSH connection easily.  Putty is hands down the best SSH/telnet app available.  Source code available.
  • SnagIt/Camtasia Studio - Because being able to record/snap your desktop and make presentations easily is a nice thing to have.  Fortunately, I got a free version and am very happy with it!!  There's no way I could get my company to shell out for the latest-and-greatest, but it sure is a neat product. 
  • Jing Project - This is a new project by the folks that made SnagIt & Camtasia.  Currently, it's free but that may change in the future.  Seems to be a pretty nice program with quite a few options.  It takes a little getting used to, but I like it.  The "top" button (in the center of your screen) can be removed and it can be made to only sit in your System Tray.
  • LINQPad - Lets you run C# expressions/statements quickly and easily, in addition to being able to test LINQ statements easily.  Joseph Albahari is the author, and did a fantastic job on this must have utility.
  • Search and Replace [SR32] by Funduc software -This is a great search and replace utility.  I use it all the time for finding things, and doing mass replaces.  I'm quite happy with it and have been using it for nearly 10 years!  I haven't really looked for an alternate application to do the same thing.
  • MySQL Front Version 2.5 - Unfortunately this is abandon ware and is hard to find, but the 2.5 [the last "real" one] version of MySQL Front is amazing.  Lightweight, easy to use, and very functional database manager.  It still works with the latest MySQL database.  I am going to be very sad when MySQL-server is no longer able to work with this software.
  • HeidiSQL - I decided to check out the new incarnation of MySQL-Front again, and to my surprise HeidiSQL is actually pretty nice.  There are some differences between it and MySQL-Front that I don't like (doesn't seem to store "LIMIT" checkbox when exiting, but I'm sure I'm missing something) but I think I can get used to it and it has a LOT more features than MySQL-Front.
  • HomeSite 5.5 - Because I still write in PHP, and it's one of the best plain-jane HTML editors available.  I hate that there have been no updates made to this thing in so long, but that's probably a good idea as it would probably get bloated and messed up.  I've never used any of it's "fancy" features, I only like the HTML, PHP, and JavaScript color coding.
  • FreeLaunchBar - OMG!  I love this product.  I have a series of button icons in my Quick Launch that open up menus with my applications in them.  I don't like TrueLaunchBar though, as it has far to many bells and whistles for me.. but I would easily pay for FreeLaunchBar if there was a fee for it.
  • True Launch Bar - Unfortunately, Free Launch Bar doesn't work with Windows Vista.  So I had to buy True Launch Bar, and I highly recommend it.  The author is very responsive to support questions (see their forums) and the product is rock solid.  Additionally, he also worked out a deal with me - so it's high on my list of excellent products, an excellent company, with excellent support.
  • NuGenUnify/ILMerge - ILMerge is a Microsoft Research application for merging .NET assemblies into a single unit (for instance, your app has 100 dlls, merge them all into one single executable with your main application, easier distribution!).  NuGenUnify is a freeware program that is a GUI for ILMerge and makes life considerably easier than the command line.  Source code available ($).
  • NotePad++ - I am still getting used to this, but it's nice having tabs in "Notepad" and color coding.  Very lightweight.
  • Reflector! - Being able to look at other peoples code with the click of a button and learn cool-new-ways that they did things.  How awesome is that!?  I am however surprised that the Source Code is NOT available, and you can't use Reflector! on it :(
  • Microsoft OneNote - I have a TabletPC, but I don't use it anymore unfortunately so note-taking is not quite as fun as it used to be, however OneNote is still a great app and I put lots of things into it, especially Programming Solutions so I don't ever lose them.
  • Microsoft Office 2007 - Duh. I am a huge Outlook fan and probably always will be.  It's a bit bloated, but I've been using it for over 10 years, and there is just no switching.  I tried Thunderbird once, but was not impressed.  I suppose the only thing I could do, is write my own client.. but that would be to much work, and it would look just like Outlook!  I really only use it for email, nothing else.
  • Windows Live Writer - I'm writing this post with it now. I like it!  It even has a "Insert from Visual Studio" plugin which makes your pasted-code look pretty.  It is simple, and works with just about any blog.  Not only that, but it is extensible.
  • WinDirStat - excellent utility for seeing a visual representation of your drive usage.  Really neat program.  Source code available.
  • PerfectDisk - Excellent disk de-fragmentation utility.  Easy to use.
  • JKDefrag - Free and excellent disk de-fragmentation utility.  A little complicated to use, few "easy" options, but an excellent piece of software none the less.  Source code available.
  • Paint.NET - Great Photoshop alternative for those of us that don't know how to use Photoshop but for the basics.  Source code available.
  • 7zip - Next gen archive utility.  Way better than WinZip/PKZip. Source code available.
  • VMWare - Because everyone needs virtualization.  Note:  Not good to run it with Virtual PC side by side. :)  I HATE the new version of VMWare Server that is Vista compatible.  It's a bunch of web-based crap.
  • XMLPad
  • TortoiseSVN - Best SVN client for Windows.  Using a VS Subversion menu toolbar that some guy made makes it really rock!
  • Gaia Ajax Widgets - This set of AJAX controls for .NET is simply AMAZING.  By far the best AJAX implementation and controls for .NET, period.  Lightweight, easy to use, powerful, and totally kicks ass over ASP.NET controls, and many of their other direct competitors.  This toolkit is the #1 AJAX library for .NET in my opinion.  It is incredibly simple, but very complex.. it allows you to do just about anything that you need to do without writing a single line of JavaScript code.  Source code available.  ("Full Disclosure" - I am somewhat involved in the project, and know the author/owner, and have made some small contributions to the project and hope to make more in the future)

Well, that is just about it for my list!!  I hope it was worth the read.  These are the utilities that I use on a daily basis and for me are the best possible.  I've seen a lot of lists like this floating around the Internet, and wanted to add my opinion to the mix.  Some of these things are just indispensable (like Webdrive) to me and I wanted to share with you what I think are the best utilities to have on your development box.

*UPDATE 06-16-08:  I added links.

- Matthew

Password Protection Utility

| | Comments (0) | TrackBacks (0)

I was browsing one of the blogs that I read from time to time, and noticed a utility posting for a program called KeePass!

It's an open source application that stores and manages your passwords for you.  I was really impressed with it.. it's fast, convenient and allows exporting of your passwords.  Above all - it seems safe and uses some of the best encryption methods available.

If you're looking for an excellent, free, secure, and open source password management tool [Windows only, it looks like] then this one looks like a fantastic tool to use.  It also auto-writes your username & passwords to a webpage with a single click!! 

For me, this means that I can A: change my passwords to more secure entities and not have to worry about remembering them all.

P.S.  I'm not sure the above is such-a-good idea :P

P.S.S.  I switched to using Windows Live Writer for writing posts in this blog, and I'm quite happy with it so far!

- Matthew

I had a requirement for a project that I am working on.  The project consists of a Windows 2003 Web Server serving up custom C# Web Services, and a public-facing LAMP [Linux, Apache, MySQL, PHP] web server.  I have certain data that I am storing in a MySQL database that must be encrypted.  Given that this is a webserver symmetric encryption does not make sense because if someone gained access to the PHP files, they would have the password to decrypt the data!!  That would be bad.

So I chose to do asymmetric encryption, thus only the Public Key would reside on the server.  The PHP scripts would encrypt the data, store it in a database, and when needed would be transmitted to the web-services server and decrypted using C#.  This proved to be a rather daunting task however. 

PHP requires either an X509 certificate, or a PEM certificate.  On the surface, .NET does neither!  The RSACryptoProviderService was able to create keys, but they were in some XML format which was incompatible with what I needed to do with PHP.

It turns out that I needed to use X509 certificates to accomplish what I needed.  Yikes, I had absolutely no idea what X509 was and how I was going to use it.  Little did I know that the internet was going to conspire against me and make finding all of the information that I needed virtually impossible.  After spending countless hours going over the MSDN, web pages, and other resources.. I finally managed to figure out what exactly needed to be done.

Following this blogpost on using Makecert I was able to create a certificate authority to sign my certificate, and create a certificate.  I installed in it in the Certificate Store, exported BOTH the Private and Public key file.  The public key I exported in BASE64 (second option) and the private key in PKCS#12 (PFX) format.  The private key is readable by .NET for the decryption.

I sent the public key to my PHP webserver.  Using the following code I was able to encrypt a string:

Now on the .NET side.. here is the code I used to decrypt the data using a private certificate file:

/// <summary>
///
Decrypt data
/// </summary>
/// <param name="Base64EncryptedData"></param>
/// <param name="PathToPrivateKey"></param>
/// <returns></returns>
public static string DecryptEncryptedData(stringBase64EncryptedData, stringPathToPrivateKeyFile) {
    X509Certificate2myCertificate;
    try{
        myCertificate = newX509Certificate2(PathToPrivateKeyFile);
    } catch{
        throw newCryptographicException("Unable to open key file.");
    }

    RSACryptoServiceProvider rsaObj;
    if(myCertificate.HasPrivateKey) {
         rsaObj = (RSACryptoServiceProvider)myCertificate.PrivateKey;
    } else
        throw new
CryptographicException("Private key not contained within certificate.");

    if(rsaObj == null)
        returnString.Empty;

    byte[] decryptedBytes;
    try{
        decryptedBytes = rsaObj.Decrypt(Convert.FromBase64String(Base64EncryptedData), false);
    } catch {
        throw newCryptographicException("Unable to decrypt data.");
    }

    //    Check to make sure we decrpyted the string
  
if(decryptedBytes.Length == 0)
        returnString.Empty;
    else
        return
System.Text.Encoding.UTF8.GetString(decryptedBytes);
}

There you have it! That's it in a nutshell. By using the X509Certificate2 class, I was able to read in the key [this reads in several key formats, by the way], then create the RSACryptoServiceProvider object and cast the .PrivateKey field into it, and perform the decryption.

- Matthew

Generic C# Object Copy Function

| | Comments (0) | TrackBacks (0)
Hi everyone, sorry I haven't completed writing about my Plugin system, but I did successfully find a solution to my issues, and created a flexible system which works very well.  I'll get more into that later, but I'm very happy with it and am not able to quickly create plugins of different types and use them within my applications.  The database code is so utterly simple [ I wrote 3 different database plugins, for MySQL/SQL Server/MS Access ] to use:




However, that's not what the subject of this article is!  I needed a quick and easy way to copy objects of differing types to one another, as long as they have matching fields.  An example would be a base class, to a derived class of similar type.. but they're different, so you can't just do a direct assignment!  Here is the code:



Usage:
tbl_myTable source = new tbl_myTable();
tbl_myTableDerived dest = new tbl_myTableDerived();
source.name = "Joe";

CopyObject(source, dest);

MessageBox.Show(dest.name); // "Joe";

Only fieldnames that are equal in both classes will be copied.  For thoroughness, it would be better to make sure the types are also equal -- but I don't need to go through the hassle of that, in my scenarios the field types and names will be equal.  YMMV.

Thank you!  I hope someone finds this very useful.

- Matthew MacSuga
So say you have a database connection [DataSet] that you have added to your project.  You do not want to store the password with it (which will end up in the .config file) and may want to change the database name at runtime from what you are using at runtime.  Doing this seems a bit off, since you can not write to the ConnectionString that is creating in the settings portion of the VS designer!  You can not change it to type User instead of Application scope either.

A useful tidbit that I discovered when looking for how to change this.  While it should seem immediately obvious how to modify a connection string at runtime, it is not.  After doing some digging I found the following code to place in Settings.cs [Go to settings, then click "View Code"].

In Settings.cs:
Now when working with your dataset, each time it needs to get the connection string it will return your custom connection string.  This is useful incase you do not want to store the password in your configuration files.  Also, this will allow switching different databases of the same type with your dataset at runtime.  I do that -- I have a "master" database that I use for development, and at runtime I switch to the live database.. both have exactly the same type of structure.

Hope you find this useful!

Matthew MacSuga

My First Post - A C# Plugin Paradise

| | Comments (0) | TrackBacks (0)
First post!

Thank you for finding my little spot on the Internet.  I hope that you find what I am planning to write to be not only helpful, but insightful.  When I'm looking over here and over there for information I come across so many sites and ideas that I have a difficult time of keeping track of everything.  With this blog, for my own purposes.. I plan on collating the ideas that I find into one solid resource on a particular subject, while injecting my own ideas and experiences into a particular subject.  I have high aspirations for what I am attempting to do here, and I hope that you thoroughly enjoy reading what I have to write.

Without further interruption, here is the first post in what I hope is a good series of posts on the elusive subject of:  Plugins, Addins, and application Extensibility.

So I've been working with C# for some time now and over the past year I have been tinkering with supporting Plugins off and on.  I decided this week that I really needed to dig deep and get a flexible plugin architecture written for my application(s) so that I, and 3rd party developers could easily extend my application beyond what I initially write. 

There are so many, and so few resources on this subject.   It's really quite surprising that it is so incredibly difficult to find the right resource.  Every article that I have read implements plugins in a slightly different way.  Some go straight for the meat and simply load the plugin (Assembly.LoadFile / Activator.CreateInstance) while others do it the "better" way and properly create a new AppDomain and then load the plugin(s).

What I am struggling with is making a system that is flexible, powerful, easily implemented, efficient, and fun to work with.  I need to have several different types of plugins -- database plugins (MySQL, SQL Server, SQLite, MS Access), different UI layers (each client has their own unique interface to the core of the application), different printing functions (again, based on client), etc.  So the huge question is, how do I implement this in a way that's effective and has a solid foundation on which to base an entire application.

Some have suggested using CAB (Composite Application Blocks) which is part of Microsoft's Patterns & Practices library.  While this is very effective, it is also a beast at first glance.  Not to mention, I am (for good or bad!) one of those programmers who just has to do it on their own.  Part of the reason for that is building a solid understanding of exactly what it is that I am doing.  Surely I could build an entire application based on and around CAB, but I would want to dig at the internals and understand all of the nuts and bolts on how it works. If I design such a system myself, then I will have complete control over the end product and fully understand exactly how it works.

In future posts, I will be posting sample code as I move along in my discovery of how building a plugin system actually works -- with real, concrete examples so that you dear reader, can take it and build something for yourself.  I hope to cite examples on how I came to my conclusions and give credit where credit is due.

Speaking of credit, I would sincerely like to thank all contributing members of The Code Project (http://www.codeproject.com) for all of their hard work in teaching me how to be a better programmer, and learn new tricks.  Without that resource, I certainly would not be where I am today and have the understanding of C# and the .NET framework that I do now.  I have found it to be an invaluable resource and check it for new articles everyday hoping that I will learn something new and exiting on which to base future works.

Thank you !

Matthew MacSuga

Find recent content on the main index or look in the archives to find all content.