Microsoft Visual Studio 2005 C# Batch Queue Plug-in

  1. Start Microsoft Visual Studio 2005 and select Create Project from the start page or File->New->Project.
  2. Select C# windows, class library project, give it a suitable name and press OK.
    screenshot
  3. Right click on the project and select properties, Build, All Configurations in the Configuration box and in the Build options select the Register for COM Interop.
    screenshot
  4. Open the AssemblyInfo.cs file (located in the Properties folder of the project) and set ComVisible to true.
    screenshot
  5. Right click on the Class1cs file and select rename and change the name to <BatchQueueItemName>Creator.cs replacing <BatchQueueItemName> with whatever makes sense in your case. In this example we use the name DemoBatchQueueItemCreator.cs
  6. Right click on the project and select Add Reference.
  7. Select the COM tab and then TestScriptRunner 5.0 Type Library then press OK.
    screenshot
  8. Open your batch queue item creator source file and a using statement for TestScriptRunnerLib and make the class inherit the IBatchQueueItemCreator interface.
         using System;
         using System.Collections.Generic;
         using System.Text;
         using TestScriptRunnerLib;
         
         namespace DemoTestQueueItem_CSharp2005
         {
             class DemoBatchQueueItemCreator : IBatchQueueItemCreator
             {
             }
         }
        
  9. Right click on IBatchQueueItemCreator and select Implement Interfaced->Implement Interface. This should add the properties NumberOfFileTypes,get_FileTypes, Version and the method create to your class.
  10. In the project class view right click on the project, select Add->Class then enter a name for your batch queue item object and press Add.
    screenshot
  11. Open the batch queue item object source file and add a using statement for TestScriptRunnerLib, make your tester class inherit the interface IBatchQueueItem. Also add a bool to hold the abort flag and a BatchQueueItemStatus variable to hold the status.
         using System;
         using System.Collections.Generic;
         using System.Text;
         using TestScriptRunnerLib;
         
         namespace DemoBatchQueueItem_CSharp2005
         {
             class DemoBatchQueueItem : IBatchQueueItem
             {
                 private bool                 myAbortFlag = false;
                 private BatchQueueItemStatus myStatus    = BatchQueueItemStatus.BatchQueueItemNotRunning;
             }
         }
        
  12. Right click on IBatchQueueItem and select Implement Interface->Implement Interface. This should add a number of methods/properties to your class.
  13. In the Abort method remove the throw statement. This method will be called to indicate that the user has pressed stop.
         public void Abort()
         {
             myAbortFlag = true;
         }
        
  14. In the get section of Description return a string indicating what this batch queue item is for.
         public string Description
         {
             get { return "A Demo Batch Queue Item"; }
         }
        
  15. In the Execute method you should add the code to perform the action required on the file type. In this case we will iterate for a period checking the abort flag and if not aborted return passed. Please note that the trace object is reserved for future logging but is currently not used.
         public void Execute(string FileName, ITrace trace)
         {
             myAbortFlag = false;
             myStatus = BatchQueueItemStatus.BatchQueueItemRunning;
             try
             {
                 using (System.IO.StreamReader in_file = new System.IO.StreamReader(FileName))
                 {
                     string line = in_file.ReadLine();
                     int sec = Int32.Parse(line);
                     while ((sec-- > 0) && !myAbortFlag)
                     {
                         System.Threading.Thread.Sleep(1000);
                     }
                     myStatus = BatchQueueItemStatus.BatchQueueItemPassed;
                 }
             }
             catch(Exception)
             {
                 myStatus = BatchQueueItemStatus.BatchQueueItemFailed;
             }
         }
        
  16. In the Reset method simply remove the throw and leave the method blank. This will be called when the batch queue is reset to the first item.
         public void Reset
         {
         }
        
  17. In the Version method you should add a string that represents the version of the tester.
         public string Version
         {
             get { return "1.0"; }
         }
        
  18. In the Status method add a get for myStatus.
         public BatchQueueItemStatus Status
         {
             get { return myStatus; }
         }
        
  19. Open your creator source file and in the NumberOfFileTypes method implement the get property to return the number of file types your batch queue plug-in will accept.
         public uint NumberOfFileTypes
         {
             get { return 1; }
         }
        
  20. In the Version method implement the get property to return the version of the creator.
         public string Version
         {
             get { return "1.0"; }
         }
        
  21. In the create method return an allocated version of your batch queue item if the index is correct.
         public IBatchQueueItem create(uint Index)
         {
             if (0 == Index)
             {
                 return new DemoBatchQueueItem();
             }
             throw new Exception("Index out of range.");
         }
        
  22. In the get_FileType method return the file extension(s) assigned to the batch queue item.
         public string get_FileType(uint Index)
         {
             if (0 == Index)
             {
                 return "bqdemo";
             }
             throw new Exception("Index out of range.");
         }
        
  23. Compile your code and run TestScriptRunnerGUI.exe
  24. Open the Admin->Add Batch Item Creator menu command and add your batch queue item to the system. The text to add is <namespace>.<BatchQueueItemCreatorName> and in this case it is DemoBatchQueueItem_CSharp2005.DemoBatchQueueItemCreator
  25. If you wish to debug your code add BatchQueuePlugInRunner.exe as the external program in the Debug tab of the project properties and run it. Open a batch queue that loads a file with the correct extension and you should be able to add break points in the execute method.

You can download the demovplug-in at MS 2005 C# Batch Queue Item.