Process() static private method

static private Process ( IPackageFile file, IPropertyProvider propertyProvider ) : string
file IPackageFile
propertyProvider IPropertyProvider
return string
Beispiel #1
0
        public static Manifest ReadFrom(Stream stream, IPropertyProvider propertyProvider)
        {
            XDocument document;

            if (propertyProvider == NullPropertyProvider.Instance)
            {
                document = XDocument.Load(stream);
            }
            else
            {
                string content = Preprocessor.Process(stream, propertyProvider);
                document = XDocument.Parse(content);
            }

            string schemaNamespace = GetSchemaNamespace(document);

            foreach (var e in document.Descendants())
            {
                // Assign the schema namespace derived to all nodes in the document.
                e.Name = XName.Get(e.Name.LocalName, schemaNamespace);
            }

            // Validate the schema
            ValidateManifestSchema(document, schemaNamespace);

            // Serialize it
            var manifest = ManifestReader.ReadManifest(document);

            // Validate before returning
            Validate(manifest);

            return(manifest);
        }
Beispiel #2
0
 private static XElement GetXml(IPackageFile file, IProjectSystem projectSystem)
 {
     using (Stream stream = file.GetStream()) {
         var content = Preprocessor.Process(file, projectSystem);
         return(XElement.Parse(content));
     }
 }
Beispiel #3
0
        private static void PerformXdtTransform(IPackageFile file, string targetPath, IProjectSystem projectSystem)
        {
            if (projectSystem.FileExists(targetPath))
            {
                string content = Preprocessor.Process(file, projectSystem);

                try
                {
                    using (var transformation = new XmlTransformation(content, isTransformAFile: false, logger: null))
                    {
                        using (var document = new XmlTransformableDocument())
                        {
                            document.PreserveWhitespace = true;

                            // make sure we close the input stream immediately so that we can override
                            // the file below when we save to it.
                            using (var inputStream = projectSystem.OpenFile(targetPath))
                            {
                                document.Load(inputStream);
                            }

                            bool succeeded = transformation.Apply(document);
                            if (succeeded)
                            {
                                using (var memoryStream = new MemoryStream())
                                {
                                    // save the result into a memoryStream first so that if there is any
                                    // exception during document.Save(), the original file won't be truncated.
                                    document.Save(memoryStream);
                                    memoryStream.Seek(0, SeekOrigin.Begin);
                                    using (var fileStream = projectSystem.CreateFile(targetPath))
                                    {
                                        memoryStream.CopyTo(fileStream);
                                    }
                                }
                            }
                        }
                    }
                }
                catch (Exception exception)
                {
                    throw new InvalidDataException(
                              String.Format(
                                  CultureInfo.CurrentCulture,
                                  NuGetResources.XdtError + " " + exception.Message,
                                  targetPath,
                                  projectSystem.ProjectName),
                              exception);
                }
            }
        }
Beispiel #4
0
        public static Manifest ReadFrom(Stream stream, IPropertyProvider propertyProvider)
        {
            string content = Preprocessor.Process(stream, propertyProvider);

            // Read the document
            XDocument document = XDocument.Parse(content);

            // Add the schema namespace if it isn't there
            foreach (var e in document.Descendants())
            {
                if (e.Name.Namespace == null || String.IsNullOrEmpty(e.Name.Namespace.NamespaceName))
                {
                    e.Name = XName.Get(e.Name.LocalName, Constants.ManifestSchemaNamespace);
                }
            }

            // Validate the schema
            ValidateManifestSchema(document);

            // Remove the namespace from the outer tag to match CTP2 expectations
            document.Root.Name = document.Root.Name.LocalName;

            var serializer = new XmlSerializer(typeof(Manifest));
            var manifest   = (Manifest)serializer.Deserialize(document.CreateReader());

            // Convert <file source="Foo.cs;.\src\bar.cs" target="content" /> to multiple individual items.
            // Do this before validating to ensure validation for files still works as before.
            manifest.SplitManifestFiles();

            // Validate before returning
            Validate(manifest);

            // Trim fields in case they have extra whitespace
            manifest.Metadata.Id          = manifest.Metadata.Id.SafeTrim();
            manifest.Metadata.Title       = manifest.Metadata.Title.SafeTrim();
            manifest.Metadata.Authors     = manifest.Metadata.Authors.SafeTrim();
            manifest.Metadata.Owners      = manifest.Metadata.Owners.SafeTrim();
            manifest.Metadata.Description = manifest.Metadata.Description.SafeTrim();
            manifest.Metadata.Summary     = manifest.Metadata.Summary.SafeTrim();
            manifest.Metadata.Language    = manifest.Metadata.Language.SafeTrim();
            manifest.Metadata.Tags        = manifest.Metadata.Tags.SafeTrim();


            return(manifest);
        }
Beispiel #5
0
        public static Manifest ReadFrom(Stream stream, IPropertyProvider propertyProvider, bool validateSchema)
        {
            XDocument document;

            if (propertyProvider == NullPropertyProvider.Instance)
            {
                document = XmlUtility.LoadSafe(stream, ignoreWhiteSpace: true);
            }
            else
            {
                string content = Preprocessor.Process(stream, propertyProvider);
                document = XDocument.Parse(content);
            }

            string schemaNamespace = GetSchemaNamespace(document);

            foreach (var e in document.Descendants())
            {
                // Assign the schema namespace derived to all nodes in the document.
                e.Name = XName.Get(e.Name.LocalName, schemaNamespace);
            }

            // Validate if the schema is a known one
            CheckSchemaVersion(document);

            if (validateSchema)
            {
                // Validate the schema
                ValidateManifestSchema(document, schemaNamespace);
            }

            // Deserialize it
            var manifest = ManifestReader.ReadManifest(document);

            // Validate before returning
            Validate(manifest);

            return(manifest);
        }
Beispiel #6
0
 private static void PerformXdtTransform(IPackageFile file, string targetPath, IProjectSystem projectSystem)
 {
     if (projectSystem.FileExists(targetPath))
     {
         string transform = Preprocessor.Process(file, projectSystem);
         try
         {
             using (XmlTransformation transformation = new XmlTransformation(transform, false, null))
             {
                 using (XmlTransformableDocument document = new XmlTransformableDocument())
                 {
                     document.PreserveWhitespace = true;
                     using (Stream stream = projectSystem.OpenFile(targetPath))
                     {
                         document.Load(stream);
                     }
                     if (transformation.Apply(document))
                     {
                         using (MemoryStream stream2 = new MemoryStream())
                         {
                             document.Save(stream2);
                             stream2.Seek(0L, SeekOrigin.Begin);
                             using (Stream stream3 = projectSystem.CreateFile(targetPath))
                             {
                                 stream2.CopyTo(stream3);
                             }
                         }
                     }
                 }
             }
         }
         catch (Exception exception)
         {
             object[] args = new object[] { targetPath, projectSystem.ProjectName };
             throw new InvalidDataException(string.Format(CultureInfo.CurrentCulture, NuGetResources.XdtError + " " + exception.Message, args), exception);
         }
     }
 }
Beispiel #7
0
 private static XElement GetXml(IPackageFile file, IProjectSystem projectSystem) =>
 XElement.Parse(Preprocessor.Process(file, projectSystem), LoadOptions.PreserveWhitespace);
        private static XElement GetXml(IPackageFile file, IProjectSystem projectSystem)
        {
            var content = Preprocessor.Process(file, projectSystem);

            return(XElement.Parse(content, LoadOptions.PreserveWhitespace));
        }
Beispiel #9
0
        public static Manifest ReadFrom(Stream stream, IPropertyProvider propertyProvider, bool validateSchema)
        {
            XDocument document        = !ReferenceEquals(propertyProvider, NullPropertyProvider.Instance) ? XDocument.Parse(Preprocessor.Process(stream, propertyProvider, true)) : XmlUtility.LoadSafe(stream, true);
            string    schemaNamespace = GetSchemaNamespace(document);

            foreach (XElement local1 in document.Descendants())
            {
                local1.Name = XName.Get(local1.Name.LocalName, schemaNamespace);
            }
            CheckSchemaVersion(document);
            if (validateSchema)
            {
                ValidateManifestSchema(document, schemaNamespace);
            }
            Manifest manifest = ManifestReader.ReadManifest(document);

            Validate(manifest);
            return(manifest);
        }