Hi, I would like to automate the installation of function file and setting it the Production. Using InstallPackage does not seem to be supported. In addition, the method using srmInstaller() can sometimes be problematic.
Is there a wrapper call that can be used to upload a function.xml file and then set that new version to Production?
Hey Bing,
Assuming you have the functions.xml file in your package, you can use SLNet messages to import it and set it active.
To upload a functions.xml file, use the 'AddFunctionsXmlRequestMessage'
var xmlContents = File.ReadAllText("..."); // The xml contents of the function file
var protocolName = "...";
var fileName = "..."; // The file name for the functions file.
var addReq = new AddFunctionsXmlRequestMessage()
{
File = xmlContents,
ProtocolName = protocolName,
FileName = fileName
};var response = _engine.SendSLNetSingleResponseMessage(addReq) as AddFunctionsXmlResponseMessage;
if (response == null || !response.Success || !response.TraceData.HasSucceeded())
{
// Something went wrong, response.TraceData might contain more information
// and can be 'ToStringed'
}
Setting a functions.xml active can be done with the 'SetCurrentFunctionsXmlRequestMessage'
var setReq = new SetCurrentFunctionsXmlRequestMessage()
{
File = fileName,
ProtocolName = protocolName,
};
var setResp = _engine.SendSLNetSingleResponseMessage(setReq) as SetCurrentFunctionsXmlResponseMessage;
if (setResp == null || !setResp.Success || !setResp.TraceData.HasSucceeded())
{
// Something went wrong
}
Activating a functions.xml can fail in case there is already a different file active and in use (by service definitions, resources…) and the update is not considered 'safe'. The following changes are considered unsafe:
- Removing a function definition
- Lowering the max instances of a function definition
- Change name of a function definition to a name that is not unique within the protocol function version
- Change the profile of function definition
- Change parent of a function definition
- Changes to the entrypoints of a function definition
- Remove an interface of a function definition
- Remove a parameter of a function definition
If there are any unsafe changes between the function versions the call will fail unless you force it, which will skip these checks. Forcing can be done with a property on the 'SetCurrentFunctionsXmlRequestMessage',but is of course not recommended to do by default.
Note that using SLNet messages directly is not recommended. I do think the relevant method in the SRMInstaller should cover your use case as well, so if you encounter an issue with that, it's best to get in touch with the A&O domain.