protected string FindBestDestination(string initiationSource, string recommendedBranchIP, List <string> limitedDestinations) { try { string subDir = null; if (RecreateSubFromRootOf != null && RecreateSubFromRootOf.Trim().Length > 0) { if (initiationSource.ToUpper().IndexOf(RecreateSubFromRootOf.ToUpper()) >= 0) { int startIndex = initiationSource.ToUpper().IndexOf(RecreateSubFromRootOf.ToUpper()) + RecreateSubFromRootOf.Length + 1; if (startIndex < STEM.Sys.IO.Path.GetDirectoryName(initiationSource).Length) { subDir = initiationSource.Substring(startIndex, STEM.Sys.IO.Path.GetDirectoryName(initiationSource).Length - startIndex); } } } string fileFirst3 = STEM.Sys.IO.Path.GetFileNameWithoutExtension(STEM.Sys.IO.Path.IPFromPath(initiationSource)); string branchFirst3 = STEM.Sys.IO.Path.GetFileNameWithoutExtension(recommendedBranchIP); string fileFirst2 = STEM.Sys.IO.Path.GetFileNameWithoutExtension(fileFirst3); string branchFirst2 = STEM.Sys.IO.Path.GetFileNameWithoutExtension(branchFirst3); string destinationPath = SelectDestination(branchFirst3, subDir, limitedDestinations); if (destinationPath == null && (branchFirst3 != fileFirst3)) { destinationPath = SelectDestination(fileFirst3, subDir, limitedDestinations); } if (destinationPath == null) { destinationPath = SelectDestination(branchFirst2, subDir, limitedDestinations); } if (destinationPath == null && (branchFirst2 != fileFirst2)) { destinationPath = SelectDestination(fileFirst2, subDir, limitedDestinations); } if (destinationPath == null) { destinationPath = SelectDestination(null, subDir, limitedDestinations); } return(destinationPath); } catch (Exception ex) { STEM.Sys.EventLog.WriteEntry("DestinationPathElectionController.FindBestDestination", ex.ToString(), STEM.Sys.EventLog.EventLogEntryType.Error); } return(null); }
/// <summary> /// Customize an iSetTemplate by applying the TemplateKVP map to the InstructionsXml /// </summary> /// <param name="iSetTemplate">A clone of the template to be modified in this method</param> /// <param name="map">The TemplateKVP map used to modify the iSetTemplate</param> /// <param name="branchIP">The branchIP this will be assigned to</param> /// <param name="initiationSource">The initiationSource passed in to GenerateDeploymentDetails()</param> /// <param name="cloneMap">Should the map be cloned as it will be modified in this method</param> public override void CustomizeInstructionSet(_InstructionSet iSetTemplate, System.Collections.Generic.Dictionary <string, string> map, string branchIP, string initiationSource, bool cloneMap = true) { if (iSetTemplate == null) { throw new ArgumentNullException(nameof(iSetTemplate)); } if (map == null) { throw new ArgumentNullException(nameof(map)); } if (String.IsNullOrEmpty(branchIP)) { throw new ArgumentNullException(nameof(branchIP)); } if (String.IsNullOrEmpty(initiationSource)) { throw new ArgumentNullException(nameof(initiationSource)); } System.Collections.Generic.Dictionary <string, string> kvp = map; if (cloneMap) { kvp = new System.Collections.Generic.Dictionary <string, string>(map); } kvp["[TargetPath]"] = STEM.Sys.IO.Path.GetDirectoryName(initiationSource); if (!String.IsNullOrEmpty(kvp["[TargetPath]"])) { kvp["[TargetDirectoryName]"] = STEM.Sys.IO.Path.GetFileName(kvp["[TargetPath]"]); kvp["[TargetName]"] = STEM.Sys.IO.Path.GetFileName(initiationSource); kvp["[TargetNameWithoutExt]"] = STEM.Sys.IO.Path.GetFileNameWithoutExtension(initiationSource); kvp["[TargetExt]"] = STEM.Sys.IO.Path.GetExtension(initiationSource); } else { kvp["[TargetPath]"] = ""; kvp["[TargetDirectoryName]"] = ""; kvp["[TargetName]"] = ""; kvp["[TargeteNameWithoutExt]"] = ""; kvp["[TargetExt]"] = ""; } kvp["[SourceAddress]"] = STEM.Sys.IO.Path.IPFromPath(initiationSource); kvp["[SourceMachineName]"] = STEM.Sys.IO.Net.MachineName(kvp["[SourceAddress]"]); string xml = iSetTemplate.SerializationSourceInstructionDocument; bool getFileInfo = false; if (xml.IndexOf("[LastWriteTimeUtc]", StringComparison.InvariantCultureIgnoreCase) >= 0) { getFileInfo = true; } if (getFileInfo == false) { if (xml.IndexOf("[LastAccessTimeUtc]", StringComparison.InvariantCultureIgnoreCase) >= 0) { getFileInfo = true; } } if (getFileInfo == false) { if (xml.IndexOf("[CreationTimeUtc]", StringComparison.InvariantCultureIgnoreCase) >= 0) { getFileInfo = true; } } if (getFileInfo == false) { if (xml.IndexOf("[FileSize]", StringComparison.InvariantCultureIgnoreCase) >= 0) { getFileInfo = true; } } if (getFileInfo == false) { foreach (string k in kvp.Keys) { if (kvp[k] != null) { if (kvp[k].IndexOf("[LastWriteTimeUtc]", StringComparison.InvariantCultureIgnoreCase) >= 0) { getFileInfo = true; break; } if (kvp[k].IndexOf("[LastAccessTimeUtc]", StringComparison.InvariantCultureIgnoreCase) >= 0) { getFileInfo = true; break; } if (kvp[k].IndexOf("[CreationTimeUtc]", StringComparison.InvariantCultureIgnoreCase) >= 0) { getFileInfo = true; break; } if (kvp[k].IndexOf("[FileSize]", StringComparison.InvariantCultureIgnoreCase) >= 0) { getFileInfo = true; break; } } } } if (getFileInfo) { STEM.Sys.IO.Listing.FileInfo info = GetFileInfo(initiationSource); if (info == null) { info = new STEM.Sys.IO.Listing.FileInfo { CreationTimeUtc = DateTime.MinValue, LastAccessTimeUtc = DateTime.MinValue, LastWriteTimeUtc = DateTime.MinValue, Size = 0 } } ; foreach (string key in kvp.Keys.Where(i => i.Equals("[LastWriteTimeUtc]", StringComparison.InvariantCultureIgnoreCase)).ToList()) { try { kvp[key] = info.LastWriteTimeUtc.ToString(kvp[key], System.Globalization.CultureInfo.CurrentCulture); } catch { } } foreach (string key in kvp.Keys.Where(i => i.Equals("[LastAccessTimeUtc]", StringComparison.InvariantCultureIgnoreCase)).ToList()) { try { kvp[key] = info.LastAccessTimeUtc.ToString(kvp[key], System.Globalization.CultureInfo.CurrentCulture); } catch { } } foreach (string key in kvp.Keys.Where(i => i.Equals("[CreationTimeUtc]", StringComparison.InvariantCultureIgnoreCase)).ToList()) { try { kvp[key] = info.CreationTimeUtc.ToString(kvp[key], System.Globalization.CultureInfo.CurrentCulture); } catch { } } foreach (string key in kvp.Keys.Where(i => i.Equals("[FileSize]", StringComparison.InvariantCultureIgnoreCase)).ToList()) { try { kvp[key] = info.Size.ToString(); } catch { } } } string subDir = null; if (!String.IsNullOrEmpty(RecreateSubFromRootOf) && RecreateSubFromRootOf.Trim().Length > 0) { if (initiationSource.ToUpper(System.Globalization.CultureInfo.CurrentCulture).IndexOf(RecreateSubFromRootOf.ToUpper(System.Globalization.CultureInfo.CurrentCulture), StringComparison.InvariantCultureIgnoreCase) >= 0) { int startIndex = initiationSource.ToUpper(System.Globalization.CultureInfo.CurrentCulture).IndexOf(RecreateSubFromRootOf.ToUpper(System.Globalization.CultureInfo.CurrentCulture), StringComparison.InvariantCultureIgnoreCase) + RecreateSubFromRootOf.Length + 1; if (startIndex < STEM.Sys.IO.Path.GetDirectoryName(initiationSource).Length) { subDir = initiationSource.Substring(startIndex, STEM.Sys.IO.Path.GetDirectoryName(initiationSource).Length - startIndex); } } } if (subDir == null) { subDir = ""; } kvp["[SubDir]"] = subDir; base.CustomizeInstructionSet(iSetTemplate, kvp, branchIP, initiationSource, false); }