Here’s some sample code for working with a…

Here’s some sample code for working with a SmartObject:

We use the following namespaces from these DLLs (They are in the GAC as well)

using SourceCode.SmartObjects.Client; (DLL: SourceCode.SmartObjects.Client)
using SourceCode.Hosting.Client.BaseAPI; (DLL: SourceCode.HostClient)


//this is your starting point

SmartObjectClientServer socSvr = new SmartObjectClientServer();

//we now have a connection string builder helper

SCConnectionStringBuilder connectionStrBuilder= new SCConnectionStringBuilder();

socSvr .Connection = socSvr.CreateConnection();

connectionStr.Host = “servernameFromConfig”;

connectionStr.Integrated = true;

connectionStr.IsPrimaryLogin = true;

connectionStr.Port = portNumberFromConfig;

try

{

socSvr.Connection.Open(connectionStrBuilder.connectionString);

SmartObject so = socSvr.GetSmartObject(“MySmartObject”);

so.MethodToExecute = “Load”;

so.Properties[“prop1”].Value = “value”;

//add more props

//you can call the Save, Delete, etc methods (scalar methods) like this

so = socSvr.ExecuteScalar(so);

//you call the list method which retrurs a SmartObjectList like this

//SmartObjectList soList = socSvr.ExecuteList(so);

}

//this is a K2 Exception Class with useful properties
catch (SmartObjectException soe)

{
StringBuilder errorMessage = new StringBuilder();

foreach (SmartObjectExceptionData smartobjectExceptionData in soe.BrokerData)
{
string message = smartobjectExceptionData.Message;
string service = smartobjectExceptionData.ServiceName;
string serviceGuid = smartobjectExceptionData.ServiceGuid;
string severity = smartobjectExceptionData.Severity.ToString();
string innermessage = smartobjectExceptionData.InnerExceptionMessage;

errorMessage.AppendLine(“Service: ” + service);
errorMessage.AppendLine(“Service Guid: ” + serviceGuid);
errorMessage.AppendLine(“Severity: ” + severity);
errorMessage.AppendLine(“Error Message: ” + message);
errorMessage.AppendLine(“InnerException Message: ” + innermessage);
}

}

2 responses to “Here’s some sample code for working with a…”

  1. […] Code manipulation of SmartObjects and Exception handling September 2007 5 […]

Leave a Reply to Here’s some sample code for working with a SmartObject | SaiCancel reply

Discover more from jeylabs

Subscribe now to keep reading and get access to the full archive.

Continue reading