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


C# Package.RelationshipExists方法代码示例

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


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

示例1: Apply

        private void Apply(Package package, string filename, bool installed)
        {
            using (var setPkg = Package.Open(filename, FileMode.Open, FileAccess.ReadWrite))
              {
            // Extract information about the target set
            var defRelationship = setPkg.GetRelationshipsByType("http://schemas.octgn.org/set/definition").First();
            var definition = setPkg.GetPart(defRelationship.TargetUri);
            Set set;
            using (var reader = XmlReader.Create(definition.GetStream(), xmlSettings))
            {
              reader.ReadToFollowing("set");  // <?xml ... ?>
              set = new Set(filename, reader, game.repository);
              // Check if the set game matches the patch
              if (set.Game != game) return;
            }

            // Check if there is a patch for this set
            string relationId = "S" + set.Id.ToString("N");
            if (!package.RelationshipExists(relationId)) return;

            var patchPart = package.GetPart(package.GetRelationship(relationId).TargetUri);
            XDocument patchDoc;
            using (var stream = patchPart.GetStream())
              patchDoc = XDocument.Load(stream);

            // Check if the set is at least the required version for patching
            if (set.Version < patchDoc.Root.Attr<Version>("minVersion")) return;
            if (set.Version > patchDoc.Root.Attr<Version>("maxVersion")) return;

            if (installed)
              game.DeleteSet(game.Sets.Single(s => s.packageName == filename));

            // Process the set
            foreach (XElement action in patchDoc.Root.Elements())
              switch (action.Name.LocalName)
              {
            case "new":
              {
                Uri targetUri = new Uri(action.Attr<string>("targetUri"), UriKind.Relative);
                string relationshipId = action.Attr<string>("relationshipId");
                string contentType = action.Attr<string>("contentType");
                PackagePart part = setPkg.PartExists(targetUri) ?
                  setPkg.GetPart(targetUri) :
                  setPkg.CreatePart(targetUri, contentType, CompressionOption.Normal);
                using (var targetStream = part.GetStream(FileMode.Create, FileAccess.Write))
                using (var srcStream = package.GetPart(patchPart.GetRelationship(relationshipId).TargetUri).GetStream())
                  srcStream.CopyTo(targetStream);
                break;
              }

            case "newrel":
              {
                Uri partUri = new Uri(action.Attr<string>("partUri"), UriKind.Relative);
                string relationshipId = action.Attr<string>("relationshipId");
                Uri targetUri = new Uri(action.Attr<string>("targetUri"), UriKind.Relative);
                string relationshipType = action.Attr<string>("relationshipType");

                PackagePart part = setPkg.GetPart(partUri);
                if (part.RelationshipExists(relationshipId)) part.DeleteRelationship(relationshipId);
                part.CreateRelationship(targetUri, TargetMode.Internal, relationshipType, relationshipId);
                break;
              }

            default:
              throw new InvalidFileFormatException("Unknown patch action: " + action.Name);
              }
              }

              OnProgress(string.Format("{0} patched.", System.IO.Path.GetFileName(filename)));

              if (installed)
            try
            { game.InstallSet(filename); }
            catch (Exception ex)
            {
              OnProgress(string.Format("{0} can't be re-installed.\nDetails: {1}", filename, ex.Message), true);
            }
        }
开发者ID:kellyelton,项目名称:octgnwlobby,代码行数:78,代码来源:Patch.cs

示例2: 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;
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:68,代码来源:PackageRelationshipSelector.cs


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