本文整理汇总了C#中System.IO.Packaging.Package.GetRelationshipsByType方法的典型用法代码示例。如果您正苦于以下问题:C# Package.GetRelationshipsByType方法的具体用法?C# Package.GetRelationshipsByType怎么用?C# Package.GetRelationshipsByType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.Packaging.Package
的用法示例。
在下文中一共展示了Package.GetRelationshipsByType方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
}
示例2: 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());
}
示例3: SignAllParts
private void SignAllParts(Package package, X509Certificate2 certificate)
{
var partsToSign = new List<Uri>();
var relationshipsToSign = new List<PackageRelationshipSelector>();
foreach (var relationship in package.GetRelationshipsByType(RtOfficeDocument))
{
AddSignableItems(relationship, partsToSign, relationshipsToSign);
}
var mgr = new PackageDigitalSignatureManager(package)
{
CertificateOption = CertificateEmbeddingOption.InSignaturePart
};
var officeObject = CreateOfficeObject(SignatureID, ManifestHashAlgorithm);
var officeObjectReference = new Reference("#" + OfficeObjectID);
mgr.Sign(partsToSign,
certificate,
relationshipsToSign,
SignatureID,
new[] { officeObject },
new[] { officeObjectReference });
package.Close();
}
示例4: Select
//------------------------------------------------------
//
// Public Methods
//
//------------------------------------------------------
#region Public Methods
/// <summary>
/// This method returns the list of selected PackageRelationships as per the
/// given criteria, from a part in the Package provided
/// </summary>
/// <param name="package">Package object from which we get the relationsips</param>
/// <returns></returns>
/// <exception cref="ArgumentNullException">If package parameter is null</exception>
public List<PackageRelationship> Select(Package package)
{
if (package == null)
{
throw new ArgumentNullException("package");
}
List<PackageRelationship> relationships = new List<PackageRelationship>(0);
switch (SelectorType)
{
case PackageRelationshipSelectorType.Id:
if (SourceUri.Equals(PackUriHelper.PackageRootUri))
{
if (package.RelationshipExists(SelectionCriteria))
relationships.Add(package.GetRelationship(SelectionCriteria));
}
else
{
if (package.PartExists(SourceUri))
{
PackagePart part = package.GetPart(SourceUri);
if (part.RelationshipExists(SelectionCriteria))
relationships.Add(part.GetRelationship(SelectionCriteria));
}
}
break;
case PackageRelationshipSelectorType.Type:
if (SourceUri.Equals(PackUriHelper.PackageRootUri))
{
foreach (PackageRelationship r in package.GetRelationshipsByType(SelectionCriteria))
relationships.Add(r);
}
else
{
if (package.PartExists(SourceUri))
{
foreach (PackageRelationship r in package.GetPart(SourceUri).GetRelationshipsByType(SelectionCriteria))
relationships.Add(r);
}
}
break;
default:
//Debug.Assert is fine here since the parameters have already been validated. And all the properties are
//readonly
Debug.Assert(false, "This option should never be called");
break;
}
return relationships;
}
示例5: CopyDecks
internal void CopyDecks(Package package)
{
string path = Path.Combine(basePath, "Decks");
var decks = package.GetRelationshipsByType("http://schemas.octgn.org/set/deck");
byte[] buffer = new byte[0x1000];
foreach(var deckRel in decks)
{
var deck = package.GetPart(deckRel.TargetUri);
string deckFilename = Path.Combine(path, Path.GetFileName(deck.Uri.ToString()));
using(var deckStream = deck.GetStream(FileMode.Open, FileAccess.Read))
using(var targetStream = File.Open(deckFilename, FileMode.Create, FileAccess.Write))
{
int read;
while(true)
{
read = deckStream.Read(buffer, 0, buffer.Length);
if(read == 0) break;
targetStream.Write(buffer, 0, read);
}
}
}
}
示例6: CopyDecks
internal void CopyDecks(Package package)
{
string path = Path.Combine(GamesRepository.BasePath, "Decks");
PackageRelationshipCollection decks = package.GetRelationshipsByType("http://schemas.octgn.org/set/deck");
var buffer = new byte[0x1000];
foreach (PackageRelationship deckRel in decks)
{
PackagePart deck = package.GetPart(deckRel.TargetUri);
string deckuri = Path.GetFileName(deck.Uri.ToString());
if (deckuri == null) continue;
string deckFilename = Path.Combine(path, deckuri);
using (Stream deckStream = deck.GetStream(FileMode.Open, FileAccess.Read))
using (
FileStream targetStream = File.Open(deckFilename, FileMode.Create, FileAccess.Write, FileShare.Read)
)
{
while (true)
{
int read = deckStream.Read(buffer, 0, buffer.Length);
if (read == 0) break;
targetStream.Write(buffer, 0, read);
}
}
}
}
示例7: GetDocumentPart
public static PackagePart GetDocumentPart(Package package)
{
PackageRelationship relationship = package.GetRelationshipsByType(OfficeDocumentRelType).FirstOrDefault();
Uri docUri = PackUriHelper.ResolvePartUri(new Uri("/", UriKind.Relative), relationship.TargetUri);
return package.GetPart(docUri);
}