/// <summary> /// utility function to write the simple setParameter.xml file /// </summary> /// <param name="loggingHelper"></param> /// <param name="parameters"></param> /// <param name="outputFileName"></param> private static void WriteManifestsToFile(Utilities.TaskLoggingHelper loggingHelper, Framework.ITaskItem[] items, string outputFileName) { Xml.XmlDocument document = new System.Xml.XmlDocument(); Xml.XmlElement manifestElement = document.CreateElement("sitemanifest"); document.AppendChild(manifestElement); if (items != null) { foreach (Framework.ITaskItem item in items) { string name = item.ItemSpec; Xml.XmlElement providerElement = document.CreateElement(name); string path = item.GetMetadata("Path"); providerElement.SetAttribute("path", path); string additionProviderSetting = item.GetMetadata("AdditionalProviderSettings"); if (!string.IsNullOrEmpty(additionProviderSetting)) { string[] providerSettings = additionProviderSetting.Split(';'); foreach (string ps in providerSettings) { string value = item.GetMetadata(ps); if (!string.IsNullOrEmpty(value)) { providerElement.SetAttribute(ps, value); } } } manifestElement.AppendChild(providerElement); } } // Save the UTF8 and Indented SaveDocument(document, outputFileName, System.Text.Encoding.UTF8); }
/// <summary> /// utility function to write the simple setParameter.xml file /// </summary> /// <param name="loggingHelper"></param> /// <param name="parameters"></param> /// <param name="outputFileName"></param> private static void WriteSetParametersToFile(Utilities.TaskLoggingHelper loggingHelper, Framework.ITaskItem[] parameters, string outputFileName, bool foptimisticParameterDefaultValue) { Xml.XmlDocument document = new System.Xml.XmlDocument(); Xml.XmlElement parametersElement = document.CreateElement("parameters"); document.AppendChild(parametersElement); if (parameters != null) { System.Collections.Generic.IList <Framework.ITaskItem> items = Utility.SortParametersTaskItems(parameters, foptimisticParameterDefaultValue, SimpleSyncParameterMetadata.Value.ToString()); // only the first value win System.Collections.Generic.Dictionary <string, Xml.XmlElement> dictionaryLookup = new System.Collections.Generic.Dictionary <string, Xml.XmlElement>(parameters.GetLength(0)); foreach (Framework.ITaskItem item in items) { string name = item.ItemSpec; if (!dictionaryLookup.ContainsKey(name)) { Xml.XmlElement parameterElement = document.CreateElement("setParameter"); parameterElement.SetAttribute("name", name); string value = item.GetMetadata("value"); parameterElement.SetAttribute("value", value); dictionaryLookup.Add(name, parameterElement); parametersElement.AppendChild(parameterElement); } } } // Save the UTF8 and Indented Utility.SaveDocument(document, outputFileName, System.Text.Encoding.UTF8); }
static Command() { Gen::List <Command> list = new System.Collections.Generic.List <Command>(); Xml::XmlDocument doc = new System.Xml.XmlDocument(); const string RES_NAME = __dll__.DEFAULT_NAMESPACE + ".Disassemble.Command.xml"; doc.Load(typeof(Command).Assembly.GetManifestResourceStream(RES_NAME)); foreach (Xml::XmlElement elem in doc.SelectNodes("//list[@name='Standard']/cmd")) { list.Add(new Command(elem)); } cmds = list.ToArray(); }
private static void WriteDeclareParametersToFile(Utilities.TaskLoggingHelper loggingHelper, Framework.ITaskItem[] parameters, string[] parameterAttributes, string outputFileName, bool foptimisticParameterDefaultValue, string optimisticParameterMetadata) { Xml.XmlDocument document = new System.Xml.XmlDocument(); Xml.XmlElement parametersElement = document.CreateElement("parameters"); document.AppendChild(parametersElement); if (parameters != null) { System.Collections.Generic.Dictionary <string, Xml.XmlElement> dictionaryLookup = new System.Collections.Generic.Dictionary <string, Xml.XmlElement>(parameters.GetLength(0), System.StringComparer.OrdinalIgnoreCase); // we are on purpose to keep the order without optimistic change the Value/Default base on the non-null optimistic System.Collections.Generic.IList <Framework.ITaskItem> items = Utility.SortParametersTaskItems(parameters, foptimisticParameterDefaultValue, optimisticParameterMetadata); foreach (Framework.ITaskItem item in items) { string name = item.ItemSpec; Xml.XmlElement parameterElement = null; bool fCreateNew = false; if (!dictionaryLookup.TryGetValue(name, out parameterElement)) { fCreateNew = true; parameterElement = document.CreateElement("parameter"); parameterElement.SetAttribute("name", name); foreach (string attributeName in parameterAttributes) { string value = item.GetMetadata(attributeName); parameterElement.SetAttribute(attributeName, value); } dictionaryLookup.Add(name, parameterElement); parametersElement.AppendChild(parameterElement); } if (parameterElement != null) { string elementValue = item.GetMetadata(ExistingParameterValiationMetadata.Element.ToString()); if (string.IsNullOrEmpty(elementValue)) { elementValue = "parameterEntry"; } string[] parameterIdentities = s_parameterEntryIdentities; if (string.Compare(elementValue, "parameterEntry", System.StringComparison.OrdinalIgnoreCase) == 0) { parameterIdentities = s_parameterEntryIdentities; } else if (string.Compare(elementValue, "parameterValidation", System.StringComparison.OrdinalIgnoreCase) == 0) { parameterIdentities = s_parameterValidationIdentities; } // from all existing node, if the parameter Entry is identical, we should not create a new one int parameterIdentitiesCount = parameterIdentities.GetLength(0); string[] identityValues = new string[parameterIdentitiesCount]; identityValues[0] = elementValue; for (int i = 1; i < parameterIdentitiesCount; i++) { identityValues[i] = item.GetMetadata(parameterIdentities[i]); if (string.Equals(parameterIdentities[i], ExistingDeclareParameterMetadata.Match.ToString().ToLowerInvariant())) { string metadataValue = item.GetMetadata(parameterIdentities[i]); if (!string.IsNullOrEmpty(metadataValue) && (Directory.Exists(metadataValue) || File.Exists(metadataValue))) { metadataValue = $"^{Regex.Escape(metadataValue)}$"; } identityValues[i] = metadataValue; } } if (!fCreateNew) { bool fIdentical = false; foreach (Xml.XmlNode childNode in parameterElement.ChildNodes) { Xml.XmlElement childElement = childNode as Xml.XmlElement; if (childElement != null) { if (string.Compare(childElement.Name, identityValues[0], System.StringComparison.OrdinalIgnoreCase) == 0) { fIdentical = true; for (int i = 1; i < parameterIdentitiesCount; i++) { // case sensitive comparesion should be O.K. if (string.CompareOrdinal(identityValues[i], childElement.GetAttribute(parameterIdentities[i])) != 0) { fIdentical = false; break; } } if (fIdentical) { break; } } } } if (fIdentical) { // same ParameterEntry, skip this item continue; } } bool fAddEntry = false; for (int i = 1; i < parameterIdentitiesCount; i++) { fAddEntry |= !string.IsNullOrEmpty(identityValues[i]); } if (fAddEntry) { Xml.XmlElement parameterEntry = document.CreateElement(identityValues[0]); for (int i = 1; i < parameterIdentitiesCount; i++) { string attributeName = parameterIdentities[i]; string value = identityValues[i]; if (!string.IsNullOrEmpty(value)) { parameterEntry.SetAttribute(attributeName, value); } } parameterElement.AppendChild(parameterEntry); } } } } // Save the UTF8 and Indented Utility.SaveDocument(document, outputFileName, System.Text.Encoding.UTF8); }