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

    BindingList<T>

    clipped from www.gavaghan.org

    After reading Bil Simser’s discussion on DataTable vs. BindingList<T>, I’m convinced that BindingList<T> is the way to go for representing domain objects in C#. However, effective use of BindingList does require a certain amount of planning and forethought on the part of the developer. There are a number of things you can do to increase your chances of success with BindingList, but this post is about having your list items implement INotifyPropertyChanged in order to propagate change events through the BindingList itself.


    using System.ComponentModel;



    public class Account : INotifyPropertyChanged


    {


    private decimal balance;



    public event PropertyChangedEventHandler PropertyChanged;



    public decimal Balance


    {


    get


    {


    return balance;


    }


    set


    {


    balance = value;


    if (PropertyChanged != null)


    {


    PropertyChanged( this, new PropertyChangedEventArgs(”Balance”) );


    }


    }


    }


    }


     blog it

    Class extensions, statci method

    clipped from blogs.msdn.com

    After the declaration of C# 3.0 I went ahead and installed the PDC bits. After reading through the language spec. I was very very very unhappy. I mean we were just getting excited over C#2.0 supporting generics, anonymous mehtods, Nullable types and then suddenly someone ruins all the fun by showing us C#3.0. C#2.0 already appears stale. Some great blogs on this are from Cyrus and Matt Warren

    List<string> first = new List<string>();

    first.AddRange (new string[] {"Hello", "how"});

    first.Print();

     blog it

    Paste Special Catch Events

    You know the situation: You have carefully setup a workbook with intricate Validation schemes. But then along comes your user and he copies and pastes at will. Result: Validation zapped, workbook structure violated.

    What to do? The only way I find to be reliable is to catch all possible paste operations. But this isn’t very easy, since there are a zilion ways to paste.

    I have put together a sample workbook and an explanatory article on how one could go about protecting a workbook by intercepting paste operations.

    Let me know what you think!!

     blog it

    excel > hook on pressed keys

    Ctrl+C , Ctrl+V , Ctrl+ X
    Copy, Paste, Paste special
    Have you considered using the Application.OnKey method? You can intercept just about any key press possible by using this method. Here is some of the description from Excel help:
    Procedure   Optional Variant. A string indicating the name of the procedure to be run. If Procedure is "" (empty text), nothing happens when Key is pressed. This form of OnKey changes the normal result of keystrokes in Microsoft Excel. If Procedure is omitted, Key reverts to its normal result in Microsoft Excel, and any special key assignments made with previous OnKey methods are cleared.
    Remarks
    The Key argument can specify any single key combined with ALT, CTRL, or SHIFT, or any combination of these keys. Each key is represented by one or more characters, such as "a" for the character a, or "{ENTER}" for the ENTER key.
    Runs a specified procedure when a particular key or key combination is pressed.
    expression.OnKey(Key, Procedure)
    expression   Required. An expression that returns an Application object.
     blog it

    Events and windows messages in Excel

    roos01, after reading about my abundance of memory do you think that is really worth doing? My declarations are as follows:

    Module 2:
    ' KEYBOARD INPUT API DECLARES
    Private Declare Sub keybd_event Lib "User32.dll" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
    ''^Presses any given key
    Private Const KEYEVENTF_KEYUP As Integer = &H2
    Private Const VK_BACKSPACE As Integer = 8
    Private Const VK_TAB As Integer = 9
    Private Const VK_SHIFT As Integer = 16
    Private Const VK_CONTROL As Integer = 17
    Private Const VK_ALT As Integer = 18
    Private Const VK_SUBTRACT As Integer = 109
    Private Const VK_DEMICAL As Integer = 110
    Private Const VK_F5 As Integer = 116
    Private Const VK_ACCENT As Integer = 192
     blog it

    Speed up VBA code tips

    clipped from www.ozgrid.com
    Sub StopAllEvents()
    Application.EnableEvents = False
    'Your code here.
    Application.EnableEvents = True
    End Sub
     blog it

    Future gmail improvements

    New chat
    All cached ... wow

    Gmail: Past, present, and future


    ZDNet Executive Editor David Berlind interviews Keith Coleman, Google's Gmail product manager, about the current status of Gmail and the future of this popular Google app. Coleman also covers other Gmail issues, including the rebuild of the Javascript engine and how strongly Google feels about users' data.

     blog it

    Data Context - blog

    clipped from blogs.msdn.com

    The Customer and Order Entity Classes

    In the previous post we dragged the Customers class from the Northwnd database onto the LINQ Object Relational Designer. A number of things happened when we did this:

    • A class called Customer was created. This class maps directly to the Customers table in the Northwnd database.
    • The DataContext was modified. I will describe how it was modified later in this post.

    When a developer accesses an instance of the Customer class, it is almost as if they have direct access to the Customer table in the database. Figure 1 shows the fields of the Customer table as they appear in the Object Relational Designer.

    image

     blog it