예제 #1
0
 public static XmlReader Create(Stream stream)
 {
     return(ManifestValidatingReader.Create(stream, ManifestValidatingReader.ManifestSchemaSet));
 }
예제 #2
0
        internal static AssemblyManifest FromDocument(string localPath, AssemblyManifest.ManifestType manifestType, Uri sourceUri)
        {
            CodeMarker_Singleton.Instance.CodeMarker(7302);
            Logger.AddMethodCall("ManifestReader.FromDocument(" + localPath + ") called.");
            if (new FileInfo(localPath).Length > 16777216L)
            {
                throw new DeploymentException(Resources.GetString("Ex_ManifestFileTooLarge"));
            }
            AssemblyManifest assemblyManifest;

            using (FileStream fileStream = new FileStream(localPath, FileMode.Open, FileAccess.Read))
            {
                try
                {
                    XmlReader xmlReader = PolicyKeys.SkipSchemaValidation() ? XmlReader.Create((Stream)fileStream, new XmlReaderSettings()
                    {
                        DtdProcessing = DtdProcessing.Prohibit,
                        XmlResolver   = (XmlResolver)null
                    }) : ManifestValidatingReader.Create((Stream)fileStream);
                    do
                    {
                        ;
                    }while (xmlReader.Read());
                    Logger.AddInternalState("Schema validation passed.");
                    assemblyManifest = new AssemblyManifest(fileStream);
                    Logger.AddInternalState("Manifest is parsed successfully.");
                    if (!PolicyKeys.SkipSemanticValidation())
                    {
                        assemblyManifest.ValidateSemantics(manifestType);
                    }
                    Logger.AddInternalState("Semantic validation passed.");
                    if (!PolicyKeys.SkipSignatureValidation())
                    {
                        fileStream.Position = 0L;
                        assemblyManifest.ValidateSignature((Stream)fileStream);
                    }
                    Logger.AddInternalState("Signature validation passed.");
                }
                catch (XmlException ex)
                {
                    throw new InvalidDeploymentException(ExceptionTypes.ManifestParse, string.Format((IFormatProvider)CultureInfo.CurrentUICulture, Resources.GetString("Ex_ManifestFromDocument"), new object[1]
                    {
                        (object)(sourceUri != (Uri)null ? sourceUri.AbsoluteUri : Path.GetFileName(localPath))
                    }), (Exception)ex);
                }
                catch (XmlSchemaValidationException ex)
                {
                    throw new InvalidDeploymentException(ExceptionTypes.ManifestParse, string.Format((IFormatProvider)CultureInfo.CurrentUICulture, Resources.GetString("Ex_ManifestFromDocument"), new object[1]
                    {
                        (object)(sourceUri != (Uri)null ? sourceUri.AbsoluteUri : Path.GetFileName(localPath))
                    }), (Exception)ex);
                }
                catch (InvalidDeploymentException ex)
                {
                    throw new InvalidDeploymentException(ExceptionTypes.ManifestParse, string.Format((IFormatProvider)CultureInfo.CurrentUICulture, Resources.GetString("Ex_ManifestFromDocument"), new object[1]
                    {
                        (object)(sourceUri != (Uri)null ? sourceUri.AbsoluteUri : Path.GetFileName(localPath))
                    }), (Exception)ex);
                }
            }
            CodeMarker_Singleton.Instance.CodeMarker(7303);
            return(assemblyManifest);
        }
        internal static AssemblyManifest FromDocument(string localPath, AssemblyManifest.ManifestType manifestType, Uri sourceUri)
        {
            AssemblyManifest manifest;

            CodeMarker_Singleton.Instance.CodeMarker(CodeMarkerEvent.perfParseBegin);
            Logger.AddMethodCall("ManifestReader.FromDocument(" + localPath + ") called.");
            FileInfo info = new FileInfo(localPath);

            if (info.Length > 0x1000000L)
            {
                throw new DeploymentException(Resources.GetString("Ex_ManifestFileTooLarge"));
            }
            FileStream input = new FileStream(localPath, FileMode.Open, FileAccess.Read);

            try
            {
                XmlReader reader = PolicyKeys.SkipSchemaValidation() ? XmlReader.Create(input) : ManifestValidatingReader.Create(input);
                while (reader.Read())
                {
                }
                Logger.AddInternalState("Schema validation passed.");
                manifest = new AssemblyManifest(input);
                Logger.AddInternalState("Manifest is parsed successfully.");
                if (!PolicyKeys.SkipSemanticValidation())
                {
                    manifest.ValidateSemantics(manifestType);
                }
                Logger.AddInternalState("Semantic validation passed.");
                if (!PolicyKeys.SkipSignatureValidation())
                {
                    input.Position = 0L;
                    manifest.ValidateSignature(input);
                }
                Logger.AddInternalState("Signature validation passed.");
            }
            catch (XmlException exception)
            {
                string message = string.Format(CultureInfo.CurrentUICulture, Resources.GetString("Ex_ManifestFromDocument"), new object[] { (sourceUri != null) ? sourceUri.AbsoluteUri : Path.GetFileName(localPath) });
                throw new InvalidDeploymentException(ExceptionTypes.ManifestParse, message, exception);
            }
            catch (XmlSchemaValidationException exception2)
            {
                string str2 = string.Format(CultureInfo.CurrentUICulture, Resources.GetString("Ex_ManifestFromDocument"), new object[] { (sourceUri != null) ? sourceUri.AbsoluteUri : Path.GetFileName(localPath) });
                throw new InvalidDeploymentException(ExceptionTypes.ManifestParse, str2, exception2);
            }
            catch (InvalidDeploymentException exception3)
            {
                string str3 = string.Format(CultureInfo.CurrentUICulture, Resources.GetString("Ex_ManifestFromDocument"), new object[] { (sourceUri != null) ? sourceUri.AbsoluteUri : Path.GetFileName(localPath) });
                throw new InvalidDeploymentException(ExceptionTypes.ManifestParse, str3, exception3);
            }
            finally
            {
                if (input != null)
                {
                    input.Dispose();
                }
            }
            CodeMarker_Singleton.Instance.CodeMarker(CodeMarkerEvent.perfParseEnd);
            return(manifest);
        }