Sunday, January 29, 2006

2191.aspx

egilhComTracker: Free component to track com+ call times with

The Component Services Console displays all sort of useful information like the number of objects in call, average call time etc. But, there is no official way to get the com+ call timers directly. You have to do the dirty work yourself and calculate the average call times. There is an official way and documented way to do this but it takes a lot of code and work. I found a way  to get the com+ call times the unofficial way which is a lot simpler. The egilh COM+ tracker gives you access to all the hidden statistics in COM+.


The egilh COM+ tracker download contains the com+ call time tracker and a VBScript example client. You can do a lot of neat stuff with it:




  • Use it a ASP page to monitor the call time of your components live
  • Use Cacti to show how average call time changes during the day.
  • Use the COM+ Admin API to automatically shut down/recycle components with high call times

Installation



  • Download the egilh Com+ Tracker
  • Extract the files
  • Register the DLL in COM+ or run regsvr32 EgilhComTracker.dll in the directory where you extracted the files

Usage
The egilh.ComTracker object only has one method: string getStatistics()


It returns a xml formatted string that contains information about all the running applications. The XML has the following layout:
/applications
  /application
     /classes 
         /class


Example:


<applications>


      <application>


      <guid>{98CDBB6E-3CAF-46F2-ABE6-EABECD6AA4EB}guid>


      <ID>10ID>


      <processID>1792processID>


      <statistics>


            <callsPerSecond>0callsPerSecond>


            <totalCalls>0totalCalls>


            <totalClasses>1totalClasses>


            <totalInstances>1totalInstances>


      statistics>


      <classes>


            <class>


                  <progID>Test.Sleep.1progID>


                  <bound>1bound>


                  <inCall>0inCall>


                  <pooled>-1pooled>


                  <references>1references>


                  <responseTime>120responseTime>


                  <callsCompleted>0callsCompleted>


                  <callsFailed>0callsFailed>


            class>


      classes>


      application>


applications>


 



Test client
The following VB code shows the call times for all classes registered in com+ on the local machine.


Dim oTracker 'As Object


Dim sResult 'As String


Dim oDOM 'As DOMDocument30


Dim oNode 'As MSXML2.IXMLDOMNode


 


'Get the com+ call times


Set oTracker = CreateObject("egilh.ComTracker")


sResult = oTracker.getStatistics()


Set oTracker = Nothing


   


'Display call times


Set oDOM = CreateObject("MSXML2.DomDocument.3.0")


oDOM.loadXML (sResult)


For Each oNode In oDOM.selectNodes("/applications/application/classes/class")


   WScript.echo oNode.selectSingleNode("progID").Text & _


          " call time: " & oNode.selectSingleNode("responseTime").Text


Next


 


With all the call information at hand, it is also possible to shut down components with high call times etc. The example below loads the XML returned by the COM+ tracker in a DOM using MSXML 3.0 and checks the responseTimes. It uses the COM+ Admin API to shut down the application if the call time is higher than the configured MAX_CALL_TIME and there are objects in call. The ShutDownApplication method works on Windows 2000 as well as Windows 2003. It has the same "brutal" effect as right clicking a COM+ application and selecting "shut down"; clients currently in call will get a COM+ error. With Windows 2003 it is possible to use recycling which routes new request to a new application instance but lets existing calls finish.


Option Explicit


 


Const MAX_CALL_TIME = 10000  'Max allowed call time in miliseconds


Const CHECK_INTERVAL = 5000  'How often we should check the call times


Const RECYCLE_REASON = 408  'The reason for the recyle. Any number is OK


 


 


'Never ending main loop that monitors the call time


Do While True


    checkCallTimes


    WScript.Sleep(CHECK_INTERVAL)


Loop


 


Private Sub checkCallTimes()


'**


'Purpose: Check the call times and shut down applications that have too high call times


    Dim oTracker 'As Object


    Dim sResult 'As String


    Dim oDOM 'As DOMDocument30


    Dim oNode 'As MSXML2.IXMLDOMNode


    Dim sProgID 'As String


    Dim lResponseTime 'As Long


    Dim lInCall 'As Long


    Dim oApp 'As MSXML2.IXMLDOMNode


    Dim bHighCallTimes 'As Boolean


 


     'Get the com+ call times


    oTracker = CreateObject("egilh.ComTracker")


    sResult = oTracker.getStatistics()


    oTracker = Nothing


 


    bHighCallTimes = False


 


    'Check call times


    oDOM = CreateObject("MSXML2.DomDocument.3.0")


    oDOM.loadXML(sResult)


    For Each oNode In oDOM.selectNodes("/applications/application/classes/class")


        lInCall = CLng(oNode.selectSingleNode("inCall").Text)


        lResponseTime = CLng(oNode.selectSingleNode("responseTime").Text)


 


        ' Check if we should recycle


        If lResponseTime > MAX_CALL_TIME And lInCall > 0 Then


            'Log that we are recycling


            sProgID = oNode.selectSingleNode("progID").Text


            WScript.Echo(Now() & " Shutting down '" & sProgID & _


                              "' because of high call time: " & lResponseTime)


 


            'We shut down the parent process: ../../processID


            oApp = oNode.parentNode.parentNode


            shutDownApplication(oApp.selectSingleNode("guid").Text)


            bHighCallTimes = True


        End If


    Next


 


    If Not bHighCallTimes Then WSCript.Echo(Now() & " Call Times OK")


End Sub


 


 


Private Sub shutDownApplication(ByVal appGuid)


'**


'Purpose: Shut down an application


'Description: Shuts down a com+ application identified by its guid.


Dim adminCatalog 'As COMAdmin.COMAdminCatalog


Dim appInstanceGUID 'As Object


 


    adminCatalog = CreateObject("COMAdmin.COMAdminCatalog")


 


    'ShutdownApplicationInstances


    adminCatalog.shutDownApplication(appGuid)


 


    adminCatalog = Nothing


End Sub


2190.aspx

poSecrets: Free password manager for Pocket PC and PC

poSecrets is a free password manager for the PC and Pocket PC.



Main features:



  • AES encryption of the entire file. There is no clear text data and no recovery of the password.
  • Same file format on the PC and Pocket PC version. The file can be synchronized with ActiveSync or transferred via mail, Bluetooth, SD Cards etc. 
  • Import/export csv/text data (5 columns; category, title, user, password, notes, url)
  • Auto Type user name and/or password in the currently active window. The Pocket PC version supports Auto Type as well. This is a great time saver as Pocket PC does not allow you to paste contents in password fields. I use strong random passwords and typing them in by hand was a major pain.
  • New in version 2.0: “Go to site“ function. It launches the default internet browser on both the Pocket PC and the PC with the entered url.
  • No installation required. Run it directly from a SD Card or an USB key.
  • Configurable generation of strong passwords

Download poSecrets for PC and Pocket PC. Current version: 2.0

2189.aspx

Free downloads on egilh.com

Finding the latest version of source code and tools in my blog can be difficult so I have created a dedicated download area for my free tools. At the moment you can find the following:



  • poGmail: a Gmail notifier that supports multiple gmail accounts
  • poDialer: An application for Pocket PC Phone edition that lets you select a list of contacts to dial automatically
  • Socket Proxy Server: Proxy any socket over http/https with ASP.NET (full source code included)
  • COM+ call time tracker: monitor the com+ call times as you see them in the COM+ Admin console. Example client programs shows how to shut down components with high call times.
  • Pocket Outlook Wrapper: Complete wrapper for the Pocket Outlook Object Model (POOM) in .NET CF. Comes with full source code.
  • poSecrets: password manager for Pocket PC and PC that uses a shared database
  • poShoplist: a simple shopping list manager for the Pocket PC
  • poToday: A Getting Things Done task manager for the Pocket PC
  • SendKeys: C# source code for SendKeys on .NET Compact Framework (based on code from http://www.opennetcf.org/)

I will update this page as I add more tools.

Wednesday, January 25, 2006

2021.aspx

The making of Windows Mobile 5.0

The Windows Mobile team has published a Fun Facts, behind the scenes, look at the making of Windows Mobile 5.0 (PDF).


Some key statistics:



  • 47 1-pound bags of peanut butter M&Ms dispensed from a gumball machine

  • Average amount of weight gained per team member since September because of missed workouts: 15 lbs.

  • On average, $2,000 "saved" in rent per developer by living in the office

  • 37 cell phones were harmed in the making of this product

  • 6 brand new 4-letter words added to the English language

  • 23% increase in nail-biting across the development staff

  • On average, 5 boxes of Band-Aids used for thumb blisters per manual device tester

  • Build lab generated close to 1 Terabyte of build data every day (which is pretty astounding for a 32 MB device!)

Thanks for the tip Marco

2020.aspx

Disney buys Pixar $7.4 billion

Disney will buy Pixar for $7.4 billion. Is it the end of great movies like The Incredibles or is it the start of something even greater? Steve Jobs gets a seat on Disney's Board of Directors and other important Pixar employees get key positions which promises well;



Pixar Chairman and CEO Steve Jobs will be appointed to Disney's Board of Directors as a non-independent member, according to the agreement reached between the companies. Pixar President Ed Catmull will serve as President of the new Pixar and Disney animation studios, reporting to Iger and Dick Cook, Chairman of The Walt Disney Studios.


In addition, Pixar Executive Vice President John Lasseter will be Chief Creative Officer of the animation studios, as well as Principal Creative Advisor at Walt Disney Imagineering.

Monday, January 23, 2006

2009.aspx

Visual Basic 2005 Starter Kits

The Visual Basic 2005 Starter Kits site has several interesting project templates:



  • Card Game Starter Kit

  • Shareware Starter Kit

  • Web Log Analyzer Starter Kit

  • Amazon-Enabled Movie Collection Starter Kit

  • Personal Website Starter Kit

  • Time Tracker Starter Kit

  • Club Website Starter Kit

  • eBay Selling Starter Kit

Get your own 15 minutes of fame by creating and sharing your own starter kit.

Wednesday, January 18, 2006

2002.aspx

Protect your data with a free SSL certificate

I have looked into getting a SSL certificate for my site in the past but I always ended up deciding it cost to much. Why should I pay hundreds of dollars for a simple certificate that is used for encrypting data? I am not interested in a super-duper publisher certificate that certificates who I am. I just want to encrypt my http traffic so I can use forms login, transfer "sensitive" data like logs etc. The developer in me always said “make one yourself“; install and configure a Certificate Authority on a PC and use it to issue certificates. I never did, and was very happy when I found StartCom last year.


The online wizard is simple to follow and allows to generate a certificate  for your web server and protect your site with https in minutes.


The StartCom Certification Authority has undergone a third party audit so the StartCom CA should be supported by most browsers and mail clients in the future. At the moment the users have to either import the StartCom CA certificate into the client or accept to browse the site with an "unknown" certificate. That is not a problem for me as I have imported the CA on my PCs and my friends will have to accept the unknown CA until StartCom is supported by everyone.


Quick, painless and highly recommended.


Update: corrected links

Wednesday, January 11, 2006

1988.aspx

How to merge multiple PDF files in ASP.NET with pdftk

There are many PDF Toolkits on the market that can merge PDF files. Most of them are expensive systems like ActivePDF but in the end I found several free alternatives that allows me to merge PDF files on the fly in ASP.NET.


The first tool I found was PDF Merge. It is a Bash command line script that uses GhostScript. I never looked into the solution in detail as I found the great pdftk toolkit.


Pdftk is a standalone executable file that you call with different command line arguments. No installation or registration, just copy the file somewhere and call it.


A DLL would have been simpler, but calling pdftk from ASP.NET only takes a few lines of code. It is a command line tool so System.Diagnostics.Process can be used to launch it with the arguments we need to merge PDFs.  The list of files and the various paths are hard coded to keep the source code short and easy to read. The list of files to merge should be passed in the request and the paths should be stored in Web.Config. One last note: the runAndWait() function below waits forever for the toolkit to return. Use a configurable timeout if you plan to use it in production code


Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    'Hard coded list of files to convert
    Dim aFiles As String() = {"c:\temp\1.pdf", "c:\temp\2.pdf", "c:\temp\3.pdf"}
    'Use a temporary output file
    Dim outputFileName = System.IO.Path.GetTempFileName()
    'Construct the command line: pdftk 1.pdf 2.pdf 3.pdf cat output 123.pdf
    Dim fileName As String
    Dim buildCommand As System.Text.StringBuilder = New System.Text.StringBuilder
    For Each fileName In aFiles
        buildCommand.AppendFormat(" ""{0}"" ", fileName)
    Next
    buildCommand.AppendFormat(" cat output ""{0}"" dont_ask", outputFileName)
    'Run PDFTK and wait for it to complete, then send the output to the user
    If runAndWait("c:\tools\pdftk.exe", buildCommand.ToString()) Then
        Response.ContentType = "application/pdf"
        Response.BinaryWrite(getFileData(outputFileName))
    Else
        'TO DO: show error message
    End If
    System.IO.File.Delete(outputFileName)
    Response.End()
End Sub
Private Function runAndWait(ByVal command As String, ByVal commandLine As String) As Boolean
    Dim runProcess As System.Diagnostics.Process
    Try
        runProcess = New System.Diagnostics.Process
        With runProcess.StartInfo
            .FileName = command
            .Arguments = commandLine
            .WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal
        End With
        runProcess.Start()
        'Wait until the process passes back an exit code 
        runProcess.WaitForExit()
 
        'Free resources associated with this process
        runProcess.Close()
        runAndWait = True
    Catch ex As Exception           
        runAndWait = False
    End Try
End Function 
Private Function getFileData(ByVal fileName As String) As Byte()
    Dim stream As System.IO.FileStream = System.IO.File.OpenRead(fileName)
 
    Dim data As Byte()
    ReDim data(stream.Length)
    stream.Read(data, 0, stream.Length)
    stream.Close()
    getFileData = data
End Function

Monday, January 9, 2006

1980.aspx

How to use .net utility classes from VBSscript

Of Kings and Cabbage discovered the a feature I did not know about: several .net utility classes are registered in com so you can use them from clients like vbscript, javascript, asp, vb, …


Some of the classes accessible from COM are:



  • System.Collections.Queue

  • System.Collections.Stack

  • System.Collections.ArrayList

  • System.Collections.SortedList

  • System.Collections.Hashtable

  • System.IO.StringWriter

  • System.IO.MemoryStream

  • System.Text.StringBuilder

  • System.Random

Good to know the next time I have to put together a quick script or asp page. Imagine using System.Text.StringBuilder.AppendFormat() instead of formatting the strings by hand!


Marvels of COM .NET interop has more information on how to use the various methods.

Tuesday, January 3, 2006

1970.aspx

DVDs from the PDC 2005 available online

Why search the online PDC 2005 presentation archive when you can download them all in in .zip format using a tool like HTTrack or GetRight? Don't try via dial up unless you want to go broke or die of old age as 200+ files with an average size of more than 100MB takes a while to download...


Get yours while the supplies last :-)


More info on the magic behind the service on eXtensible Mind Lounge.