本文整理汇总了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());
}
}
示例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);
}
示例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);
}
}
}
示例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);
}
}
示例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));
}
}
示例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;
}
示例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);
}
}
示例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;
}
示例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;
}
}
示例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;
}
示例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());
}
示例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);
}
}
示例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;
}
示例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;
}
}
示例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);
}
}