How can we apply a service template from an automation script?
Hi Jason,
This is a snippet from one of our regression tests.
public string getServiceTemplateId(string strName, Engine engine)
{
GetServiceByNameMessage GSBMM = new GetServiceByNameMessage(strName);
ServiceInfoEventMessage SIEM = engine.SendSLNetSingleResponseMessage(GSBMM) as ServiceInfoEventMessage;
return SIEM.DataMinerID + "/" + SIEM.ElementID;
}
public TryCreateServiceResult ApplyServiceTemplate(string strServiceTemplateId, Engine engine)
{
TryCreateServiceResult TCSR = new TryCreateServiceResult();
try
{
TryCreateServiceMessage TCSM = new TryCreateServiceMessage();
TCSM.CreateAll = false;
TCSM.DataMinerID = -1;
TCSM.EditInputDataOnUpdate = false;
TCSM.ElementsToConsider = null;
//TCSM.ExtraData = null;
TCSM.HostingDataMinerID = -1;
//get only TCSM.IsCsvImport = false;
TCSM.IsReApply = false;
TCSM.Options = TryCreateServiceOptions.None;
TCSM.ServiceTemplateID = strServiceTemplateId;
TCSM.ViewID = -1;
TCSM.ViewIDs = new int[] { -1 };
TCSR = engine.SendSLNetSingleResponseMessage(TCSM) as TryCreateServiceResult;
}
catch (Exception ex)
{
bFail = true;
engine.GenerateInformation("Exception while applying ServiceTemplate: " + ex.Message);
}
return TCSR;
}
note: This is an internal call and we do not recommend using this, as it is not officially supported and we cannot guarantee that it will still work in the future. As a rule, you should avoid using SLNet calls, as these are subject to change without notice.
Thanks for the example. I slightly tweaked it to my needs.