コード例 #1
0
ファイル: XmlLoaderBase.cs プロジェクト: 40a/PowerShell
        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;
            }
        }
コード例 #2
0
ファイル: XmlLoaderBase.cs プロジェクト: nickchal/pash
 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;
 }