GetRelationship() public méthode

public GetRelationship ( string id ) : PackageRelationship
id string
Résultat PackageRelationship
Exemple #1
0
        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;
        }
Exemple #2
0
 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")};
 }
Exemple #3
0
        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};
        }
Exemple #4
0
        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)
                       };
        }
Exemple #5
0
        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)
                       };
        }
Exemple #6
0
        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()
                       };
        }
        //------------------------------------------------------
        //
        //  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);
        }
Exemple #8
0
 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") };
 }
Exemple #9
0
        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;
        }