BreakPoints and Runtime Object Editor (Inspector)

Version 0.1.0.2 of the Workbench now allows to set 'BreakPoints' in your instructions.
This is a very humble yet functional alpha implementation.

The breakpoints can be set with a new method in the AbstractInstruction class.
// New methods
public abstract class AbstractInstruction
{
      public void Inspect(object prop, InspectArgs args);

      public void Inspect(object prop, string message);
}
The Inspect methods take an object as a parameter and a string/InspectArgs (not yet used).

[#Sample] 
public class InspectSample : AbstractInstruction
{
	
	public override void Run()
	{
		var dt = new DataTable("MyTable");		
		dt.Columns.Add(new DataColumn("Col 1"));
		
		var row = dt.NewRow();		
		row[0] = "Hello World!";

		dt.Rows.Add(row);
		dt.AcceptChanges();

		// Modify the table as needed in the Inspector tab
		Inspect(dt, "My BreakPoint");
		
		// Display table in the "Data Table" Tab
		ResultTable = dt;
		
	}
}
When called the instruction will be paused and the live object properties will be displayed in the new 'Inspector' tab.



Current Limitations
As the Workbench is a multithreaded application the objects modified need to be thread safe.

In the submitted sample we edit an SPWeb object, which is not thread safe. However we can modify its properties by using a static variable.

Sample 1

In this sample we work with a custom class 'Person'. Notice the use of properties, fields are not currently editable.
public class Inspect_PersonSample : AbstractInstruction
{
	
	public override void Run()
	{
		var me = new Person(){ Name = "Martin"};
	
		// NotifyInformation will display events in the Logs tab
		NotifyInformation(me.RawPrint());
		
		// BreakPoint allows to edit 'me'
		// after modifying press the 'Run' button to continue.
		Inspect(me, "Change one of the Properties");
		
		// Show changes in Logs
		NotifyInformation(me.RawPrint());
		
	}
	
	// Custom class to modify
	public class Person
	{
		public string Name {get;set;}
		public string Phone {get;set;}
	}
}
Download Sample 1

Sample 2

For this example we use the WebAppInstruction which lets you iterate over site collections.
In this case we want to edit an SPWeb instace.
The problem with SPWeb is that it is not thread safe. To work around this we store the instance in a static variable.

Updates seem to work correctly, but notice that not all the properties are editable in the Inspector tab

/// <summary>
/// Process all site collections in a web application ( sync )
/// </summary>
public class WebAppSample : WebAppInstruction
{
    public WebAppSample()
    {
        OnProcessSite += WebAppSample_OnProcessSite;
        WebAppUrl = "http://localhost";
    }

	private static SPWeb web = null;
	
	void WebAppSample_OnProcessSite(SPSite site)
    {
				
		web = site.OpenWeb();
		
		NotifyInformation(web.Title);
		
		Inspect(web, "");
		
		web.Update();
		
		NotifyInformation(web.Title);

		web.Dispose();			
	}
}
Download Sample 2

Last edited Aug 8, 2013 at 1:14 PM by xsolon, version 11

Comments

No comments yet.