Example #1
0
        private void Page_Loaded(object sender, RoutedEventArgs e)
        {
            XElement xels;

            using (var buffer = new FileStream(ApplicationData.Current.LocalFolder.Path + @"\testData.xml", FileMode.Open, FileAccess.Read))
            {
                xels = XElement.Load(buffer);
            }

            foreach (var portitem in xels.Elements())
            {
                var port = new Port()
                {
                    Name = portitem.FirstAttribute.Value,
                    City = portitem.LastAttribute.Value
                };
                foreach (var berthitem in portitem.Elements())
                {
                    if (berthitem.Attribute("IsSeparable").Value == "true")
                    {
                        var berth = new Berth()
                        {
                            Name = berthitem.Attribute("No").Value,
                            Port = port
                        };
                        foreach (var item in berthitem.Elements())
                        {
                            berth.SubBerth.Add(new Berth()
                            {
                                Name     = item.Attribute("No").Value,
                                Length   = double.Parse(item.Attribute("Length").Value),
                                MaxDepth = double.Parse(item.Attribute("MaxDepth").Value),
                                Capacity = item.Attribute("Capacity").Value,
                                Port     = port
                            });
                        }
                        port.Berths.Add(berth);
                    }
                    else
                    {
                        port.Berths.Add(new Berth()
                        {
                            Name     = berthitem.Attribute("No").Value,
                            Length   = double.Parse(berthitem.Attribute("Length").Value),
                            MaxDepth = double.Parse(berthitem.Attribute("MaxDepth").Value),
                            Capacity = berthitem.Attribute("Capacity").Value,
                            Port     = port
                        });
                    }
                }
                port.Berths.ForEach(i => BerthsList.Add(i));
            }
        }
Example #2
0
        /// <summary>
        /// Add newBerth to target port, flush xml file
        /// </summary>
        /// <param name="portElement"></param>
        /// <param name="newBerth"></param>
        /// <param name="path"></param>
        public void AddBerthToPort(XElement portElement, Berth newBerth)
        {
            //  Create new Berth element
            var berthElement = new XElement("Berth",
                                            new XAttribute("No", newBerth.Name),
                                            new XAttribute("IsSeparable", "false"),
                                            new XAttribute("Length", newBerth.Length.ToString()),
                                            new XAttribute("MaxDepth", newBerth.MaxDepth.ToString()),
                                            new XAttribute("Capacity", newBerth.Capacity)
                                            );

            portElement.Add(berthElement);
        }
Example #3
0
        private Berth GetNewBerth(Port port)
        {
            var newBerth = new Berth()
            {
                Name     = NameTextBox.Text,
                Port     = port,
                Length   = double.Parse(LengthTextBox.Text),
                Capacity = CapacityTextBox.Text,
                MaxDepth = double.Parse(DepthTextBox.Text)
            };

            port.Berths.Add(newBerth);
            return(newBerth);
        }
Example #4
0
 private void GetBerthRecursive(Berth berth, XElement berthElement)
 {
     if (berth.SubBerth.Count > 0)
     {
         berthElement.SetAttributeValue("IsSeparable", "true");
         foreach (var subBerth in berth.SubBerth)
         {
             var subElement = new XElement(subBerth.GetType().Name,
                                           new XAttribute("No", subBerth.Name)
                                           );
             GetBerthRecursive(subBerth, subElement);
             berthElement.Add(subElement);
         }
     }
     else
     {
         berthElement.SetAttributeValue("IsSeparable", "false");
         berthElement.SetAttributeValue("Length", berth.Length);
         berthElement.SetAttributeValue("MaxDepth", berth.MaxDepth);
         berthElement.SetAttributeValue("Capacity", berth.Capacity);
     }
 }