private bool ChangeRecursiveSubRoutine(ref Dictionary<string, CMSObject> dictBaseLineInfo, string GUID, string NewAuthor, string Role, string Resolution = "") { //Dim requestmetadata As StringBuilder = BuildRequestedMetadata() string RequestedXMLObject = ""; XmlDocument doc = new XmlDocument(); XmlDocument docorig = new XmlDocument(); //Version is determined by the baseline. string version = null; CMSObject objCMSObject = new CMSObject("", "", ""); dictBaseLineInfo.TryGetValue(GUID, out objCMSObject); if (objCMSObject.Version.Length > 0) { version = objCMSObject.Version; } else { //failed to find object in the baseline modErrorHandler.Errors.PrintMessage(2, "Failed to find object in baseline. Info: " + GUID + ".", strModuleName + "-ChangeRecursiveSubRoutine"); return false; } try { oISHAPIObjs.ISHDocObj.GetMetaData(GUID, ref version, "en", Resolution, oCommonFuncs.BuildRequestedMetadata().ToString(), ref RequestedXMLObject); } catch (Exception ex) { //failed to get object modErrorHandler.Errors.PrintMessage(2, "Failed to get object in DB. Info: " + GUID + "=" + version + ". Message: " + ex.Message.ToString(), strModuleName + "-ChangeRecursiveSubRoutine"); return false; } //Load the XML and get the metadata: doc.LoadXml(RequestedXMLObject); //keep the original for matching later. docorig.LoadXml(RequestedXMLObject); string IshType = oCommonFuncs.GetISHTypeFromMeta(doc); //Get the children and recurse if applicable (by type). switch (IshType) { case "ISHMasterDoc": case "ISHModule": //if a map or topic, get children //Dim CurMeta As Object = IshReports.GetReportedObjects(doc) Hashtable children = new Hashtable(); GetReferencedModules(GUID, children, version, "en"); foreach (DictionaryEntry childmodule in children) { if (!(childmodule.Value.GUID == GUID) & !m_recursion_hash.Contains(childmodule.Value.GUID)) { //Track the GUID we're diving into so that we don't accidently try to process it again later (endless looping). m_recursion_hash.Add(childmodule.Value.GUID, childmodule.Value.GUID); ChangeRecursiveSubRoutine(ref dictBaseLineInfo, childmodule.Value.GUID, NewAuthor, Role, childmodule.Value.Resolution); } } break; default: break; //Returned something that we don't need to parse for children... //Return False } //change owner by GUID Stuff XmlNode ishfields = doc.SelectSingleNode("//ishfields"); XmlNode ishfieldsorig = docorig.SelectSingleNode("//ishfields"); XmlNode funame = ishfields.SelectSingleNode("ishfield[@name='" + Role + "']"); //If there's no currently assigned name to the role specified, we need to insert it. if (funame == null) { XmlDocument funamedoc = new XmlDocument(); funamedoc.LoadXml("<funame><ishfield name='" + Role + "' level='lng'>" + NewAuthor + "</ishfield></funame>"); funame = funamedoc.FirstChild; ishfields.AppendChild(doc.ImportNode(funame.FirstChild, true)); funame = ishfields.LastChild; } funame.InnerText = NewAuthor; XmlNode ishver = ishfields.SelectSingleNode("ishfield[@name='VERSION']"); ishfields.RemoveChild(ishver); //change the owner of the GUID at the specified ver switch (IshType) { case "ISHMasterDoc": case "ISHModule": //if a map or topic, update the guid with simple command try { oISHAPIObjs.ISHDocObj.SetMetaData(GUID, ref version, "en", "", ishfields.OuterXml.ToString(), RequestedXMLObject); } catch (Exception ex) { modErrorHandler.Errors.PrintMessage(2, "Unable to change assignee on object " + GUID + "=" + version + ". Message: " + ex.Message.ToString(), strModuleName + "-ChangeRecursiveSubRoutine"); return false; } break; case "ISHIllustration": if (!(Role == "FEDITOR") & !(Role == "FCODEREVIEWER")) { //If illustration, need to update all possible resolutions. //For Images, we need to replace ALL instances which means we need to trick it into thinking that we've returned the matching resolution for each type. //Start by making the original res match the High resolution. XmlNode res = doc.SelectSingleNode("//ishfields/ishfield[@name='FRESOLUTION']"); XmlNode resOrig = docorig.SelectSingleNode("//ishfields/ishfield[@name='FRESOLUTION']"); res.InnerText = "High"; resOrig.InnerText = "High"; try { oISHAPIObjs.ISHDocObj.SetMetaData(GUID, ref version, "en", "High", ishfields.OuterXml.ToString(), ishfieldsorig.OuterXml.ToString()); } catch (Exception ex) { } res.InnerText = "Low"; resOrig.InnerText = "Low"; try { oISHAPIObjs.ISHDocObj.SetMetaData(GUID, ref version, "en", "Low", ishfields.OuterXml.ToString(), ishfieldsorig.OuterXml.ToString()); } catch (Exception ex) { } res.InnerText = "Thumbnail"; resOrig.InnerText = "Thumbnail"; try { oISHAPIObjs.ISHDocObj.SetMetaData(GUID, ref version, "en", "Thumbnail", ishfields.OuterXml.ToString(), ishfieldsorig.OuterXml.ToString()); } catch (Exception ex) { } res.InnerText = "Source"; resOrig.InnerText = "Source"; try { oISHAPIObjs.ISHDocObj.SetMetaData(GUID, ref version, "en", "Source", ishfields.OuterXml.ToString(), ishfieldsorig.OuterXml.ToString()); } catch (Exception ex) { } } break; default: break; //Something else altogether... Not sure what to do here. } //Track the GUID we're diving into so that we don't accidently try to process it again later (endless looping). if (!m_recursion_hash.Contains(GUID)) { m_recursion_hash.Add(GUID, GUID); } return true; }
public Dictionary<string, CMSObject> GetBaselineObjects(string GUID, string Version, string Language = "en") { //Get the pub's baseline ID from the pub object string outObjectList = ""; string[] GUIDs = new string[1]; GUIDs[0] = GUID; string[] Languages = new string[1]; Languages[0] = Language; string[] Resolutions = null; //[UPGRADE to 2013SP1] Changed the result to return the result instead of just some arbitrary response. Resolutions = oISHAPIObjs.ISHMetaObj.GetLOVValues("DRESOLUTION"); //Get the existing publication content at the specified version. outObjectList = oISHAPIObjs.ISHPubOutObj25.RetrieveVersionMetadata(GUIDs, Version, oCommonFuncs.BuildMinPubMetadata().ToString()); XmlDocument VerDoc = new XmlDocument(); VerDoc.LoadXml(outObjectList); if (VerDoc == null | VerDoc.HasChildNodes == false) { modErrorHandler.Errors.PrintMessage(3, "Unable to find publication for specified GUID: " + GUID, strModuleName + "-GetBaselineObjects"); return null; } //Get the Baseline ID from the publication: string baselineID = ""; string baselinename = null; XmlNode ishfields = VerDoc.SelectSingleNode("//ishfields"); baselinename = ishfields.SelectSingleNode("ishfield[@name='FISHBASELINE']").InnerText; //Pull the baseline info string myBaseline = ""; //[UPGRADE to 2013SP1] Changed the result to return the result instead of just some arbitrary response. baselineID = oISHAPIObjs.ISHBaselineObj.GetBaselineId(baselinename); //[UPGRADE to 2013SP1] Changed the result to return the result instead of just some arbitrary response. outObjectList = oISHAPIObjs.ISHBaselineObj.GetReport(baselineID, null, Languages, Languages, Languages, Resolutions); //Load the resulting baseline string as an xml document XmlDocument baselineDoc = new XmlDocument(); baselineDoc.LoadXml(outObjectList); Dictionary<string, CMSObject> dictBaselineObjects = new Dictionary<string, CMSObject>(); //for each object referenced, store the various info in an object and then store them in the hashtable. GUIDs are the keys. foreach (XmlNode baselineObject in baselineDoc.SelectNodes("/baseline/objects/object")) { //create a new CMSObject storage container string refGuid = baselineObject.Attributes.GetNamedItem("ref").Value; string ishtype = baselineObject.Attributes.GetNamedItem("type").Value; if (ishtype == "ISHNone") { continue; } string refver = baselineObject.Attributes.GetNamedItem("versionnumber").Value; string reportitems = baselineObject.SelectSingleNode("reportitems").OuterXml.ToString(); CMSObject CMSObject = new CMSObject(refGuid, refver, ishtype, reportitems); //save the object to the hash using the GUID as the key. dictBaselineObjects.Add(refGuid, CMSObject); } return dictBaselineObjects; }