Hello everyone, I'm not a C# programmer nor am I super familiar with the SDK, but I'm working on an automation script to import a deployment archive and I'm running into the following error in the DeployContent method (the line throwing the error is bold and red below):
CM-REQ-4317 Content Manager cannot access the history object.
If anyone has successfully done this in C#, I would love some tips. Thank you.
Here is the code that I call the Deployment methods (I took the java version and used Co-Pilot to help convert it to C#)
archiveName = "..\\deployment\\" + tenant.EamVersion + "EAM";
deployArchiveName = tenant.EamVersion + "EAM";
var deployment = new CognosDeployment();
var publicFolderContent = deployment.GetPubFolderContent(archiveName, c8CMS);
string[] selectedPubContent = CognosDeployment.GetSelectedPackageName(publicFolderContent);
string result = deployment.DeployContent("import", archiveName, deployArchiveName, selectedPubContent, c8CMS);
Here is the contents of the CognosDeployment.cs that is the converted Deployment.java:
EDITED TO ADD: This is the updated code that works! Originally the post contained the version that had issues, but I figured the working version would be more helpful for those trying to solve the same issue.
using cognosdotnet_10_2;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Services.Description;
namespace Server_Config_SDK
{
internal class CognosDeployment
{
public const string strlocale = "en";
// private Dictionary<string, searchPathSingleObject> packageInformation = new Dictionary<string, searchPathSingleObject>();
private Dictionary<string, string> packageInformation = new Dictionary<string, string>();
private static String DEPLOY_OPTION_NAME = "deploymentOptionObjectInformationArray";
public string[] GetListOfArchives(contentManagerService1 connection)
{
string[] listOfArchives = null;
try
{
listOfArchives = connection.listArchives();
}
catch (Exception ex)
{
Console.WriteLine("An error occurred while retrieving archive list:" + "\n" + ex.Message);
}
return listOfArchives;
}
public string[] GetAllFolders(contentManagerService1 myCon)
{
baseClass[] listOfFolders = null;
string[] allFolders = null;
int count = 0;
string packName = null;
string packSearchPath = null;
searchPathSingleObject myPackSearchPath = null;
string[] mySearchPath = new string[2];
mySearchPath[0] = "/content//package";
mySearchPath[1] = "/content/folder";
// get available packages
baseClass[] packageList = GetCSObject(myCon, mySearchPath[0]);
// get available folders
baseClass[] folderList = GetCSObject(myCon, mySearchPath[1]);
var packageInformation = new Dictionary<string, searchPathSingleObject>(packageList.Length + folderList.Length);
for (int i = 0; i < packageList.Length; i++)
{
packName = packageList[i].defaultName.value;
packSearchPath = packageList[i].searchPath.value;
myPackSearchPath = new searchPathSingleObject();
myPackSearchPath.Value = packSearchPath;
packageInformation[packName] = myPackSearchPath;
}
for (int j = 0; j < folderList.Length; j++)
{
packName = folderList[j].defaultName.value;
packSearchPath = folderList[j].searchPath.value;
myPackSearchPath = new searchPathSingleObject();
myPackSearchPath.Value = packSearchPath;
packageInformation[packName] = myPackSearchPath;
}
listOfFolders = new baseClass[packageList.Length + folderList.Length];
allFolders = new string[packageList.Length + folderList.Length];
if (packageList != null && packageList.Length > 0)
{
for (int j = 0; j < packageList.Length; j++)
{
listOfFolders[count] = packageList[j];
allFolders[count] = listOfFolders[count].ToString();
count++;
}
}
if (folderList != null && folderList.Length > 0)
{
for (int i = 0; i < folderList.Length; i++)
{
listOfFolders[count] = folderList[i];
allFolders[count] = listOfFolders[count].ToString();
count++;
}
}
return allFolders;
}
public static string[] GetSelectedPackageName(Dictionary<string, string> selectedPackageNamePath)
{
string[] selectedPackage = null;
if (selectedPackageNamePath.Count > 0)
{
var mySelectedPackage = selectedPackageNamePath.Keys.ToArray();
selectedPackage = new string[mySelectedPackage.Length];
for (int n = 0; n < mySelectedPackage.Length; n++)
{
selectedPackage[n] = mySelectedPackage[n];
}
}
return selectedPackage;
}
public baseClass[] GetCSObject(contentManagerService1 con, string myPathStr)
{
searchPathMultipleObject cmSearchPath = new searchPathMultipleObject();
cmSearchPath.Value = myPathStr;
baseClass[] myCMObject = null;
propEnum[] props = new propEnum[] { propEnum.searchPath, propEnum.defaultName };
sort[] sortOptions = { new sort() };
sortOptions[0].order = orderEnum.ascending;
sortOptions[0].propName = propEnum.defaultName;
try
{
myCMObject = con.query(cmSearchPath, props, sortOptions, new queryOptions());
}
catch (Exception ex)
{
Console.WriteLine("An error occurred while querying CM object:\n" + ex.Message);
}
return myCMObject;
}
//public Dictionary<string, searchPathSingleObject> GetPubFolderContent(string myArchive, contentManagerService1 myConnection)
public Dictionary<string, string> GetPubFolderContent(string myArchive, contentManagerService1 myConnection)
{
option[] deployOptEnum = new option[] { };
//Dictionary<string, searchPathSingleObject> arrOfPublicFolder = new Dictionary<string, searchPathSingleObject>();
Dictionary<string, string> arrOfPublicFolder = new Dictionary<string, string>();
try
{
deployOptEnum = myConnection.getDeploymentOptions(myArchive, new option[] { });
foreach (var option in deployOptEnum)
{
string oName = option.GetType().Name;
if (oName.Equals(DEPLOY_OPTION_NAME))
{
var packDeployInfo = ((deploymentOptionObjectInformationArray)option).value;
foreach (var info in packDeployInfo)
{
string packFoldername = info.defaultName;
searchPathSingleObject packagePath = info.searchPath;
string strPackagePath = packagePath.Value;
arrOfPublicFolder[packFoldername] = strPackagePath;
}
}
}
}
catch (Exception e)
{
Console.WriteLine("An error occurred in getting Deployment options." + "\n" + "The error: " + e.Message);
}
//packageInformation = new Dictionary<string, searchPathSingleObject>(arrOfPublicFolder);
packageInformation = new Dictionary<string, string>(arrOfPublicFolder);
return arrOfPublicFolder;
}
public string DeployContent(string myDeployType, string strArchiveName, string strDeployArchive, string[] selectedPubContent, contentManagerService1 connection)
{
asynchReply asynchReply = null;
string reportEventID = "-1";
string deployPath;
searchPathSingleObject searchPathObject = new searchPathSingleObject();
baseClass[] ArchiveInfo = AddArchive(myDeployType, strArchiveName, connection);
if (ArchiveInfo != null && ArchiveInfo.Length == 1)
{
deployPath = ArchiveInfo[0].searchPath.value;
searchPathObject.Value = deployPath;
}
else
{
return reportEventID;
}
option[] myDeploymentOptionsEnum = null;
if (myDeployType.Equals("import", StringComparison.OrdinalIgnoreCase))
{
myDeploymentOptionsEnum = SetdeploymentOptionEnum(myDeployType, strDeployArchive, selectedPubContent, connection);
}
optionArrayProp deploymentOptionsArray = new optionArrayProp();
deploymentOptionsArray.value = myDeploymentOptionsEnum;
if (myDeployType.Equals("import", StringComparison.OrdinalIgnoreCase))
{
((importDeployment)ArchiveInfo[0]).options = deploymentOptionsArray;
}
try
{
connection.update(ArchiveInfo, new updateOptions());
option[] arConnectRunOpt = new option[] { };
parameterValue[] arConnectRunParam = new parameterValue[] { };
monitorService1 monSrv = new monitorService1();
monSrv.Url = connection.Url;
monSrv.biBusHeaderValue = connection.biBusHeaderValue;
asynchReplyVar = monSrv.run(searchPathObject, arConnectRunParam, arConnectRunOpt);
}
catch (Exception remoteEx)
{
Console.WriteLine("An error occurred while deploying content:" + "\n" + remoteEx.Message);
}
if (asynchReply != null)
{
reportEventID = "Success";
}
else
{
reportEventID = "Failed";
}
return reportEventID;
}
private baseClass[] AddArchive(string deploySpec, string nameOfArchive, contentManagerService1 con)
{
importDeployment importDeploy = null;
exportDeployment exportDeploy = null;
baseClass[] addedDeploymentObjects = null;
baseClass[] bca = new baseClass[1];
addOptions addOpts = null;
searchPathSingleObject objOfSearchPath = new searchPathSingleObject();
objOfSearchPath.Value = "/adminFolder";
multilingualTokenProp multilingualTokenProperty = new multilingualTokenProp();
multilingualToken[] multilingualTokenArr = new multilingualToken[1];
multilingualToken myMultilingualToken = new multilingualToken();
myMultilingualToken.locale = strlocale;
myMultilingualToken.value = nameOfArchive;
multilingualTokenArr[0] = myMultilingualToken;
multilingualTokenProperty.value = multilingualTokenArr;
if (deploySpec.Equals("import", StringComparison.OrdinalIgnoreCase))
{
importDeploy = new importDeployment();
addOpts = new addOptions();
importDeploy.name = multilingualTokenProperty;
addOpts.updateAction = updateActionEnum.replace;
bca[0] = importDeploy;
}
else
{
exportDeploy = new exportDeployment();
addOpts = new addOptions();
exportDeploy.name = multilingualTokenProperty;
addOpts.updateAction = updateActionEnum.replace;
bca[0] = exportDeploy;
}
try
{
addedDeploymentObjects = con.add(objOfSearchPath, bca, addOpts);
}
catch (Exception remoEx)
{
Console.WriteLine("An error occurred when adding a deployment object:" + "\n" + remoEx.Message);
}
return addedDeploymentObjects;
}
private option[] SetdeploymentOptionEnum(string deploymentType, string nameOfArchive, string[] listOfSelectedFolders, contentManagerService1 con)
{
List<option> deploymentOptions = new List<option>();
int num = 0;
int eOptionCount = 2;
string[] deployOptionEnumBoolean = { "archiveOverwrite", "dataSourceSelect", "namespaceSelect", "namespaceThirdParty", "objectPolicies", "packageHistories", "packageOutputs", "packageSchedules", "packageSelect", "recipientsSelect", "takeOwnership", "packageDatasetOutputs" };
string[] deployOptionEnumResolution = { "dataSourceConflictResolution", "namespaceConflictResolution", "objectPoliciesConflictResolution", "ownershipConflictResolution", "packageHistoriesConflictResolution", "packageOutputsConflictResolution", "packageSchedulesConflictResolution", "recipientsConflictResolution", "packageDatasetOutputsConflictResolution" };
var deployOption = new deploymentOptionEnum();
deploymentOptions.Capacity = eOptionCount + deployOptionEnumBoolean.Length + deployOptionEnumResolution.Length;
// Define the deployment options
deploymentOptions.Add(SetImportDeploymentOptionPackageInfo(listOfSelectedFolders));
deploymentOptions.Add(SetDeploymentOptionString(nameOfArchive));
// change default value into 'true'
deploymentOptions.Add(SetArchiveOverWrite(true));
// use default value
deploymentOptions.Add(SetDataSourceSelect(false));
// use default value
deploymentOptions.Add(SetNameSpaceSelect(false));
// change default value into 'false'
deploymentOptions.Add(SetNameSpaceThirdParty(false));
// use default value
deploymentOptions.Add(SetObjectPolicies(false));
// use default value
deploymentOptions.Add(SetPackageHistories(false));
// use default value
deploymentOptions.Add(SetPackageOutputs(false));
// use default value
deploymentOptions.Add(SetPackageSchedules(false));
// use default value
deploymentOptions.Add(SetPackageSelect(true));
// use default value
deploymentOptions.Add(SetRecipientsSelect(false));
// change default value into 'true'
deploymentOptions.Add(SetTakeOwnership(true));
// this sample uses 'false' (default) value for export and 'true' for import
if (deploymentType.Equals("import", StringComparison.OrdinalIgnoreCase))
{
deploymentOptions.Add(SetPackageDatasetOutputs(true));
}
// use default value
deploymentOptions.Add(SetDataSourceConflictResolution(true));
// use default value
deploymentOptions.Add(SetNamespaceConflictResolution(true));
// use default value
deploymentOptions.Add(SetObjectPoliciesConflictResolution(true));
// use default value
deploymentOptions.Add(SetOwnershipConflictResolution(true));
// use default value
deploymentOptions.Add(SetPackageHistoriesConflictResolution(true));
// use default value
deploymentOptions.Add(SetPackageOutputsConflictResolution(true));
// use default value
deploymentOptions.Add(SetPackageSchedulesConflictResolution(true));
// use default value
deploymentOptions.Add(SetRecipientsConflictResolution(true));
// use default value
deploymentOptions.Add(SetPackageDatasetOutputsConflictResolution(true));
return deploymentOptions.ToArray();
}
// set import deployment option property (mandatory)
private deploymentOptionImportRuleArray SetImportDeploymentOptionPackageInfo(string[] arrOfFolders)
{
var pkgDeployInfoArr = new deploymentImportRule[arrOfFolders.Length];
deploymentImportRule pkgDeployInfo;
multilingualToken[] multilingualTokenArr;
multilingualToken multilingualToken;
searchPathSingleObject packSearchPath = null;
for (int i = 0; i < arrOfFolders.Length; i++)
{
multilingualToken = new multilingualToken();
multilingualTokenArr = new multilingualToken[1];
pkgDeployInfo = new deploymentImportRule();
multilingualToken.locale = strlocale;
multilingualToken.value = arrOfFolders[i];
multilingualTokenArr[0] = multilingualToken;
string myPackageName = arrOfFolders[i];
//var myPackInfo = new Dictionary<string, searchPathSingleObject>(packageInformation);
var myPackInfo = new Dictionary<string, string>(packageInformation);
if (myPackInfo.ContainsKey(myPackageName))
{
packSearchPath = new searchPathSingleObject();
packSearchPath.Value = myPackInfo[myPackageName];
}
pkgDeployInfo.archiveSearchPath = packSearchPath;
pkgDeployInfo.name = multilingualTokenArr;
pkgDeployInfo.parent = new searchPathSingleObject();
pkgDeployInfo.parent.Value = "/content";
pkgDeployInfoArr[i] = pkgDeployInfo;
}
var deployOptionPkgInfo = new deploymentOptionImportRuleArray
{
name = deploymentOptionEnum.import,
value = pkgDeployInfoArr
};
return deployOptionPkgInfo;
}
// set DeploymentOptionString property (mandatory)
private deploymentOptionString SetDeploymentOptionString(string archiveName)
{
var archiveDefault = new multilingualString
{
locale = strlocale,
value = archiveName
};
var deployOptionStr = new deploymentOptionString
{
name = deploymentOptionEnum.archive,
value = archiveDefault.value
};
return deployOptionStr;
}
// allow the deployment overwrites the archive
private deploymentOptionBoolean SetArchiveOverWrite(bool setValue)
{
var deployOptionBool = new deploymentOptionBoolean
{
name = deploymentOptionEnum.archiveOverwrite,
value = !setValue
};
return deployOptionBool;
}
// set dataSourceSelect as default value - 'false'
private deploymentOptionBoolean SetDataSourceSelect(bool setValue)
{
var deployOptionBool = new deploymentOptionBoolean
{
name = deploymentOptionEnum.dataSourceSelect,
value = !setValue
};
return deployOptionBool;
}
// set namespaceSelect as default value - 'false'
private deploymentOptionBoolean SetNameSpaceSelect(bool setValue)
{
var deployOptionBool = new deploymentOptionBoolean
{
name = deploymentOptionEnum.namespaceSelect,
value = !setValue
};
return deployOptionBool;
}
// Not include references to external namespaces - value is false
private deploymentOptionBoolean SetNameSpaceThirdParty(bool setValue)
{
var deployOptionBool = new deploymentOptionBoolean
{
name = deploymentOptionEnum.namespaceThirdParty,
value = setValue
};
return deployOptionBool;
}
// set objectPolicies as default value - 'false'
private deploymentOptionBoolean SetObjectPolicies(bool setValue)
{
var deployOptionBool = new deploymentOptionBoolean
{
name = deploymentOptionEnum.objectPolicies,
value = !setValue
};
return deployOptionBool;
}
// set packageHistories as default value - 'false'
private deploymentOptionBoolean SetPackageHistories(bool setValue)
{
var deployOptionBool = new deploymentOptionBoolean
{
name = deploymentOptionEnum.packageHistories,
value = !setValue
};
return deployOptionBool;
}
// set packageOutputs as default value - 'false'
private deploymentOptionBoolean SetPackageOutputs(bool setValue)
{
var deployOptionBool = new deploymentOptionBoolean
{
name = deploymentOptionEnum.packageOutputs,
value = !setValue
};
return deployOptionBool;
}
// set packageSchedules as default value - 'false'
private deploymentOptionBoolean SetPackageSchedules(bool setValue)
{
var deployOptionBool = new deploymentOptionBoolean
{
name = deploymentOptionEnum.packageSchedules,
value = !setValue
};
return deployOptionBool;
}
// set packageSelect as default value - 'true'
private deploymentOptionBoolean SetPackageSelect(bool setValue)
{
var deployOptionBool = new deploymentOptionBoolean
{
name = deploymentOptionEnum.packageSelect,
value = setValue
};
return deployOptionBool;
}
// set recipientsSelect as default value - 'false'
private deploymentOptionBoolean SetRecipientsSelect(bool setValue)
{
var deployOptionBool = new deploymentOptionBoolean
{
name = deploymentOptionEnum.recipientsSelect,
value = !setValue
};
return deployOptionBool;
}
// set the owner to the owner from the source - the value is 'true'
private deploymentOptionBoolean SetTakeOwnership(bool setValue)
{
var deployOptionBool = new deploymentOptionBoolean
{
name = deploymentOptionEnum.takeOwnership,
value = !setValue
};
return deployOptionBool;
}
// set upload data for packages - the default value is 'false' (this sample uses 'true' for import)
private deploymentOptionBoolean SetPackageDatasetOutputs(bool setValue)
{
var deployOptionBool = new deploymentOptionBoolean
{
name = deploymentOptionEnum.packageDatasetOutputs,
value = setValue
};
return deployOptionBool;
}
// set dataSourceConflictResolution as default value - 'replace'
private deploymentOptionResolution SetDataSourceConflictResolution(bool setValue)
{
var deployOptionResolute = new deploymentOptionResolution
{
name = deploymentOptionEnum.dataSourceConflictResolution,
value = setValue ? conflictResolutionEnum.replace : conflictResolutionEnum.keep
};
return deployOptionResolute;
}
// set namespaceConflictResolution as default value - 'replace'
private deploymentOptionResolution SetNamespaceConflictResolution(bool setValue)
{
var deployOptionResolute = new deploymentOptionResolution
{
name = deploymentOptionEnum.namespaceConflictResolution,
value = setValue ? conflictResolutionEnum.replace : conflictResolutionEnum.keep
};
return deployOptionResolute;
}
// set objectPoliciesConflictResolution as default value - 'replace'
private deploymentOptionResolution SetObjectPoliciesConflictResolution(bool setValue)
{
var deployOptionResolute = new deploymentOptionResolution
{
name = deploymentOptionEnum.objectPoliciesConflictResolution,
value = setValue ? conflictResolutionEnum.replace : conflictResolutionEnum.keep
};
return deployOptionResolute;
}
// set ownershipConflictResolution as default value - 'replace'
private deploymentOptionResolution SetOwnershipConflictResolution(bool setValue)
{
var deployOptionResolute = new deploymentOptionResolution
{
name = deploymentOptionEnum.ownershipConflictResolution,
value = setValue ? conflictResolutionEnum.replace : conflictResolutionEnum.keep
};
return deployOptionResolute;
}
// set packageHistoriesConflictResolution as default value - 'replace'
private deploymentOptionResolution SetPackageHistoriesConflictResolution(bool setValue)
{
var deployOptionResolute = new deploymentOptionResolution
{
name = deploymentOptionEnum.packageHistoriesConflictResolution,
value = setValue ? conflictResolutionEnum.replace : conflictResolutionEnum.keep
};
return deployOptionResolute;
}
// set packageOutputsConflictResolution as default value - 'replace'
private deploymentOptionResolution SetPackageOutputsConflictResolution(bool setValue)
{
var deployOptionResolute = new deploymentOptionResolution
{
name = deploymentOptionEnum.packageOutputsConflictResolution,
value = setValue ? conflictResolutionEnum.replace : conflictResolutionEnum.keep
};
return deployOptionResolute;
}
// set packageSchedulesConflictResolution as default value - 'replace'
private deploymentOptionResolution SetPackageSchedulesConflictResolution(bool setValue)
{
var deployOptionResolute = new deploymentOptionResolution
{
name = deploymentOptionEnum.packageSchedulesConflictResolution,
value = setValue ? conflictResolutionEnum.replace : conflictResolutionEnum.keep
};
return deployOptionResolute;
}
// set recipientsConflictResolution as default value - 'replace'
private deploymentOptionResolution SetRecipientsConflictResolution(bool setValue)
{
var deployOptionResolute = new deploymentOptionResolution
{
name = deploymentOptionEnum.recipientsConflictResolution,
value = setValue ? conflictResolutionEnum.replace : conflictResolutionEnum.keep
};
return deployOptionResolute;
}
// set packageDatasetOutputsConflictResolution as default value - 'replace'
private deploymentOptionResolution SetPackageDatasetOutputsConflictResolution(bool setValue)
{
var deployOptionResolute = new deploymentOptionResolution
{
name = deploymentOptionEnum.packageDatasetOutputsConflictResolution,
value = setValue ? conflictResolutionEnum.replace : conflictResolutionEnum.keep
};
return deployOptionResolute;
}
}
}
------------------------------
Marc Percy
------------------------------