示例#1
1
        public void ContainerAdd()
        {
            XElement element = new XElement("foo");

            // Adding null does nothing.
            element.Add(null);
            Assert.Empty(element.Nodes());

            // Add node, attrbute, string, some other value, and an IEnumerable.
            XComment comment = new XComment("this is a comment");
            XComment comment2 = new XComment("this is a comment 2");
            XComment comment3 = new XComment("this is a comment 3");
            XAttribute attribute = new XAttribute("att", "att-value");
            string str = "this is a string";
            int other = 7;

            element.Add(comment);
            element.Add(attribute);
            element.Add(str);
            element.Add(other);
            element.Add(new XComment[] { comment2, comment3 });

            Assert.Equal(
                new XNode[] { comment, new XText(str + other), comment2, comment3 },
                element.Nodes(),
                XNode.EqualityComparer);

            Assert.Equal(new[] { attribute.Name }, element.Attributes().Select(x => x.Name));
            Assert.Equal(new[] { attribute.Value }, element.Attributes().Select(x => x.Value));

            element.RemoveAll();
            Assert.Empty(element.Nodes());

            // Now test params overload.
            element.Add(comment, attribute, str, other);

            Assert.Equal(new XNode[] { comment, new XText(str + other) }, element.Nodes(), XNode.EqualityComparer);

            Assert.Equal(new[] { attribute.Name }, element.Attributes().Select(x => x.Name));
            Assert.Equal(new[] { attribute.Value }, element.Attributes().Select(x => x.Value));

            // Not allowed to add a document as a child.
            XDocument document = new XDocument();
            Assert.Throws<ArgumentException>(() => element.Add(document));
        }
示例#2
0
 protected override void GenerateXmlContent(XElement RootNode)
 {
     //清空节点原有数据
     RootNode.RemoveAll();
     //所有飞机
     var AllAircraft = this.GetAllAircraft().Where(o => o.FactoryDate != null).ToList();
     //所有机型
     var AircraftTypeList = this.GetAllAircraftTypeList();
     //按月生成每个月的数据
     DateTime startTime = GetMonthEndofDateTime(Convert.ToDateTime(AllAircraft.Min(p => p.FactoryDate)));
     DateTime endTime = GetMonthEndofDateTime(DateTime.Now);
     if (startTime.Year < 1900) startTime = endTime;
     for (DateTime time = startTime; time <= endTime; time = GetMonthEndofDateTime(time.AddMonths(1)))
     {
         //生成时间节点
         XElement DateTimeNode = new XElement("DateTime", new XAttribute("EndOfMonth", FormatDate(time)));
         RootNode.Add(DateTimeNode);
         //每个月份可计算机龄的飞机集合
         var MonthAircraft = AllAircraft.Where(o => o.AircraftBusinesses.Any(p => p.StartDate <= time && !(p.EndDate != null && p.EndDate < time)) && o.FactoryDate <= time && !(o.ExportDate != null && o.ExportDate < time));
         //所有飞机的平均机年龄分布
         GetAgeNodeByDateTime(ref DateTimeNode, MonthAircraft, time, "所有机型");
         foreach (string AircraftType in AircraftTypeList)
         {
             GetAgeNodeByDateTime(ref DateTimeNode, MonthAircraft, time, AircraftType);
         }
     }
 }
示例#3
0
 protected override void GenerateXmlContent(XElement RootNode)
 {
     //清空节点原有数据
     RootNode.RemoveAll();
     //所有飞机运行记录(引进类型的飞机)
     var AllOperationHistory = this.GetAllAircraftOperationHistory().Where(p =>
             p.ImportCategory.ActionType == "引进").ToList();
     //引进方式列表
     IEnumerable<string> AircraftImportList = this.GetAllImportTypeList();
     DateTime startTime = GetOperationStartDate();
     DateTime endTime = GetOperationEndDate();
     for (DateTime time = startTime; time <= endTime; time = GetMonthEndofDateTime(time.AddMonths(1)))
     {
         //计算time对应时间所有引进飞机
         var MonthOperationHistory = AllOperationHistory.Where(p => p.StartDate <= time && !(p.EndDate != null && p.EndDate < time));
         //时间节点
         XElement DateTimeNode = new XElement("DateTime", new XAttribute("EndOfMonth", FormatDate(time)));
         RootNode.Add(DateTimeNode);
         //引进飞机总数
         int Amount = MonthOperationHistory.Count();
         //引进方式
         XElement RegionalNode = new XElement("Type", new XAttribute("TypeName", "引进方式"), new XAttribute("Amount", Amount));
         DateTimeNode.Add(RegionalNode);
         // 各种引进方式
         foreach (var name in AircraftImportList)
         {
             int AirNum = MonthOperationHistory.Where(p => this.SameImportType(p.ImportCategory.ActionName, name)).Count();
             XElement CategoryNode = new XElement("Item", new XAttribute("Name", name), new XAttribute("Percent", GetPercent(AirNum, Amount)), AirNum);
             RegionalNode.Add(CategoryNode);
         }
     }
 }
示例#4
0
        protected override void GenerateXmlContent(XElement RootNode)
        {
            //清空节点原有数据
            RootNode.RemoveAll();
            //当前版本的计划
            var AllPlan = GetAllPlan().ToList();
            //航空公司列表
            IEnumerable<string> AirLinesList = AllPlan.Select(p => p.Airlines.CnShortName).Distinct();
            //开始年
            int BeginYear = !AllPlan.Any() ? DateTime.Now.Year : AllPlan.Min(q => q.Annual.Year);
            //结束年
            int EndYear = !AllPlan.Any() ? DateTime.Now.Year : AllPlan.Max(q => q.Annual.Year);

            //按年生成每年的数据
            for (int year = BeginYear; year <= EndYear; year++)
            {
                //时间节点
                XElement DateTimeNode = new XElement("DateTime", new XAttribute("EndOfMonth", year.ToString()));
                RootNode.Add(DateTimeNode);

                //年度计划
                var YearPlan = AllPlan.Where(p => p.Annual.Year == year);
                //航空公司节点
                XElement TypeNode = new XElement("Type", new XAttribute("TypeName", "航空公司"));
                DateTimeNode.Add(TypeNode);
                //每个航空公司节点
                foreach (var name in AirLinesList) // 航空公司
                {
                    var AirlinesPlan = YearPlan.Where(p => p.Airlines.CnShortName == name);
                    decimal AirlinesPercent = GetPlanPerformance(AirlinesPlan);
                    XElement AirlinesNode = new XElement("Item", new XAttribute("Name", name), FormatDecimal(AirlinesPercent));
                    TypeNode.Add(AirlinesNode);
                }
            }
        }
示例#5
0
        protected override void GenerateXmlContent(XElement RootNode)
        {
            //清空节点原有数据
            RootNode.RemoveAll();
            //获取所有飞机
            var AllAircraft = this.GetAllAircraft();
            //供应商列表
            IEnumerable<string> SupplierList = _XmlService.AllOwnershipHistory.Select(q => q.Supplier.CnShortName).Distinct();
            //按月生成每个月的数据
            DateTime startTime = GetOperationStartDate();
            DateTime endTime = GetOperationEndDate();
            for (DateTime time = startTime; time <= endTime; time = GetMonthEndofDateTime(time.AddMonths(1)))
            {
                //时间节点
                XElement DateTimeNode = new XElement("DateTime", new XAttribute("EndOfMonth", FormatDate(time)));
                RootNode.Add(DateTimeNode);
                //当前时间点的飞机总数
                int Amount = AllAircraft.Count(p => p.OperationHistories.Any(pp => pp.StartDate <= time && !(pp.EndDate != null && pp.EndDate < time)) &&
                                                    p.OwnershipHistories.Any(pp => pp.StartDate <= time && !(pp.EndDate != null && pp.EndDate < time)));
                //供应商节点
                XElement SupplierNode = new XElement("Type", new XAttribute("TypeName", "供应商"), new XAttribute("Amount", Amount));
                DateTimeNode.Add(SupplierNode);

                //各个供应商数据节点
                foreach (var name in SupplierList)
                {
                    int AirNum = AllAircraft.Count(p => p.OperationHistories.Any(pp => pp.StartDate <= time && !(pp.EndDate != null && pp.EndDate < time)) &&
                                                        p.OwnershipHistories.Any(pp => pp.Supplier.CnShortName == name &&
                                                                                       pp.StartDate <= time && !(pp.EndDate != null && pp.EndDate < time)));
                    XElement EachSupplierNode = new XElement("Item", new XAttribute("Name", name), new XAttribute("Percent", GetPercent(AirNum, Amount)), AirNum);
                    SupplierNode.Add(EachSupplierNode);
                }
            }
        }
示例#6
0
    public void Test()
    {
      DatabaseOptions option = new DatabaseOptions()
      {
        Location = "c:\\d",
        AccessNumberPattern = "ddd",
        ContaminationNamePattern = "ccc",
        DecoyPattern = "eee",
        RemovePeptideFromDecoyDB = true
      };

      XElement root = new XElement("Root");
      option.Save(root);

      DatabaseOptions target = new DatabaseOptions();
      target.Load(root);

      root.RemoveAll();
      target.Save(root);

      Assert.AreEqual(option.Location, target.Location);
      Assert.AreEqual(option.AccessNumberPattern, target.AccessNumberPattern);
      Assert.AreEqual(option.ContaminationNamePattern, target.ContaminationNamePattern);
      Assert.AreEqual(option.DecoyPattern, target.DecoyPattern);
      Assert.AreEqual(option.RemovePeptideFromDecoyDB, target.RemovePeptideFromDecoyDB);
    }
示例#7
0
 protected override void GenerateXmlContent(XElement RootNode)
 {
     //清空节点原有数据
     RootNode.RemoveAll();
     //获取所有飞机
     var AllAircraft = this.GetAllAircraft().ToList();
     //所有制造商列表
     IEnumerable<string> ManafacturerList = AllAircraft.Select(p => p.AircraftType.Manufacturer.CnName).Distinct();
     //按月生成每个月的数据
     DateTime startTime = GetOperationStartDate();
     DateTime endTime = GetOperationEndDate();
     for (DateTime time = startTime; time <= endTime; time = GetMonthEndofDateTime(time.AddMonths(1)))
     {
         //当前时间点的所有飞机
         var MonthAircraft = AllAircraft.Where(p => p.OperationHistories.Any(pp =>
              pp.StartDate <= time && !(pp.EndDate != null && pp.EndDate < time)));
         //时间节点
         XElement DateTimeNode = new XElement("DateTime", new XAttribute("EndOfMonth", FormatDate(time)));
         RootNode.Add(DateTimeNode);
         //飞机总数
         int Amount = MonthAircraft.Count();
         //制造商节点
         XElement ManafacturerNode = new XElement("Type", new XAttribute("TypeName", "制造商"), new XAttribute("Amount", Amount));
         DateTimeNode.Add(ManafacturerNode);
         //各个制造商数据节点
         foreach (var name in ManafacturerList)
         {
             int AirNum = MonthAircraft.Where(p => p.AircraftType.Manufacturer.CnName == name).Count();
             XElement EachManaFacturerNode = new XElement("Item", new XAttribute("Name", name), new XAttribute("Percent", GetPercent(AirNum, Amount)), AirNum);
             ManafacturerNode.Add(EachManaFacturerNode);
         }
     }
 }
示例#8
0
 public void XLinq5() {
     XmlReader reader = XmlReader.Create(dataPath + "config.xml");
     //the file has comments and whitespace at the start
     reader.Read();
     reader.Read();
     XElement config = new XElement("appSettings",
                                    "This content will be replaced");
     config.RemoveAll();
     while (!reader.EOF)
         config.Add(XNode.ReadFrom(reader));
     Console.WriteLine(config);
 }
示例#9
0
                /// <summary>
                /// Tests the Add methods on Container.
                /// </summary>
                /// <param name="context"></param>
                /// <returns></returns>
                //[Variation(Desc = "ContainerAdd")]
                public void ContainerAdd()
                {
                    XElement element = new XElement("foo");

                    // Adding null does nothing.
                    element.Add(null);
                    Validate.Count(element.Nodes(), 0);

                    // Add node, attrbute, string, some other value, and an IEnumerable.
                    XComment comment = new XComment("this is a comment");
                    XComment comment2 = new XComment("this is a comment 2");
                    XComment comment3 = new XComment("this is a comment 3");
                    XAttribute attribute = new XAttribute("att", "att-value");
                    string str = "this is a string";
                    int other = 7;

                    element.Add(comment);
                    element.Add(attribute);
                    element.Add(str);
                    element.Add(other);
                    element.Add(new XComment[] { comment2, comment3 });

                    Validate.EnumeratorDeepEquals(
                        element.Nodes(),
                        new XNode[] { comment, new XText(str + other), comment2, comment3 });

                    Validate.EnumeratorAttributes(element.Attributes(), new XAttribute[] { attribute });

                    element.RemoveAll();
                    Validate.Count(element.Nodes(), 0);

                    // Now test params overload.
                    element.Add(comment, attribute, str, other);

                    Validate.EnumeratorDeepEquals(
                        element.Nodes(),
                        new XNode[] { comment, new XText(str + other) });

                    Validate.EnumeratorAttributes(element.Attributes(), new XAttribute[] { attribute });

                    // Not allowed to add a document as a child.
                    XDocument document = new XDocument();
                    try
                    {
                        element.Add(document);
                        Validate.ExpectedThrow(typeof(ArgumentException));
                    }
                    catch (Exception ex)
                    {
                        Validate.Catch(ex, typeof(ArgumentException));
                    }
                }
示例#10
0
        protected override void GenerateXmlContent(XElement RootNode)
        {
            //清空节点原有数据
            RootNode.RemoveAll();
            //获取所有的飞机
            var OprerationAf = this.GetAllAircraft().Where(p => p.IsOperation == true);
            //计划中的客机
            var AircraftPnr = OprerationAf == null ?
                    null :
                    OprerationAf.Where(p => p.AircraftType.AircraftCategory.Category == "客机");

            //计划中的货机机
            var AircraftCargo = OprerationAf == null ?
                    null :
                    OprerationAf.Where(p => p.AircraftType.AircraftCategory.Category == "货机");

            if (AircraftPnr != null || AircraftPnr.Any())
            {
                //客机总计划数
                decimal totalAfCount = AircraftPnr.Count();
                //客机的子节点
                XElement PnrNode = new XElement("Pnr", new XAttribute("Amount", totalAfCount));
                //根据航空公司分组,统计客机的各个航空公司所在的比例
                foreach (var Item in AircraftPnr.GroupBy(t => t.Airlines.ShortName))
                {
                    //获取节点
                    XElement ItemNode = new XElement("Type",
                         new XAttribute(Item.Key.ToString(), Item.Count()),
                         new XAttribute("Percent", GetPercent(Item.Count(), totalAfCount)));
                    PnrNode.Add(ItemNode);
                }
                RootNode.Add(PnrNode);
            }

            if (AircraftCargo != null || AircraftCargo.Any())
            {
                //货机总计划数
                decimal totalAfCount = AircraftCargo.Count();
                //货机的子节点
                XElement CargoNode = new XElement("Cargo", new XAttribute("Amount", totalAfCount));
                //根据航空公司分组,统计货机的各个航空公司所在的比例
                foreach (var Item in AircraftCargo.GroupBy(t => t.Airlines.ShortName))
                {
                    //获取节点
                    XElement ItemNode = new XElement("Type",
                         new XAttribute(Item.Key.ToString(), Item.Count()),
                         new XAttribute("Percent", GetPercent(Item.Count(), totalAfCount)));
                    CargoNode.Add(ItemNode);
                }
                RootNode.Add(CargoNode);
            }
        }
示例#11
0
        public static void SaveFeeds(List<RssFeed> feedList)
        {
            XDocument xml = XDocument.Load(RssDataPath);
            XElement element = new XElement("Feeds");
            element.RemoveAll();

            XElement newXml = new XElement("Feeds",
                                        from f in feedList
                                        select new XElement("Feed",
                                                    new XElement("Url", f.Url),
                                                    new XElement("LastUpdated", f.LastUpdated))
                                       );
            newXml.Save(RssDataPath);
        }
示例#12
0
        protected override void GenerateXmlContent(XElement RootNode)
        {
            RootNode.RemoveAll();
            //所有飞机
            List<Aircraft> AllAircraft = this.GetAllAircraft().ToList();
            //所有座级
            List<string> AircraftRegionalList = this.GetAllAircraftAircraftBusiness().Select(p => p.AircraftType.AircraftCategory.Regional).Distinct().ToList();
            //所有机型
            List<string> AircraftTypeList = this.GetAllAircraftAircraftBusiness().Select(p => p.AircraftType.Name).Distinct().ToList();

            DateTime startTime = GetOperationStartDate();
            DateTime endTime = GetOperationEndDate();
            for (DateTime time = startTime; time <= endTime; time = GetMonthEndofDateTime(time.AddMonths(1)))
            {

                //得到time对应时间的所有飞机,且在该时间点处于运行状态
                var MonthAircraft = AllAircraft.Where(p => p.OperationHistories.Any(pp => pp.StartDate <= time && !(pp.EndDate != null && pp.EndDate < time))
                    && p.AircraftBusinesses.Any(pp => pp.StartDate <= time && !(pp.EndDate != null && pp.EndDate < time)));
                //日期节点
                XElement DateTimeNode = new XElement("DateTime", new XAttribute("EndOfMonth", FormatDate(time)));
                RootNode.Add(DateTimeNode);
                //总飞机数
                int Amount = MonthAircraft.Count();

                //座级
                XElement RegionalNode = new XElement("Type", new XAttribute("TypeName", "座级"), new XAttribute("Amount", Amount));
                DateTimeNode.Add(RegionalNode);
                // 所有座级
                foreach (string name in AircraftRegionalList)
                {
                    int AirNum = MonthAircraft.Count(p =>
                            p.AircraftBusinesses.FirstOrDefault(q => q.StartDate <= time && !(q.EndDate != null && q.EndDate < time)).AircraftType.AircraftCategory.Regional == name);
                    XElement CategoryNode = new XElement("Item", new XAttribute("Name", name), new XAttribute("Percent", GetPercent(AirNum, Amount)), AirNum);
                    RegionalNode.Add(CategoryNode);
                }

                //机型
                XElement TypeNode = new XElement("Type", new XAttribute("TypeName", "机型"), new XAttribute("Amount", Amount));
                DateTimeNode.Add(TypeNode);
                // 所有机型
                foreach (string name in AircraftTypeList)
                {
                    int AirNum = MonthAircraft.Count(p => p.AircraftBusinesses.FirstOrDefault(q => q.StartDate <= time && !(q.EndDate != null && q.EndDate < time)).AircraftType.Name == name);
                    XElement CategoryNode = new XElement("Item", new XAttribute("Name", name), new XAttribute("Percent", GetPercent(AirNum, Amount)), AirNum);
                    TypeNode.Add(CategoryNode);
                }
            }
        }
        public void AddingMultipleNodesIntoElement(TestedFunction testedFunction, CalculateExpectedValues calculateExpectedValues)
        {
            runWithEvents = (bool)Params[0];
            var isConnected = (bool)Variation.Params[0];
            var lengthOfVariations = (int)Variation.Params[1];

            object[] toAdd = { new XElement("ToAddEmpty"), new XElement("ToAddWithAttr", new XAttribute("id", "a1")), new XElement("ToAddWithContent", new XAttribute("id", "a1"), new XElement("inner", "innerContent"), "content"), new XProcessingInstruction("PiWithData", "data"), "", new XProcessingInstruction("PiNOData", ""), new XComment("comment"), new XCData("xtextCdata"), new XText("xtext"), "plaintext1", "plaintext2", null };

            if (isConnected)
            {
                var dummy = new XElement("dummy", toAdd);
            }

            var referenceElement = new XElement("testElement", "text0", new XElement("tin"), new XElement("tin2", new XAttribute("id", "a2")), //
                "text1", new XAttribute("hu", "ha"), new XProcessingInstruction("PI", "data"), new XText("heleho"), new XComment("M&M"), "textEnd");

            for (int startPos = 0; startPos < referenceElement.Nodes().Count(); startPos++)
            {
                // iterate over all nodes in the original element
                foreach (var newNodes in toAdd.NonRecursiveVariations(lengthOfVariations))
                {
                    var orig = new XElement(referenceElement);

                    IEnumerable<ExpectedValue> expectedNodes = Helpers.ProcessNodes(calculateExpectedValues(orig, startPos, newNodes)).ToList();

                    // Add node on the expected place
                    XNode n = orig.FirstNode;
                    for (int position = 0; position < startPos; position++)
                    {
                        n = n.NextNode;
                    }

                    if (runWithEvents)
                    {
                        eHelper = new EventsHelper(orig);
                    }
                    testedFunction(n, newNodes);

                    // Node Equals check
                    TestLog.Compare(expectedNodes.EqualAll(orig.Nodes(), XNode.EqualityComparer), "constructed != added :: nodes Deep equals");

                    // release nodes
                    orig.RemoveAll();
                }
            }
        }
示例#14
0
文件: BaseXml.cs 项目: unicloud/AFRP
        public DateTime DeleteXmlByYear(XElement xelement, DateTime datetime)
        {
            if (this.EditState == TEditState.esEdit)
            {
                if (xelement != null && xelement.Descendants("DateTime").Count() >0)
                {
                    int year = DateTime.Now.AddYears(-1).Year;
                    IEnumerable<XElement> NodeByYear = xelement.Descendants("DateTime")
                        .Where(p => Convert.ToDateTime(p.Attribute("EndOfMonth").Value).Year >= year);
                    if (NodeByYear != null  && NodeByYear.Count()!= 0)
                    {
                        NodeByYear.Remove();
                        //存在去年的数据,则只要生成去年和今年的数据即可
                        datetime = new DateTime(year, 1, 1);
                    }
                }

            }
            else if (this.EditState == TEditState.esNew)
            {
                xelement.RemoveAll();
            }
            return datetime;
        }
示例#15
0
        public void ElementRemove()
        {
            XElement e = new XElement(
                "x",
                new XAttribute("a1", 1),
                new XAttribute("a2", 2),
                new XText("abcd"),
                10,
                new XElement("y", new XComment("comment")),
                new XElement("z"));

            Assert.Equal(5, e.DescendantNodesAndSelf().Count());
            Assert.Equal(2, e.Attributes().Count());

            e.RemoveAll();
            Assert.Equal(1, e.DescendantNodesAndSelf().Count());
            Assert.Empty(e.Attributes());

            // Removing all from an already empty one.
            e.RemoveAll();
            Assert.Equal(1, e.DescendantNodesAndSelf().Count());
            Assert.Empty(e.Attributes());
        }
        public void WriteTo(XElement element)
        {
            if (element != null)
            {
                element.RemoveAll();

                lock (AudioPluginViewSettings.lockObj)
                {
                    OnWriteTo(element);
                }
            }
        }
示例#17
0
                /// <summary>
                /// Validates remove methods on elements.
                /// </summary>
                /// <param name="contextValue"></param>
                /// <returns></returns>
                //[Variation(Desc = "ElementRemove")]
                public void ElementRemove()
                {
                    XElement e =
                        new XElement("x",
                            new XAttribute("a1", 1),
                            new XAttribute("a2", 2),
                            new XText("abcd"),
                            10,
                            new XElement("y",
                                new XComment("comment")),
                            new XElement("z"));

                    Validate.Count(e.DescendantNodesAndSelf(), 5);
                    Validate.Count(e.Attributes(), 2);

                    e.RemoveAll();
                    Validate.Count(e.DescendantNodesAndSelf(), 1);
                    Validate.Count(e.Attributes(), 0);

                    // Removing all from an already empty one.
                    e.RemoveAll();
                    Validate.Count(e.DescendantNodesAndSelf(), 1);
                    Validate.Count(e.Attributes(), 0);
                }
示例#18
0
        //convert the current configuration into an XElement node
        public void SaveCurrentConfig(byte group)
        {
            XElement cfgNode = new XElement("Item");
            XElement sNode = new XElement("Item");
            //group = pack|vib|sub
            if (group > 3) //save pack config
            {
                _curr_cfg.ToElement(ref cfgNode);
                pkg_confs.AddConfig(pkg_confs.cfg_name, cfgNode);
            }

            if ((group % 4) > 1) //save vib config
            {
                sNode.RemoveAll();
                try
                {
                    agent.GetNodeElement(vib_addr, ref sNode);
                    nodes_config[vib_addr].AddConfig(pkg_confs.cfg_name, sNode);
                    if (bot_addr != vib_addr)
                    {
                        agent.GetNodeElement(bot_addr, ref sNode);
                        nodes_config[bot_addr].AddConfig(pkg_confs.cfg_name, sNode);
                    }
                }
                catch
                {
                }
            }
            if ((group % 2) == 1) //save sub config
            {
                
                foreach (byte n in weight_nodes)
                {
                    sNode.RemoveAll();
                    try
                    {
                        agent.GetNodeElement(n, ref sNode);
                        nodes_config[n].AddConfig(pkg_confs.cfg_name, sNode);
                    }
                    catch
                    {
                    }
                }
            }
        }
示例#19
0
        /// <summary>
        /// Modifies the payload order of the specified element.
        /// </summary>
        /// <param name="errorElement">The error element to modify the payload order for.</param>
        /// <returns>An enumerable of cloned error elements with a modified payload order.</returns>
        /// <remarks>The method assumes that the target elements has a certain shape; it does not work for arbitrary elements.</remarks>
        private static IEnumerable<XElement> GeneratePayloadOrders(XElement errorElement)
        {
            // generate all payload orders of the immediate children of the error element
            IList<XElement> children = errorElement.Elements().ToList();
            IEnumerable<XElement[]> permutations = children.Permutations();

            // clone the error element and remove all children
            XElement errorElementWithoutChildren = new XElement(errorElement);
            errorElementWithoutChildren.RemoveAll();

            foreach (XElement[] permutation in permutations)
            {
                XElement targetElement = new XElement(errorElementWithoutChildren);
                targetElement.Add(permutation);
                yield return targetElement;
            }

            // generate all payload orders of the inner error of the error element
            XElement innerErrorElement = errorElement.Element(TestAtomConstants.ODataMetadataXNamespace + TestAtomConstants.ODataInnerErrorElementName);
            children = innerErrorElement.Elements().ToList();
            permutations = children.Permutations();

            // clone the error element and remove all children of the <m:innererror> element.
            XElement errorElementWithoutInnerErrorChildren = new XElement(errorElement);
            innerErrorElement = errorElementWithoutInnerErrorChildren.Element(TestAtomConstants.ODataMetadataXNamespace + TestAtomConstants.ODataInnerErrorElementName);
            innerErrorElement.RemoveAll();

            foreach (XElement[] permutation in permutations)
            {
                XElement targetElement = new XElement(errorElementWithoutInnerErrorChildren);
                innerErrorElement = targetElement.Element(TestAtomConstants.ODataMetadataXNamespace + TestAtomConstants.ODataInnerErrorElementName);
                innerErrorElement.Add(permutation);
                yield return targetElement;
            }
        }
示例#20
0
 /// <summary>
 /// 保存配置
 /// </summary>
 public static void SaveConfig()
 {
     char dp = '0';
     //char sync = '0';
     if (isDefaultPath) dp = '1';
     //if (isAutoSync) sync = '1';
     XElement xe = new XElement("Config",
         new XElement("defaultPath", dp.ToString()),
         new XElement("WorkPath", strWorkPath),
         new XElement("FTP_IP", FTP_IP),
         new XElement("FTP_user", FTP_user),
         new XElement("FTP_password", FTP_password),
         new XElement("paginalItems", paginalItems),
         new XElement("CameraIndex", CameraIndex),
         new XElement("resolutionIndex", resolutionIndex)
         //new XElement("AutoSync", sync.ToString())
         );
     xe.Save(".\\Config.xml");
     xe.RemoveAll();
 }
示例#21
0
 public void ExecuteXElementVariation()
 {
     XObject[] content = Variation.Params as XObject[];
     XElement xElem = new XElement("root", content);
     XElement xElemOriginal = new XElement(xElem);
     using (UndoManager undo = new UndoManager(xElem))
     {
         undo.Group();
         using (EventsHelper elemHelper = new EventsHelper(xElem))
         {
             xElem.RemoveAll();
             TestLog.Compare(xElem.IsEmpty, "Not all content were removed");
             TestLog.Compare(!xElem.HasAttributes, "RemoveAll did not remove attributes");
             xElem.Verify();
             elemHelper.Verify(XObjectChange.Remove, content);
         }
         undo.Undo();
         TestLog.Compare(xElem.Nodes().SequenceEqual(xElemOriginal.Nodes(), XNode.EqualityComparer), "Undo did not work!");
         TestLog.Compare(xElem.Attributes().EqualsAllAttributes(xElemOriginal.Attributes(), Helpers.MyAttributeComparer), "Undo did not work!");
     }
 }
        public bool Write(XElement attachmentElement = null)
        {
            if (attachmentElement == null)
            {
                if (Slot.MirroredSlots != null && MirroredChildren != null)
                {
                    foreach (var mirroredAttachment in MirroredChildren)
                    {
                        Write(Slot.GetWriteableElement(mirroredAttachment.Slot.Name));
                        mirroredAttachment.Write(null);
                    }

                    return true;
                }

                var currentAttachment = Slot.Current;
                if (currentAttachment != null)
                {
                    if (currentAttachment.SubAttachmentVariations != null)
                    {
                        foreach (var subAttachment in currentAttachment.SubAttachmentVariations)
                            subAttachment.Slot.Clear();
                    }
                }

                attachmentElement = Slot.GetWriteableElement();
                if (attachmentElement == null)
                    throw new CustomizationConfigurationException(string.Format("Failed to locate attachments for slot {0}!", Slot.Name));
            }

            var slotName = attachmentElement.Attribute("AName").Value;

            if (Slot.EmptyAttachment == this)
            {
                attachmentElement.RemoveAll();

                attachmentElement.SetAttributeValue("AName", slotName);
            }
            else
            {
                var baseAttachmentElement = Slot.Manager.GetAttachmentElements(Slot.Manager.BaseDefinition).FirstOrDefault(x => x.Attribute("AName").Value == slotName);

                WriteAttribute(attachmentElement, baseAttachmentElement, "Name", Name);

                WriteAttribute(attachmentElement, baseAttachmentElement, "Type", Type);
                WriteAttribute(attachmentElement, baseAttachmentElement, "BoneName", BoneName);

                WriteAttribute(attachmentElement, baseAttachmentElement, "Binding", Object);

                if (Material != null)
                    Material.Save();

                var materialPath = Material != null ? Material.FilePath : null;
                WriteAttribute(attachmentElement, baseAttachmentElement, "Material", materialPath);

                WriteAttribute(attachmentElement, baseAttachmentElement, "Flags", Flags);

                WriteAttribute(attachmentElement, baseAttachmentElement, "Position", Position);
                WriteAttribute(attachmentElement, baseAttachmentElement, "Rotation", Rotation);

                if (SubAttachment != null)
                    SubAttachment.Write();
            }

            return true;
        }
示例#23
0
		private static bool ConvertRefToString(XElement refElem, Dictionary<string, Tuple<string, DomainObjectDTO, XElement>> guidToWsInfo,
			HashSet<string> referencedWsIds)
		{
			if (refElem == null)
				return false;

			var sb = new StringBuilder();
			bool first = true;
			foreach (XElement surElem in refElem.Elements("objsur"))
			{
				var guid = (string)surElem.Attribute("guid");
				if (guid != null)
				{
					string wsId = guidToWsInfo[guid.ToLowerInvariant()].Item1;
					if (!first)
						sb.Append(" ");
					sb.Append(wsId);
					referencedWsIds.Add(wsId);
					first = false;
				}
			}
			refElem.RemoveAll();
			refElem.Add(new XElement("Uni", sb.ToString()));
			return true;
		}
示例#24
0
        protected void GenerateXmlContentNew(XElement RootNode)
        {
            RootNode.RemoveAll();
            //所有飞机运行历史
            var AllOperationHistory = this.GetAllAircraftOperationHistory().OrderBy(p => p.StartDate).ToList();
            //获取所有飞机
            var AllAircrafts = GetAllAircraft().ToList();
            DateTime startTime = GetOperationStartDate();
            DateTime endTime = GetOperationEndDate();

            //所有座级
            IEnumerable<string> AircraftRegionalList = this.GetAllAircraftRegionalList();
            //所有机型
            IEnumerable<string> AircraftTypeList = this.GetAllAircraftTypeList();

            DateNodeList dnlXml = new DateNodeList(startTime, endTime);

            for (DateTime time = startTime; time <= endTime; time = GetMonthEndofDateTime(time.AddMonths(1)))
            {
                DateNode dtNode = new DateNode();
                dtNode.Name = FormatDate(time);
                dtNode.Time = time;
                dnlXml.AddNode(dtNode);

                //座级
                RegionalNode rnNode = new RegionalNode();
                rnNode.Name = "座级";
                rnNode.Amount = 0;
                dtNode.AddChildNode(rnNode);
                // 所有座级
                foreach (var name in AircraftRegionalList)
                {
                    LeafNode lfNode = new LeafNode();
                    lfNode.Name = name;
                    lfNode.Amount = 0;
                    lfNode.Percent = 0;
                    rnNode.AddChildNode(lfNode);
                }
                //机型
                TypeNode tpNode = new TypeNode();
                tpNode.Name = "机型";
                tpNode.Amount = 0;
                dtNode.AddChildNode(tpNode);

                // 所有机型
                foreach (var name in AircraftTypeList)
                {
                    LeafNode lfNode = new LeafNode();
                    lfNode.Name = name;
                    lfNode.Amount = 0;
                    lfNode.Percent = 0;
                    tpNode.AddChildNode(lfNode);
                }

            }

            foreach (var OperationHistory in AllOperationHistory)
            {
                DateTime dtStart = OperationHistory.StartDate == null ? DateTime.Now : (DateTime)OperationHistory.StartDate;
                DateTime dtEnd = OperationHistory.EndDate == null ? DateTime.Now : (DateTime)OperationHistory.EndDate;
                DateNode dtNode;
                int intBeginIndex, intEndIndex;
                dnlXml.GetDataNodeRange(dtStart, dtEnd, out intBeginIndex, out intEndIndex);
                var aircraft = AllAircrafts.FirstOrDefault(p => p.Id == OperationHistory.AircraftId);
                if (aircraft != null && aircraft.AircraftType != null && aircraft.AircraftType.AircraftCategory != null)
                {
                    string RegionalName = aircraft.AircraftType.AircraftCategory.Regional;
                    string TypeName = aircraft.AircraftType.Name;

                    for (int i = intBeginIndex; i <= intEndIndex; i++)
                    {
                        dtNode = dnlXml.GetItem(i);
                        if (dtNode != null)
                        {
                            List<BaseNode> childNodes;
                            childNodes = dtNode.ChildNodes[0].ChildNodes;

                            int intCount = childNodes.Count();
                            for (int j = 0; j < intCount; j++)
                            {
                                LeafNode lfNode = (LeafNode)childNodes[j];
                                if (lfNode.Name == RegionalName)
                                {
                                    lfNode.Amount += 1;
                                    dtNode.ChildNodes[0].Amount += 1;
                                    break;
                                }
                            }

                            childNodes = dtNode.ChildNodes[1].ChildNodes;
                            intCount = childNodes.Count();
                            for (int j = 0; j < intCount; j++)
                            {
                                LeafNode lfNode = (LeafNode)childNodes[j];
                                if (lfNode.Name == TypeName)
                                {
                                    lfNode.Amount += 1;
                                    dtNode.ChildNodes[1].Amount += 1;
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            NodeToXmlContent(dnlXml, RootNode);
        }
示例#25
0
 private void removeXElement(XElement root)
 {
     root.RemoveAll();
     root.Remove();
 }
示例#26
0
        public void XLinq67()
        {
            XElement elem = new XElement("customer",
                                         new XElement("name", "jack"),
                                         "this is an XElement",
                                         new XComment("new customer"),
                                         new XAttribute("id", "abc"));
            Console.WriteLine("Original element {0}", elem);

            elem.RemoveAll();
            Console.WriteLine("Stripped element {0}", elem);
        }
        public void WriteTo(XElement element)
        {
            if (element != null)
            {
                element.RemoveAll();

                lock (DepthPlugin3DViewSettings.lockObj)
                {
                    element.SetAttributeValue("viewType", this.viewType.ToString());
                    element.SetAttributeValue("surface", this.surface.ToString());
                }
            }
        }
 private void RemoveSccElements(XElement node)
 {
     if (node.Name.LocalName.Contains("Scc"))
     {
         node.RemoveAll();
     }
     else if (node.HasElements)
     {
         foreach (var element in node.Elements())
         {
             this.RemoveSccElements(element);
         }
     }
 }
示例#29
0
        protected override void GenerateXmlContent(XElement RootNode)
        {
            //清空节点原有数据
            RootNode.RemoveAll();
            //所有飞机
            var AllAircraft = this.GetAllAircraft().Where(o => o.AircraftBusinesses != null).ToList();
            //所有机型
            var AircraftTypeList = this.GetAllAircraftTypeList();
            //按月生成每个月的数据
            DateTime startTime = GetMonthEndofDateTime(Convert.ToDateTime(AllAircraft.Min(p => p.AircraftBusinesses.Min(pp => pp.StartDate))));
            DateTime endTime = GetMonthEndofDateTime(DateTime.Now);
            if (startTime.Year < 1900) startTime = endTime;
            for (DateTime time = startTime; time <= endTime; time = GetMonthEndofDateTime(time.AddMonths(1)))
            {
                //生成时间节点
                XElement DateTimeNode = new XElement("DateTime", new XAttribute("EndOfMonth", FormatDate(time)));
                RootNode.Add(DateTimeNode);
                //获取当月可统计在册的所有飞机
                var MonthAircraft = AllAircraft.Where(p =>
                    {
                        var aircraftbusinesses = p.AircraftBusinesses;
                        if (aircraftbusinesses.Count() == 0) return false;
                        if (aircraftbusinesses.Min(pp => pp.StartDate) > time) return false;
                        if (aircraftbusinesses.Any(pp => pp.EndDate == null)) return true;
                        if (aircraftbusinesses.Max(pp => pp.EndDate < time.AddDays(1 - time.Day))) return false;
                        return true;
                    });

                //当月的全部在册飞机数
                double averageall = MonthAircraft.Sum(p =>
                    {
                        var aircraftbusinesses = p.AircraftBusinesses;
                        //当月最小时间
                        DateTime? minstartdate = time.AddDays(1 - time.Day);
                        if (aircraftbusinesses.Min(pp => pp.StartDate) > minstartdate)
                        {
                            minstartdate = aircraftbusinesses.Min(pp => pp.StartDate);
                        }
                        //当月最大时间
                        DateTime? maxstartdate = time;
                        if (!aircraftbusinesses.Any(pp => pp.EndDate == null) && aircraftbusinesses.Max(pp => pp.EndDate) <= time)
                        {
                            maxstartdate = aircraftbusinesses.Max(pp => pp.EndDate);
                        }
                        return Convert.ToDateTime(maxstartdate).Day - Convert.ToDateTime(minstartdate).Day;
                    }) / Convert.ToDouble(time.Day);

                //所有机型的在册飞机数节点
                XElement TypeNode = new XElement("Type", new XAttribute("TypeName", "机型"), new XAttribute("Amount", Math.Round(averageall, 4)));
                DateTimeNode.Add(TypeNode);
                foreach (string AircraftType in AircraftTypeList)
                {
                    //当月所选机型的可统计在册的所有飞机
                    var AircraftByType = MonthAircraft.Where(o => o.AircraftBusinesses.Any(oo => oo.AircraftType.Name == AircraftType
                        && oo.StartDate <= time && !(oo.EndDate != null && oo.EndDate < time.AddDays(1 - time.Day))));

                    //当月含有所选机型的在册飞机数
                    double average = AircraftByType.Sum(p =>
                        {
                            var aircraftbusinesses = p.AircraftBusinesses.Where(oo => oo.AircraftType.Name == AircraftType
                                && oo.StartDate <= time && !(oo.EndDate != null && oo.EndDate < time.AddDays(1 - time.Day)));

                            return aircraftbusinesses.Sum(pp =>
                                {
                                    //当月最小时间
                                    DateTime? minstartdate = time.AddDays(1 - time.Day);
                                    if (pp.StartDate > minstartdate)
                                    {
                                        minstartdate = pp.StartDate;
                                    }
                                    //当月最大时间
                                    DateTime? maxstartdate = time;
                                    if (pp.EndDate != null && pp.EndDate <= time)
                                    {
                                        maxstartdate = pp.EndDate;
                                    }
                                    return Convert.ToDateTime(maxstartdate).Day - Convert.ToDateTime(minstartdate).Day;
                                });
                        }) / Convert.ToDouble(time.Day);

                    //对应机型的在册飞机数节点
                    XElement ItemNode = new XElement("Item", new XAttribute("Name", AircraftType), Math.Round(average, 4));
                    TypeNode.Add(ItemNode);
                }
            }
        }
示例#30
0
                /// <summary>
                /// Tests the AddFirst methods on Container.
                /// </summary>
                /// <param name="context"></param>
                /// <returns></returns>
                //[Variation(Desc = "ContainerAddFirst")]
                public void ContainerAddFirst()
                {
                    XElement element = new XElement("foo");

                    // Adding null does nothing.
                    element.AddFirst(null);
                    Validate.Count(element.Nodes(), 0);

                    // Add a sentinal value.
                    XText text = new XText("abcd");
                    element.AddFirst(text);

                    // Add node and string.
                    XComment comment = new XComment("this is a comment");
                    string str = "this is a string";

                    element.AddFirst(comment);
                    element.AddFirst(str);

                    Validate.EnumeratorDeepEquals(element.Nodes(), new XNode[] { new XText(str), comment, text });

                    element.RemoveAll();
                    Validate.Count(element.Nodes(), 0);

                    // Now test params overload.
                    element.AddFirst(text);
                    element.AddFirst(comment, str);

                    Validate.EnumeratorDeepEquals(element.Nodes(), new XNode[] { comment, new XText(str), text });

                    // Can't use to add attributes.
                    XAttribute a = new XAttribute("foo", "bar");
                    try
                    {
                        element.AddFirst(a);
                        Validate.ExpectedThrow(typeof(ArgumentException));
                    }
                    catch (Exception ex)
                    {
                        Validate.Catch(ex, typeof(ArgumentException));
                    }
                }