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


C# Package.CreateRelationship方法代码示例

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


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

示例1: ExcelPackage

        /// <summary>
        /// Creates a new instance of the ExcelPackage class based on a existing file or creates a new file. 
        /// </summary>
        /// <param name="newFile">If newFile exists, it is opened.  Otherwise it is created from scratch.</param>
        private ExcelPackage(FileInfo newFile)
        {
            _outputFolderPath = newFile.DirectoryName;
            if (newFile.Exists)
            {
                // open the existing package
                _package = Package.Open(newFile.FullName, FileMode.Open, FileAccess.ReadWrite);
            }
            else
            {
                // create a new package and add the main workbook.xml part
                _package = Package.Open(newFile.FullName, FileMode.Create, FileAccess.ReadWrite);

                // save a temporary part to create the default application/xml content type
                var uriDefaultContentType = new Uri("/default.xml", UriKind.Relative);
                var partTemp = _package.CreatePart(uriDefaultContentType, "application/xml");

                var workbook = Workbook.WorkbookXml; // this will create the workbook xml in the package

                // create the relationship to the main part
                _package.CreateRelationship(Workbook.WorkbookUri,
                                            TargetMode.Internal,
                                            schemaRelationships + "/officeDocument");

                // remove the temporary part that created the default xml content type
                _package.DeletePart(uriDefaultContentType);
            }
        }
开发者ID:HedinRakot,项目名称:Zierer,代码行数:32,代码来源:ExcelPackage.cs

示例2: AddPackageManifest

        void AddPackageManifest(Package package, PackageDefinition manifest)
        {
            var manifestPartUri = PackUriHelper.CreatePartUri(new Uri("/package.xml", UriKind.Relative));
            var manifestPart = package.CreatePart(manifestPartUri, System.Net.Mime.MediaTypeNames.Application.Octet, CompressionOption.Maximum);
            using (var manifestPartStream = manifestPart.GetStream())
            {
                manifest.ToXml().Save(manifestPartStream);
            }

            package.CreateRelationship(manifestPartUri, TargetMode.External, AzureCloudServiceConventions.CtpFormatPackageDefinitionRelationshipType);
        }
开发者ID:bjewell52,项目名称:Calamari,代码行数:11,代码来源:RePackageCloudServiceConvention.cs

示例3: WriteCache

		private void WriteCache(Package package)
		{
			Uri cacheUri = GetPartUri(cacheName);
			PackagePart part = package.CreatePart(cacheUri, MediaTypeNames.Application.Octet, CompressionOption.Fast);

			BinaryFormatter formatter = new BinaryFormatter();
			using (Stream stream = part.GetStream())
			{
				formatter.Serialize(stream, Cache);
			}

			package.CreateRelationship(cacheUri, TargetMode.Internal, D3AssemblyConstants.DefaultXmlNamespace);
		}
开发者ID:elsiete,项目名称:DynamicDataDisplay,代码行数:13,代码来源:ZipFileTileServer.cs

示例4: WriteManifest

    static void WriteManifest(Package package, string nuspecPath)
    {
        var uri = PackUriHelper.CreatePartUri(new Uri(Uri.EscapeDataString(Path.GetFileName(nuspecPath)), UriKind.Relative));

        // Create the manifest relationship
        package.CreateRelationship(uri, TargetMode.Internal, "http://schemas.microsoft.com/packaging/2010/07/manifest");

        // Create the part
        var packagePart = package.CreatePart(uri, "application/octet", CompressionOption.Maximum);

        using (var stream = packagePart.GetStream())
        using (var fileStream = File.OpenRead(nuspecPath))
        {
            fileStream.CopyTo(stream);
        }
    }
开发者ID:SimonCropp,项目名称:Pepita,代码行数:16,代码来源:Runner.cs

示例5: WriteManifest

        private void WriteManifest(Package package)
        {
            Uri uri = UriUtility.CreatePartUri(Id + Constants.ManifestExtension);

            // Create the manifest relationship
            package.CreateRelationship(uri, TargetMode.Internal, Constants.PackageRelationshipNamespace + ManifestRelationType);

            // Create the part
            PackagePart packagePart = package.CreatePart(uri, DefaultContentType, CompressionOption.Maximum);

            using (Stream stream = packagePart.GetStream())
            {
                Manifest manifest = Manifest.Create(this);
                manifest.Save(stream);
            }
        }
开发者ID:xero-github,项目名称:Nuget,代码行数:16,代码来源:PackageBuilder.cs

示例6: WriteManifest

        private void WriteManifest(Package package, int minimumManifestVersion)
        {
            Uri uri = UriUtility.CreatePartUri(Id + Constants.ManifestExtension);

            // Create the manifest relationship
            package.CreateRelationship(uri, TargetMode.Internal,
                                       Constants.PackageRelationshipNamespace + ManifestRelationType);

            // Create the part
            PackagePart packagePart = package.CreatePart(uri, DefaultContentType, CompressionOption.Maximum);

            using (Stream stream = packagePart.GetStream())
            {
                Manifest manifest = Manifest.Create(this);
                //if (PackageAssemblyReferences.Any())
                //{
                //    manifest.Metadata.References = new List<ManifestReference>(
                //        PackageAssemblyReferences.Select(reference => new ManifestReference {File = reference.File}));
                //}
                manifest.Save(stream, minimumManifestVersion);
            }
        }
开发者ID:304NotModified,项目名称:NuGetPackageExplorer-1,代码行数:22,代码来源:PackageBuilder.cs

示例7: AddFile

 /// <summary>
 /// Adds a file to the zip file
 /// </summary>
 /// <param name="File">File to add</param>
 /// <param name="FileInfo">File information</param>
 /// <param name="Package">Package to add the file to</param>
 protected virtual void AddFile(string File, FileInfo FileInfo, Package Package)
 {
     File.ThrowIfNullOrEmpty("File");
     if (!FileInfo.Exists)
         throw new ArgumentException("FileInfo does not exist");
     Uri UriPath = PackUriHelper.CreatePartUri(new Uri(File, UriKind.Relative));
     PackagePart PackagePart = Package.CreatePart(UriPath, System.Net.Mime.MediaTypeNames.Text.Xml, CompressionOption.Maximum);
     byte[] Data = FileInfo.ReadBinary();
     PackagePart.GetStream().Write(Data, 0, Data.Count());
     Package.CreateRelationship(PackagePart.Uri, TargetMode.Internal, "http://schemas.microsoft.com/opc/2006/sample/document");
 }
开发者ID:Adilson,项目名称:Craig-s-Utility-Library,代码行数:17,代码来源:ZipFile.cs

示例8: PostCreation

        internal static void PostCreation(Package package, DocumentTypes documentType = DocumentTypes.Document)
        {
            XDocument mainDoc, stylesDoc, numberingDoc;

            #region MainDocumentPart
            // Create the main document part for this package
            PackagePart mainDocumentPart;
            if (documentType == DocumentTypes.Document)
            {
                mainDocumentPart = package.CreatePart(new Uri("/word/document.xml", UriKind.Relative), "application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml");
            }
            else
            {
                mainDocumentPart = package.CreatePart(new Uri("/word/document.xml", UriKind.Relative), "application/vnd.openxmlformats-officedocument.wordprocessingml.template.main+xml");
            }
            package.CreateRelationship(mainDocumentPart.Uri, TargetMode.Internal, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument");

            // Load the document part into a XDocument object
            using (TextReader tr = new StreamReader(mainDocumentPart.GetStream(FileMode.Create, FileAccess.ReadWrite)))
            {
                mainDoc = XDocument.Parse
                (@"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes""?>
                   <w:document xmlns:ve=""http://schemas.openxmlformats.org/markup-compatibility/2006"" xmlns:o=""urn:schemas-microsoft-com:office:office"" xmlns:r=""http://schemas.openxmlformats.org/officeDocument/2006/relationships"" xmlns:m=""http://schemas.openxmlformats.org/officeDocument/2006/math"" xmlns:v=""urn:schemas-microsoft-com:vml"" xmlns:wp=""http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing"" xmlns:w10=""urn:schemas-microsoft-com:office:word"" xmlns:w=""http://schemas.openxmlformats.org/wordprocessingml/2006/main"" xmlns:wne=""http://schemas.microsoft.com/office/word/2006/wordml"" xmlns:a=""http://schemas.openxmlformats.org/drawingml/2006/main"" xmlns:c=""http://schemas.openxmlformats.org/drawingml/2006/chart"">
                   <w:body>
                    <w:sectPr w:rsidR=""003E25F4"" w:rsidSect=""00FC3028"">
                        <w:pgSz w:w=""11906"" w:h=""16838""/>
                        <w:pgMar w:top=""1440"" w:right=""1440"" w:bottom=""1440"" w:left=""1440"" w:header=""708"" w:footer=""708"" w:gutter=""0""/>
                        <w:cols w:space=""708""/>
                        <w:docGrid w:linePitch=""360""/>
                    </w:sectPr>
                   </w:body>
                   </w:document>"
                );
            }

            // Save the main document
            using (TextWriter tw = new StreamWriter(mainDocumentPart.GetStream(FileMode.Create, FileAccess.Write)))
                mainDoc.Save(tw, SaveOptions.None);
            #endregion

            #region StylePart
            stylesDoc = HelperFunctions.AddDefaultStylesXml(package);
            #endregion

            #region NumberingPart
            numberingDoc = HelperFunctions.AddDefaultNumberingXml(package);
            #endregion

            package.Close();
        }
开发者ID:EnergonV,项目名称:BestCS,代码行数:50,代码来源:DocX.cs

示例9: WriteThumbnail

 /// <summary>
 /// Writes the thumbnail part of a CDDX file.
 /// </summary>
 /// <param name="package">The package to write to.</param>
 /// <param name="document">The document contatining the preview to write.</param>
 void WriteThumbnail(Package package)
 {
     // Create the thumbnail part
     Uri thumbnailUri = PackUriHelper.CreatePartUri(new Uri("docProps\\thumbnail.xml", UriKind.Relative));
     PackagePart thumbnailPart = package.CreatePart(thumbnailUri, CircuitDiagram.Render.XmlRenderer.PreviewContentType, CompressionOption.Normal);
     package.CreateRelationship(thumbnailPart.Uri, TargetMode.Internal, RelationshipTypes.Thumbnail);
     using (var stream = thumbnailPart.GetStream(FileMode.Create))
     {
         (RenderContext as CircuitDiagram.Render.XmlRenderer).WriteXmlTo(stream);
     }
 }
开发者ID:csuffyy,项目名称:circuitdiagram,代码行数:16,代码来源:CDDXWriter.cs

示例10: WriteMetadata

        /// <summary>
        /// Writes the metadata parts of a CDDX file.
        /// </summary>
        /// <param name="package">The package to write to.</param>
        /// <param name="document">Options for saving.</param>
        void WriteMetadata(Package package)
        {
            // Write core properties
            Uri coreUri = PackUriHelper.CreatePartUri(new Uri("docProps\\core.xml", UriKind.Relative));
            PackagePart corePart = package.CreatePart(coreUri, ContentTypeNames.CoreProperties, CompressionOption.Normal);
            package.CreateRelationship(coreUri, TargetMode.Internal, RelationshipTypes.CoreProperties);

            using (var stream = corePart.GetStream(FileMode.Create))
            {
                XmlTextWriter writer = new XmlTextWriter(stream, Encoding.UTF8);
                writer.Formatting = Formatting.Indented;
                writer.WriteStartDocument();
                writer.WriteStartElement("coreProperties", "http://schemas.circuit-diagram.org/circuitDiagramDocument/2012/metadata/core-properties");
                writer.WriteAttributeString("xmlns", "dc", null, Namespaces.DublinCore);

                if (!String.IsNullOrEmpty(Document.Metadata.Creator))
                    writer.WriteElementString("creator", Namespaces.DublinCore, Document.Metadata.Creator);
                if (!String.IsNullOrEmpty(Document.Metadata.Description))
                    writer.WriteElementString("description", Namespaces.DublinCore, Document.Metadata.Description);
                if (!String.IsNullOrEmpty(Document.Metadata.Title))
                    writer.WriteElementString("title", Namespaces.DublinCore, Document.Metadata.Title);

                if (Document.Metadata.Created.HasValue)
                    writer.WriteElementString("date", Namespaces.DublinCore, Document.Metadata.Created.Value.ToUniversalTime().ToString("u", System.Globalization.CultureInfo.InvariantCulture));

                writer.WriteEndElement();
                writer.WriteEndDocument();

                writer.Flush();
            }

            // Write extended properties
            Uri extendedUri = PackUriHelper.CreatePartUri(new Uri("docProps\\extended.xml", UriKind.Relative));
            PackagePart extendedPart = package.CreatePart(extendedUri, ContentTypeNames.ExtendedProperties, CompressionOption.Normal);
            package.CreateRelationship(extendedUri, TargetMode.Internal, RelationshipTypes.ExtendedProperties);

            using (var stream = extendedPart.GetStream(FileMode.Create))
            {
                XmlTextWriter writer = new XmlTextWriter(stream, Encoding.UTF8);
                writer.Formatting = Formatting.Indented;
                writer.WriteStartDocument();
                writer.WriteStartElement("extendedProperties", "http://schemas.circuit-diagram.org/circuitDiagramDocument/2012/metadata/extended-properties");

                writer.WriteElementString("application", ApplicationInfo.Name);
                writer.WriteElementString("appVersion", ApplicationInfo.Version);

                writer.WriteEndElement();
                writer.WriteEndDocument();

                writer.Flush();
            }
        }
开发者ID:csuffyy,项目名称:circuitdiagram,代码行数:57,代码来源:CDDXWriter.cs

示例11: WriteMainDocument

        /// <summary>
        /// Writes the main document part of a CDDX file, and embeds components as required.
        /// </summary>
        /// <param name="package">The package to write to.</param>
        /// <param name="document">The document containing the metadata to write.</param>
        /// <param name="options">Options for saving.</param>
        void WriteMainDocument(Package package)
        {
            // Prevent EmbedComponents from being null
            if (EmbedComponents == null)
                EmbedComponents = new Dictionary<IOComponentType, EmbedComponentData>();

            // Create the main Document part
            Uri DocumentUri = PackUriHelper.CreatePartUri(new Uri("circuitdiagram\\Document.xml", UriKind.Relative));
            PackagePart DocumentPart = package.CreatePart(DocumentUri, ContentTypeNames.MainDocument, CompressionOption.Normal);
            package.CreateRelationship(DocumentPart.Uri, TargetMode.Internal, RelationshipTypes.Document);

            using (var stream = DocumentPart.GetStream(FileMode.Create))
            {
                XmlTextWriter writer = new XmlTextWriter(stream, Encoding.UTF8);
                writer.Formatting = Formatting.Indented;
                writer.WriteStartDocument();
                writer.WriteStartElement("circuit", Namespaces.Document);
                writer.WriteAttributeString("version", String.Format("{0:0.0}", FormatVersion));
                writer.WriteAttributeString("xmlns", "r", null, Namespaces.Relationships);
                writer.WriteAttributeString("xmlns", "ec", null, Namespaces.DocumentComponentDescriptions);

                // Document size
                writer.WriteStartElement("properties");
                writer.WriteElementString("width", Document.Size.Width.ToString());
                writer.WriteElementString("height", Document.Size.Height.ToString());
                writer.WriteEndElement();

                // Component types
                int idCounter = 0; // generate IDs for each IOComponentType
                Dictionary<IOComponentType, int> typeIDs = new Dictionary<IOComponentType, int>(); // store IDs for use in <elements> section
                writer.WriteStartElement("definitions");
                foreach (KeyValuePair<string, List<IOComponentType>> collection in Document.GetComponentTypes())
                {
                    writer.WriteStartElement("src");

                    // Write the collection name if it is known
                    if (collection.Key != IODocument.UnknownCollection)
                        writer.WriteAttributeString("col", collection.Key);

                    foreach (IOComponentType item in collection.Value)
                    {
                        writer.WriteStartElement("add");
                        writer.WriteAttributeString("id", idCounter.ToString());

                        // Write the collection item if it belongs to a collection
                        if (collection.Key != IODocument.UnknownCollection)
                            writer.WriteAttributeString("item", item.Item);

                        // Write additional attributes for opening with the same component description
                        if (!String.IsNullOrEmpty(item.Name))
                            writer.WriteAttributeString("name", Namespaces.DocumentComponentDescriptions, item.Name);
                        if (item.GUID != Guid.Empty)
                            writer.WriteAttributeString("guid", Namespaces.DocumentComponentDescriptions, item.GUID.ToString());

                        // Write additional attributes for embedding
                        if (EmbedComponents.ContainsKey(item))
                        {
                            // Generate unique file name
                            Uri descriptionPath = PackUriHelper.CreatePartUri(new Uri("circuitdiagram/components/" + item.Name.Replace(' ', '_') + EmbedComponents[item].FileExtension, UriKind.Relative));
                            int addedInt = 0;
                            while (package.PartExists(descriptionPath))
                            {
                                descriptionPath = PackUriHelper.CreatePartUri(new Uri("circuitdiagram/components/" + item.Name.Replace(' ', '_') + addedInt.ToString() + ".cdcom", UriKind.Relative));
                                addedInt++;
                            }

                            // Write part
                            PackagePart descriptionPart = package.CreatePart(PackUriHelper.CreatePartUri(descriptionPath), EmbedComponents[item].ContentType, CompressionOption.Normal);
                            using (var descriptionStream = descriptionPart.GetStream(FileMode.Create))
                            {
                                // Copy stream
                                int num;
                                byte[] buffer = new byte[4096];
                                while ((num = EmbedComponents[item].Stream.Read(buffer, 0, buffer.Length)) != 0)
                                {
                                    descriptionStream.Write(buffer, 0, num);
                                }
                            }
                            PackageRelationship relationship = DocumentPart.CreateRelationship(descriptionPart.Uri, TargetMode.Internal, CDDX.RelationshipTypes.IncludedComponent);

                            // Write the relationship ID
                            writer.WriteAttributeString("id", Namespaces.Relationships, relationship.Id);

                            // Store the relationship ID for use later
                            EmbedComponents[item].Tag = relationship.Id;
                        }
                        else if (EmbedComponents.ContainsKey(item) && !EmbedComponents[item].IsEmbedded)
                        {
                            // Already embedded - write relationship ID
                            writer.WriteAttributeString("id", Namespaces.DocumentComponentDescriptions, EmbedComponents[item].Tag as string);
                        }

                        writer.WriteEndElement();

//.........这里部分代码省略.........
开发者ID:csuffyy,项目名称:circuitdiagram,代码行数:101,代码来源:CDDXWriter.cs

示例12: CreateDocumentPart

        /// <summary>
        /// Adds the speficied file to the package as document part
        /// </summary>
        private static void CreateDocumentPart(Package package, FileInfo file, string contentType, bool storeInDirectory)
        {
            Uri partUriDocument;

            // Convert system path and file names to Part URIs.
            if (storeInDirectory)
                partUriDocument = PackUriHelper.CreatePartUri(new Uri(Path.Combine(file.Directory.Name, file.Name), UriKind.Relative));
            else
                partUriDocument = PackUriHelper.CreatePartUri(new Uri(file.Name, UriKind.Relative));

            // Add the Document part to the Package
            PackagePart packagePartDocument = package.CreatePart(
                partUriDocument, contentType);

            // Copy the data to the Document Part
            using (FileStream fileStream = new FileStream(file.FullName, FileMode.Open, FileAccess.Read))
            {
                CopyStream(fileStream, packagePartDocument.GetStream());
            }

            // Add a Package Relationship to the Document Part
            package.CreateRelationship(packagePartDocument.Uri, TargetMode.Internal, PackageRelationshipType);
        }
开发者ID:olcayseker,项目名称:PostSharp-Toolkits,代码行数:26,代码来源:OPCUtility.cs


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