当前位置: 首页>>代码示例>>C#>>正文


C# Package.GetPart方法代码示例

本文整理汇总了C#中System.IO.Packaging.Package.GetPart方法的典型用法代码示例。如果您正苦于以下问题:C# Package.GetPart方法的具体用法?C# Package.GetPart怎么用?C# Package.GetPart使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.IO.Packaging.Package的用法示例。


在下文中一共展示了Package.GetPart方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Generate

        public void Generate(Package sourcePackage, Package targetPackage, FileInfo outputFile)
        {
            var serializer = new XmlSerializer(typeof(DataSchemaModel));
            var uri = PackUriHelper.CreatePartUri(new Uri("/replication.xml", UriKind.Relative));

            var sourceModel = (DataSchemaModel)serializer.Deserialize(sourcePackage.GetPart(uri).GetStream());
            var targetModel = (DataSchemaModel)serializer.Deserialize(targetPackage.GetPart(uri).GetStream());

            var outputFileSql = new List<string>();

            foreach (var publicationToCreate in sourceModel.Model.Elements.Except(targetModel.Model.Elements, x => x.Name))
            {
                var createPublicationStep = new CreatePublicationStep(publicationToCreate);
                outputFileSql.AddRange(createPublicationStep.GenerateTSQL());
            }

            foreach (var publicationToAlter in sourceModel.Model.Elements.Intersect(targetModel.Model.Elements, x => x.Name))
            {
                var sqlPublicationComparer = new SqlPublicationComparer();
                var matchingPublicationInTarget = targetModel.Model.Elements.Single(x => x.Name == publicationToAlter.Name);

                var alterPublicationStep = new AlterPublicationStep(sqlPublicationComparer.Compare(publicationToAlter, matchingPublicationInTarget));
                outputFileSql.AddRange(alterPublicationStep.GenerateTSQL());
            }

            foreach (var publicationToDrop in targetModel.Model.Elements.Except(sourceModel.Model.Elements, x => x.Name))
            {
                var dropPublicationStep = new DropPublicationStep(publicationToDrop);
                outputFileSql.AddRange(dropPublicationStep.GenerateTSQL());
            }
        }
开发者ID:richardgavel,项目名称:SqlServerDataToolsReplication,代码行数:31,代码来源:SqlPublicationScriptGenerator.cs

示例2: UpdatePackageManifest

        private void UpdatePackageManifest(Package package, PackagePart updatedPart)
        {
            if (package == null)
                throw new ArgumentNullException(nameof(package));
            if (updatedPart == null)
                throw new ArgumentNullException(nameof(updatedPart));
            if (package.FileOpenAccess != FileAccess.ReadWrite)
                throw new InvalidOperationException("Package must be open for reading and writing");

            var manifestRelation = package.GetRelationship("MANIFEST");
            var manifestPart = package.GetPart(manifestRelation.TargetUri);

            // parse manifest
            var manifest = new PackageManifest(manifestPart, null);

            // rehash updated part
            var csDefPart = manifest.Items.FirstOrDefault(i => i.PartUri == updatedPart.Uri);
            if (csDefPart == null)
                throw new InvalidOperationException(string.Format("Unable to find part '{0}' in package manifest", updatedPart.Uri));

            csDefPart.Hash = manifest.HashAlgorithm.ComputeHash(updatedPart.GetStream(FileMode.Open, FileAccess.Read)); ;
            csDefPart.ModifiedDate = DateTime.UtcNow;

            var manifestStream = manifestPart.GetStream(FileMode.Open, FileAccess.Write);
            manifest.WriteToStream(manifestStream);
        }
开发者ID:dolly22,项目名称:CloudServicePackageTools,代码行数:26,代码来源:ServiceDescriptionVisitor.cs

示例3: ExtractLayouts

        void ExtractLayouts(Package package, PackageDefinition manifest, string workingDirectory)
        {
            var localContentDirectory = Path.Combine(workingDirectory, AzureCloudServiceConventions.PackageFolders.LocalContent);
            fileSystem.EnsureDirectoryExists(localContentDirectory);

            foreach (var layout in manifest.Layouts)
            {
                if (!layout.Name.StartsWith(AzureCloudServiceConventions.RoleLayoutPrefix))
                    continue;

                var layoutDirectory = Path.Combine(localContentDirectory, layout.Name.Substring(AzureCloudServiceConventions.RoleLayoutPrefix.Length));
                fileSystem.EnsureDirectoryExists(layoutDirectory);

                foreach (var fileDefinition in layout.FileDefinitions)
                {
                    var contentDefinition =
                        manifest.GetContentDefinition(fileDefinition.Description.DataContentReference);

                    var destinationFileName = Path.Combine(layoutDirectory, fileDefinition.FilePath.TrimStart('\\'));
                    ExtractPart(
                        package.GetPart(PackUriHelper.ResolvePartUri(new Uri("/", UriKind.Relative),
                            contentDefinition.Description.DataStorePath)),
                        destinationFileName);
                }
            }
        }
开发者ID:bjewell52,项目名称:Calamari,代码行数:26,代码来源:ExtractAzureCloudServicePackageConvention.cs

示例4: ExtractContents

 void ExtractContents(Package package, PackageDefinition manifest, string contentNamePrefix, string workingDirectory)
 {
     foreach (var namedStreamsContent in manifest.Contents.Where(x => x.Name.StartsWith(contentNamePrefix)))
     {
         var destinationFileName = Path.Combine(workingDirectory, ConvertToWindowsPath(namedStreamsContent.Description.DataStorePath.ToString()).TrimStart('\\'));
         ExtractPart(package.GetPart(PackUriHelper.ResolvePartUri(new Uri("/", UriKind.Relative), namedStreamsContent.Description.DataStorePath)),
             destinationFileName);
     }
 }
开发者ID:bjewell52,项目名称:Calamari,代码行数:9,代码来源:ExtractAzureCloudServicePackageConvention.cs

示例5: GetFooterParts

 public static IEnumerable<PackagePart> GetFooterParts(Package package)
 {
     var documentPart = GetDocumentPart(package);
     var footerRelationships = documentPart.GetRelationshipsByType(FooterRelationshipType);
     foreach (var relationship in footerRelationships)
     {
         yield return package.GetPart(PackUriHelper.ResolvePartUri(documentPart.Uri, relationship.TargetUri));
     }
 }
开发者ID:koZZZdya,项目名称:TsSoft.Docx.TemplateEngine,代码行数:9,代码来源:DocxPartResolver.cs

示例6: GetPackagePart

        private static PackagePart GetPackagePart(Package package, string partFilePath)
        {
            Uri packagePartUri = GetPackagePartUri(partFilePath);

            if (package.PartExists(packagePartUri))
                return package.GetPart(packagePartUri);
            else
                return null;
        }
开发者ID:kurthamilton,项目名称:Utilities,代码行数:9,代码来源:WorkbookCleaner.cs

示例7: ReadPackageManifest

        public static PackageDefinition ReadPackageManifest(Package package)
        {
            var manifestPart = package.GetPart(
                package.GetRelationshipsByType(CtpFormatPackageDefinitionRelationshipType).Single().TargetUri);

            using (var manifestStream = manifestPart.GetStream())
            using (var xmlReader = XmlReader.Create(manifestStream, XmlUtils.DtdSafeReaderSettings))
            {
               return new PackageDefinition(XDocument.Load(xmlReader).Root);
            }
        }
开发者ID:merbla,项目名称:Calamari,代码行数:11,代码来源:AzureCloudServiceConventions.cs

示例8: UpdateServiceDescription

        private PackagePart UpdateServiceDescription(Package servicePackage)
        {
            var descRelation = servicePackage.GetRelationship("SERVICEDESCRIPTION");
            if (descRelation == null)
                throw new ArgumentException("SERVICEDESCRIPTION part not found inside package", nameof(servicePackage));

            var descPart = servicePackage.GetPart(descRelation.TargetUri);
            UpdateServiceDescriptionPackage(descPart);

            return descPart;
        }
开发者ID:dolly22,项目名称:CloudServicePackageTools,代码行数:11,代码来源:ServiceDescriptionVisitor.cs

示例9: DocxReader

        public DocxReader(Stream stream)
        {
            if (stream == null)
                throw new ArgumentNullException("stream");

            this.package = Package.Open(stream, FileMode.Open, FileAccess.Read);

            foreach (var relationship in this.package.GetRelationshipsByType(MainDocumentRelationshipType))
            {
                this.mainDocumentPart = package.GetPart(PackUriHelper.CreatePartUri(relationship.TargetUri));
                break;
            }
        }
开发者ID:Dascarecrow72,项目名称:AdventureVerse,代码行数:13,代码来源:DocxReader.cs

示例10: DecompressData

        private byte[] DecompressData(Package p, string u)
        {
            Logger.VSLog("Decompressing data...");

            byte[] buffer;
            Uri partUri = new Uri(u, UriKind.Relative);
            using (Stream stream = p.GetPart(partUri).GetStream())
            {
                buffer = new byte[(int)stream.Length];
                stream.Read(buffer, 0, buffer.Length);
            }

            return buffer;
        }
开发者ID:KenMacD,项目名称:NETDeob,代码行数:14,代码来源:Unpacker.cs

示例11: ProcessManifest

        PackageMetadata ProcessManifest(Package package)
        {
            var packageRelationship =
                package.GetRelationshipsByType("http://schemas.microsoft.com/packaging/2010/07/manifest")
                .SingleOrDefault();

            if (packageRelationship == null)
            {
                throw new InvalidOperationException("Package does not contain a manifest");
            }

            var part = package.GetPart(packageRelationship.TargetUri);

            return ReadManifestStream(part.GetStream());
        }
开发者ID:bjewell52,项目名称:Calamari,代码行数:15,代码来源:LightweightPackageExtractor.cs

示例12: VerifyPartsAreTheSame

 void VerifyPartsAreTheSame(Package package1, Package package2)
 {
     foreach (var part1 in package1.GetParts())
     {
         if (part1.Uri.OriginalString.EndsWith("psmdcp"))
         {
             continue;
         }
         if (part1.Uri.OriginalString.EndsWith("rels"))
         {
             continue;
         }
         var part2 = package2.GetPart(part1.Uri);
         var hash1 = GetFileHash(part1);
         var hash2 = GetFileHash(part2);
         Assert.AreEqual(hash1, hash2, part1.Uri.OriginalString);
     }
 }
开发者ID:SimonCropp,项目名称:Pepita,代码行数:18,代码来源:IntegrationTests.cs

示例13: L

		private static Assembly L(Package p, string u)
		{
		    byte[] buffer;
		    Uri partUri = new Uri(u, UriKind.Relative);
		    using (Stream stream = p.GetPart(partUri).GetStream())
		    {
		        buffer = new byte[(int) stream.Length];
		        stream.Read(buffer, 0, buffer.Length);
		    }
		    
		    ByteArrayToFile(@"C:\Kohl\"+u, buffer);
		    
		    Assembly assembly = Assembly.Load(buffer);
		    if (assembly == null)
		    {
		        throw new ArgumentException("Unable to load assembly: " + u);
		    }
		    return assembly;
		}
开发者ID:RSchwoerer,项目名称:Terminals,代码行数:19,代码来源:Program.cs

示例14: ExcelVbaProject

 internal ExcelVbaProject(ExcelWorkbook wb)
 {
     _wb = wb;
     _pck = _wb._package.Package;
     References = new ExcelVbaReferenceCollection();
     Modules = new ExcelVbaModuleCollection(this);
     var rel = _wb.Part.GetRelationshipsByType(schemaRelVba).FirstOrDefault();
     if (rel != null)
     {
         Uri = PackUriHelper.ResolvePartUri(rel.SourceUri, rel.TargetUri);
         Part = _pck.GetPart(Uri);
         GetProject();
     }
     else
     {
         Lcid = 0;
         Part = null;
     }
 }
开发者ID:ylatuya,项目名称:EPPlus,代码行数:19,代码来源:ExcelVBAProject.cs

示例15: RenamePath

 public static void RenamePath(Package package, string oldUri, string newUri)
 {
     Uri partUri = new Uri(oldUri, UriKind.Relative);
     Uri uri2 = new Uri(newUri, UriKind.Relative);
     if (package.PartExists(partUri))
     {
         PackagePart part = package.GetPart(partUri);
         PackagePart part2 = package.CreatePart(uri2, part.ContentType, part.CompressionOption);
         using (Stream stream = part.GetStream())
         {
             using (Stream stream2 = part2.GetStream())
             {
                 CopyStream(stream, stream2);
             }
         }
         package.DeletePart(partUri);
     }
 }
开发者ID:RSchwoerer,项目名称:Terminals,代码行数:18,代码来源:PackageHelper.cs


注:本文中的System.IO.Packaging.Package.GetPart方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。