Ejemplo n.º 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();
 }
Ejemplo n.º 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();
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 4
0
        /* Any XmlCommentAttributes in obj are inserted into xElements as XML comments (XComment objects).
         *
         * This method assumes xElements is a serialization of obj.
         * If that's not the case, the behavior of this method is unpredictable. */
        private static void InsertXmlComments(Object obj, IEnumerable <XElement> xElements, Int32 level)
        {
            /* Base case. */
            if ((obj == null) || !xElements.Any())
            {
                return;
            }

            Func <XmlCommentAttribute, XComment> getXCommentWithIndentedText =
                xmlCommentAttribute =>
            {
                if (xmlCommentAttribute.ShouldIndent)
                {
                    var prefixSpaces = " ".Repeat((level * xmlCommentAttribute.IndentSize) + "<!-- ".Length);
                    return(new XComment(xmlCommentAttribute.Value.Replace(Environment.NewLine, Environment.NewLine + prefixSpaces)));
                }
                else
                {
                    return(new XComment(xmlCommentAttribute.Value));
                }
            };

            /* Recursive case. */
            foreach (var propertyInfo in obj.GetType().GetProperties())
            {
                if (propertyInfo.CanRead && propertyInfo.GetIndexParameters().Length == 0)
                {
                    if (propertyInfo.IsDefined(_xmlCommentAttributeType, _shouldSearchInheritanceChain))
                    {
                        var xmlComment =
                            propertyInfo
                            .GetCustomAttributes(_xmlCommentAttributeType, _shouldSearchInheritanceChain)
                            .Cast <XmlCommentAttribute>()
                            .Single();

                        xElements
                        .Elements(propertyInfo.Name)
                        .Single()
                        .AddBeforeSelf(getXCommentWithIndentedText(xmlComment));
                    }

                    InsertXmlComments(propertyInfo.GetValue(obj, null), xElements.Elements(propertyInfo.Name), level + 1);
                }
            }
        }
Ejemplo n.º 5
0
 internal Spine(IEnumerable <XElement> spineXElements)
 {
     // ItemRefs
     ItemRefs = new Collection <ItemRef>();
     foreach (XElement itemrefXElement in spineXElements.Elements(Loader.IdpfOrg2007OpfNameSpace + "itemref"))
     {
         ItemRefs.Add(new ItemRef(itemrefXElement));
     }
 }
Ejemplo n.º 6
0
        public XmlParseClass()
        {
            var aa = _xelements.Elements("aa");

            foreach (var x in aa)
            {
                Console.WriteLine((string)x);
            }
        }
Ejemplo n.º 7
0
 internal Manifest(IEnumerable <XElement> manifestXElements)
 {
     // Items
     Items = new Collection <Item>();
     foreach (XElement itemXElement in manifestXElements.Elements(Loader.IdpfOrg2007OpfNameSpace + "item"))
     {
         Items.Add(new Item(itemXElement));
     }
 }
Ejemplo n.º 8
0
 public static string TryExtrinsicValue(this IEnumerable <XElement> list, string field)
 {
     try {
         return(list.Elements("Extrinsic").Where(x => x.Attribute("name").Value == field).First().Value);
     }
     catch {
         return("");
     }
 }
Ejemplo n.º 9
0
 /// <summary>
 /// 根据Key获取Value
 /// </summary>
 /// <param name="key"></param>
 /// <returns></returns>
 private string GetValueByKey(string key)
 {
     XElement setting = appSettings.Elements().SingleOrDefault(s => s.Attribute("key").Value == key);
     if (setting != null && setting.Attribute("value") != null)
     {
         return setting.Attribute("value").Value;
     }
     return null;
 }
Ejemplo n.º 10
0
        internal BasePurl(string elementName, IEnumerable <XElement> metadataXElements)
        {
            XElement xe = metadataXElements.Elements(PurlOrgDcElementsNameSpace + elementName).SingleOrDefault();

            if (xe != null)
            {
                Value = xe.Value;
            }
        }
Ejemplo n.º 11
0
        public static void UpdateCalendars(DateTime start_data, DateTime end_data)
        {
            List <Interval> intlist     = new List <Interval>();
            List <Interval> doneintlist = new List <Interval>();

            sdata.Save(path + "system.xml");
            sdata = XDocument.Load(path + "system.xml");
            df    = sdata.Root.Name.Namespace;
            XElement root            = sdata.Root;
            XElement elm             = XElement.Parse(root.FirstNode.ToString());
            XElement eg              = XElement.Parse(elm.FirstNode.ToString());
            IEnumerable <XElement> l = eg.Elements();

            if (l.First().Name == df + "Include")
            {
            }
            IEnumerable <XElement> l1 = l.Elements(df + "Include");

            foreach (XElement inc in eg.Elements(df + "Include"))
            {
                DateTime tmpdata = start_data;
                while ((tmpdata.Day != end_data.Day) || (tmpdata.Month != end_data.Month) || (tmpdata.Year != end_data.Year)) //при старой проверке из-за несовпадения часов был бесконечный цикл и вылет за границы
                {
                    if ((int)tmpdata.DayOfWeek == int.Parse(inc.Attribute("day_of_week").Value))
                    {
                        int ind = inc.Attribute("time_period").Value.IndexOf("-");
                        int sh  = int.Parse(inc.Attribute("time_period").Value.Substring(0, 1));
                        int eh  = int.Parse(inc.Attribute("time_period").Value.Substring(ind + 1, 2));

                        intlist.Add(new Interval(new DateTime(tmpdata.Year, tmpdata.Month, tmpdata.Day, sh, 0, 0), new DateTime(tmpdata.Year, tmpdata.Month, tmpdata.Day, eh, 0, 0)));
                    }
                    tmpdata = tmpdata.AddDays(1);
                }
            }
            foreach (XElement exc in eg.Elements(df + "Exclude"))
            {
                foreach (Interval t in intlist)
                {
                    if ((int)t.GetStartTime().DayOfWeek == int.Parse(exc.Attribute("day_of_week").Value))
                    {
                        int ind = exc.Attribute("time_period").Value.IndexOf("-");
                        int sh  = int.Parse(exc.Attribute("time_period").Value.Substring(0, 2));
                        int eh  = int.Parse(exc.Attribute("time_period").Value.Substring(ind + 1, 2));

                        DateTime dt = t.GetStartTime().AddHours(-t.GetStartTime().Hour);
                        Interval tmpint;
                        doneintlist.Add(SeparateInterval(t, dt.AddHours(sh), dt.AddHours(eh), out tmpint));
                        doneintlist.Add(tmpint);
                    }
                }
            }

            foreach (XElement eq in root.Descendants(df + "Equipment"))
            {
                equipments[int.Parse(eq.Attribute("id").Value)].GetCalendar().AddIntervals(doneintlist);
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BasicLineString" /> class.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <exception cref="System.ArgumentNullException">The source is null.</exception>
        public BasicLineString(IEnumerable <Coordinate> source)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            this.coordinates = new List <Coordinate>(source.Elements());
        }
Ejemplo n.º 13
0
 public static IEnumerable <XElement> ElementsAnyNamespace <T>(this IEnumerable <T> source, string localName)
     where T : XContainer
 {
     if (source == null)
     {
         throw new ArgumentNullException(nameof(source));
     }
     return(source.Elements().Where(e => e.Name.LocalName == localName));
 }
Ejemplo n.º 14
0
        private void PopulateMainNav(XElement currentElement, char key)
        {
            if (currentElement == null)
            {
                return;
            }

            IEnumerable <XElement> elements =
                from el in currentElement.Elements()
                where (string)el.Attribute("Key") == key.ToString()
                select el;

            if (elements.First().Elements().First().Name.LocalName.Equals("Screen"))
            {
                try
                {
                    String formNamespace = elements.First().Elements().First().Value;
                    if (formNamespace.Equals(String.Empty))
                    {
                        return;
                    }

                    ShowForm(formNamespace, currentElement.Attribute("Tag").Value, currentElement.Attribute("Color").Value);
                }
                catch (Exception ex)
                {
                    if (CDS.Shared.Exception.UserInterfaceExceptionHandler.HandleException(ref ex))
                    {
                        throw ex;
                    }
                }
            }
            else
            {
                if (elements.Count() != 0)
                {
                    tileGroup.Items.Clear();
                    element = elements.First();
                }

                foreach (var element in elements.Elements())
                {
                    Bitmap bmp = new Bitmap(
                        System.Reflection.Assembly.GetEntryAssembly().GetManifestResourceStream("CDS.Client.Desktop.Resources.Navigation." + element.Attribute("Image").Value + ".png"));

                    String[] colorRGB    = element.Attribute("Color").Value.Split(',');
                    Color    color       = Color.FromArgb(Convert.ToInt16(colorRGB[0]), Convert.ToInt16(colorRGB[1]), Convert.ToInt16(colorRGB[2]));
                    String   keycode     = element.Elements().First().Name.LocalName.Equals("Screen") ? "" : String.Format("({0})", element.Elements().Count().ToString());
                    TileItem currentTile = CreateDashTile(element.Name.LocalName, String.Format("{0} {1}", element.Attribute("Tag").Value, keycode), element.Attribute("Key").Value, bmp, color, new DevExpress.XtraEditors.TileItemClickEventHandler(TileItem_ItemPress));
                    currentTile.Tag = element;

                    tileGroup.Items.Add(currentTile);
                }
                tileGroup.Items[0].Checked = true;
            }
        }
Ejemplo n.º 15
0
        public override void Load(IEnumerable <XElement> data)
        {
            IEnumerable <XElement> elements = data.Elements();

            foreach (XElement element in elements)
            {
                Entity rootEntity = DeserializeSceneEntity(element);
                Graph.RootEntities.Add(rootEntity);
            }
        }
Ejemplo n.º 16
0
        // ListBox構成のために艦娘リストを取得
        public string[,] GetYomeList()
        {
            XDocument xdoc = XDocument.Load(directoryPath + @"\YomeNotif\YomeDB.xml");
            XElement  xele = xdoc.Element("YomeDB");

            IEnumerable <XElement> yome = xele.Elements("yome");

            int num = yome.Count();

            string[,] data = new string[num, 2];

            for (int i = 0; i < num; i++)
            {
                data[i, 0] = yome.Elements("Name").ToArray()[i].Value;
                data[i, 1] = yome.Elements("Image").ToArray()[i].Value;
            }

            return(data);
        }
Ejemplo n.º 17
0
        public void LinqToXml()
        {
            string xmlStr = @"
<root>
  <main>
    <a>45</a>
    <b>hej</b>
    <c>4</c>
  </main>
  <main>
    <a>22</a>
    <b>davb</b>
    <c>7</c>
    <subs>
      <sub>
        <f1>rt</f1> 
        <f2>4</f2> 
        <f3>hg</f3> 
      </sub>
      <sub>
        <f1>er</f1> 
        <f2>5</f2> 
        <f3>hj</f3> 
      </sub>
    </subs>
  </main>
</root>";
            //TextReader tr = new StringReader("<?xml version=\"1.0\"?>" + xmlStr);
            //XDocument doc = XDocument.Load(tr);
            XElement elem = XElement.Load(new StringReader(xmlStr));

            string elemStr = elem.ToString();

            Assert.AreEqual("<root>", elemStr.Substring(0, 6), "How to read xml");

            // Linq query example
            IEnumerable <XElement> a22subs = elem.Elements("main").Where(item => (string)item.Element("a") == "22").
                                             Select(item => item.Element("subs"));
            //IEnumerable<XElement> a22subs = from item in elem.Elements("main")
            //                                where (string)item.ElementBase("a") == "22"
            //                                select item.ElementBase("subs");
            IEnumerable <string> a22f3s = from item in a22subs.Elements("sub")
                                          select item.Element("f3").Value;

            Assert.AreEqual("hg", a22f3s.First(), "How to read xml. Linq query");

            // Linq lambda example
            IEnumerable <string> a22f3s2 = from item in
                                           (elem.Elements("main").
                                            Where(item => (string)item.Element("a") == "22").
                                            Select(item => item.Element("subs"))).Elements("sub")
                                           select item.Element("f2").Value;

            Assert.AreEqual("5", a22f3s2.Last(), "How to read xml. Linq lambda");
        }
Ejemplo n.º 18
0
        private static PluralRuleSet[] GetPluralRuleSets(bool ordinals = false)
        {
            if (options != null && ((ordinals && !options.IncludeOrdinalRuleSets) ||
                                    (!ordinals && !options.IncludePluralRuleSets)))
            {
                return(null);
            }

            string filename    = ordinals ? "ordinals" : "plurals";
            string ruleSetType = ordinals ? "ordinal" : "plural";

            XDocument document = GetXmlDocument(String.Format(@"common\supplemental\{0}.xml", filename));

            IEnumerable <XElement> ldmlElements       = document.Elements("supplementalData");
            List <XElement>        pluralRuleSetDatas = (from item in ldmlElements.Elements("plurals")
                                                         .Elements("pluralRules")
                                                         select item).ToList();

            if (pluralRuleSetDatas != null && pluralRuleSetDatas.Count > 0)
            {
                List <PluralRuleSet> pluralRuleSets = new List <PluralRuleSet>();
                foreach (XElement data in pluralRuleSetDatas)
                {
                    string cultureNames = data.Attribute("locales").Value.ToString();
                    Progress(String.Format("Adding {0} rule set", ruleSetType), cultureNames);

                    PluralRuleSet pluralRuleSet = new PluralRuleSet();
                    pluralRuleSet.CultureNames = cultureNames.Split(' ');

                    List <XElement> pluralRuleDatas = (from item in data
                                                       .Elements("pluralRule")
                                                       select item).ToList();
                    if (pluralRuleDatas != null)
                    {
                        List <PluralRule> pluralRules = new List <PluralRule>();
                        foreach (XElement pluralRuleData in pluralRuleDatas)
                        {
                            PluralRule pluralRule = new PluralRule();
                            pluralRule.Id   = GetPluralRuleCount(pluralRuleData.Attribute("count").Value.ToString());
                            pluralRule.Rule = pluralRuleData.Value;
                            pluralRules.Add(pluralRule);
                        }

                        pluralRuleSet.PluralRules = pluralRules.ToArray();
                    }

                    pluralRuleSets.Add(pluralRuleSet);
                    Progress(String.Format("Added {0} rule set", ruleSetType), cultureNames, ProgressEventType.Added, pluralRuleSet);
                }

                return(pluralRuleSets.ToArray());
            }

            return(null);
        }
Ejemplo n.º 19
0
        private void CSprayElement(IEnumerable <XElement> cSprayElements)
        {
            foreach (XElement element in cSprayElements.Elements())
            {
                string elementName = element.Name.LocalName.ToUpper();

                if (elementName == "NAME")
                {
                    SprayName = element.Attribute("value").Value;
                }
                else if (elementName == "SORTNAME")
                {
                    SpraySortName = element.Attribute("value").Value;
                }
                else if (elementName == "DESCRIPTION")
                {
                    SprayDescription = element.Attribute("value").Value;
                }
                else if (elementName == "ADDITIONALSEARCHTEXT")
                {
                    SprayAdditionalSearchText = element.Attribute("value").Value;
                }
                else if (elementName == "RELEASEDATE")
                {
                    if (!int.TryParse(element.Element("Year").Attribute("value").Value, out int year))
                    {
                        year = 2014;
                    }

                    if (!int.TryParse(element.Element("Month").Attribute("value").Value, out int month))
                    {
                        month = 1;
                    }

                    if (!int.TryParse(element.Element("Day").Attribute("value").Value, out int day))
                    {
                        day = 1;
                    }

                    SprayReleaseDate = new DateTime(year, month, day);
                }
                else if (elementName == "HYPERLINKID")
                {
                    SprayHyperlinkId = element.Attribute("value").Value;
                }
                else if (elementName == "ANIMCOUNT")
                {
                    SprayAnimationCount = int.Parse(element.Attribute("value").Value);
                }
                else if (elementName == "ANIMDURATION")
                {
                    SprayAnimationDuration = int.Parse(element.Attribute("value").Value);
                }
            }
        }
        public static List <string[]> GetEPGData(string frequency, string bandwidth, string id)
        {
            List <string[]>        epgData       = new List <string[]>();
            MediaFile              tsFile        = null;
            string                 tsData        = "";
            MatchCollection        matches       = null;
            XDocument              doc           = null;
            IEnumerable <XElement> epgInfoSource = null;
            Process                process       = new Process();

            process.StartInfo.RedirectStandardOutput = true;
            process.StartInfo.UseShellExecute        = false;
            process.StartInfo.CreateNoWindow         = true;
            process.StartInfo.FileName  = @"DVPiper.exe";
            process.StartInfo.Arguments = "-type DVB-T -frequency " + frequency + " -bandwidth " + bandwidth + " -command \"record(rid(123),send(file('" + frequency + ".ts')))\" -command sleep(2000) -command exit";
            process.Start();
            process.WaitForExit();

            tsFile  = new MediaFile(frequency + ".ts");
            tsData  = Regex.Replace("<?xml version=\"1.0\" encoding=\"UTF-8\"?><data>" + tsFile.MediaInfo_HTML.Replace("&nbsp;", "").Replace(" nowrap", "") + "</data>", " colspan=[0-9]+", "");
            matches = Regex.Matches(tsData, "(>)([^<>]+)(<)");
            System.IO.File.Delete(frequency + ".ts");
            foreach (Match match in matches)
            {
                tsData = tsData.Replace(match.Groups[2].Value, SecurityElement.Escape(match.Groups[2].Value));
            }

            tsData = new string(tsData.ToCharArray().Where(ch => XmlConvert.IsXmlChar(ch)).ToArray());

            doc           = XDocument.Load(new StringReader(tsData));
            epgInfoSource = doc.Element("data")
                            .Elements("table").Where(x => Regex.Match(x.Element("thead").Element("tr").Element("th").Value, "Menu #[0-9]+").Success&&
                                                     Regex.Match(x.Element("tbody").Elements("tr").ElementAt(1).Elements("td").ElementAt(1).Value.Trim(), id + " [(]0x[0-9a-fA-F]+[)]").Success);

            for (int i = 0; i < epgInfoSource.Elements("tbody").Elements("tr").Where(x => x.Element("td").Value.Contains("UTC")).Elements("td").Count(); i += 2)
            {
                var detail = (new string[] { epgInfoSource.Elements("tbody").Elements("tr").Where(x => x.Element("td").Value.Contains("UTC")).Elements("td").ElementAt(i).Value })
                             .Concat(epgInfoSource.Elements("tbody").Elements("tr").Where(x => x.Element("td").Value.Contains("UTC")).Elements("td").ElementAt(i + 1).Value.Split('/'));
                epgData.Add(detail.ToArray());
            }
            return(epgData);
        }
Ejemplo n.º 21
0
        public static string ReadVal(string tag, IEnumerable <XElement> root)
        {
            string value = null;
            IEnumerable <XElement> elements = root.Elements(tag);

            if (elements.Count() > 0)
            {
                value = elements.First().Value;
            }
            return(value);
        }
Ejemplo n.º 22
0
        private void EmitTemplate(ref StringBuilder sb, XElement evt, XElement templates)
        {
            if (evt.Attribute(AttributeNames.Template) == null)
            {
                return;
            }

            IEnumerable <XElement> template = from t in templates.Elements()
                                              where
                                              t.Attribute(AttributeNames.Tid).Value ==
                                              evt.Attribute(AttributeNames.Template).Value
                                              select t;

            int order = 0;

            foreach (XElement f in template.Elements(ElementNames.Data))
            {
                if (order > 0)
                {
                    sb.AppendLine();
                }

                var length = f.Attribute(AttributeNames.Length);

                if (null != length)
                {
                    sb.AppendFormat("        [EventField(\"{0}\", \"{1}\")]",
                                    f.Attribute(AttributeNames.InType).Value, length.Value);
                }
                else
                {
                    sb.AppendFormat("        [EventField(\"{0}\")]",
                                    f.Attribute(AttributeNames.InType).Value);
                }

                sb.AppendLine();

                if (f.Attribute(AttributeNames.Map) == null)
                {
                    sb.AppendFormat("        public {0} {1}",
                                    CleanType(f.Attribute(AttributeNames.InType).Value),
                                    NameUtils.CreateIdentifier(f.Attribute(AttributeNames.Name).Value));
                }
                else
                {
                    sb.AppendFormat("        public {0} {1}",
                                    NameUtils.CreateIdentifier(f.Attribute(AttributeNames.Map).Value),
                                    NameUtils.CreateIdentifier(f.Attribute(AttributeNames.Name).Value));
                }

                sb.AppendLine(" { get; set; }");
                order++;
            }
        }
Ejemplo n.º 23
0
 public static void UpdateValueForElement(string elmName, string value)
 {
     InitXDocument();
     if (_doc != null)
     {
         IEnumerable <XElement> kiosks = _doc.Elements(KIOSKS);
         var elm = kiosks.Elements(SECURITY).Elements().FirstOrDefault(x => x.Name.LocalName.ToLower().Equals(elmName.ToLower()));
         elm.SetValue(value);
         _doc.Save(string.Format(@"{0}\{1}", AppDomain.CurrentDomain.BaseDirectory, PATH));
     }
 }
Ejemplo n.º 24
0
        private static List <string> LoadValueOnlySection(XElement doc, string section)
        {
            List <string>          list     = new List <string>();
            IEnumerable <XElement> step1pre = doc.Elements(section);

            foreach (var x in step1pre.Elements())
            {
                list.Add(x.Value);
            }
            return(list);
        }
Ejemplo n.º 25
0
        /// <summary>
        /// LoadConfigurationInfo
        /// </summary>
        private void LoadConfigurationInfo()
        {
            try
            {
                Constants.log.Info("Entering EditorView LoadConfigurationInfo Method!");

                Constants.log.Info("Loading config data...");
                _configdata = XElement.Load("config.xml");

                if (_configdata != null)
                {
                    IEnumerable <XElement> mConfig = _configdata.Descendants("Main_configuration");
                    foreach (var mainElement in mConfig.Elements())
                    {
                        if (mainElement.FirstAttribute.Name == "server_ip")
                        {
                            txtServerIP.Text = mainElement.FirstAttribute.Value;
                        }
                        else if (mainElement.FirstAttribute.Name == "port")
                        {
                            txtPortNumber.Text = mainElement.FirstAttribute.Value;
                        }
                        else if (mainElement.FirstAttribute.Name == "main_controller_ip")
                        {
                            txtControllerIP.Text = mainElement.FirstAttribute.Value;
                        }
                        else if (mainElement.FirstAttribute.Name == "total_spaces")
                        {
                            txtTotalSpace.Text = mainElement.FirstAttribute.Value;
                        }
                        else if (mainElement.FirstAttribute.Name == "total_levels")
                        {
                            txtTotalLevels.Text = mainElement.FirstAttribute.Value;

                            if (!string.IsNullOrEmpty(mainElement.FirstAttribute.Value))
                            {
                                IEnumerable <XElement> levelConfig = _configdata.Descendants("Level_configuration");
                                Constants.log.Info("Adding Levels...");
                                foreach (var levelElement in levelConfig.Elements())
                                {
                                    AddLevelController(levelElement);
                                }
                            }
                        }
                    }
                }

                Constants.log.Info("Exiting EditorView LoadConfigurationInfo Method!");
            }
            catch (Exception ex)
            {
                Constants.log.Error(ex.Message);
            }
        }
Ejemplo n.º 26
0
        private IEnumerable <XElement> ParseMetadata(string contentOpfcontent)
        {
            IEnumerable <XElement> parsedContentOpfcontentPackage = XDocument.Parse(contentOpfcontent).Elements(IdpfOrg2007OpfNameSpace + "package");

            IEnumerable <XElement> xElements = parsedContentOpfcontentPackage.
                                               Elements(IdpfOrg2007OpfNameSpace + "metadata");

            _ePubViewer.Book.Metadata = new Contents.Metadata(xElements);

            return(parsedContentOpfcontentPackage);
        }
Ejemplo n.º 27
0
        /// <summary>
        /// Loads a rule object.
        /// </summary>
        /// <param name="ruleID">The rule of of the rule that should be loaded.</param>
        /// <returns>The loaded rule.</returns>
        public Rule LoadRule(string ruleID)
        {
            //  Load searched rule from file and get all elements
            IEnumerable <XElement> rules = LoadData(_fileNameRule, "rule", new KeyValuePair <string, string>("id", "_" + ruleID));

            //  new rule
            Rule rule = new Rule();

            rule.RuleID       = ruleID;
            rule.RuleElements = new List <RuleElement>();

            if (rules.Elements().Count() > 0)
            {
                rules = rules.Elements();

                rule.RuleElements = this.GetRuleElements(rules);
            }

            return(rule);
        }
Ejemplo n.º 28
0
        public ComercioExterior DesSerializarComercioExterior(XElement element, ref string erroresNom)
        {
            ComercioExterior result;

            try
            {
                IEnumerable <XElement> nomina12 = element.Elements(this._ns + "Complemento");
                if (nomina12 != null)
                {
                    string comerci = nomina12.First <XElement>().ToString();
                    if (comerci == "<cfdi:Complemento xmlns:cfdi=\"http://www.sat.gob.mx/cfd/3\" />")
                    {
                        erroresNom = "CCE154 - El nodo cce11:ComercioExterior debe registrarse como un nodo hijo del nodo Complemento en el CFDI.";
                        result     = null;
                        return(result);
                    }
                    nomina12 = nomina12.Elements(this._ns3 + "ComercioExterior");
                    if (nomina12 != null)
                    {
                        IEnumerable <XAttribute> version = nomina12.Attributes("Version");
                        foreach (XAttribute att in version)
                        {
                            if (nomina12.Count <XElement>() > 1)
                            {
                                erroresNom = "CCE153 - El nodo cce11:ComercioExterior no puede registrarse mas de una vez.";
                                result     = null;
                                return(result);
                            }
                            using (IEnumerator <XElement> enumerator2 = nomina12.GetEnumerator())
                            {
                                if (enumerator2.MoveNext())
                                {
                                    XElement         e                  = enumerator2.Current;
                                    XmlSerializer    ser                = new XmlSerializer(typeof(ComercioExterior));
                                    string           xml                = e.ToString();
                                    StringReader     reader             = new StringReader(xml);
                                    ComercioExterior comLXMLComprobante = (ComercioExterior)ser.Deserialize(reader);
                                    result = comLXMLComprobante;
                                    return(result);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                erroresNom = "CCE218 - " + ex.InnerException.Message;
                result     = null;
                return(result);
            }
            result = null;
            return(result);
        }
Ejemplo n.º 29
0
        public static Dictionary <string, string> ObtenerParametrosPorProgramaXML(string programa)
        {
            Dictionary <string, string> dict      = new Dictionary <string, string>();
            IEnumerable <XElement>      xElements = GetProgramas();

            foreach (XElement elemento in xElements.Elements("parameter"))
            {
                dict.Add(elemento.Attribute("key").Value, elemento.Value);
            }
            return(dict);
        }
Ejemplo n.º 30
0
        public PackageInfo(string FileName)
        {
            BaseDirectory = FileName.GetDirectoryFromFileLocation();

            XElement xelement = XElement.Load(FileName);

            this.Name        = xelement.Element("packagename").Value;
            this.Author      = xelement.Element("author").Value;
            this.DisplayName = xelement.Element("displayname").Value;

            try
            {
                this.EditDate = Convert.ToDateTime(xelement.Element("date").Value);
            }
            catch
            {
                this.EditDate = DateTime.MinValue;
            }

            IEnumerable <XElement> PackageObjects = xelement.Elements().Where(x => x.Name.ToString() == "objects");

            foreach (var packageobject in PackageObjects.Elements().Where(x => x.Name.ToString() == "object"))
            {
                string _ObjectLocation = BaseDirectory.NavigateUpDirectory(2, true);

                Objects _NewObject = new Assets.Objects(_ObjectLocation + "objects\\" + packageobject.Element("name").Value + "\\info.xml", this.Name);
                LoadedObjects.Add(_NewObject);
            }

            IEnumerable <XElement> TextureObjects = xelement.Elements().Where(x => x.Name.ToString() == "textures");

            foreach (var textureobject in TextureObjects.Elements().Where(x => x.Name.ToString() == "texture"))
            {
                string _ObjectLocation = BaseDirectory.NavigateUpDirectory(2, true);

                Textures _NewTextures = new Assets.Textures(_ObjectLocation + "textures\\" + textureobject.Element("name").Value + "\\info.xml", this.Name);
                LoadedTextures.Add(_NewTextures);
            }

            IEnumerable <XElement> ActorObjects = xelement.Elements().Where(x => x.Name.ToString() == "actors");

            foreach (var actorobject in ActorObjects.Elements().Where(x => x.Name.ToString() == "actor"))
            {
                string _ObjectLocation = BaseDirectory.NavigateUpDirectory(2, true);

                Actors _NewActors = new Assets.Actors(_ObjectLocation + "actors\\" + actorobject.Element("name").Value + "\\info.xml", this.Name);
                LoadedActors.Add(_NewActors);
            }

            ActorObjects   = null;
            TextureObjects = null;
            PackageObjects = null;
            xelement       = null;
        }
Ejemplo n.º 31
0
        static void Main(string[] args)
        {
            XElement contacts =
                new XElement("Contacts",
                             new XElement("Contact",
                                          new XElement("Name", "Patrick Hines"),
                                          new XElement("phone", "206-555-0144",
                                                       new XAttribute("Type", "Home")),
                                          new XElement("phone", "425-555-0145",
                                                       new XAttribute("Type", "Work")),
                                          new XElement("Address",
                                                       new XElement("Street1", "123 Main St"),
                                                       new XElement("City", "Mercer Island"),
                                                       new XElement("State", "WA"),
                                                       new XElement("Postal", "68042")
                                                       )
                                          ),
                             new XElement("Contact",
                                          new XElement("Name", "John Smith"),
                                          new XElement("phone", "206-555-0144",
                                                       new XAttribute("Type", "Home")),
                                          new XElement("phone", "425-555-0145",
                                                       new XAttribute("Type", "Work")),
                                          new XElement("Address",
                                                       new XElement("Street1", "456 Secondary St"),
                                                       new XElement("City", "Malibu"),
                                                       new XElement("State", "LA"),
                                                       new XElement("Postal", "11111")
                                                       )
                                          )
                             );

            IEnumerable <XElement> info =
                from el in contacts.Elements("Contact")
                where (string)el.Element("Name") == "Patrick Hines"
                select el;

            foreach (XElement el in info)
            {
                Console.WriteLine(el);
            }

            Console.WriteLine();

            IEnumerable <XElement> info1 =
                from el in info.Elements("phone")
                where (string)el.Attribute("Type") == "Home"
                select el;

            foreach (XElement el in info1)
            {
                Console.WriteLine(el);
            }
        }
Ejemplo n.º 32
0
        /// <summary>
        /// Returns a collection of the child elements of every element and document in the source collection. Optionally ignores case.
        /// </summary>
        /// <param name="elements"></param>
        /// <param name="name"></param>
        /// <param name="ignoreCase"></param>
        /// <returns></returns>
        public static IEnumerable <XElement> Elements(this IEnumerable <XElement> elements, XName name, bool ignoreCase)
        {
            var collection = elements.Elements();

            if (ignoreCase)
            {
                collection = collection.Where(p => p.Name.ToString().ToLower() == name.ToString().ToLower());
            }

            return(collection);
        }
Ejemplo n.º 33
0
 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);
         }
     }
 }
Ejemplo n.º 34
0
        private void ScanElements(IEnumerable <XElement> elements)
        {
            foreach (XElement x in elements.Elements())
            {
                Console.WriteLine(x.Name.LocalName + " " + x.Value);

                if (x.HasElements)
                {
                    ScanElements(x.Elements());
                }
            }
        }
Ejemplo n.º 35
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;
                }
            }
        }
Ejemplo n.º 37
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;
        }
Ejemplo n.º 38
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 );
                }
            }
        }
Ejemplo n.º 39
0
 private IEnumerable<XElement> getSourceSimpleItems(IEnumerable<XElement> messages)
 {
     return from source in messages.Elements("Source")
            from simpleItem in source.Elements("SimpleItem")
            select simpleItem;
 }
Ejemplo n.º 40
0
 private IEnumerable<XElement> getDataSimpleItems(IEnumerable<XElement> messages)
 {
     return from data in messages.Elements("Data")
            from simpleItem in data.Elements("SimpleItem")
            select simpleItem;
 }
Ejemplo n.º 41
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;
 }
Ejemplo n.º 42
0
 private static IEnumerable<XElement> GetFileNameElements(string filename, IEnumerable<XElement> files)
 {
     var fileNameElement = files.Elements("name").Where(el => el.Value.Equals(filename));
     return fileNameElement;
 }
Ejemplo n.º 43
0
 private static string GetFirstSongId(IEnumerable<XElement> fileElements)
 {
     var songId = fileElements.Elements("songId").First().Value;
     return songId;
 }
Ejemplo n.º 44
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;
        }
Ejemplo n.º 45
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);
        }
Ejemplo n.º 46
0
 public bool TryExtractElements(GetMemberBinder binder, out object result, IEnumerable<XElement> dynamicObject)
 {
     result = TryGetElementsOrValue(dynamicObject.Elements(binder.Name));
     if (result != null) return true;
     return false;
 }
Ejemplo n.º 47
0
        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;
        }
Ejemplo n.º 48
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++;
     }
 }
Ejemplo n.º 49
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;
 }
 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();
     }
 }
Ejemplo n.º 51
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;
 }
Ejemplo n.º 52
0
        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;
        }
Ejemplo n.º 53
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;
        }
Ejemplo n.º 54
0
        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;
        }
Ejemplo n.º 55
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));
         }
     }
 }
Ejemplo n.º 56
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();
 }
 // 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));
         }
     }
 }
Ejemplo n.º 58
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 "";
            }
        }
Ejemplo n.º 59
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;
 }
Ejemplo n.º 60
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;
 }