How to get the SmartObject definition as XML
You can access a deployed SmartObject, retrieve its definition as XML and perform actions with that XML, like writing it to the console. The XML can be transformed into a format for documenting existing SmartObjects.
The SmartObject has the following properties:
References to SourceCode.HostClientAPI, SourceCode.SmartObjects.Client, SourceCode.SmartObject.Management, SourceCode.SmartObjects.Authoring and SourceCode.Framework are also required.
Retrieve a deployed SmartObject definition as XML
// TODO: Use the SCConnectionStringBuilder Class to construct a connection string
string _connectionstring = "[K2environmentConnectionString]";
// open a K2 Server connection
SmartObjectClientServer serverName = new SmartObjectClientServer();
serverName.CreateConnection();
serverName.Connection.Open(_connectionstring.ToString());
// open a K2 SmartObject Management Server connection
SmartObjectManagementServer smoMServer = new SmartObjectManagementServer();
smoMServer.CreateConnection();
smoMServer.Connection.Open(_connectionstring.ToString());
try {
// get a handle to the "Employee" SmartObject
SmartObject smartObject = serverName.GetSmartObject("Employee");
// retrieve the SmartObject definition and write the XML out to the console
// the XML could be transformed using the Authoring namespace and used for documenting existing SmartObjects
string smoDefinition = smoMServer.GetSmartObjectDefinition(smartObject.Guid);
Console.WriteLine(smoDefinition);
Console.ReadLine();
} catch (Exception ex) {
// write error to console
Console.WriteLine("Error: " + ex.Message);
Console.ReadLine();
} finally {
// close the connections
serverName.Connection.Close();
smoMServer.Connection.Close();
}