Archive for the Category development

 
 

Invoking the Microsoft Log Parser COM Interface from managed code ( C# )

This will create an XML file that has your url’s that are refered to, hit count, and the referrer.

try
{
    Type comLogQueryType = 
        Type.GetTypeFromProgID("MSUtil.LogQuery", true);
    object comLogQueryObject = 
        Activator.CreateInstance(comLogQueryType);
 
    // Get the IIS Input and XML output filters
    Type ws3LogType = 
        Type.GetTypeFromProgID("MSUtil.LogQuery.IISW3CInputFormat", true);
    object ws3LogObject = 
        Activator.CreateInstance(ws3LogType);
    Type xmlLogType = 
        Type.GetTypeFromProgID("MSUtil.LogQuery.XMLOutputFormat", true);
    object xmlLogObject = 
        Activator.CreateInstance(xmlLogType);
 
    // Setup input and output files
    string inPath = "someIISlog.log";
    string outpath = "temp.xml";
 
    // Create a SQL query to get the referers, count and uri-to. Order by total hits
    string query = 
        "SELECT cs(Referer) as Referer,cs-uri-stem as To,COUNT(*) as Total from " +
        inPath + " TO " + outpath +
        " WHERE (sc-status=200) AND (Referer LIKE 'http:%') GROUP BY Referer,To ORDER BY Total DESC";
 
    // Invoke the ExcuteBatch method
    object[] inputArgs = {query, ws3LogObject, xmlLogObject};
    comLogQueryType.InvokeMember("ExecuteBatch", BindingFlags.InvokeMethod, 
        null, comLogQueryObject, inputArgs);
}
catch (Exception e)
{
    string errorString = "An exception has occurred: " + e.Message;
    Console.WriteLine(errorString);
}
 
[Via Steve Makofsky ]
 

Effective .NET Framework based development: Exception handing and Memory Management

Check out Brad’s slides on structured exception handling and memory management that he just published on his blog.

"This downloadable presentation is an overview of best practices and issues with the usage of exceptions, and different issues surrounding memory management including the IDisposable pattern, finalizers, memory pressure, HandleCollector, and why the using statement (Using in VB) is your friend! It’s an excellent overview of some fundamental exception and memory management topics."

CLR Exception and Memory Management

You can also check out more elaborate documentation ( .NET Framework Resource Management ) of the recommended guidelines for IDisposable and finalizers.

[ Via rgabostyle.com ]

Memory management best practices in C#.

If you’re interested in learning about memory management best practices in C#,you can download presentation that helps you to understand some aspects of managed memory.

Download Power Point Slides

[Via dougturn's Weblog]

JetBrains ReSharper v1.5 Released

This version features contains following refactorings

  • Extract Interface

    This refactoring allows users to create interface from a class and make that class implement the created interface. A user can choose members to extract to the interface and name of the interface. The refactoring is useful for specifying a class interface and using it where appropriate.

  • Extract Superclass

    With this refactoring you can create base class for a class and move some members to it. Just place caret at a class declaration, select members to extract and run the refactoring. It is very useful for moving some logic up to share it later.

  • Copy Type

    Create copy of a type with different name or namespace easily. The refactoring will also create separate file for it.

  • Introduce Field

    Select and expression or a local variable and apply this refactoring. It will create a new field or constant and initialize it with the expression or local variable initializer. The field can be initialized in its initializer, constructors or the current member.

  • Encapsulate Field

    Forgot to create accessor property for a field? Just invoke the refactoring and it will create it and also replace usages of the field with usages of the property.

  • Introduce Parameter

    Select an expression or a local variable in a method and this refactoring will create new parameter which will be properly initialized at all call sites.

  • Convert Interface to Abstract Class

    If you want to add some logic to interface or feel it better be a class you should invoke the refactoring and all appropriate conversions will be made.

  • Convert Abstract Class to Interface

    You can apply this refactoring to an abstract class and it will be converted to interface.

  • Generating «delegation» methods

    If you need to delegate the execution of particular methods to an instance of a particular class, you no longer have to do it manually. Just call the ReSharper | Code | Generate… command or press Alt+Insert shortcut, choose "Generate delegating members" and specify the target and methods to become delegates. ReSharper will generate all necessary code immediately.

Download ReSharper 1.5

[ Via David Hayden’s blog]

DataAdapter for CSV files

Cathi Gero posted some code that allows you work with CSV files using CSVDataAdapter . Nice job!

To read the contents of a CSV file:

CSVDataAdapter CSVda = new CSVDataAdapter(@"c:\MyFile.csv");
CSVda.HasHeaderRow = true;
DataSet ds = new DataSet();
CSVda.Fill(ds);
 

To write to a CSV file:

CSVDataAdapter CSVda = new CSVDataAdapter(@"c:\MyFile.csv");
bool InclHeader = true;
CSVda.Update(MyDataSet,"MyTable",InclHeader);
 

Page 34 of 37« First...1020...3233343536...Last »