MAPILab - Microsoft Outlook Add-ins and Software for Microsoft Exchange Server
EnglishGermanRussian

Building scripts

Building scripts is performed via writing program code in C# language. All work with scripts is done in the script building window.

When opening window of script creation, MAPILab Spy for SharePoint generates it`s minimal program code:

using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;

public class Tester
{
	static object main(
		 MAPILab.SharePoint.Spy.CodeForm thisForm
		)
	{
		return null;
	}
}

This code contains description of class Tester, that includes statistical method main.

The method main is a start point for executing the script. Signature of this method is generated automatically on basis of selected objects in browser windows. Not depending on the condition of browser windows, method main always gets parameter thisForm and returns object of type object. Parameter thisForm contains reference to script building window itself. Object returned by method main is displayed in new browser window (except for cases when null reference is returned).

Only name of class Tester and signature of method mainmust remain unchanged in the script programming code – everything else can be changed as you like. It is possible to add descriptions of additional types, modify description of both class Tester and body of method main, and etc.

As mentioned before, signature of method main is generated automatically depending on the number of objects flagged in browser windows. Considering the fact that in browser window not only property or field, but also any method can be flagged, the result of generation of method main may strongly vary. To demonstrate this, let`s review two examples.

Example of generating method main when selecting property or field

For instance, several properties or fields are flagged in browser window as shown below.

For instance, several properties or fields are flagged in browser window

In this case, when creating new script window, method main will look the following way:

using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;

public class Tester
{
	static object main(
		 System.Version buildVersion1
		,bool canRenameOnRestore2
		,bool canSelectForBackup3
		,MAPILab.SharePoint.Spy.CodeForm thisForm
		)
	{
		return null;
	}
}

As seen in the example, the generated signature of method main contains, besides obligatory parameter thisForm , automatically added parameters buildVersion1, canRenameOnRestore2, canSelectForBackup3 relevant to objects selected in browser window.

Let`s perform simple modification of generated method. Place string representation of SharePoint version in the header of script window and put string Current SharePoint version is … in output box of results:

using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;

public class Tester
{
	static object main(
		 System.Version buildVersion1
		,bool canRenameOnRestore2
		,bool canSelectForBackup3
		,MAPILab.SharePoint.Spy.CodeForm thisForm
		)
	{
		// Put SharePoint version to code windows caption
		thisForm.Text = buildVersion1.ToString();

		// Make debug output
		Debug.Print("Current SharePoint version is {0}", buildVersion1);

		return null;
	}
}

In order to be sure of no errors in the programming code, it can be compiled by clicking button F7 or selecting menu item Action – Compile.

In order to execute script, click button F5 or select menu item Action – Run.

After executing the given script, window will become as follows (pay attention to points marked with red rectangles):


Click to open real size screenshot

Example of generating method main when selecting method

When some method is selected in the browser tree, not only signature of method main, but also the part of its part is generated – template of call of selected method is put in it beforehand. Let`s demonstrate it.

Assume that one of methods (one for simplicity) is flagged in browser window as shown on the image below (by the way, method selected for the example allows receiving description of SharePoint feature in XML format).


Click to open real size screenshot

In this case, when creating new script window, method main will be the following:

using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;

public class Tester
{
	static object main(
		 Microsoft.SharePoint.Administration.SPFeatureDefinition mo_getXmlDefinition1
		,System.Reflection.MethodInfo getXmlDefinition1
		,MAPILab.SharePoint.Spy.CodeForm thisForm
		)
	{
		// Calling method GetXmlDefinition
		System.Globalization.CultureInfo value1 = ;
		
		System.Xml.XmlNode value2 = 
			mo_getXmlDefinition1.GetXmlDefinition(
				value1);

		return null;
	}
}

As seen in the example, besides object of type MethodInfoselected in the browser, the list of parameters of method main includes also parameter mo_getXmlDefinition1containing reference to an object that must be called. Moreover, method body already contains template that can simplify the call of selected method. It remains only to supply it (actually to define value of variable value1) and use the result of call that will be placed in variable value2. Modify the code for xml describing property of SharePoint feature to be shown in pop-up window, and after that – object of type XmlNode to appear in new browser window:

using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;

public class Tester
{
	static object main(
		 Microsoft.SharePoint.Administration.SPFeatureDefinition mo_getXmlDefinition1
		,System.Reflection.MethodInfo getXmlDefinition1
		,MAPILab.SharePoint.Spy.CodeForm thisForm
		)
	{
		// Calling method GetXmlDefinition
		System.Globalization.CultureInfo value1 = 
			System.Threading.Thread.CurrentThread.CurrentCulture;
		
		System.Xml.XmlNode value2 = 
			mo_getXmlDefinition1.GetXmlDefinition(
				value1);

		// Show Feature XML using MessageBox class
		System.Windows.Forms.MessageBox.Show(value2.OuterXml);

		// Return results to the new object browser
		return value2;
	}
}

As a result of script execution (button F5) we will sequentially see:


Click to open real size screenshot


Click to open real size screenshot

Here we have reviewed examples of operations with properties or methods separately, however nothing prevents from selecting both of them in the browser simultaneously. In this case, signature of method main, which includes both first and second variant, will be generated.

MAPILab Spy for SharePoint downloaden Download 15-days trial version MAPILab Spy for SharePoint (3930 KB):
 Primary server
 Secondary server
MAPILab Spy for SharePoint bestellen Purchase MAPILab Spy for SharePoint online through a secure server.
Product homepage
Screenshots
Version history
Ïðèìåðû èñïîëüçîâàíèÿ MAPILab Spy for SharePoint
Example of work with MAPILab Spy for SharePoint:
Building scripts
Operations with persisted objects
Example of work with Active Directory
Example of work with Windows Forms
Debugging of regular expressions
Exploration of W3C Document Object Model (DOM)
Leave your Suggestion:
Name:
E-mail:
 
 
Search on MAPILab.com:
Get our Newsletter:
E-mail:
© 2003-2009 MAPILab Ltd. All Rights Reserved.

Microsoft and the Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries.

See also: Office-Outlook.Com :: Office-Excel.Com

Quick links to MAPILab software:

MAPILab Reports

Add-ins for Outlook

Plugins for Outlook

Addons for Office

Software for SharePoint

Add-ons for Exchange

Groupware tools

Developer solutions