Building a K2 Smartform spider part 5

In parts 1 to 4 we looked at some of the different classes and methods that are available in the Smartform API. In part 5 we will be taking these methods and building a complete assembly for us to use.

Smartform spider library

The Smartform spider library is what we will use to create an endpoint assembly so we can create SmartObjects from it and then eventually Smartforms.

Getting Started

1. Open up Visual studio and create a class library project

2.Add the following references to the library

using SourceCode.Forms.Management;
using SourceCode.Forms.Deployment;
using SourceCode.Forms;
using SourceCode.Forms.Authoring;

 

3.Create a class called ‘Common.cs’, this will contain all the common classes to hold the form and view data.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CloudFish.FormSpider
{
public class SmartFormViewSml
{
public string name
{
get;
set;
}
public string displayname
{
get;
set;
}

public string description
{
get;
set;
}

public Guid guid
{
get;
set;
}
public int version
{
get;
set;
}
}

public class SmartFormView
{
public string name
{
get;
set;
}
public string displayname
{
get;
set;
}

public string description
{
get;
set;
}

public Guid guid
{
get;
set;
}
public int version
{
get;
set;
}

public string theme
{
get;
set;
}

}

public class SmartFormViewProperties
{
public string name
{

get;
set;
}

public string value
{

get;
set;
}
}
public class SmartFormViewControls
{
public string name
{
get;
set;
}

public string type
{
get;
set;
}

public Guid guid
{
get;
set;
}

}

public class SmartFormViewParameters
{
public string name
{
get;
set;
}

public string type
{
get;
set;
}

public string defaultvalue
{
get;
set;
}
}

public class SmartFormViewEvents
{
public string name
{
get;
set;
}

public string type
{
get;
set;
}

public Guid GUID
{
get;
set;
}
}
public class SmartFromViewHandlers
{

public string Name
{

get;
set;
}

public Guid GUID
{

get;
set;
}

 

public Guid GUID
{

get;
set;
}

}

public class SmartFormViewActions
{
public Guid GUID
{

get;
set;
}

public Guid viewguid
{
get;
set;
}

public Guid formguid
{
get;
set;
}

public string method
{
get;
set;
}

public string executiontype
{
get;
set;
}

public Guid controlguid
{
get;
set;
}

public string actiontype
{
get;
set;
}
}
public class SmartFormViewActionParameters
{

 

public string targettype
{

get;
set;
}
public string targetpath
{

get;
set;
}
public string targetid
{

get;
set;
}

public string sourcevalue
{

get;
set;
}

public string sourcetype
{

get;
set;
}
public string sourcepath
{

get;
set;
}

public string sourceid
{

get;
set;
}
}
public class SmartFormViewActionValidation
{

public string status
{
get;
set;
}
}

public class SmartFormViewActionValidationMessage
{

public string message { get; set; }
}

}

 

4.Create another class called ‘properties.cs’, this will contain a generic method to get the properties of an item.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CloudFish.FormSpider
{
class Properties
{

public List<SmartFormViewProperties> ArtefactProperties(SourceCode.Forms.Authoring.PropertyCollection properties)
{
List<SmartFormViewProperties> list = new List<SmartFormViewProperties>();
foreach (SourceCode.Forms.Authoring.Property prop in properties)
{
list.Add(new SmartFormViewProperties
{
name = prop.Name,
value = prop.Value,

});

}
return list;
}
}
}

SmartObject Object

5.Now lets create a class called ‘Smartform.cs’ this class will contain all the public static methods for accessing key information from a Smartform and is the object that will be used as a Service Object by K2.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SourceCode.Forms.Management;
using SourceCode.Forms.Deployment;
using SourceCode.Forms;
using SourceCode.Forms.Authoring;

/// <summary>
/// Explores the content of the SmartForm
/// </summary>
namespace CloudFish.FormSpider
{
public class Smartform
{

/// <summary>
/// Gets the details of the form
/// </summary>
/// <param name=”FormName”></param>
public static SmartFormView LoadForm(string formname)
{

FormsManager frm = new FormsManager(“dlx”, 5555);
FormInfo forminfo = frm.GetForm(formname);
SourceCode.Forms.Authoring.Form form = new SourceCode.Forms.Authoring.Form(frm.GetViewDefinition(formname));

SmartFormView sf = new SmartFormView();
sf.guid = form.Guid;
sf.description = form.Description;

sf.displayname = form.DisplayName;
sf.name = form.Name;
sf.guid = form.Guid;
sf.theme = form.Theme;

return sf;
}
/// <summary>
/// Get a list of all the forms
/// </summary>
/// <returns></returns>
public static List<SmartFormView> GetAllForms()
{
List<SmartFormView> list = new List<SmartFormView>();
FormsManager frm = new FormsManager(“dlx”, 5555);
FormExplorer formexplorer = frm.GetForms();
foreach (SourceCode.Forms.Management.FormInfo forminfo in formexplorer.Forms)
{

SourceCode.Forms.Authoring.Form form = new SourceCode.Forms.Authoring.Form(frm.GetFormDefinition(forminfo.Name));

list.Add(new SmartFormView
{
name = forminfo.Name,
displayname = forminfo.DisplayName,
description = forminfo.Description,
guid = forminfo.Guid,
version = forminfo.Version

});

}
return list;
}
/// <summary>
/// Get a list of all the forms that contain a certain view
/// </summary>
/// <param name=”ViewName”></param>
/// <returns></returns>
public static List<SmartFormView> GetAllFormsbyView(string ViewName)
{
List<SmartFormView> list = new List<SmartFormView>();
FormsManager frm = new FormsManager(“dlx”, 5555);
FormExplorer formexplorer = frm.GetFormsForView(ViewName);
foreach (SourceCode.Forms.Management.FormInfo forminfo in formexplorer.Forms)
{
SourceCode.Forms.Authoring.Form form = new SourceCode.Forms.Authoring.Form(frm.GetViewDefinition(forminfo.Name));

list.Add(new SmartFormView
{
name = forminfo.Name,
displayname = forminfo.DisplayName,
description = forminfo.Description,
guid = forminfo.Guid,
version = forminfo.Version

});

}
return list;
}
/// <summary>
/// List of form properties
/// </summary>
/// <param name=”FormName”></param>
/// <returns></returns>
public static List<SmartFormViewProperties> GetFormProperties(string FormName)
{
List<SmartFormView> list = new List<SmartFormView>();
FormsManager frm = new FormsManager(“dlx”, 5555);

SourceCode.Forms.Authoring.Form form = new SourceCode.Forms.Authoring.Form(frm.GetFormDefinition(FormName));
Properties prop = new Properties();
return prop.ArtefactProperties( form.Properties);

}
/// <summary>
/// Gets a list of the form parameters
/// </summary>
/// <param name=”FormName”></param>
/// <returns></returns>
public static List<SmartFormViewParameters> FormParameters(string FormName)
{
List<SmartFormViewParameters> list = new List<SmartFormViewParameters>();
FormsManager frm = new FormsManager(“dlx”, 5555);
SourceCode.Forms.Authoring.Form form = new SourceCode.Forms.Authoring.Form(frm.GetFormDefinition(FormName));

foreach (SourceCode.Forms.Authoring.FormParameter parameter in form.Parameters)
{
list.Add(new SmartFormViewParameters
{
name = parameter.Name,
type = parameter.DataType.ToString(),
defaultvalue = parameter.DefaultValue
});
}

return list;

}

/// <summary>
/// Form Controls
/// </summary>
/// <param name=”FormName”></param>
/// <returns></returns>
public static List<SmartFormViewControls> FormControls(string FormName)
{
List<SmartFormViewControls> list = new List<SmartFormViewControls>();
FormsManager frm = new FormsManager(“dlx”, 5555);
SourceCode.Forms.Authoring.Form form = new SourceCode.Forms.Authoring.Form(frm.GetFormDefinition(FormName));

foreach (SourceCode.Forms.Authoring.Control control in form.Controls)
{
list.Add(new SmartFormViewControls
{
name = control.Name,
type = control.Type,
guid = control.Guid,

});

}
return list;
}
/// <summary>
/// Form Events
/// </summary>
/// <param name=”FormName”></param>
/// <returns></returns>
public static List<SmartFormViewEvents> FormEventsEvents(string FormName)
{
List<SmartFormViewEvents> list = new List<SmartFormViewEvents>();
FormsManager frm = new FormsManager(“dlx”, 5555);
SourceCode.Forms.Authoring.Form form = new SourceCode.Forms.Authoring.Form(frm.GetFormDefinition(FormName));

foreach (SourceCode.Forms.Authoring.Eventing.Event ev in form.Events)
{

if (ev.SourceType == SourceCode.Forms.Authoring.Eventing.EventSourceType.Rule)
{
list.Add(new SmartFormViewEvents
{
name = ev.Name,
type = ev.EventType.ToString(),
GUID = ev.Guid

});

}
}

return list;
}

/// <summary>
/// Event Handlers
/// </summary>
/// <param name=”EventGUID”></param>
/// <returns></returns>
public static List<SmartFromViewHandlers> FormHandlers(String FormName,Guid EventGUID)
{
List<SmartFromViewHandlers> list = new List<SmartFromViewHandlers>();
FormsManager frm = new FormsManager(“dlx”, 5555);
SourceCode.Forms.Authoring.Form form = new SourceCode.Forms.Authoring.Form(frm.GetFormDefinition(FormName));
var ev = form.Events[EventGUID];

SourceCode.Forms.Authoring.Eventing.Event e = form.Events[EventGUID];

foreach (SourceCode.Forms.Authoring.Eventing.Handler handle in e.Handlers)
{
list.Add(new SmartFromViewHandlers
{

Name = handle.HandlerType.ToString(),
GUID = handle.Guid
});

}
return list;

}

/// <summary>
/// Conditions
/// </summary>
/// <param name=”FormName”></param>
/// <param name=”EventGUID”></param>
/// <param name=”HandleGUID”></param>
/// <returns></returns>
public static List<SmartFormViewConditions> ArtefactConditions(String FormName,Guid EventGUID,Guid HandleGUID)
{
List<SmartFormViewConditions> list = new List<SmartFormViewConditions>();
FormsManager frm = new FormsManager(“dlx”, 5555);
SourceCode.Forms.Authoring.Form form = new SourceCode.Forms.Authoring.Form(frm.GetFormDefinition(FormName));
var ev = form.Events[EventGUID].Handlers[HandleGUID];
SourceCode.Forms.Authoring.Eventing.Handler e = form.Events[EventGUID].Handlers[HandleGUID];

foreach (SourceCode.Forms.Authoring.Eventing.Condition condition in e.Conditions)
{

list.Add(new SmartFormViewConditions
{
GUID = condition.Guid,

});
}

return list;
}
/// <summary>
/// Actions
/// </summary>
/// <param name=”HandleGUID”></param>
/// <returns></returns>
public static List<SmartFormViewActions> ArtefactActionss(String FormName, Guid EventGUID, Guid HandleGUID)
{
List<SmartFormViewActions> list = new List<SmartFormViewActions>();
FormsManager frm = new FormsManager(“dlx”, 5555);

SourceCode.Forms.Authoring.Form form = new SourceCode.Forms.Authoring.Form(frm.GetFormDefinition(FormName));
var ev = form.Events[EventGUID].Handlers[HandleGUID];
SourceCode.Forms.Authoring.Eventing.Handler e = form.Events[EventGUID].Handlers[HandleGUID];

foreach (SourceCode.Forms.Authoring.Eventing.Action action in e.Actions)
{
list.Add(new SmartFormViewActions
{
GUID = action.Guid,

viewguid = action.ViewGuid,
method = action.Method,
formguid = action.FormGuid,
executiontype = action.ExecutionType.ToString(),
controlguid = action.ControlGuid,
actiontype = action.ActionType.ToString()
});
}
return list;
}
/// <summary>
/// Actions Parameters
/// </summary>
/// <param name=”FormName”></param>
/// <param name=”EventGUID”></param>
/// <param name=”HandleGUID”></param>
/// <param name=”ActionGUID”></param>
/// <returns></returns>
public static List<SmartFormViewActionParameters> SmartFormViewActionParameters(String FormName, Guid EventGUID, Guid HandleGUID,Guid ActionGUID)
{
List<SmartFormViewActionParameters> list = new List<SmartFormViewActionParameters>();
FormsManager frm = new FormsManager(“dlx”, 5555);

SourceCode.Forms.Authoring.Form form = new SourceCode.Forms.Authoring.Form(frm.GetFormDefinition(FormName));
SourceCode.Forms.Authoring.Eventing.Action e = form.Events[EventGUID].Handlers[HandleGUID].Actions[ActionGUID];

foreach (SourceCode.Forms.Authoring.Eventing.Mapping map in e.Parameters)
{

list.Add(new SmartFormViewActionParameters
{
targettype = map.TargetType.ToString(),
targetpath = map.TargetPath,
targetid = map.TargetID,
sourcevalue = map.SourceValue,
sourcetype = map.SourceType.ToString(),
sourcepath = map.SourcePath,
sourceid = map.SourceID

});
}

return list;
}
/// <summary>
/// Actions Results
/// </summary>
/// <param name=”FormName”></param>
/// <param name=”EventGUID”></param>
/// <param name=”HandleGUID”></param>
/// <param name=”ActionGUID”></param>
/// <returns></returns>
public static List<SmartFormViewActionParameters> SmartFormViewActionResults(String FormName, Guid EventGUID, Guid HandleGUID, Guid ActionGUID)
{
List<SmartFormViewActionParameters> list = new List<SmartFormViewActionParameters>();
FormsManager frm = new FormsManager(“dlx”, 5555);

SourceCode.Forms.Authoring.Form form = new SourceCode.Forms.Authoring.Form(frm.GetFormDefinition(FormName));
SourceCode.Forms.Authoring.Eventing.Action e = form.Events[EventGUID].Handlers[HandleGUID].Actions[ActionGUID];

foreach (SourceCode.Forms.Authoring.Eventing.Mapping map in e.Results)
{

list.Add(new SmartFormViewActionParameters
{
targettype = map.TargetType.ToString(),
targetpath = map.TargetPath,
targetid = map.TargetID,
sourcevalue = map.SourceValue,
sourcetype = map.SourceType.ToString(),
sourcepath = map.SourcePath,
sourceid = map.SourceID

});
}

return list;
}
/// <summary>
/// Validation Messages
/// </summary>
/// <param name=”FormName”></param>
/// <param name=”EventGUID”></param>
/// <param name=”HandleGUID”></param>
/// <param name=”ActionGUID”></param>
/// <returns></returns>
public static List<SmartFormViewActionValidationMessage> SmartFormViewActionValidation(String FormName, Guid EventGUID, Guid HandleGUID, Guid ActionGUID)
{
List<SmartFormViewActionValidationMessage> list = new List<SmartFormViewActionValidationMessage>();
FormsManager frm = new FormsManager(“dlx”, 5555);

SourceCode.Forms.Authoring.Form form = new SourceCode.Forms.Authoring.Form(frm.GetFormDefinition(FormName));
SourceCode.Forms.Authoring.Eventing.Action e = form.Events[EventGUID].Handlers[HandleGUID].Actions[ActionGUID];

foreach (SourceCode.Forms.Authoring.ValidationMessage val in e.Validation.Messages)
{

list.Add(new SmartFormViewActionValidationMessage
{
message = val.Message
});
}

return list;
}

}
}

View Object

6.Create a class called ‘View.cs’, like ‘Smartform.cs’ this class will contain all the methods for accessing information about views  on the K2 environment

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SourceCode.Forms.Management;
using SourceCode.Forms.Deployment;
using SourceCode.Forms;
using SourceCode.Forms.Authoring;

namespace CloudFish.FormSpider
{
public class Views
{

/// <summary>
/// Gets all the views on the environment
/// </summary>
/// <returns></returns>
public static List<SmartFormView> GetAllViews()
{
List<SmartFormView> list = new List<SmartFormView>();
FormsManager frm = new FormsManager(“dlx”, 5555);
ViewExplorer formexplorer = frm.GetViews();
foreach (SourceCode.Forms.Management.ViewInfo viewinfo in formexplorer.Views)
{

SourceCode.Forms.Authoring.View view = new SourceCode.Forms.Authoring.View(frm.GetViewDefinition(viewinfo.Name));

list.Add(new SmartFormView
{
name = viewinfo.Name,
displayname = viewinfo.DisplayName,
description = viewinfo.Description,
guid = viewinfo.Guid,
version = viewinfo.Version,
});

}
return list;
}

/// <summary>
/// Gets all the views that are attached to a form
/// </summary>
/// <param name=”formname”></param>
/// <returns></returns>
public static List<SmartFormView> GetAllViews(string formname)
{
List<SmartFormView> list = new List<SmartFormView>();
FormsManager frm = new FormsManager(“dlx”, 5555);
ViewExplorer formexplorer = frm.GetViewsForForm(formname);
foreach (SourceCode.Forms.Management.ViewInfo viewinfo in formexplorer.Views)
{

SourceCode.Forms.Authoring.View view = new SourceCode.Forms.Authoring.View(frm.GetViewDefinition(viewinfo.Name));

list.Add(new SmartFormView
{
name = viewinfo.Name,
displayname = viewinfo.DisplayName,
description = viewinfo.Description,
guid = viewinfo.Guid,
version = viewinfo.Version,

});

}
return list;
}
/// <summary>
/// List of view properties
/// </summary>
/// <param name=”ViewName”></param>
/// <returns></returns>
public static List<SmartFormViewProperties> GetViewProperties(string ViewName)
{
List<SmartFormView> list = new List<SmartFormView>();
FormsManager frm = new FormsManager(“dlx”, 5555);
SourceCode.Forms.Authoring.View view = new SourceCode.Forms.Authoring.View(frm.GetViewDefinition(ViewName));
Properties prop = new Properties();
return prop.ArtefactProperties(view.Properties);

}
/// <summary>
/// Gets a list of the view parameters
/// </summary>
/// <param name=”ViewName”></param>
/// <returns></returns>
public static List<SmartFormViewParameters> ViewParameters(string ViewName)
{
List<SmartFormViewParameters> list = new List<SmartFormViewParameters>();
FormsManager frm = new FormsManager(“dlx”, 5555);
SourceCode.Forms.Authoring.View view = new SourceCode.Forms.Authoring.View(frm.GetViewDefinition(ViewName));

foreach (SourceCode.Forms.Authoring.ViewParameter parameter in view.Parameters)
{
list.Add(new SmartFormViewParameters
{
name = parameter.Name,
type = parameter.DataType.ToString(),
defaultvalue = parameter.DefaultValue
});
}

return list;

}

/// <summary>
/// View Controls
/// </summary>
/// <param name=”ViewName”></param>
/// <returns></returns>
public static List<SmartFormViewControls> ViewControls(string ViewName)
{
List<SmartFormViewControls> list = new List<SmartFormViewControls>();
FormsManager frm = new FormsManager(“dlx”, 5555);
SourceCode.Forms.Authoring.View view = new SourceCode.Forms.Authoring.View(frm.GetViewDefinition(ViewName));

foreach (SourceCode.Forms.Authoring.Control control in view.Controls)
{
list.Add(new SmartFormViewControls
{
name = control.Name,
type = control.Type,
guid = control.Guid,

});

}
return list;
}
/// <summary>
/// View Events
/// </summary>
/// <param name=”ViewName”></param>
/// <returns></returns>
public static List<SmartFormViewEvents> ViewEventsEvents(string ViewName)
{
List<SmartFormViewEvents> list = new List<SmartFormViewEvents>();
FormsManager frm = new FormsManager(“dlx”, 5555);
SourceCode.Forms.Authoring.View view = new SourceCode.Forms.Authoring.View(frm.GetViewDefinition(ViewName));

foreach (SourceCode.Forms.Authoring.Eventing.Event ev in view.Events)
{
if (ev.SourceType == SourceCode.Forms.Authoring.Eventing.EventSourceType.Rule)
{
list.Add(new SmartFormViewEvents
{
name = ev.Name,
type = ev.EventType.ToString(),
GUID = ev.Guid

});

}
}

return list;
}

/// <summary>
/// Event Handlers
/// </summary>

/// <param name=”ViewName”></param>
/// <param name=”EventGUID”></param>
/// <returns></returns>
public static List<SmartFromViewHandlers> ViewHandlers(String ViewName, Guid EventGUID)
{
List<SmartFromViewHandlers> list = new List<SmartFromViewHandlers>();
FormsManager frm = new FormsManager(“dlx”, 5555);
SourceCode.Forms.Authoring.View view = new SourceCode.Forms.Authoring.View(frm.GetViewDefinition(ViewName));
var ev = view.Events[EventGUID];

SourceCode.Forms.Authoring.Eventing.Event e = view.Events[EventGUID];

foreach (SourceCode.Forms.Authoring.Eventing.Handler handle in e.Handlers)
{
list.Add(new SmartFromViewHandlers
{

Name = handle.HandlerType.ToString(),
GUID = handle.Guid
});

}
return list;

}

/// <summary>
/// Conditions
/// </summary>
/// <param name=”ViewName”></param>
/// <param name=”EventGUID”></param>
/// <param name=”HandleGUID”></param>
/// <returns></returns>
public static List<SmartFormViewConditions> ArtefactConditions(String ViewName, Guid EventGUID, Guid HandleGUID)
{
List<SmartFormViewConditions> list = new List<SmartFormViewConditions>();
FormsManager frm = new FormsManager(“dlx”, 5555);
SourceCode.Forms.Authoring.View view = new SourceCode.Forms.Authoring.View(frm.GetViewDefinition(ViewName));
var ev = view.Events[EventGUID].Handlers[HandleGUID];
SourceCode.Forms.Authoring.Eventing.Handler e = view.Events[EventGUID].Handlers[HandleGUID];

foreach (SourceCode.Forms.Authoring.Eventing.Condition condition in e.Conditions)
{

list.Add(new SmartFormViewConditions
{
GUID = condition.Guid

});
}

return list;
}
/// <summary>
/// Actions
/// </summary>
/// <param name=”HandleGUID”></param>
/// <returns></returns>
public static List<SmartFormViewActions> ArtefactActionss(String ViewName, Guid EventGUID, Guid HandleGUID)
{
List<SmartFormViewActions> list = new List<SmartFormViewActions>();
FormsManager frm = new FormsManager(“dlx”, 5555);

SourceCode.Forms.Authoring.View view = new SourceCode.Forms.Authoring.View(frm.GetViewDefinition(ViewName));
var ev = view.Events[EventGUID].Handlers[HandleGUID];
SourceCode.Forms.Authoring.Eventing.Handler e = view.Events[EventGUID].Handlers[HandleGUID];

foreach (SourceCode.Forms.Authoring.Eventing.Action action in e.Actions)
{
list.Add(new SmartFormViewActions
{
GUID = action.Guid,

viewguid = action.ViewGuid,
method = action.Method,
formguid = action.FormGuid,
executiontype = action.ExecutionType.ToString(),
controlguid = action.ControlGuid,
actiontype = action.ActionType.ToString()
});
}
return list;
}
/// <summary>
/// Actions Parameters
/// </summary>
/// <param name=”ViewName”></param>
/// <param name=”EventGUID”></param>
/// <param name=”HandleGUID”></param>
/// <param name=”ActionGUID”></param>
/// <returns></returns>
public static List<SmartFormViewActionParameters> ViewActionParameters(String ViewName, Guid EventGUID, Guid HandleGUID, Guid ActionGUID)
{
List<SmartFormViewActionParameters> list = new List<SmartFormViewActionParameters>();
FormsManager frm = new FormsManager(“dlx”, 5555);

SourceCode.Forms.Authoring.View view = new SourceCode.Forms.Authoring.View(frm.GetViewDefinition(ViewName));
SourceCode.Forms.Authoring.Eventing.Action e = view.Events[EventGUID].Handlers[HandleGUID].Actions[ActionGUID];

foreach (SourceCode.Forms.Authoring.Eventing.Mapping map in e.Parameters)
{

list.Add(new SmartFormViewActionParameters
{
targettype = map.TargetType.ToString(),
targetpath = map.TargetPath,
targetid = map.TargetID,
sourcevalue = map.SourceValue,
sourcetype = map.SourceType.ToString(),
sourcepath = map.SourcePath,
sourceid = map.SourceID

});
}

return list;
}
/// <summary>
/// Actions Results
/// </summary>
/// <param name=”ViewName”></param>
/// <param name=”EventGUID”></param>
/// <param name=”HandleGUID”></param>
/// <param name=”ActionGUID”></param>
/// <returns></returns>
public static List<SmartFormViewActionParameters> ViewActionResults(String ViewName, Guid EventGUID, Guid HandleGUID, Guid ActionGUID)
{
List<SmartFormViewActionParameters> list = new List<SmartFormViewActionParameters>();
FormsManager frm = new FormsManager(“dlx”, 5555);

SourceCode.Forms.Authoring.View view = new SourceCode.Forms.Authoring.View(frm.GetViewDefinition(ViewName));
SourceCode.Forms.Authoring.Eventing.Action e = view.Events[EventGUID].Handlers[HandleGUID].Actions[ActionGUID];

foreach (SourceCode.Forms.Authoring.Eventing.Mapping map in e.Results)
{

list.Add(new SmartFormViewActionParameters
{
targettype = map.TargetType.ToString(),
targetpath = map.TargetPath,
targetid = map.TargetID,
sourcevalue = map.SourceValue,
sourcetype = map.SourceType.ToString(),
sourcepath = map.SourcePath,
sourceid = map.SourceID

});
}

return list;
}
/// <summary>
/// Validation Messages
/// </summary>
/// <param name=”ViewName”></param>
/// <param name=”EventGUID”></param>
/// <param name=”HandleGUID”></param>
/// <param name=”ActionGUID”></param>
/// <returns></returns>
public static List<SmartFormViewActionValidationMessage> ViewActionValidation(String ViewName, Guid EventGUID, Guid HandleGUID, Guid ActionGUID)
{
List<SmartFormViewActionValidationMessage> list = new List<SmartFormViewActionValidationMessage>();
FormsManager frm = new FormsManager(“dlx”, 5555);

SourceCode.Forms.Authoring.View view = new SourceCode.Forms.Authoring.View(frm.GetViewDefinition(ViewName));
SourceCode.Forms.Authoring.Eventing.Action e = view.Events[EventGUID].Handlers[HandleGUID].Actions[ActionGUID];

foreach (SourceCode.Forms.Authoring.ValidationMessage val in e.Validation.Messages)
{

list.Add(new SmartFormViewActionValidationMessage
{
message = val.Message

});
}

return list;
}

}
}

7.Now we can build the solution and we are ready to tell K2 about it and make it a service object and then a SmartObject.

You can download the code from this location

 

Creating the Service Object

Creating the service object is really easy, open up the ‘SmartObject Service Tester’

ServiceObjectTester

1.Right Click on the ‘Endpoints Assembly’ and click on ‘Register Service Instance’

AddServiceInstance

2.In the ‘Assembly Full Path’ enter in the full address of where the dll of the assembly is kept.

3.Click on ‘Next’ and enter in ‘Form Spider’ in the ‘Display Name’ and ‘System Name’

4.Click ‘Finish’

K2 will then integrate the Dll and map out all the public static methods.

ServiceObjectTester

Now that we have the service objects we can now create the SmartObjects. For this project i have just created two SmartObjects one for Smartforms and for the Views. Each of these objects will contain all the public static methods we created in the class library earlier.

Below is an example of one

ServiceObjectTester

 

 

 

More information on Endpoint Assemblies can be found here 

 

In the final part of this series we will take the SmartObjects and build the  Smartforms and Views.

 

 

 

 

2 thoughts on “Building a K2 Smartform spider part 5

  1. Simon, its real cool stuff. I think nobody builld the same things on k2 platform and share it.
    We are Waiting for next part. If possible, plz include P&D package.

    Thanks

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s