This blog is a knowledge base...where I clip cool tricks and urls

Create / Edit Site

clipped from www.dotnet247.com
namespace IIS6
{
public class SiteCreator {
static void Main() {
// path to root of virtual directory, is not created by creating the
site!!
string rootVirtualDir = "c:\\NewSite";
string site = "MySpecialSite";
ConnectionOptions oConn = new ConnectionOptions();
oConn.Username = "webAdministrator";
oConn.Password = "adminpwd";
ManagementPath myPath = new ManagementPath();
myPath.Server = "HostNameOfWebserver";
myPath.NamespacePath = @"root\MicrosoftIISv2";
myPath.RelativePath = "IIsWebService.Name='W3SVC'";
ManagementScope scope = new ManagementScope(myPath, oConn);
using (ManagementObject nac = new ManagementObject(scope, myPath, null))
{
// create a ServerBinding WMI object
ManagementObject Bindings = CreateInstance(oConn);
 blog it

WMI Properties

clipped from www.csharphelp.com
  • IIsWebServiceSetting the IIS itself. This includes ASP settings, logging settings, authentication
    settings, etc.

  • IIsApplicationPoolSetting application pools (IIS 6.x specific). For each you can see the user
    credentials
    used, application pool recycling policy information, etc.

  • IIsWebServerSetting
  • IIsWebVirtualDirSetting
  • Win32_Battery
  • Win32_BIOS
  • Win32_ComputerSystem owner, the hardware model and manufacturer, etc.

  • Win32_ComputerSystemProduct hardware system including the serial number, name, vendor, version,
    etc.

  • Win32_DiskPartition
    Returns the created disk partitions (a
    disk partition may span multiple physical disks and contain multiple logical
    disks). For each you find the size, block size, number of blocks, etc.

  • Win32_Environment each you can see the name, value, if it is a system or user defined
    variable, etc.
  •  blog it

    WMI to config IIS

    clipped from blogs.msdn.com
    <?xml version="1.0" encoding="utf-8" ?>
    <webSettings>
         <webSites>
                 <webSite ServerId="1234" ServerComment="My Test WebSite" PathOfDefaultVroot="c:\inetpub\wwwroot\Test" >
                        <siteSettings>
                              <propertyList>
                                     <property name="AllowKeepAlive" value="True"/>
                                     <property name="ConnectionTimeout" value="90"/>
                              </propertyList>
                             <serverBinding Hostname="" IP="" Port="80"/>
                       </siteSettings>
                </webSite>
         </webSites>
    </webSettings>
    Many of us use scripts to setup our web servers, a lot of the work is boilerplate - create sites, vroots.... To ease  maintanence work over the last year i've moved to a data driven approach to setting up web sites. I use an XML configuration file to describe the web site and a driver program that uses WMI to configure IIS based on the XML. Some of the benefits of this are : you only need to make fixes to the single driver program
     blog it

    C# WMI to configure VirtualDirectory

    clipped from channel9.msdn.com

    ' Add a virtual directory to the site. This requires SpawnInstance().
    Set vdirClassObj = providerObj.Get("IIsWebDirectorySetting")
    Set vdirObj = vdirClassObj.SpawnInstance_()
    vdirObj.Name = strNewVdir
    vdirObj.AuthFlags = 5 ' AuthNTLM + AuthAnonymous
    vdirObj.EnableDefaultDoc = True
    vdirObj.DirBrowseFlags = &H4000003E ' date, time, size, extension, longdate

    vdirObj.AccessFlags = 513 ' read, script

    ' Save the new settings to the metabase

    vdirObj.Put_()
    ManagementClass clsIIsWebDirectorySetting = new ManagementClass(scope, new ManagementPath("IIsWebDirectorySetting"), null);
    ManagementObject dir = clsIIsWebDirectorySetting.CreateInstance();
    dir.Properties["Name"].Value = "W3SVC/" + account + "/ROOT" + path;

    dir.Put()
     blog it

    Unit Testing - extensions

    I know a bunch of people have not been too enthusiastic about the unit testing features built into VSTS. Some people have become infatuated to many of the features of mbUnit. They are cool. But I like VSTS because of the built in code coverage capabilities and the integration with TFS.

    1. Rollback. Yes...inspired by Roy, I created a Rollback attribute that wraps the annotated test in a System.Transaction that always gets rolled back. Usage

    [TestMethod]
    [Rollback]
    public void PerformSomeDatabaseTests()
    {
        //Make some databasebase calls...
    }
     blog it

    Bug with singleton and BindingList

    clipped from www.codeprof.com

    Data.Instance.Projects.ListChanged+=

    I have a Class, Data. This class contains several BindingLists, implemented via encapsulation. This class is a singleton, which is implemented on the following manner:

     blog it

    Bind - Part2

    clipped from msdn2.microsoft.com

    BindingList<T>

    BindingList<T> is a generic implementation of the IBindingList interface (from the System.ComponentModel namespace), the minimum interface required by the data binding infrastructure for list data sources to support editing. While IList is the minimum interface required to implement a binding-capable list data source, it doesn't provide editing capability, which is fine when bound to a non-editable control like ListBox. When bound to a control with full editing support like DataGridView, however, the ability to edit in a list data source is a must, as well as support for features like sorting, searching, indexing, and change notification. IBindingList derives from IList and extends to provide all of this support:

     blog it

    Bind Business Object to Datagridview

    clipped from msdn2.microsoft.com
    So, to build the UI, we need to turn a single Word type into a list data source, which should then be displayed through a suitable list or data grid style control. In this situation, I think the DataGridView control is a great candidate. Next, we need to ensure any edits are synchronized between the DataGridView and list data source. Because I'm anticipating a lot of data, a VCR-style control is needed to simplify navigation. Any such control should ensure that currency (current list position) is synchronized between it and the DataGridView as navigation occurs in either.
     blog it