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


C# PackagePart.GetRelationship方法代码示例

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


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

示例1: LoadFromXml

        internal static CardDef LoadFromXml(XElement xml, PackagePart part)
        {
            var backUri = xml.Attr<string>("back");
            if (backUri != null) backUri = part.GetRelationship(backUri).TargetUri.OriginalString;

            var frontUri = xml.Attr<string>("front");
            if (frontUri != null) frontUri = part.GetRelationship(frontUri).TargetUri.OriginalString;

            var cd = new CardDef
                       {
                           back = backUri,
                           front = frontUri,
                           Width = xml.Attr<int>("width"),
                           Height = xml.Attr<int>("height"),
                           CornerRadius = xml.Attr<int>("cornerRadius"),
                           //Properties = xml.Elements(Defs.XmlnsOctgn + "property")
                           //    //.Select(PropertyDef.LoadFromXml)
                           //    .ToDictionary(x => x.Name)
                       };
            var list = xml.Elements(Defs.XmlnsOctgn + "property");
            var proplist = new Dictionary<string,PropertyDef>();
            foreach (var l in list)
            {
                var name = l.Attr<string>("name");

                string kindStr = l.Attr("textKind", "Free");
                PropertyTextKind kind;
                switch (kindStr)
                {
                    case "Free":
                        kind = PropertyTextKind.FreeText;
                        break;
                    case "Enum":
                        kind = PropertyTextKind.Enumeration;
                        break;
                    case "Tokens":
                        kind = PropertyTextKind.Tokens;
                        break;
                    default:
                        throw new InvalidFileFormatException(
                            string.Format("Unknown value '{0}' for textKind attribute (Property = {1})",
                                          kindStr, name));
                }

                var prop = new PropertyDef
                {
                    Name = name,
                    Type = l.Attr<PropertyType>("type"),
                    IgnoreText = l.Attr<bool>("ignoreText"),
                    TextKind = kind,
                    Hidden = l.Attr<bool>("hidden")
                };
                proplist.Add(name,prop);
            }
            cd.Properties = proplist;
            return cd;
        }
开发者ID:voidbeast,项目名称:OCTGN,代码行数:57,代码来源:CardDef.cs

示例2: FromXml

 private static IconDef FromXml(XElement xml, PackagePart part)
 {
     var icon = xml.Attr<string>("icon");
     if (icon != null)
         icon = part.GetRelationship(icon).TargetUri.OriginalString;
     return new IconDef { Icon = icon, Pattern = xml.Attr<string>("pattern")};
 }
开发者ID:jonbonne,项目名称:OCTGN,代码行数:7,代码来源:IconDef.cs

示例3: FromXml

        public static ScriptDef FromXml(XElement xml, PackagePart part)
        {
            string srcUri = part.GetRelationship(xml.Attr<string>("src")).TargetUri.OriginalString;
            PackagePart scriptPart = part.Package.GetPart(new Uri(srcUri, UriKind.Relative));

            using (Stream stream = scriptPart.GetStream(FileMode.Open, FileAccess.Read))
            using (var textReader = new StreamReader(stream))
                return new ScriptDef {Python = textReader.ReadToEnd(), FileName = srcUri};
        }
开发者ID:jonbonne,项目名称:OCTGN,代码行数:9,代码来源:ScriptDef.cs

示例4: LoadFromXml

        internal static CardDef LoadFromXml(XElement xml, PackagePart part)
        {
            var backUri = xml.Attr<string>("back");
            if (backUri != null) backUri = part.GetRelationship(backUri).TargetUri.OriginalString;

            var frontUri = xml.Attr<string>("front");
            if (frontUri != null) frontUri = part.GetRelationship(frontUri).TargetUri.OriginalString;

            return new CardDef
                       {
                           back = backUri,
                           front = frontUri,
                           Width = xml.Attr<int>("width"),
                           Height = xml.Attr<int>("height"),
                           CornerRadius = xml.Attr<int>("cornerRadius"),
                           Properties = xml.Elements(Defs.XmlnsOctgn + "property")
                               .Select(PropertyDef.LoadFromXml)
                               .ToDictionary(x => x.Name)
                       };
        }
开发者ID:0M3G4,项目名称:OCTGN,代码行数:20,代码来源:CardDef.cs

示例5: LoadFromXml

        internal static CounterDef LoadFromXml(XElement xml, PackagePart part, int index)
        {
            var icon = xml.Attr<string>("icon");
            if (icon != null)
                icon = part.GetRelationship(icon).TargetUri.OriginalString;

            return new CounterDef
                       {
                           Id = (byte) index,
                           Name = xml.Attr<string>("name"),
                           Icon = icon,
                           Start = xml.Attr<int>("default"),
                           Reset = xml.Attr("reset", true)
                       };
        }
开发者ID:voidbeast,项目名称:OCTGN,代码行数:15,代码来源:CounterDef.cs

示例6: LoadFromXml

        internal static GroupDef LoadFromXml(XElement xml, PackagePart part, int index)
        {
            var bg = xml.Attr<string>("background");
            if (bg != null)
                bg = part.GetRelationship(bg).TargetUri.OriginalString;

            var board = xml.Attr<string>("board");
            if (board != null)
                board = part.GetRelationship(board).TargetUri.OriginalString;

            var icon = xml.Attr<string>("icon");
            if (icon != null)
                icon = part.GetRelationship(icon).TargetUri.OriginalString;

            return new GroupDef
                       {
                           Id = (byte) index,
                           Name = xml.Attr<string>("name"),
                           icon = icon,
                           Shortcut = xml.Attr<string>("shortcut"),
                           background = bg,
                           BackgroundStyle = xml.Attr<string>("backgroundStyle"),
                           board = board,
                           BoardPosition = xml.Attr<Rect>("boardPosition"),
                           Visibility = xml.Attr<GroupVisibility>("visibility"),
                           Width = xml.Attr<int>("width"),
                           Height = xml.Attr<int>("height"),
                           Ordered = xml.Attr("ordered", true),
                           Collapsed = xml.Attr<bool>("collapsed"),
                           CardActions = xml.Elements()
                               .Where(
                                   x =>
                                   x.Name == Defs.XmlnsOctgn + "cardaction" || x.Name == Defs.XmlnsOctgn + "cardactions")
                               .Select(BaseActionDef.LoadFromXml)
                               .ToArray(),
                           GroupActions = xml.Elements()
                               .Where(
                                   x =>
                                   x.Name == Defs.XmlnsOctgn + "groupaction" ||
                                   x.Name == Defs.XmlnsOctgn + "groupactions")
                               .Select(BaseActionDef.LoadFromXml)
                               .ToArray()
                       };
        }
开发者ID:bejumi,项目名称:OCTGN,代码行数:44,代码来源:GroupDef.cs

示例7: FromXml

 public static FontDef FromXml(XElement xml, PackagePart part)
 {
     string srcUri = part.GetRelationship(xml.Attr<string>("src")).TargetUri.OriginalString;
     return new FontDef { FileName = srcUri, Size = xml.Attr<int>("size"), Target = xml.Attr<string>("target"), Id = xml.Attr<string>("src") };
 }
开发者ID:rexperalta,项目名称:OCTGN,代码行数:5,代码来源:FontDef.cs

示例8: FromXmlReader

        public Card FromXmlReader(XmlReader reader, Game game, Set set, PackagePart definition, Package package)
        {
            var ret = new Card();
            var Properties = new SortedList<PropertyDef, object>(game.CustomProperties.Count());
            reader.MoveToAttribute("name");
            ret.Name = reader.Value;
            reader.MoveToAttribute("id");
            ret.Id = new Guid(reader.Value);
            //           isMutable = false;
            if (reader.MoveToAttribute("alternate"))
            {
                try { ret.Alternate = new Guid(reader.Value); }
                catch (Exception e)
                {
                    throw new ArgumentException(String.Format("The value {0} is not of expected type for property Alternate. Alternate must be a GUID.",
                                                reader.Value));
                }
            }
            else { ret.Alternate = System.Guid.Empty; }
            if (reader.MoveToAttribute("dependent"))
            {
                try
                {
                    ret.Dependent = new Guid(reader.Value).ToString();
                }
                catch
                {
                    try
                    {
                        ret.Dependent = Boolean.Parse(reader.Value).ToString();
                    }
                    catch
                    {

                        throw new ArgumentException(String.Format("The value {0} is not of expected type for property Dependent. Dependent must be either true/false, or the Guid of the card to use instead.",
                                                      reader.Value));
                    }
                }
            }
            else { ret.Dependent = String.Empty; }
            Uri cardImageUri = definition.GetRelationship("C" + ret.Id.ToString("N")).TargetUri;
            ret.ImageUri = cardImageUri.OriginalString;
            if (!package.PartExists(cardImageUri))
                throw new Exception(string.Format("Image for card '{0}', with URI '{1}' was not found in the package.",
                                                  ret.Name, ret.ImageUri));
            reader.Read(); // <card>

            while (reader.IsStartElement("property"))
            {
                reader.MoveToAttribute("name");
                PropertyDef prop = game.CustomProperties.FirstOrDefault(p => p.Name == reader.Value);
                if (prop == null)
                    throw new ArgumentException(string.Format("The property '{0}' is unknown", reader.Value));
                reader.MoveToAttribute("value");
                try
                {
                    switch (prop.Type)
                    {
                        case PropertyType.String:
                            Properties.Add(prop, reader.Value);
                            break;
                        case PropertyType.Integer:
                            Properties.Add(prop, Int32.Parse(reader.Value));
                            break;
                        case PropertyType.Char:
                            Properties.Add(prop, Char.Parse(reader.Value));
                            break;
                        default:
                            throw new NotImplementedException();
                    }
                }
                catch (FormatException)
                {
                    throw new ArgumentException(String.Format("The value {0} is not of expected type for property {1}",
                                                                reader.Value, prop.Name));
                }
                reader.Read(); // <property/>
            }
            ret.Properties = Properties;

            reader.Read(); // </card>
            return ret;
        }
开发者ID:voidbeast,项目名称:OCTGN,代码行数:83,代码来源:CardManager.cs


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