Jim's Blog Ramblings about novels, comics, programming, and other geek topics

29Jun/110

Comicster Plug-In: Debugster

Google AdSense

Debugster is a suite of debugging and development tools for Comicster. I’ll go over each of the various tools below.

  • Property Window
  • Output Console
  • Dynamic Execution

Property Window

The Property Window allows you to view all of the properties (attributes) of the selected item. For example, if you select "Action Comics 1" then you’ll see results similar to the screenshot below.

The Property Window is useful for developers, so they can see all of the attributes of a particular object and better understand Comicster’s data structure. Additionally, any edits made in the Property Window will update the actual item, so you can use it as your editor! The Property Window does not update when you select a new item. Instead, you'll need to re-choose the menu item to open/refresh the Property Window.

Comicster Plug-In: Debugster Property Window

Output Console Window

The Output Console capture output from calls to Console, Trace, and Debug. For example, Console.WriteLine("This is a test") will produce “This is a test” in the Output Console. This is useful for developers since they can write out variables and tests within their code and see the output. A few examples include:

Debug.WriteLine("This is a debug test");
Trace.WriteLine("This is a trace test");
Console.WriteLine("This is a console test");
Trace.WriteLineIf( 1 < 2, "This message WILL appear");
Trace.WriteLineIf( 1 > 2, "This message will NOT appear");
Trace.Assert( 1 > 2, "This message will NOT appear");
Trace.Assert( 1 < 2, "This message WILL appear");

All of the other methods such as Indent() and Unindent() of Debug and Trace will also work. This console will redirect all standard output to the window, so anything that normally outputs to your Output Console (Debug, Trace, Console) in Visual Studio will work here as well.

Just remember that Debug output will only be shown if the assembly (plug-in) is compiled in debug mode. If you take the DLL from the /bin/release folder, then that’ll mean that it’s been compiled in release mode. You’ll need to take the DLL from the /bin/debug folder, if you want to see Debug output.

Comicster Plug-In: Debugster Output Console Window

Dynamic Execution Window

The Dynamic Execution allows you to execute code snippets within Comicster without having a plug-in. You could use this to prototype your plug-in or to run tests against your Comicster collection without having to build, compile, and package a plug-in.

The Dynamic Execution supports both C# and Visual Basic.NET languages and can be used as a code snippet or class coding structures. In the Code Snippet mode, you enter code fragments that would typically execute within a method. In the Class mode, you must implement a Main() method and then you can write additional code just like you were writing a class within Visual Studio.

This window also comes with an easy way to access your current collection. The class property of MyCollection will return the active collection. So you don’t need to worry about how to get access to the collection. If you were implementing Comicster’s ITool interface, this would be the same as IToolContext.Collection.

Here’s a few code snippets that will work within the Dynamic Execution window:

Language: C#, Mode: Code Snippet

foreach (Publisher item in MyCollection.Publishers)
{
   MessageBox.Show(item.Name, “Publisher”);
}

This will also work with the Output Console window. You should open the Output Console window before executing the code snippet. If you wanted to output to the console, just replace the above snippet with:

Language: C#, Mode: Code Snippet

foreach (Publisher item in MyCollection.Publishers)
{
   Console.WriteLine(item.Name);
}

The same code snippet can be written using Visual Basic.NET

Language: Visual Basic.NET, Mode: Code Snippet

For Each item As Publisher In MyCollection.Publishers
   Console.WriteLine(item.Name)
Next

You can also write code in class mode, which means you’ll need to implement the Main() which is the entry point into your code.

Language: C#, Mode: Class

public void Main()
{
    foreach (Publisher item in MyCollection.Publishers)
    {
         WritePublisherName(item);
    }
}

public void WritePublisherName(Comicster.Publisher publisher)
{
     Console.WriteLine(publisher.Name);
}

Language: Visual Basic.NET, Mode: Class

Public Sub Main()
   For Each item As Publisher In MyCollection.Publishers
       WritePublisherName(item)
   Next
End Sub

Public Sub WritePublisherName(publisher As Comicster.Publisher)
   Console.WriteLine(publisher.Name)
End Sub 

All compile errors will be displayed in the Errors table shown below the coding window.

Comicster Plug-In: Debugster Dynamic Execution Window

Some Useful Code Snippets/Examples
// Select all issues in Green Lantern, Volume 1
// could select by Title's ID instead, but this shows a bit more query
// loop through each selected issue
foreach (Issue item in MyCollection.Owned.Issues
       .Where(i => i.Title.Name == "Green Lantern" && i.Title.Volume == "1"))
{
    // set the image source to a local cover scan of the issue # . jpg
   item.ImageSource = new Uri(string.Format(
         @"C:\temp\GreenLantern\{0}.jpg", item.Number));
   // refresh the thumbnail
   Comicster.Windows.Controls.ThumbnailImage.Reload(item.Id, item.ImageSource);
}

// select all titles
// loop through each selected title
foreach (Title item in MyCollection.Owned.Titles )
{
    // if title's details is not null or empty then continue
    if(!string.IsNullOrEmpty(item.Details))
    {
        // let's remove all HTML tags from the details using Regular Expression
        item.Details = System.Text.RegularExpressions.Regex.Replace(
              item.Details, @"<[^>]*>", string.Empty);
        // let's replace all &nbsp; values with spaces
        item.Details = item.Details.Replace("&nbsp;", " ");
    }
}

As you can see, it still requires a working knowledge of both C# (or VB.NET) and Comicster's libraries. However, with a few examples like the ones posted above, anyone with technical knowledge (and back ups of their collection) can modify the code snippets to do some automated routines.

Installation

Version 1.0
Updated on June 29, 2011

Version 1.0.1
Updated on July 2, 2011
* Added File menu with Open and Save menu choices to Dynamic Execution window
* Provided sample C# and VB.NET code snippets
* Bug fixes

You can install the plug-in via Comicster’s Extension Gallery. Just choose “Extensions…” menu choice under the Tools menu.

James Welch

James Welch is a software engineer in Vermont working for a large information technology company and specializing in .NET. Additionally, he holds a Master’s Degree in Software Engineering and a Bachelor of Science Degree in Computer Science. Jim also enjoys local craft beer, comic books, and science-fiction and fantasy novels, games, and movies.

Comments (0) Trackbacks (0)

No comments yet.


Leave a comment

(required)

No trackbacks yet.