Example #1
0
 private GameParameters()
 {
     Path = System.Environment.CurrentDirectory;
     _xmlDoc = XDocument.Load(ParameterPath);
     _root = _xmlDoc.Descendants("GameParameters");
     Type = GameType.Classic;
     GameTime = Convert.ToInt32(_root.Elements("CommonParameter").Elements("GameTime").FirstOrDefault().Attribute("count").Value);
     Network = Network.Local;
     Theme = "Basic";
     _menutextureList = new Dictionary<string, BitmapImage>();
     ExplosionDelay = Convert.ToInt32(_root.Elements("CommonParameter").Elements("ExplosionDelay").FirstOrDefault().Attribute("count").Value);
     LoadAllSystemResources();
 }
Example #2
0
 public static string GetVarfield(IEnumerable<XElement> nodes, string id, string subfieldLabel)
 {
     var varfield =
         nodes.Elements("varfield").Where(x => ((string)x.Attribute("id")).Equals(id)).Elements("subfield");
     return
         varfield.Where(x => ((string)x.Attribute("label")).Equals(subfieldLabel)).Select(x => x.Value).FirstOrDefault();
 }
Example #3
0
 private static IEnumerable<XElement> GetMatchingSongIdElements(IEnumerable<XElement> songs, string songId)
 {
     Debug.WriteLine(songs.Count());
     var songIdElements = songs.Elements("id");
     Debug.WriteLine("ids" + songIdElements.Count());
     var songIdElement = songIdElements.Where(el => el.Value.Equals(songId));
     return songIdElement;
 }
 private IEnumerable<Task> LoadTasksForItem(IEnumerable<XElement> childrenElement, int parentId)
 {
     // Get the "child" elements of this element, which would be the tasks
     var tasks = childrenElement.Elements("child");
     if (tasks != null && tasks.Count() > 0)
     {
         foreach (var task in tasks)
         {
             yield return CreateTask(task, parentId);
         }
     }
 }
Example #5
0
        public static List<PdfInfo> GetPdfInfos(IEnumerable<XElement> pdfInfosElement)
        {
            IEnumerable<XElement> elements = pdfInfosElement.Elements("PdfInfo");
            var pdfInfos = new List<PdfInfo>();

            foreach (XElement element in elements)
            {
                // TODO validate by using a schema
                string filePrefix = element.Element("FilePrefix").Value;
                string folder = element.Element("Folder").Value;
                string textRegExPattern = element.Element("TextRegExPattern").Value;
                string dateRegExPattern = element.Element("DateRegExPattern").Value;

                var pdfInfo = new PdfInfo(filePrefix, folder, textRegExPattern, dateRegExPattern);
                pdfInfos.Add(pdfInfo);
            }

            return pdfInfos;
        }
        //  Invoked from World.Settings
        internal static void LoadSettings(IEnumerable<XElement> xmlToolSettings)
        {
            foreach (var xElement in xmlToolSettings.Elements("Tool"))
            {
                string toolName = (string)xElement.Attribute("Name");

                switch (toolName)
                {
                    case "Paint":
                        _paintMode = (PaintMode)ToEnum(typeof(PaintMode), (string)xElement.Attribute("Mode") ?? PaintMode.TileAndWall.ToString());
                        break;
                    case "Brush":
                        _brushWidth = (int?)xElement.Attribute("Width") ?? 20;
                        _brushHeight = (int?)xElement.Attribute("Height") ?? 20;
                        _brushOutline = (int?)xElement.Attribute("Outline") ?? 1;
                        _brushShape = (BrushShape)ToEnum(typeof(BrushShape), (string)xElement.Attribute("Shape") ?? BrushShape.Square.ToString());
                        break;
                    case "Tile":
                        _paintTile = (int?)xElement.Attribute("Tile") ?? 0;
                        _paintTileMask = (int?)xElement.Attribute("Mask") ?? 0;
                        _paintTileActive = (bool)xElement.Attribute("Active");
                        _paintTileMaskMode = (MaskMode)ToEnum(typeof(MaskMode), (string)xElement.Attribute("Mode") ?? MaskMode.Off.ToString());
                        break;
                    case "Wall":
                        _paintWall = (int?)xElement.Attribute("Wall") ?? 0;
                        _paintWallMask = (int?)xElement.Attribute("Mask") ?? 0;
                        _paintWallActive = (bool)xElement.Attribute("Active");
                        _paintWallMaskMode = (MaskMode)ToEnum(typeof(MaskMode), (string)xElement.Attribute("Mode") ?? MaskMode.Off.ToString());
                        break;
                    case "Wire":
                        _redWire = (bool)xElement.Attribute("Red");
                        _blueWire = (bool)xElement.Attribute("Blue");
                        _greenWire = (bool)xElement.Attribute("Green");
                        break;
                }
            }
        }
Example #7
0
        public static bool GetActions(IEnumerable<XElement> actionsXml, out IList<IHttpAction> actions, out IList<IRequestAction> requestActions, out IList<IResponseAction> responseActions)
        {
            actions = new List<IHttpAction>();
            requestActions = new List<IRequestAction>();
            responseActions = new List<IResponseAction>();
            var actionsTemp = actions;
            Func<IList<IHttpAction>, IHttpAction, bool> addFunc = (a, ra) =>
                                                                     {
                                                                         a.Add(ra);
                                                                         return true;
                                                                     }; // hmm, this is just to keep the query below as a single statement, perhaps there is a better way?
            foreach (var ruleAction in from actionXml in actionsXml.Elements()
                                       let name = actionXml.Name.ToString()
                                       where RuleActionTypes.ContainsKey(name)
                                       let actionType = RuleActionTypes[name]
                                       where actionType != null
                                       let constructor = actionType.GetConstructor(new Type[] {})
                                       where constructor != null
                                       let ruleAction = (IHttpAction) constructor.Invoke(new object[] {})
                                       where ruleAction != null && addFunc(actionsTemp, ruleAction)
                                       where ruleAction.Deserialize(actionXml)
                                       select ruleAction)
            {
                if (ruleAction is IRequestAction)
                {
                    requestActions.Add((IRequestAction)ruleAction);
                }

                if (ruleAction is IResponseAction)
                {
                    responseActions.Add((IResponseAction)ruleAction);
                }
            }

            return true;
        }
Example #8
0
 private IEnumerable<XElement> GetXElementByLocalName(IEnumerable<XElement> xElements, String eName)
 {
     if (xElements != null)
     {
         IEnumerable<XElement> returnValues = xElements.Where(x => x.Name.LocalName == eName);
         if (returnValues.Count() > 0)
             return returnValues;
         else if (xElements.Elements().Count() > 0)
             return GetXElementByLocalName(xElements.Elements(), eName);
     }
     return null;
 }
Example #9
0
 private static IEnumerable<XElement> GetFileNameElements(string filename, IEnumerable<XElement> files)
 {
     var fileNameElement = files.Elements("name").Where(el => el.Value.Equals(filename));
     return fileNameElement;
 }
Example #10
0
 protected static IEnumerable<string> GetVarfieldAsList(IEnumerable<XElement> nodes, string id,
                                                        string subfieldLabel)
 {
     var varfield =
         nodes.Elements("varfield").Where(x => ((string)x.Attribute("id")).Equals(id)).Elements("subfield");
     return varfield.Where(x => ((string)x.Attribute("label")).Equals(subfieldLabel)).Select(x => x.Value).ToList();
 }
Example #11
0
        private static string GetFixfield(IEnumerable<XElement> nodes, string id, int fromPos, int toPos)
        {
            var fixfield = nodes.Elements("fixfield").Where(x => ((string)x.Attribute("id")).Equals(id)).Select(x => x.Value).FirstOrDefault();

            if (!string.IsNullOrEmpty(fixfield) && toPos < fixfield.Length)
            {
                if (fromPos == toPos)
                {
                    return fixfield.ElementAt(fromPos).ToString();
                }
                else
                {
                    return fixfield.Substring(fromPos, (toPos - fromPos) + 1);
                }
            }
            else
            {
                return "";
            }
        }
 // If the set of paragraphs from sourceDocument don't have a complete start/end for bookmarks,
 // comments, etc., then this adds them to the paragraph.  Note that this adds them to
 // sourceDocument, and is impure.
 private static void FixRange(XDocument sourceDocument, IEnumerable<XElement> newContent,
     XName startElement, XName endElement, XName idAttribute, XName refElement)
 {
     foreach (XElement start in newContent.DescendantsAndSelf(startElement))
     {
         string rangeId = start.Attribute(idAttribute).Value;
         if (newContent
             .DescendantsAndSelf(endElement)
             .Where(e => e.Attribute(idAttribute).Value == rangeId)
             .Count() == 0)
         {
             XElement end = sourceDocument
                 .Descendants(endElement)
                 .Where(o => o.Attribute(idAttribute).Value == rangeId)
                 .FirstOrDefault();
             if (end != null)
             {
                 AddAtEnd(newContent, new XElement(end));
                 if (refElement != null)
                 {
                     XElement newRef = new XElement(refElement, new XAttribute(idAttribute, rangeId));
                     AddAtEnd(newContent, new XElement(newRef));
                 }
             }
         }
     }
     foreach (XElement end in newContent.Elements(endElement))
     {
         string rangeId = end.Attribute(idAttribute).Value;
         if (newContent
             .DescendantsAndSelf(startElement)
             .Where(s => s.Attribute(idAttribute).Value == rangeId)
             .Count() == 0)
         {
             XElement start = sourceDocument
                 .Descendants(startElement)
                 .Where(o => o.Attribute(idAttribute).Value == rangeId)
                 .FirstOrDefault();
             if (start != null)
                 AddAtBeginning(newContent, new XElement(start));
         }
     }
 }
Example #13
0
 public IEnumerable<XElement> ParseSchema(string tag, IEnumerable<XElement> data, XNamespace nsSchema)
 {
     var query = from e in data.Elements(nsSchema + tag)
                 select e;
     return query;
 }
Example #14
0
        /// <summary>
        /// Adds the person attributes and values found in the XML to the person's attribute-value collection.
        /// </summary>
        /// <param name="groupMember"></param>
        /// <param name="attributes"></param>
        private void AddPersonAttributes( GroupMember groupMember, IEnumerable<XElement> attributes, RockContext rockContext )
        {
            // In order to add attributes to the person, you have to first load them all
            groupMember.Person.LoadAttributes( rockContext );

            foreach ( var personAttribute in attributes.Elements( "attribute" ) )
            {
                // Add them to the list of people who need to have their attribute values saved.
                // This will be done after all the family groups have been saved.
                _personWithAttributes[groupMember.Person.Guid] = true;
                foreach ( var pa in personAttribute.Attributes() )
                {
                    groupMember.Person.SetAttributeValue( pa.Name.LocalName, pa.Value );
                }
            }
        }
Example #15
0
 private static void FixRange(XDocument oldDoc, IEnumerable<XElement> paragraphs, XName startElement, XName endElement, XName idAttribute, XName refElement)
 {
     foreach (XElement start in paragraphs.Elements(startElement))
     {
         string rangeId = start.Attribute(idAttribute).Value;
         if (paragraphs.Elements(endElement).Where(e => e.Attribute(idAttribute).Value == rangeId).Count() == 0)
         {
             XElement end = oldDoc.Descendants().Elements(endElement).Where(o => o.Attribute(idAttribute).Value == rangeId).First();
             if (end != null)
             {
                 paragraphs.Last().Add(new XElement(end));
                 if (refElement != null)
                 {
                     XElement newRef = new XElement(refElement, new XAttribute(idAttribute, rangeId));
                     paragraphs.Last().Add(newRef);
                 }
             }
         }
     }
     foreach (XElement end in paragraphs.Elements(endElement))
     {
         string rangeId = end.Attribute(idAttribute).Value;
         if (paragraphs.Elements(startElement).Where(s => s.Attribute(idAttribute).Value == rangeId).Count() == 0)
         {
             XElement start = oldDoc.Descendants().Elements(startElement).Where(o => o.Attribute(idAttribute).Value == rangeId).First();
             if (start != null)
                 paragraphs.First().AddFirst(new XElement(start));
         }
     }
 }
 public bool TryExtractElements(GetMemberBinder binder, out object result, IEnumerable<XElement> dynamicObject)
 {
     result = TryGetElementsOrValue(dynamicObject.Elements(binder.Name));
     if (result != null) return true;
     return false;
 }
 private IEnumerable<XElement> getDataSimpleItems(IEnumerable<XElement> messages)
 {
     return from data in messages.Elements("Data")
            from simpleItem in data.Elements("SimpleItem")
            select simpleItem;
 }
Example #18
0
 public IEnumerable<XElement> GetSchema(IEnumerable<XElement> data, XNamespace nsEdmx, XNamespace nsSchema)
 {
     var query = from schema in data.Elements(nsSchema + "Schema")
                 select schema;
     return query;
 }
        public static ObservableCollection<Attachment> GetAttachmentListFromXml(IEnumerable<XElement> xmlAttachments)
        {
            ObservableCollection<Attachment> attachmentList = new ObservableCollection<Attachment>();

            foreach(XElement file in xmlAttachments.Elements())
            {
                Attachment attachment = new Attachment();
                attachment.Type = file.Element("Type").Value.ToString();
                attachment.Name = file.Element("Name").Value.ToString();
                attachment.Comments = (file.Element("Comments") == null ? "" : file.Element("Comments").Value.ToString());

                attachmentList.Add(attachment);
            }

            return attachmentList;
        }
        public static ObservableCollection<Dependency> GetDependenciesListFromXml(IEnumerable<XElement> xmlInstructions)
        {
            ObservableCollection<Dependency> dependencyList;

            var dependencies =
                    from dep in xmlInstructions.
                        Elements()
                    select new Dependency
                    {
                        HarvestId = dep.Value
                    };

            dependencyList = new ObservableCollection<Dependency>(dependencies.ToList<Dependency>());

            return dependencyList;
        }
        public static ObservableCollection<SpecialInstruction> GetInstructionListFromXml(IEnumerable<XElement> xmlInstructions)
        {
            ObservableCollection<SpecialInstruction> instructionList;
            var recompileIns =
                    from ins in xmlInstructions.
                        Elements("Forms").Elements()
                    select new SpecialInstruction
                    {
                        Instruction = "Recompile Object",
                        Argument = ins.Value
                    };

            var customIns =
                    from ins in xmlInstructions.
                        Elements()
                    where ins.Name != "Forms"
                    select new SpecialInstruction
                    {
                        Instruction = "Custom Instruction",
                        Argument = ins.Value
                    };

            instructionList = new ObservableCollection<SpecialInstruction>(recompileIns.ToList<SpecialInstruction>().
                Union(customIns.ToList<SpecialInstruction>()));

            return instructionList;
        }
Example #22
0
        public EntityContainer(IEnumerable<XElement> model, XNamespace nsEdmx, XNamespace nsSchema)
        {
            var container = this.GetEntityContainer(model, nsEdmx, nsSchema);
            var n = from schema in model.Elements(nsSchema + "Schema")
                    from e in schema.Elements(nsSchema + "EntityContainer")
                    select e.Attribute("Name");
            this.Name = n.ToArray()[0].Value;

            this.EntitySets = ParseEntityContainer("EntitySet", container, nsSchema);
            this.AssociationSets = ParseEntityContainer("AssociationSet", container, nsSchema);
        }
 private IEnumerable<XElement> getSourceSimpleItems(IEnumerable<XElement> messages)
 {
     return from source in messages.Elements("Source")
            from simpleItem in source.Elements("SimpleItem")
            select simpleItem;
 }
Example #24
0
 private static string GetFirstSongId(IEnumerable<XElement> fileElements)
 {
     var songId = fileElements.Elements("songId").First().Value;
     return songId;
 }
Example #25
0
 public IEnumerable<XElement> GetEntityContainerMapping(IEnumerable<XElement> data, XNamespace nsEdmx, XNamespace nsSchema)
 {
     var query = from schema in data.Elements(nsSchema + "Mapping")
                 from e in schema.Elements(nsSchema + "EntityContainerMapping")
                 select e;
     return query;
 }
Example #26
0
        protected static IEnumerable<Organization> GenerateOrganizationsFromXml(IEnumerable<XElement> nodes, string id)
        {
            var organizations = new List<Organization>();

            var varfields = nodes.Elements("varfield").Where(x => ((string)x.Attribute("id")).Equals(id)).ToList();

            foreach (var varfield in varfields)
            {
                var org = new Organization()
                              {
                                  Name = GetSubFieldValue(varfield, "a"),
                                  UnderOrganization = GetSubFieldValue(varfield, "b"),
                                  Role = GetSubFieldValue(varfield, "e"),
                                  FurtherExplanation = GetSubFieldValue(varfield, "q"),
                                  ReferencedPublication = GetSubFieldValue(varfield, "t")
                              };

                organizations.Add(org);

            }

            return organizations;
        }
Example #27
0
 private static void CopyComments(WordprocessingDocument oldDoc, WordprocessingDocument newDoc, IEnumerable<XElement> paragraphs)
 {
     int number = 0;
     XDocument oldComments = null;
     XDocument newComments = null;
     foreach (XElement comment in paragraphs.Descendants(ns + "commentReference"))
     {
         if (oldComments == null)
             oldComments = oldDoc.MainDocumentPart.WordprocessingCommentsPart.GetXDocument();
         if (newComments == null)
         {
             if (newDoc.MainDocumentPart.WordprocessingCommentsPart != null)
             {
                 newComments = newDoc.MainDocumentPart.WordprocessingCommentsPart.GetXDocument();
                 var ids = newComments.Root.Elements(ns + "comment").Select(f => (int)f.Attribute(ns + "id"));
                 if (ids.Any())
                     number = ids.Max() + 1;
             }
             else
             {
                 newDoc.MainDocumentPart.AddNewPart<WordprocessingCommentsPart>();
                 newComments = newDoc.MainDocumentPart.WordprocessingCommentsPart.GetXDocument();
                 newComments.Add(new XElement(ns + "comments", ns_attrs));
             }
         }
         string id = (string)comment.Attribute(ns + "id");
         XElement element = oldComments.Descendants().Elements(ns + "comment").Where(p => ((string)p.Attribute(ns + "id")) == id).First();
         XElement newElement = new XElement(element);
         newElement.Attribute(ns + "id").Value = number.ToString();
         newComments.Root.Add(newElement);
         comment.Attribute(ns + "id").Value = number.ToString();
         XElement commentRange = paragraphs.Elements(ns + "commentRangeStart").Where(s => ((string)s.Attribute(ns + "id")) == id).FirstOrDefault();
         if (commentRange != null)
             commentRange.Attribute(ns + "id").Value = number.ToString();
         commentRange = paragraphs.Elements(ns + "commentRangeEnd").Where(s => ((string)s.Attribute(ns + "id")) == id).FirstOrDefault();
         if (commentRange != null)
             commentRange.Attribute(ns + "id").Value = number.ToString();
         number++;
     }
 }
Example #28
0
        protected static IEnumerable<Person> GeneratePersonsFromXml(IEnumerable<XElement> nodes, string id)
        {
            var persons = new List<Person>();

            var varfields = nodes.Elements("varfield").Where(x => ((string)x.Attribute("id")).Equals(id)).ToList();

            foreach (var varfield in varfields)
            {
                var nationality = GetSubFieldValue(varfield, "j");
                string nationalityLookupValue = null;
                if (nationality != null)
                    NationalityDictionary.TryGetValue(nationality, out nationalityLookupValue);

                var role = GetSubFieldValue(varfield, "e");
                string roleLookupValue = null;
                if (role != null)
                    RoleDictionary.TryGetValue(role, out roleLookupValue);

                var person = new Person()
                                 {
                                     Name = GetSubFieldValue(varfield, "a"),
                                     LivingYears = GetSubFieldValue(varfield, "d"),
                                     Nationality = nationalityLookupValue ?? nationality,
                                     Role = roleLookupValue ?? role,
                                     ReferredWork = GetSubFieldValue(varfield, "t")
                                 };

                string tempName = GetSubFieldValue(varfield, "a");
                if (tempName != null)
                    person.InvertName(tempName);

                if (!string.IsNullOrEmpty(person.Name) && !persons.Any(x => x.Name.Equals(person.Name)))
                {
                    persons.Add(person);
                }

            }

            return persons;
        }
 private static void DeleteUnmatchedRange(XDocument sourceDocument, IEnumerable<XElement> newContent,
     XName startElement, XName endElement, XName matchTo, XName matchAttr, XName idAttr)
 {
     List<string> deleteList = new List<string>();
     foreach (XElement start in newContent.Elements(startElement))
     {
         string id = start.Attribute(matchAttr).Value;
         if (!newContent.Elements(matchTo).Where(n => n.Attribute(matchAttr).Value == id).Any())
             deleteList.Add(start.Attribute(idAttr).Value);
     }
     foreach (string item in deleteList)
     {
         newContent.Elements(startElement).Where(n => n.Attribute(idAttr).Value == item).Remove();
         newContent.Elements(endElement).Where(n => n.Attribute(idAttr).Value == item).Remove();
         newContent.Where(p => p.Name == startElement && p.Attribute(idAttr).Value == item).Remove();
         newContent.Where(p => p.Name == endElement && p.Attribute(idAttr).Value == item).Remove();
     }
 }
Example #30
0
 public IEnumerable<XElement> ParseEntityContainer(string tag, IEnumerable<XElement> data, XNamespace nsSchema)
 {
     var query = from entitysets in data.Elements(nsSchema + tag)
                 select entitysets;
     return query;
 }