Esempio n. 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="addKnight"></param>
        /// <returns></returns>
        public bool Add(ArrayKnight addKnight)
        {
            _knights.Add(addKnight);

            return(true);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="knightXElement"></param>
        /// <returns></returns>
        public static ArrayKnight Parse(XElement knightXElement)
        {
            Debug.WriteLine("Inbound knightXElement: " + knightXElement);

            var retKnight = new ArrayKnight();

            if (knightXElement is null)
            {
                return(retKnight);
            }

            if (knightXElement.HasElements)
            {
                string searchName         = knightXElement.Elements("name").FirstOrDefault()?.Value;
                string searchDateElevated = knightXElement.Elements("date_elevated").FirstOrDefault()?.Value;
                string searchType         = knightXElement.Elements("type").FirstOrDefault()?.Value;
                var    wbElementKnights   = _whiteBeltXml.Elements("knight").FirstOrDefault(wb => (string)wb.Element("name") == searchName && (string)wb.Element("date_elevated") == searchDateElevated && (string)wb.Element("type") == searchType);
                if (wbElementKnights is null)
                {
                    retKnight.Name         = knightXElement.Elements("name").FirstOrDefault()?.Value;
                    retKnight.DateElevated = DateTime.Parse(knightXElement.Elements("date_elevated").FirstOrDefault()?.Value);
                    retKnight.Type         = knightXElement.Elements("type").FirstOrDefault()?.Value;
                    if (knightXElement.Elements("type").FirstOrDefault()?.Value == "knight")
                    {
                        if (knightXElement.Elements("notes").FirstOrDefault()?.Value != "")
                        {
                            string strValue = knightXElement.Elements("notes").FirstOrDefault()?.Value + "|not in wbXml";
                            retKnight.Notes = strValue;
                        }
                        else
                        {
                            retKnight.Notes = "not in wbXml";
                        }
                    }
                }
                else
                {
                    //Found him in whiteBelt file
                    retKnight.SocietyPrecedence = !string.IsNullOrEmpty(wbElementKnights.Elements("society_precedence").FirstOrDefault()?.Value) ? int.Parse(wbElementKnights.Elements("society_precedence").FirstOrDefault()?.Value) : -1;
                    retKnight.Name              = wbElementKnights.Elements("name").FirstOrDefault()?.Value;
                    retKnight.Type              = wbElementKnights.Elements("type").FirstOrDefault()?.Value;
                    retKnight.KnightNumber      = !string.IsNullOrEmpty(wbElementKnights.Elements("society_knight_number").FirstOrDefault()?.Value) ? int.Parse(wbElementKnights.Elements("society_knight_number").FirstOrDefault()?.Value) : 0;
                    retKnight.MasterNumber      = !string.IsNullOrEmpty(wbElementKnights.Elements("society_master_number").FirstOrDefault()?.Value) ? int.Parse(wbElementKnights.Elements("society_master_number").FirstOrDefault()?.Value) : 0;
                    retKnight.DateElevated      = DateTime.Parse(wbElementKnights.Elements("date_elevated").FirstOrDefault()?.Value ?? "1/1/1966");
                    retKnight.AnnoSocietatous   = !string.IsNullOrEmpty(wbElementKnights.Elements("anno_societatous").FirstOrDefault()?.Value) ? int.Parse(wbElementKnights.Elements("anno_societatous").FirstOrDefault()?.Value) : 0;
                    retKnight.Kingdom           = wbElementKnights.Elements("kingdom_of_elevation").FirstOrDefault()?.Value;
                    retKnight.KingdomPrecedence = !string.IsNullOrEmpty(wbElementKnights.Elements("kingdom_precedence").FirstOrDefault()?.Value) ? int.Parse(wbElementKnights.Elements("kingdom_precedence").FirstOrDefault()?.Value) : 0;
                    retKnight.ResignedOrRemoved = wbElementKnights.Elements("resigned_or_removed").FirstOrDefault()?.Value;
                    retKnight.PassedAway        = wbElementKnights.Elements("passed_away").FirstOrDefault()?.Value;
                    retKnight.Notes             = wbElementKnights.Elements("notes").FirstOrDefault()?.Value;
                }

                List <ArrayKnight> squiresList = new List <ArrayKnight>();

                if (knightXElement.Elements("squires").Elements("knight").Any())
                {
                    squiresList.AddRange(knightXElement.Elements("squires").Elements("knight").Select(ParseSquire));
                }

                retKnight.Squires = squiresList.ToArray();
            }

            Debug.WriteLine(" -- out: ");
            Debug.WriteLine(retKnight);
            return(retKnight);
        }