private void ProcessXmlFile(string filePath) { try { XmlDocument xmlNode = InternalDeserializer.LoadUnsafeXmlDocument(new FileInfo(filePath), true, null); this.ProcessXmlNode(xmlNode, filePath); } catch (NotSupportedException exception) { this.WriteFileReadError(filePath, exception); } catch (IOException exception2) { this.WriteFileReadError(filePath, exception2); } catch (SecurityException exception3) { this.WriteFileReadError(filePath, exception3); } catch (UnauthorizedAccessException exception4) { this.WriteFileReadError(filePath, exception4); } catch (XmlException exception5) { this.WriteFileReadError(filePath, exception5); } catch (InvalidOperationException exception6) { this.WriteFileReadError(filePath, exception6); } }
protected XmlDocument LoadXmlDocumentFromFileLoadingInfo(AuthorizationManager authorizationManager, PSHost host, out bool isFullyTrusted) { // get file contents ExternalScriptInfo ps1xmlInfo = new ExternalScriptInfo(FilePath, FilePath); string fileContents = ps1xmlInfo.ScriptContents; isFullyTrusted = false; if (ps1xmlInfo.DefiningLanguageMode == PSLanguageMode.FullLanguage) { isFullyTrusted = true; } if (authorizationManager != null) { try { authorizationManager.ShouldRunInternal(ps1xmlInfo, CommandOrigin.Internal, host); } catch (PSSecurityException reason) { string errorMessage = StringUtil.Format(TypesXmlStrings.ValidationException, string.Empty /* TODO/FIXME snapin */, FilePath, reason.Message); ReportLogEntryHelper(errorMessage, XmlLoaderLoggerEntry.EntryType.Error, failToLoadFile: true); return(null); } } // load file into XML document try { XmlDocument doc = InternalDeserializer.LoadUnsafeXmlDocument( fileContents, true, /* preserve whitespace, comments, etc. */ null); /* default maxCharacters */ this.ReportTrace("XmlDocument loaded OK"); return(doc); } catch (XmlException e) { this.ReportError(StringUtil.Format(FormatAndOutXmlLoadingStrings.ErrorInFile, FilePath, e.Message)); this.ReportTrace("XmlDocument discarded"); return(null); } catch (Exception e) // will rethrow { CommandProcessor.CheckForSevereException(e); throw; } }
protected XmlDocument LoadXmlDocumentFromFileLoadingInfo(AuthorizationManager authorizationManager, PSHost host, out bool isFullyTrusted) { XmlDocument document2; ExternalScriptInfo commandInfo = new ExternalScriptInfo(this.FilePath, this.FilePath); string scriptContents = commandInfo.ScriptContents; isFullyTrusted = false; if (((PSLanguageMode)commandInfo.DefiningLanguageMode) == PSLanguageMode.FullLanguage) { isFullyTrusted = true; } if (authorizationManager != null) { try { authorizationManager.ShouldRunInternal(commandInfo, CommandOrigin.Internal, host); } catch (PSSecurityException exception) { string message = StringUtil.Format(TypesXmlStrings.ValidationException, new object[] { string.Empty, this.FilePath, exception.Message }); this.ReportLogEntryHelper(message, XmlLoaderLoggerEntry.EntryType.Error, true); return(null); } } try { XmlDocument document = InternalDeserializer.LoadUnsafeXmlDocument(scriptContents, true, null); this.ReportTrace("XmlDocument loaded OK"); document2 = document; } catch (XmlException exception2) { this.ReportError(StringUtil.Format(FormatAndOutXmlLoadingStrings.ErrorInFile, this.FilePath, exception2.Message)); this.ReportTrace("XmlDocument discarded"); document2 = null; } catch (Exception exception3) { CommandProcessorBase.CheckForSevereException(exception3); throw; } return(document2); }
private void ProcessXmlFile(string filePath) { // Cannot use ImportXMLHelper because it will throw terminating error which will // not be inline with Select-String // So doing self processing of the file. try { XmlDocument xmlDocument = InternalDeserializer.LoadUnsafeXmlDocument( new FileInfo(filePath), true, /* preserve whitespace, comments, etc. */ null); /* default maxCharactersInDocument */ this.ProcessXmlNode(xmlDocument, filePath); } catch (NotSupportedException notSupportedException) { this.WriteFileReadError(filePath, notSupportedException); } catch (IOException ioException) { this.WriteFileReadError(filePath, ioException); } catch (SecurityException securityException) { this.WriteFileReadError(filePath, securityException); } catch (UnauthorizedAccessException unauthorizedAccessException) { this.WriteFileReadError(filePath, unauthorizedAccessException); } catch (XmlException xmlException) { this.WriteFileReadError(filePath, xmlException); } catch (InvalidOperationException invalidOperationException) { this.WriteFileReadError(filePath, invalidOperationException); } }
internal static object ConvertFromCimToDotNet(object cimObject, Type expectedDotNetType) { if (expectedDotNetType != null) { if (cimObject != null) { if (expectedDotNetType.IsGenericType && expectedDotNetType.GetGenericTypeDefinition().Equals(typeof(Nullable <>))) { expectedDotNetType = expectedDotNetType.GetGenericArguments()[0]; } if (!LanguagePrimitives.IsCimIntrinsicScalarType(expectedDotNetType)) { if (!expectedDotNetType.Equals(typeof(CimInstance))) { if (expectedDotNetType.IsArray) { Type elementType = CimValueConverter.GetElementType(expectedDotNetType); if (elementType != null) { Array arrays = (Array)LanguagePrimitives.ConvertTo(cimObject, typeof(Array), CultureInfo.InvariantCulture); Array arrays1 = Array.CreateInstance(elementType, arrays.Length); for (int i = 0; i < arrays1.Length; i++) { object dotNet = CimValueConverter.ConvertFromCimToDotNet(arrays.GetValue(i), elementType); arrays1.SetValue(dotNet, i); } return(arrays1); } } Type convertibleCimType = CimValueConverter.GetConvertibleCimType(expectedDotNetType); if (convertibleCimType == null) { Func <Func <object>, object> func = (Func <object> innerAction) => { object obj; try { obj = innerAction(); } catch (Exception exception1) { Exception exception = exception1; CommandProcessorBase.CheckForSevereException(exception); throw CimValueConverter.GetInvalidCastException(exception, "InvalidCimToDotNetCast", cimObject, expectedDotNetType.FullName); } return(obj); } ; if (!typeof(ObjectSecurity).IsAssignableFrom(expectedDotNetType)) { if (!typeof(X509Certificate2).Equals(expectedDotNetType)) { if (!typeof(X500DistinguishedName).Equals(expectedDotNetType)) { if (!typeof(PhysicalAddress).Equals(expectedDotNetType)) { if (!typeof(IPEndPoint).Equals(expectedDotNetType)) { if (!typeof(XmlDocument).Equals(expectedDotNetType)) { throw CimValueConverter.GetInvalidCastException(null, "InvalidCimToDotNetCast", cimObject, expectedDotNetType.FullName); } else { return(func(() => { int?nullable = null; XmlDocument xmlDocument = InternalDeserializer.LoadUnsafeXmlDocument((string)LanguagePrimitives.ConvertTo(cimObject, typeof(string), CultureInfo.InvariantCulture), true, nullable); return xmlDocument; } )); } } else { return(func(() => { int num = ((string)LanguagePrimitives.ConvertTo(cimObject, typeof(string), CultureInfo.InvariantCulture)).LastIndexOf(':'); int num1 = int.Parse(((string)LanguagePrimitives.ConvertTo(cimObject, typeof(string), CultureInfo.InvariantCulture)).Substring(num + 1), NumberStyles.Integer, CultureInfo.InvariantCulture); IPAddress pAddress = IPAddress.Parse(((string)LanguagePrimitives.ConvertTo(cimObject, typeof(string), CultureInfo.InvariantCulture)).Substring(0, num)); return new IPEndPoint(pAddress, num1); } )); } } else { return(func(() => PhysicalAddress.Parse((string)LanguagePrimitives.ConvertTo(cimObject, typeof(string), CultureInfo.InvariantCulture)))); } } else { return(func(() => new X500DistinguishedName((byte[])LanguagePrimitives.ConvertTo(cimObject, typeof(byte[]), CultureInfo.InvariantCulture)))); } } else { return(func(() => new X509Certificate2((byte[])LanguagePrimitives.ConvertTo(cimObject, typeof(byte[]), CultureInfo.InvariantCulture)))); } } else { return(func(() => { ObjectSecurity objectSecurity = (ObjectSecurity)Activator.CreateInstance(expectedDotNetType); objectSecurity.SetSecurityDescriptorSddlForm((string)LanguagePrimitives.ConvertTo(cimObject, typeof(string), CultureInfo.InvariantCulture)); return objectSecurity; } )); } } else { object obj1 = LanguagePrimitives.ConvertTo(cimObject, convertibleCimType, CultureInfo.InvariantCulture); object obj2 = LanguagePrimitives.ConvertTo(obj1, expectedDotNetType, CultureInfo.InvariantCulture); return(obj2); } } else { return(LanguagePrimitives.ConvertTo(cimObject, expectedDotNetType, CultureInfo.InvariantCulture)); } } else { return(LanguagePrimitives.ConvertTo(cimObject, expectedDotNetType, CultureInfo.InvariantCulture)); } } else { return(null); } } else { throw new ArgumentNullException("expectedDotNetType"); } }
/// <exception cref="PSInvalidCastException">The only kind of exception this method can throw.</exception> internal static object ConvertFromCimToDotNet(object cimObject, Type expectedDotNetType) { if (expectedDotNetType == null) { throw new ArgumentNullException("expectedDotNetType"); } if (cimObject == null) { return(null); } if (expectedDotNetType.GetTypeInfo().IsGenericType&& expectedDotNetType.GetGenericTypeDefinition() == typeof(Nullable <>)) { expectedDotNetType = expectedDotNetType.GetGenericArguments()[0]; } if (LanguagePrimitives.IsCimIntrinsicScalarType(expectedDotNetType)) { return(LanguagePrimitives.ConvertTo(cimObject, expectedDotNetType, CultureInfo.InvariantCulture)); } if (expectedDotNetType == typeof(CimInstance)) { return(LanguagePrimitives.ConvertTo(cimObject, expectedDotNetType, CultureInfo.InvariantCulture)); } if (expectedDotNetType.IsArray) { Type dotNetElementType = GetElementType(expectedDotNetType); if (dotNetElementType != null) { var cimArray = (Array)LanguagePrimitives.ConvertTo(cimObject, typeof(Array), CultureInfo.InvariantCulture); Array dotNetArray = Array.CreateInstance(dotNetElementType, cimArray.Length); for (int i = 0; i < dotNetArray.Length; i++) { object dotNetElement = ConvertFromCimToDotNet(cimArray.GetValue(i), dotNetElementType); dotNetArray.SetValue(dotNetElement, i); } return(dotNetArray); } } Type convertibleCimType = GetConvertibleCimType(expectedDotNetType); if (convertibleCimType != null) { object cimIntrinsicValue = LanguagePrimitives.ConvertTo(cimObject, convertibleCimType, CultureInfo.InvariantCulture); object dotNetObject = LanguagePrimitives.ConvertTo(cimIntrinsicValue, expectedDotNetType, CultureInfo.InvariantCulture); return(dotNetObject); } Func <Func <object>, object> exceptionSafeReturn = delegate(Func <object> innerAction) { try { return(innerAction()); } catch (Exception e) { throw CimValueConverter.GetInvalidCastException( e, "InvalidCimToDotNetCast", cimObject, expectedDotNetType.FullName); } }; if (typeof(ObjectSecurity).IsAssignableFrom(expectedDotNetType)) { var sddl = (string)LanguagePrimitives.ConvertTo(cimObject, typeof(string), CultureInfo.InvariantCulture); return(exceptionSafeReturn(delegate { var objectSecurity = (ObjectSecurity)Activator.CreateInstance(expectedDotNetType); objectSecurity.SetSecurityDescriptorSddlForm(sddl); return objectSecurity; })); } if (typeof(X509Certificate2) == expectedDotNetType) { var cimIntrinsicValue = (byte[])LanguagePrimitives.ConvertTo(cimObject, typeof(byte[]), CultureInfo.InvariantCulture); return(exceptionSafeReturn(delegate { return new X509Certificate2(cimIntrinsicValue); })); } if (typeof(X500DistinguishedName) == expectedDotNetType) { var cimIntrinsicValue = (byte[])LanguagePrimitives.ConvertTo(cimObject, typeof(byte[]), CultureInfo.InvariantCulture); return(exceptionSafeReturn(delegate { return new X500DistinguishedName(cimIntrinsicValue); })); } if (typeof(PhysicalAddress) == expectedDotNetType) { var cimIntrinsicValue = (string)LanguagePrimitives.ConvertTo(cimObject, typeof(string), CultureInfo.InvariantCulture); return(exceptionSafeReturn(delegate { return PhysicalAddress.Parse(cimIntrinsicValue); })); } if (typeof(IPEndPoint) == expectedDotNetType) { var cimIntrinsicValue = (string)LanguagePrimitives.ConvertTo(cimObject, typeof(string), CultureInfo.InvariantCulture); return(exceptionSafeReturn(delegate { int indexOfLastColon = cimIntrinsicValue.LastIndexOf(':'); int port = int.Parse(cimIntrinsicValue.Substring(indexOfLastColon + 1), NumberStyles.Integer, CultureInfo.InvariantCulture); IPAddress address = IPAddress.Parse(cimIntrinsicValue.Substring(0, indexOfLastColon)); return new IPEndPoint(address, port); })); } // WildcardPattern is only supported as an "in" parameter - we do not support the reverse translation (i.e. from "a%" to "a*") if (typeof(XmlDocument) == expectedDotNetType) { var cimIntrinsicValue = (string)LanguagePrimitives.ConvertTo(cimObject, typeof(string), CultureInfo.InvariantCulture); return(exceptionSafeReturn(delegate { XmlDocument doc = InternalDeserializer.LoadUnsafeXmlDocument( cimIntrinsicValue, true, /* preserve non elements: whitespace, processing instructions, comments, etc. */ null); /* default maxCharactersInDocument */ return doc; })); } // unrecognized type = throw invalid cast exception throw CimValueConverter.GetInvalidCastException( null, /* inner exception */ "InvalidCimToDotNetCast", cimObject, expectedDotNetType.FullName); }
internal static PSConsoleFileElement CreateFromFile(string path) { _mshsnapinTracer.WriteLine("Loading console info from file {0}.", new object[] { path }); XmlDocument document = InternalDeserializer.LoadUnsafeXmlDocument(new FileInfo(path), false, null); if (document["PSConsoleFile"] == null) { _mshsnapinTracer.TraceError("Console file {0} doesn't contain tag {1}.", new object[] { path, "PSConsoleFile" }); throw new XmlException(StringUtil.Format(ConsoleInfoErrorStrings.MonadConsoleNotFound, path)); } if ((document["PSConsoleFile"]["PSVersion"] == null) || string.IsNullOrEmpty(document["PSConsoleFile"]["PSVersion"].InnerText)) { _mshsnapinTracer.TraceError("Console file {0} doesn't contain tag {1}.", new object[] { path, "PSVersion" }); throw new XmlException(StringUtil.Format(ConsoleInfoErrorStrings.MonadVersionNotFound, path)); } XmlElement element = document["PSConsoleFile"]; if (element.HasAttribute("ConsoleSchemaVersion")) { if (!element.GetAttribute("ConsoleSchemaVersion").Equals("1.0", StringComparison.OrdinalIgnoreCase)) { string format = StringUtil.Format(ConsoleInfoErrorStrings.BadConsoleVersion, path); string errorMessageFormat = string.Format(Thread.CurrentThread.CurrentCulture, format, new object[] { "1.0" }); _mshsnapinTracer.TraceError(errorMessageFormat, new object[0]); throw new XmlException(errorMessageFormat); } } else { _mshsnapinTracer.TraceError("Console file {0} doesn't contain tag schema version.", new object[] { path }); throw new XmlException(StringUtil.Format(ConsoleInfoErrorStrings.BadConsoleVersion, path)); } element = document["PSConsoleFile"]["PSVersion"]; PSConsoleFileElement element2 = new PSConsoleFileElement(element.InnerText.Trim()); bool flag = false; bool flag2 = false; for (System.Xml.XmlNode node = document["PSConsoleFile"].FirstChild; node != null; node = node.NextSibling) { if (node.NodeType != XmlNodeType.Comment) { element = node as XmlElement; if (element == null) { throw new XmlException(ConsoleInfoErrorStrings.BadXMLFormat); } if (element.Name == "PSVersion") { if (flag2) { _mshsnapinTracer.TraceError("Console file {0} contains more than one msh versions", new object[] { path }); throw new XmlException(StringUtil.Format(ConsoleInfoErrorStrings.MultipleMshSnapinsElementNotSupported, "PSVersion")); } flag2 = true; } else { if (element.Name != "PSSnapIns") { _mshsnapinTracer.TraceError("Tag {0} is not supported in console file", new object[] { element.Name }); throw new XmlException(StringUtil.Format(ConsoleInfoErrorStrings.BadXMLElementFound, new object[] { element.Name, "PSConsoleFile", "PSVersion", "PSSnapIns" })); } if (flag) { _mshsnapinTracer.TraceError("Console file {0} contains more than one mshsnapin lists", new object[] { path }); throw new XmlException(StringUtil.Format(ConsoleInfoErrorStrings.MultipleMshSnapinsElementNotSupported, "PSSnapIns")); } flag = true; for (System.Xml.XmlNode node2 = element.FirstChild; node2 != null; node2 = node2.NextSibling) { XmlElement element3 = node2 as XmlElement; if ((element3 == null) || (element3.Name != "PSSnapIn")) { throw new XmlException(StringUtil.Format(ConsoleInfoErrorStrings.PSSnapInNotFound, node2.Name)); } string attribute = element3.GetAttribute("Name"); if (string.IsNullOrEmpty(attribute)) { throw new XmlException(ConsoleInfoErrorStrings.IDNotFound); } element2.mshsnapins.Add(attribute); _mshsnapinTracer.WriteLine("Found in mshsnapin {0} in console file {1}", new object[] { attribute, path }); } } } } return(element2); }
/// <summary> /// Reads a Monad Console file specified by <paramref name="path"/> and constructs /// a PSConsoleFileElement. /// </summary> /// <param name="path">The absolute path of the file to read from.</param> /// <returns>A MShConsoleFileElement object that represents content of the console file.</returns> /// <remarks>The return object wont be null.</remarks> /// <exception cref="XmlException"> /// There is a load or parser error in the XML. /// </exception> /// <!-- /// Caller should not pass a null value for path. /// --> internal static PSConsoleFileElement CreateFromFile(string path) { Diagnostics.Assert(path != null, "Filename should not be null"); s_mshsnapinTracer.WriteLine("Loading console info from file {0}.", path); XmlDocument doc = InternalDeserializer.LoadUnsafeXmlDocument( new FileInfo(path), false, /* ignore whitespace, comments, etc. */ null); /* default maxCharactersInDocument */ // Validate content if (doc[MSHCONSOLEFILE] == null) { s_mshsnapinTracer.TraceError("Console file {0} doesn't contain tag {1}.", path, MSHCONSOLEFILE); throw new XmlException( StringUtil.Format(ConsoleInfoErrorStrings.MonadConsoleNotFound, path)); } if ((doc[MSHCONSOLEFILE][PSVERSION] == null) || (string.IsNullOrEmpty(doc[MSHCONSOLEFILE][PSVERSION].InnerText))) { s_mshsnapinTracer.TraceError("Console file {0} doesn't contain tag {1}.", path, PSVERSION); throw new XmlException( StringUtil.Format(ConsoleInfoErrorStrings.MonadVersionNotFound, path)); } // This will never be null.. XmlElement xmlElement = (XmlElement)doc[MSHCONSOLEFILE]; if (xmlElement.HasAttribute(CSCHEMAVERSION)) { if (!xmlElement.GetAttribute(CSCHEMAVERSION).Equals(CSCHEMAVERSIONNUMBER, StringComparison.OrdinalIgnoreCase)) { string resourceTemplate = StringUtil.Format(ConsoleInfoErrorStrings.BadConsoleVersion, path); string message = string.Format(CultureInfo.CurrentCulture, resourceTemplate, CSCHEMAVERSIONNUMBER); s_mshsnapinTracer.TraceError(message); throw new XmlException(message); } } else { s_mshsnapinTracer.TraceError("Console file {0} doesn't contain tag schema version.", path); throw new XmlException( StringUtil.Format(ConsoleInfoErrorStrings.BadConsoleVersion, path)); } //process MonadVersion //This will never be null.. xmlElement = (XmlElement)doc[MSHCONSOLEFILE][PSVERSION]; // Construct PSConsoleFileElement as we seem to have valid data PSConsoleFileElement consoleFileElement = new PSConsoleFileElement(xmlElement.InnerText.Trim()); bool isPSSnapInsProcessed = false; bool isPSVersionProcessed = false; for (XmlNode mshSnapInsNode = doc["PSConsoleFile"].FirstChild; mshSnapInsNode != null; mshSnapInsNode = mshSnapInsNode.NextSibling) { if (mshSnapInsNode.NodeType == XmlNodeType.Comment) { // support comments inside a PSConsoleFile Element continue; } //populate mshsnapin information xmlElement = mshSnapInsNode as XmlElement; if (null == xmlElement) { throw new XmlException(ConsoleInfoErrorStrings.BadXMLFormat); } if (xmlElement.Name == PSVERSION) { if (isPSVersionProcessed) { s_mshsnapinTracer.TraceError("Console file {0} contains more than one msh versions", path); throw new XmlException(StringUtil.Format(ConsoleInfoErrorStrings.MultipleMshSnapinsElementNotSupported, PSVERSION)); } isPSVersionProcessed = true; continue; } if (xmlElement.Name != SNAPINS) { s_mshsnapinTracer.TraceError("Tag {0} is not supported in console file", xmlElement.Name); throw new XmlException(StringUtil.Format(ConsoleInfoErrorStrings.BadXMLElementFound, xmlElement.Name, MSHCONSOLEFILE, PSVERSION, SNAPINS)); } // PSSnapIns element is already processed. We dont support multiple // PSSnapIns elements if (isPSSnapInsProcessed) { s_mshsnapinTracer.TraceError("Console file {0} contains more than one mshsnapin lists", path); throw new XmlException(StringUtil.Format(ConsoleInfoErrorStrings.MultipleMshSnapinsElementNotSupported, SNAPINS)); } // We are about to process mshsnapins element..so we should not // process some more mshsnapins elements..this boolean keeps track // of this. isPSSnapInsProcessed = true; // decode all the child nodes of <PSSnapIns> node... for (XmlNode mshSnapInNode = xmlElement.FirstChild; mshSnapInNode != null; mshSnapInNode = mshSnapInNode.NextSibling) { XmlElement mshSnapInElement = mshSnapInNode as XmlElement; if ((null == mshSnapInElement) || (mshSnapInElement.Name != SNAPIN)) { throw new XmlException( StringUtil.Format(ConsoleInfoErrorStrings.PSSnapInNotFound, mshSnapInNode.Name)); } string id = mshSnapInElement.GetAttribute(SNAPINNAME); if (string.IsNullOrEmpty(id)) { throw new XmlException(ConsoleInfoErrorStrings.IDNotFound); } consoleFileElement.PSSnapIns.Add(id); s_mshsnapinTracer.WriteLine("Found in mshsnapin {0} in console file {1}", id, path); } } return(consoleFileElement); }
/// <summary> /// Load help file provided. /// </summary> /// <remarks> /// This will load providerHelpInfo from help file into help cache. /// </remarks> /// <param name="providerInfo">ProviderInfo for which to locate help.</param> private void LoadHelpFile(ProviderInfo providerInfo) { if (providerInfo == null) { throw PSTraceSource.NewArgumentNullException(nameof(providerInfo)); } string helpFile = providerInfo.HelpFile; if (string.IsNullOrEmpty(helpFile) || _helpFiles.Contains(helpFile)) { return; } string helpFileToLoad = helpFile; // Get the mshsnapinfo object for this cmdlet. PSSnapInInfo mshSnapInInfo = providerInfo.PSSnapIn; // Search fallback // 1. If PSSnapInInfo exists, then always look in the application base // of the mshsnapin // Otherwise, // Look in the default search path and cmdlet assembly path Collection <string> searchPaths = new Collection <string>(); if (mshSnapInInfo != null) { Diagnostics.Assert(!string.IsNullOrEmpty(mshSnapInInfo.ApplicationBase), "Application Base is null or empty."); // not minishell case.. // we have to search only in the application base for a mshsnapin... // if you create an absolute path for helpfile, then MUIFileSearcher // will look only in that path. helpFileToLoad = Path.Combine(mshSnapInInfo.ApplicationBase, helpFile); } else if ((providerInfo.Module != null) && (!string.IsNullOrEmpty(providerInfo.Module.Path))) { helpFileToLoad = Path.Combine(providerInfo.Module.ModuleBase, helpFile); } else { searchPaths.Add(GetDefaultShellSearchPath()); searchPaths.Add(GetProviderAssemblyPath(providerInfo)); } string location = MUIFileSearcher.LocateFile(helpFileToLoad, searchPaths); if (string.IsNullOrEmpty(location)) { throw new FileNotFoundException(helpFile); } XmlDocument doc = InternalDeserializer.LoadUnsafeXmlDocument( new FileInfo(location), false, /* ignore whitespace, comments, etc. */ null); /* default maxCharactersInDocument */ // Add this file into _helpFiles hashtable to prevent it to be loaded again. _helpFiles[helpFile] = 0; XmlNode helpItemsNode = null; if (doc.HasChildNodes) { for (int i = 0; i < doc.ChildNodes.Count; i++) { XmlNode node = doc.ChildNodes[i]; if (node.NodeType == XmlNodeType.Element && string.Equals(node.Name, "helpItems", StringComparison.OrdinalIgnoreCase)) { helpItemsNode = node; break; } } } if (helpItemsNode == null) { return; } using (this.HelpSystem.Trace(location)) { if (helpItemsNode.HasChildNodes) { for (int i = 0; i < helpItemsNode.ChildNodes.Count; i++) { XmlNode node = helpItemsNode.ChildNodes[i]; if (node.NodeType == XmlNodeType.Element && string.Equals(node.Name, "providerHelp", StringComparison.OrdinalIgnoreCase)) { HelpInfo helpInfo = ProviderHelpInfo.Load(node); if (helpInfo != null) { this.HelpSystem.TraceErrors(helpInfo.Errors); // Add snapin qualified type name for this command.. // this will enable customizations of the help object. helpInfo.FullHelp.TypeNames.Insert(0, string.Format(CultureInfo.InvariantCulture, "ProviderHelpInfo#{0}#{1}", providerInfo.PSSnapInName, helpInfo.Name)); if (!string.IsNullOrEmpty(providerInfo.PSSnapInName)) { helpInfo.FullHelp.Properties.Add(new PSNoteProperty("PSSnapIn", providerInfo.PSSnapIn)); helpInfo.FullHelp.TypeNames.Insert(1, string.Format(CultureInfo.InvariantCulture, "ProviderHelpInfo#{0}", providerInfo.PSSnapInName)); } AddCache(providerInfo.PSSnapInName + "\\" + helpInfo.Name, helpInfo); } } } } } }