Ejemplo n.º 1
0
        public void AddKnownTypesToCategory(string category, List <string> types)
        {
            XmlNode categoryNode = null;

            foreach (XmlNode node in XMLFunctions.FindChild(PlayerNode.FirstChild, "known").ChildNodes)
            {
                if (node.Attributes["type"].Value == category)
                {
                    categoryNode = node;
                    break;
                }
            }

            if (categoryNode == null)
            {
                Logger.Error("Cannot find category " + category + " to add types.");
                return;
            }

            foreach (string type in types)
            {
                XmlNode      newNode = PlayerNode.OwnerDocument.CreateNode(XmlNodeType.Element, "entry", "");
                XmlAttribute att     = PlayerNode.OwnerDocument.CreateAttribute("id");
                att.Value = type;
                newNode.Attributes.Append(att);
                categoryNode.AppendChild(newNode);
                PlayerKnown[category].Add(type);
            }
        }
        public HighwayData(XmlNode highwayNode, CatDatExtractor cde)
        {
            // 1 Celestialbody: <connection connection="region_zone_011_connection"> -> <component class="celestialbody" component="cluster_b" connection="space" id="[0x1b5e7]">
            try
            {
                this.cde    = cde;
                HighwayNode = highwayNode.FirstChild;
                HighwayName = highwayNode.Attributes["connection"].Value;

                XmlNode childNode = XMLFunctions.FindChild(HighwayNode, "connections").FirstChild;

                while (childNode != null)
                {
                    try
                    {
                        if (childNode.Attributes["connection"].Value == "ships")
                        {
                            Ships.Add(new ShipData(childNode, cde));
                        }
                    }
                    catch (Exception ex)
                    {
                        Logger.Error("Unable to add Highway child", ex);
                    }
                    childNode = childNode.NextSibling;
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Unable to parse Highway node.", ex);
            }
        }
        public GalaxyData(XmlNode galaxyNode, CatDatExtractor cde)
        {
            try
            {
                GalaxyNode = galaxyNode;
                XmlNode childNode = XMLFunctions.FindChild(GalaxyNode, "connections").FirstChild;
                while (childNode != null)
                {
                    try
                    {
                        if (childNode.Attributes["connection"].Value.ToLower() != "clusters")
                        {
                            Clusters.Add(new ClusterData(childNode, cde));
                        }
                    }
                    catch (Exception ex)
                    {
                        Logger.Error("Unable to parse child of galaxy.", ex);
                    }

                    childNode = childNode.NextSibling;
                }

                GetSkunk();
                this.cde = cde;
            }
            catch (Exception ex)
            {
                throw new Exception("Unable to parse galaxy node.", ex);
            }
        }
Ejemplo n.º 4
0
        public RegionData(XmlNode regionNode, CatDatExtractor cde)
        {
            try
            {
                // 1 Region: <connection connection="region_zone_011_connection"> -> <component class="region" macro="region_zone_011_macro" connection="cluster" id="[0x17266]">
                RegionNode = regionNode.FirstChild;
                RegionName = regionNode.Attributes["connection"].Value;
                // Some region does not have any "connections" node.
                if (XMLFunctions.FindChild(RegionNode, "connections") != null)
                {
                    XmlNode childNode = XMLFunctions.FindChild(RegionNode, "connections").FirstChild;
                    this.cde = cde;

                    while (childNode != null)
                    {
                        try
                        {
                            if (childNode.Attributes["connection"].Value == "ships")
                            {
                                Ships.Add(new ShipData(childNode, cde));
                            }
                        }
                        catch (Exception ex)
                        {
                            Logger.Error("Unable to add child to region.", ex);
                        }
                        childNode = childNode.NextSibling;
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Unable to parse region.", ex);
            }
        }
Ejemplo n.º 5
0
        public static byte[] CreateTDGProvisionWorkbook()
        {
            SetupBasicLogging();

            //don't need act rn
            var actFraXml  = LegApiClient.GetActFromJustice("fra");
            var tdgFraActs = XML.XMLFunctions.ParseRegs(actFraXml, "Body", "441564");

            var actXml = LegApiClient.GetActFromJustice();
            var regXml = LegApiClient.GetRegulationFromJustice();

            //XML to "Regulation" class
            //act       = XMLFunctions.ParseRegs(actXml, "Body", "452135");
            tdgr      = XMLFunctions.ParseRegs(regXml, "Body", "1227365");
            schedule1 = XMLFunctions.ParseRegs(regXml, "Schedule", "1230876");
            schedule2 = XMLFunctions.ParseRegs(regXml, "Schedule", "1230890");
            schedule3 = XMLFunctions.ParseRegs(regXml, "Schedule", "1231645");

            //flag data we're interested in
            //TODO: can be added in the parsing to avoid an extra sweep
            act.PopulateDataFlags();
            tdgr.PopulateDataFlags();
            schedule1.PopulateDataFlags();
            schedule2.PopulateDataFlags();
            schedule3.PopulateDataFlags();

            //output List of Regulations to JSON
            XMLFunctions.SerializeRegulationsToFile(act, actFileName);
            XMLFunctions.SerializeRegulationsToFile(tdgr, regFileName);
            XMLFunctions.SerializeRegulationsToFile(schedule1, schedule1FileName);
            XMLFunctions.SerializeRegulationsToFile(schedule2, schedule2FileName);
            XMLFunctions.SerializeRegulationsToFile(schedule3, schedule3FileName);

            return(CreateExcelWorkbook());
        }
        public void AddBooster(string faction, float value, double time)
        {
            // On the selected faction toward the targeted one
            XmlNode relationsNode = XMLFunctions.FindChild(FactionNode, "relations");

            if (relationsNode == null)
            {
                relationsNode = FactionNode.OwnerDocument.CreateElement("relations");
                FactionNode.AppendChild(relationsNode);
            }
            Boosters.Add(new BoosterData(faction, value, time, XMLFunctions.FindChild(FactionNode, "relations"), cde));

            // On the targeted faction toward the selected
            string      SelectedFaction = FactionName;
            FactionData TargetedFaction = factionsData[faction];

            if (TargetedFaction == null)
            {
                TargetedFaction = factionsData.AddFactionData(faction);
            }
            relationsNode = XMLFunctions.FindChild(TargetedFaction.FactionNode, "relations");
            if (relationsNode == null)
            {
                relationsNode = TargetedFaction.FactionNode.OwnerDocument.CreateElement("relations");
                TargetedFaction.FactionNode.AppendChild(relationsNode);
            }
            TargetedFaction.Boosters.Add(new BoosterData(SelectedFaction, value, time, XMLFunctions.FindChild(TargetedFaction.FactionNode, "relations"), cde));
        }
 public void RemoveLicence(LicenceData licence)
 {
     licence.Remove();
     Licences.Remove(licence);
     if (Licences.Count <= 0)
     {
         FactionNode.RemoveChild(XMLFunctions.FindChild(FactionNode, "licences"));
     }
 }
 public void RemovePatch(PatchInfoData patch)
 {
     patch.Remove();
     Patches.Remove(patch);
     if (Patches.Count <= 0)
     {
         SaveGameInfoNode.RemoveChild(XMLFunctions.FindChild(SaveGameInfoNode, "patches"));
     }
 }
 public void RemoveBooster(BoosterData booster)
 {
     booster.Remove();
     Boosters.Remove(booster);
     if (Boosters.Count <= 0 && Relations.Count <= 0)
     {
         // Only removed if both Relations and Boosters are null (they have the same parent node "relations" in save file).
         FactionNode.RemoveChild(XMLFunctions.FindChild(FactionNode, "relations"));
     }
 }
Ejemplo n.º 10
0
        public void AddKnownTypeCategory(string category)
        {
            XmlNode      newNode = PlayerNode.OwnerDocument.CreateNode(XmlNodeType.Element, "entries", "");
            XmlAttribute att     = PlayerNode.OwnerDocument.CreateAttribute("type");

            att.Value = category;
            newNode.Attributes.Append(att);
            XMLFunctions.FindChild(PlayerNode.FirstChild, "known").AppendChild(newNode);
            PlayerKnown.Add(category, new List <string>());
        }
 public void RemoveRelation(RelationData relation)
 {
     relation.Remove();
     Relations.Remove(relation);
     if (Relations.Count <= 0 && Boosters.Count <= 0)
     {
         // Only removed if both Relations and Boosters are null (they have the same parent node "relations" in save file).
         FactionNode.RemoveChild(XMLFunctions.FindChild(FactionNode, "relations"));
     }
 }
Ejemplo n.º 12
0
        public XmlNode GetSkillNode(string skill)
        {
            XmlNode node = XMLFunctions.FindChild(NPCNode.ChildNodes[0], "skills").FirstChild;

            while (node != null)
            {
                if (XMLFunctions.GetSafeAttribute(node, "type") == skill)
                {
                    return(node);
                }
                node = node.NextSibling;
            }

            return(null);
        }
Ejemplo n.º 13
0
        public SectorData(XmlNode sectorNode, CatDatExtractor cde)
        {
            try
            {
                this.cde = cde;

                // 1 Sector: <connection connection="cluster_b_sector04_connection"> -> <component class="sector" macro="cluster_b_sector04_macro" connection="cluster" knownto="player" id="[0x17267]">
                SectorNode = sectorNode.FirstChild;
                SectorName = sectorNode.Attributes["connection"].Value;

                XmlNode childNode = XMLFunctions.FindChild(SectorNode, "connections").FirstChild;
                while (childNode != null)
                {
                    try
                    {
                        if (childNode.FirstChild.Attributes["class"].Value.ToLower() == "zone" &&
                            childNode.FirstChild.Attributes["macro"].Value.ToLower() == "tempzone"
                            )
                        {
                            TempZones.Add(new ZoneData(childNode, cde));
                        }
                        else if (childNode.FirstChild.Attributes["class"].Value.ToLower() == "zone")
                        {
                            Zones.Add(new ZoneData(childNode, cde));
                        }
                        else if (childNode.FirstChild.Attributes["class"].Value.ToLower() == "highway")
                        {
                            Highways.Add(new HighwayData(childNode, cde));
                        }
                        else
                        {
                            throw new Exception("Not a zone or highway. This is a " + childNode.FirstChild.Attributes["class"].Value);
                        }
                    }
                    catch (Exception ex)
                    {
                        Logger.Error("Unable to add child to sector", ex);
                    }

                    childNode = childNode.NextSibling;
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Failed to parse sector.", ex);
            }
        }
        public SaveGameInfoData(XmlNode saveGameInfoNode, CatDatExtractor cde)
        {
            SaveGameInfoNode = saveGameInfoNode;
            this.cde         = cde;
            XmlNode patches = XMLFunctions.FindChild(saveGameInfoNode, "patches");

            if (patches != null)
            {
                XmlNode patch = patches.FirstChild;

                while (patch != null)
                {
                    Patches.Add(new PatchInfoData(patch, cde));
                    patch = patch.NextSibling;
                }
            }
        }
Ejemplo n.º 15
0
        private static void CreateProvisionExcelSheet(Regulation provision, string name, bool lastSheet = false)
        {
            //flatten list and output to DataTable <--faster output to excel
            var dt = XMLFunctions.CreateDataTableFromRegulation(provision);

            //export to datatable
            excel.BulkExportDataTableToExcel(dt);

            excel.SetWorksheetName(name);

            excel.FreezeFrame(3, 1);

            //create new worksheet
            if (!lastSheet)
            {
                excel.CreateNewWorksheet();
            }
        }
        public void AddLicence(string licence, string faction)
        {
            XmlNode licencesNode = XMLFunctions.FindChild(FactionNode, "licences");

            if (licencesNode == null)
            {
                licencesNode = FactionNode.OwnerDocument.CreateElement("licences");
                FactionNode.AppendChild(licencesNode);
            }

            if (Licences.Exists(a => a.Type == licence))
            {
                Licences.First(a => a.Type == licence).AddFaction(faction);
            }
            else
            {
                Licences.Add(new LicenceData(faction, licence, licencesNode, cde));
            }
        }
        public ShipSoftwareData(string macro, string softwareSlot, XmlNode shipNode, CatDatExtractor cde)
        {
            // Create software
            XmlElement   connection    = shipNode.OwnerDocument.CreateElement("connection");
            XmlAttribute connectionAtt = shipNode.OwnerDocument.CreateAttribute("connection");

            connectionAtt.Value = softwareSlot;
            connection.Attributes.Append(connectionAtt);
            XmlElement   component         = shipNode.OwnerDocument.CreateElement("component");
            XmlAttribute componentAttClass = shipNode.OwnerDocument.CreateAttribute("clas");

            componentAttClass.Value = "software";
            component.Attributes.Append(componentAttClass);
            XmlAttribute componentAttmacro = shipNode.OwnerDocument.CreateAttribute("macro");

            componentAttmacro.Value = macro;
            component.Attributes.Append(componentAttmacro);
            XmlAttribute componentAttConn = shipNode.OwnerDocument.CreateAttribute("connection");

            componentAttConn.Value = "softwareconnection";
            component.Attributes.Append(componentAttConn);
            XmlAttribute componentAttId = shipNode.OwnerDocument.CreateAttribute("id");

            componentAttId.Value = XMLFunctions.DetermineNewId(shipNode.OwnerDocument);
            component.Attributes.Append(componentAttId);
            connection.AppendChild(component);

            XmlNode insertAfter = null;

            if (SoftwareSlot == 2)
            {
                insertAfter = XMLFunctions.FindChild(shipNode.FirstChild, "connections").SelectSingleNode("connection[@connection='connection_software01']");
            }

            if (insertAfter == null)
            {
                insertAfter = XMLFunctions.FindChild(shipNode.FirstChild, "connections").SelectSingleNode("connection[@connection='storage']");
            }
            XMLFunctions.FindChild(shipNode.FirstChild, "connections").InsertAfter(connection, insertAfter);

            this.cde         = cde;
            ShipSoftwareNode = connection;
        }
Ejemplo n.º 18
0
        public List <string> GetAllFactions()
        {
            XmlDocument t = new XmlDocument();

            t.LoadXml(Structure.GetFile(new List <string>()
            {
                "libraries"
            }, "factions.xml").GetFileAsString(BasePath));
            List <string> retList = new List <string>();

            foreach (XmlNode node in XMLFunctions.FindChild(t, "factions").ChildNodes)
            {
                if (node.Name == "faction")
                {
                    retList.Add(node.Attributes["id"].Value);
                }
            }

            return(retList);
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Return the node containing requested ressources for construction.
        /// </summary>
        /// <returns></returns>
        public XmlNode GetNeededRessourcesNode()
        {
            XmlNode ressourcesNode = null;

            if (!IsBuildingCV())
            {
                return(ressourcesNode);
            }

            XmlNode childNode = XMLFunctions.FindChild(ShipNode.FirstChild, "connections");

            if (childNode == null)
            {
                Logger.Warning("CV: connections node not found");
                return(ressourcesNode);
            }
            XmlNode buildModuleNode = null;

            foreach (XmlNode connectionNode in childNode.ChildNodes)
            {
                if (connectionNode.Attributes["connection"].Value == "connection_buildmodule01")
                {
                    buildModuleNode = connectionNode;
                    break;
                }
            }
            if (buildModuleNode == null)
            {
                Logger.Warning("CV: no connection_buildmodule01 node found");
                return(ressourcesNode);
            }
            XmlNode buildNode = XMLFunctions.FindChild(buildModuleNode.FirstChild, "build");

            if (buildNode == null)
            {
                Logger.Verbose("CV: no build node found");
                return(ressourcesNode);
            }
            ressourcesNode = buildNode.FirstChild;
            return(ressourcesNode);
        }
Ejemplo n.º 20
0
        public List <string> GetPlayerWeaponConnectionList()
        {
            XmlDocument t = new XmlDocument();

            t.LoadXml(Structure.GetFile(new List <string>()
            {
                "assets", "units", "player", "macros"
            }, "unit_player_ship_macro.xml").GetFileAsString(BasePath));
            XmlNode       weaponSlotNodes = XMLFunctions.FindChild(XMLFunctions.FindChild(XMLFunctions.FindChild(t, "macros").FirstChild, "properties"), "weapons");
            List <string> retList         = new List <string>();

            foreach (XmlNode weaponSlotNode in weaponSlotNodes)
            {
                string refValue = weaponSlotNode.Attributes["ref"].Value;
                if (weaponSlotNode.Attributes["ref"].Value.StartsWith("conn_primaryweapon"))
                {
                    retList.Add(refValue);
                }
            }
            return(retList);
        }
Ejemplo n.º 21
0
        public void SetSkillNode(string skill, ushort value)
        {
            if (value > 5)
            {
                Logger.Warning("Warning value higher than 5. reset to 5.");
                value = 5;
            }

            XmlNode node = GetSkillNode(skill);

            if (node == null)
            {
                node = NPCNode.OwnerDocument.CreateElement("skill");
                XmlAttribute att = NPCNode.OwnerDocument.CreateAttribute("type");
                att.Value = skill;
                node.Attributes.Append(att);
                XMLFunctions.FindChild(NPCNode.ChildNodes[0], "skills").AppendChild(node);
            }

            XMLFunctions.SetSafeAttribute(node, "value", value.ToString());
        }
Ejemplo n.º 22
0
        public ZoneData(XmlNode zoneNode, CatDatExtractor cde)
        {
            try
            {
                this.cde = cde;
                // 1 Zone: <connection connection="tzonecluster_d_sector18_zone45_connection"> -> <component class="zone" macro="tzonecluster_d_sector18_zone45_macro" connection="sector" owner="canteran" knownto="player" id="[0x1c2c5]">
                ZoneNode = zoneNode.FirstChild;
                ZoneName = zoneNode.Attributes["connection"].Value;
                // Some zone does not have any "connections" node.
                if (XMLFunctions.FindChild(ZoneNode, "connections") != null)
                {
                    XmlNode childNode = XMLFunctions.FindChild(ZoneNode, "connections").FirstChild;

                    while (childNode != null)
                    {
                        try
                        {
                            if (childNode.Attributes["connection"].Value == "ships")
                            {
                                Ships.Add(new ShipData(childNode, cde));
                            }
                            else if (childNode.HasChildNodes && childNode.FirstChild.Attributes["class"] != null && childNode.FirstChild.Attributes["class"].Value.StartsWith("ship"))
                            {
                                Ships.Add(new ShipData(childNode, cde));
                            }
                        }
                        catch (Exception ex)
                        {
                            Logger.Error("Unable to add child node for zone", ex);
                        }
                        childNode = childNode.NextSibling;
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Unable to parse zone node", ex);
            }
        }
Ejemplo n.º 23
0
/*
 *      <connection connection="conn_primaryweapon_impuls">
 * <component class="playerweapon" macro="weapon_player_impulse_mk1_macro" connection="shipconnection" lastshottime="0" ammunition="-1" targetseen="0" id="[0xc68]">
 * <offset>
 * <position x="-3.294" y="-0.1191" z="-2.88" />
 * </offset>
 * <shootcontroller class="playerprimary" shooter="[0xc68]" starttime="118.091" angle="0.0872665" />
 * <connections />
 * </component>
 * </connection>
 */

        public ShipWeaponData(string macro, string connection, XmlNode shipNode, CatDatExtractor cde)
        {
            this.cde = cde;

            ShipWeaponNode = shipNode.OwnerDocument.CreateElement("connection");
            XmlAttribute shipWeaponNodeAtt = shipNode.OwnerDocument.CreateAttribute("connection");

            shipWeaponNodeAtt.Value = connection;
            ShipWeaponNode.Attributes.Append(shipWeaponNodeAtt);
            XmlNode      comp      = shipNode.OwnerDocument.CreateElement("component");
            XmlAttribute compClass = shipNode.OwnerDocument.CreateAttribute("class");

            compClass.Value = "playerweapon";
            comp.Attributes.Append(compClass);
            XmlAttribute compMacro = shipNode.OwnerDocument.CreateAttribute("macro");

            compMacro.Value = macro;
            comp.Attributes.Append(compMacro);
            XmlAttribute compConn = shipNode.OwnerDocument.CreateAttribute("connection");

            if (connection.Contains("beam"))
            {
                compConn.Value = "shipconnection01";
            }
            else
            {
                compConn.Value = "shipconnection";
            }
            comp.Attributes.Append(compConn);
            XmlAttribute compLastShot = shipNode.OwnerDocument.CreateAttribute("lastshottime");

            compLastShot.Value = "0";
            comp.Attributes.Append(compLastShot);
            XmlAttribute compAmm = shipNode.OwnerDocument.CreateAttribute("ammunition");

            compAmm.Value = "-1";
            comp.Attributes.Append(compAmm);
            XmlAttribute compTar = shipNode.OwnerDocument.CreateAttribute("targetseen");

            compTar.Value = "0";
            comp.Attributes.Append(compTar);
            XmlAttribute compId  = shipNode.OwnerDocument.CreateAttribute("id");
            string       shooter = XMLFunctions.DetermineNewId(shipNode.OwnerDocument);

            compId.Value = shooter;
            comp.Attributes.Append(compId);
            comp.AppendChild(shipNode.OwnerDocument.ImportNode(cde.GetPlayerConnectionOffset(connection), true));
            XmlNode      shoot      = shipNode.OwnerDocument.CreateElement("shootcontroller");
            XmlAttribute shootClass = shipNode.OwnerDocument.CreateAttribute("class");

            shootClass.Value = "playerprimary";
            shoot.Attributes.Append(shootClass);
            XmlAttribute shootShoot = shipNode.OwnerDocument.CreateAttribute("shooter");

            shootShoot.Value = shooter;
            shoot.Attributes.Append(shootShoot);
            XmlAttribute shootST = shipNode.OwnerDocument.CreateAttribute("starttime");

            shootST.Value = "1";
            shoot.Attributes.Append(shootST);
            XmlAttribute shootAngle = shipNode.OwnerDocument.CreateAttribute("angle");

            shootAngle.Value = "0.0872665";
            shoot.Attributes.Append(shootAngle);
            comp.AppendChild(shoot);
            XmlNode connections = shipNode.OwnerDocument.CreateElement("connections");

            comp.AppendChild(connections);
            ShipWeaponNode.AppendChild(comp);
            XMLFunctions.FindChild(shipNode.FirstChild, "connections").InsertAfter(ShipWeaponNode, XMLFunctions.FindChild(shipNode.FirstChild, "connections").SelectSingleNode("connection[@connection='primaryship']"));
        }
Ejemplo n.º 24
0
        public void AddAmmunition(string macro, string value)
        {
            try
            {
                if (string.IsNullOrEmpty(macro))
                {
                    throw new Exception("macro must contain a value");
                }

                if (string.IsNullOrEmpty(value))
                {
                    throw new Exception("value must contain a value");
                }

                try
                {
                    Convert.ToInt64(value);
                }
                catch (Exception ex)
                {
                    throw new Exception("value must contain a valid integer value", ex);
                }

                XmlNode childNode   = XMLFunctions.FindChild(ShipNode.FirstChild, "ammunition");
                XmlNode newAmmoNode = null;

                if (childNode == null)
                {
                    XmlNode previousChildNode = XMLFunctions.FindChild(ShipNode.FirstChild, "shields");
                    childNode = ShipNode.OwnerDocument.CreateElement("ammunition");
                    childNode.AppendChild(ShipNode.OwnerDocument.CreateElement("available"));
                    ShipNode.FirstChild.InsertAfter(childNode, previousChildNode);
                }

                childNode = childNode.FirstChild;

                try
                {
                    newAmmoNode = childNode.OwnerDocument.CreateNode(XmlNodeType.Element, "item", "");
                    newAmmoNode.Attributes.Append(childNode.OwnerDocument.CreateAttribute("macro"));
                    newAmmoNode.Attributes.Append(childNode.OwnerDocument.CreateAttribute("amount"));
                    newAmmoNode.Attributes["macro"].Value  = macro;
                    newAmmoNode.Attributes["amount"].Value = value;
                }
                catch (Exception ex)
                {
                    throw new Exception("Unable to create the new inventory node", ex);
                }

                try
                {
                    childNode.AppendChild(newAmmoNode);
                    Ammunition.Add(new ShipAmmunitionItemData(newAmmoNode, cde));
                }
                catch (Exception ex)
                {
                    throw new Exception("Unable to add the new inventory node", ex);
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Unable to add new player inventory item", ex);
            }
        }
Ejemplo n.º 25
0
        public ShipData(XmlNode shipNode, CatDatExtractor cde)
        {
            try
            {
                this.cde = cde;
                ShipNode = shipNode;

                XmlNode childNode = null;
                //<shields> ???

                // Storages
                XmlNode storage = null;
                storage = shipNode.SelectSingleNode(".//connection[@connection='connection_storage01']");
                if (storage != null)
                {
                    ShipStorage.Add(1, new ShipStorageData(storage, cde));
                }

                storage = null;
                storage = shipNode.SelectSingleNode(".//connection[@connection='connection_storage02']");
                if (storage != null)
                {
                    ShipStorage.Add(2, new ShipStorageData(storage, cde));
                }

                storage = null;
                storage = shipNode.SelectSingleNode(".//connection[@connection='connection_storage03']");
                if (storage != null)
                {
                    ShipStorage.Add(3, new ShipStorageData(storage, cde));
                }

                storage = null;
                storage = shipNode.SelectSingleNode(".//connection[@connection='connection_storage04']");
                if (storage != null)
                {
                    ShipStorage.Add(4, new ShipStorageData(storage, cde));
                }

                storage = null;
                storage = shipNode.SelectSingleNode(".//connection[@connection='connection_storage05']");
                if (storage != null)
                {
                    ShipStorage.Add(5, new ShipStorageData(storage, cde));
                }


                #region Skunk
                if (IsSkunk()) // Some prats should only be handled for skunk at the moment
                {
                    try
                    {
                        //<weaponcycle>
                        childNode = XMLFunctions.FindChild(ShipNode.FirstChild, "weaponcycle");

                        if (childNode != null)
                        {
                            childNode = childNode.FirstChild;

                            while (childNode != null)
                            {
                                try
                                {
                                    WeaponCycleSlot.Add(new ShipWeaponCycleSlotData(childNode, cde));
                                }
                                catch (Exception ex)
                                {
                                    Logger.Error("Unable to add weaponcycle.", ex);
                                }
                                childNode = childNode.NextSibling;
                            }
                        }
                        else
                        {
                            throw new Exception("weaponcycle child node not found.");
                        }
                    }
                    catch (Exception ex)
                    {
                        Logger.Error("Unable to parse weaponcycle.", ex);
                    }

                    try
                    {
                        //<connections>
                        childNode = XMLFunctions.FindChild(ShipNode.FirstChild, "connections");

                        if (childNode != null)
                        {
                            childNode = childNode.FirstChild;

                            while (childNode != null)
                            {
                                try
                                {
                                    if (childNode.Attributes["connection"].Value == "connection_software01" ||
                                        childNode.Attributes["connection"].Value == "connection_software02" ||
                                        childNode.Attributes["connection"].Value == "connection_software03" ||//Just in case
                                        childNode.Attributes["connection"].Value == "connection_software04"   //Just in case
                                        )
                                    {
                                        InstalledSoftware.Add(new ShipSoftwareData(childNode, cde));
                                    }
                                    else if (childNode.Attributes["connection"].Value == "scannerconnection")
                                    {
                                        InstalledScanner = new ShipScannerData(childNode, cde);
                                    }
                                    else if (childNode.Attributes["connection"].Value == "shields" ||
                                             childNode.Attributes["connection"].Value == "shieldgenerators"
                                             )
                                    {// I need it!
                                        InstalledShields.Add(new ShipShieldData(childNode, cde));
                                    }
                                    else if (childNode.Attributes["connection"].Value == "engine_r" ||
                                             childNode.Attributes["connection"].Value == "engine_l"
                                             )
                                    {// I need it!
                                        InstalledEngines.Add(new ShipEngineData(childNode, cde));
                                    }
                                    else if (childNode.Attributes["connection"].Value == "conn_primaryweapon_shotgun" ||
                                             childNode.Attributes["connection"].Value == "conn_primaryweapon_impuls" ||
                                             childNode.Attributes["connection"].Value == "conn_primaryweapon_beam" ||
                                             childNode.Attributes["connection"].Value == "conn_primaryweapon_plasma" ||
                                             childNode.Attributes["connection"].Value == "conn_primaryweapon_mg"
                                             )
                                    {// I need it!
                                        InstalledWeapons.Add(new ShipWeaponData(childNode, cde));
                                    }
                                    else if (childNode.Attributes["connection"].Value == "cockpit")
                                    {// I need it!
                                        ShipCockpit = new ShipCockpitData(childNode, cde);
                                    }
                                    else if (childNode.Attributes["connection"].Value == "connection_radar01")
                                    {// Do I need it?
                                    }
                                    else if (childNode.Attributes["connection"].Value == "connection_dock_s01")
                                    {// Do I need it?
                                    }
                                    else if (childNode.Attributes["connection"].Value == "tagweaponconnection01")
                                    {// Do I need it?
                                    }
                                    else if (childNode.Attributes["connection"].Value == "weaponconnection4")
                                    {// Do I need it?
                                    }
                                    else if (childNode.Attributes["connection"].Value == "weaponconnection3")
                                    {// Do I need it?
                                    }
                                }
                                catch (Exception ex)
                                {
                                    Logger.Error("Unable to add this ship conection", ex);
                                }

                                childNode = childNode.NextSibling;
                            }
                        }
                        else
                        {
                            throw new Exception("connections child node not found.");
                        }
                    }
                    catch (Exception ex)
                    {
                        Logger.Error("Unable to parse connections.", ex);
                    }
                }
                #endregion
            }
            catch (Exception ex)
            {
                throw new Exception("Unable to parse ship.", ex);
            }
        }
 public void AddFaction(string faction)
 {
     XMLFunctions.SetSafeAttribute(LicenseNode, "factions", XMLFunctions.GetSafeAttribute(LicenseNode, "factions") + " " + faction);
 }
        public void CalculationRegressionAdd(string InputXML, string OutputXML, string CalcReference, string Scheme, string CalcType, Boolean Run)
        {
            CalculationRegression CalcRegression = new CalculationRegression();

            string OldOutput = "";
            int resultid = 0;
            using (var context = new CalculationDBContext())
            {
                var Regression = context.CalculationRegression
                .Where(b => b.Reference == CalcReference && b.Scheme == Scheme && b.Type == CalcType)
                .FirstOrDefault();

                if (Regression == null)
                {
                    resultid = 0;
                }
                else
                {
                    OldOutput = Regression.OutputOld;
                    resultid = Regression.Id;
                }

            }

            if (Run == true)
            {
                XMLFunctions XMLFunction = new XMLFunctions();

                string Difference = XMLFunction.MatchXML(OldOutput, OutputXML);
                CalcRegression.OutputNew = OutputXML;
                CalcRegression.LatestRunDate = DateTime.Now;
                CalcRegression.Difference = Difference;

                if (Difference == null)
                {
                    CalcRegression.Pass = "******";
                }
                else
                {
                    CalcRegression.Pass = "******";
                }
            }
            else
            {
                CalcRegression.Scheme = Scheme;
                CalcRegression.Type = CalcType;
                CalcRegression.Input = InputXML;
                CalcRegression.OutputOld = OutputXML;
                CalcRegression.Reference = CalcReference;
                CalcRegression.OriginalRunDate = DateTime.Now;
                CalcRegression.LatestRunDate = DateTime.Now;
            }

            if (resultid > 0)
            {
                CalcRegression.Id = resultid;
                EditCalcRegression(CalcRegression, Run);
            }
            else
            {
                CreateCalcRegression(CalcRegression);
            }
        }
    public void XMLToExcel(string xmlFilePath)
    {
        var dt = XMLFunctions.CreateDataTableFromXmlFile(xmlFilePath);

        AddDataTableToExcel(dt);
    }
Ejemplo n.º 29
0
        public void AddToPlayerInventory(string ware, string amount)
        {
            try
            {
                if (string.IsNullOrEmpty(ware))
                {
                    throw new Exception("ware must contain a value");
                }

                if (string.IsNullOrEmpty(amount))
                {
                    throw new Exception("amount must contain a value");
                }

                try
                {
                    Convert.ToInt64(amount);
                }
                catch (Exception ex)
                {
                    throw new Exception("amount must contain a valid integer value", ex);
                }

                XmlNode childNode        = XMLFunctions.FindChild(PlayerNode.FirstChild, "inventory");
                XmlNode newInventoryNode = null;

                if (childNode == null)
                {
                    XmlNode previousChildNode = XMLFunctions.FindChild(PlayerNode.FirstChild, "account");
                    childNode = PlayerNode.OwnerDocument.CreateElement("inventory");
                    PlayerNode.FirstChild.InsertAfter(childNode, previousChildNode);
                    //throw new Exception("Unable to locate inventory node");
                }

                try
                {
                    newInventoryNode = childNode.OwnerDocument.CreateNode(XmlNodeType.Element, "ware", "");
                    newInventoryNode.Attributes.Append(childNode.OwnerDocument.CreateAttribute("ware"));
                    newInventoryNode.Attributes.Append(childNode.OwnerDocument.CreateAttribute("amount"));
                    newInventoryNode.Attributes["ware"].Value   = ware;
                    newInventoryNode.Attributes["amount"].Value = amount;
                }
                catch (Exception ex)
                {
                    throw new Exception("Unable to create the new inventory node", ex);
                }

                try
                {
                    childNode.AppendChild(newInventoryNode);
                    PlayerInventory.Add(new ShipInventoryItemData(newInventoryNode, cde));
                }
                catch (Exception ex)
                {
                    throw new Exception("Unable to add the new inventory node", ex);
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Unable to add new player inventory item", ex);
            }
        }
Ejemplo n.º 30
0
        public ClusterData(XmlNode clusterNode, CatDatExtractor cde)
        {
            // 1 Cluster: <connection connection="cluster_b_connection"> -> <component class="cluster" macro="cluster_b_macro" connection="galaxy" knownto="player" id="[0x1712f]">
            try
            {
                ClusterNode = clusterNode.FirstChild;
                ClusterName = clusterNode.Attributes["connection"].Value;

                XmlNode childNode = XMLFunctions.FindChild(ClusterNode, "connections").FirstChild;

                while (childNode != null)
                {
                    try
                    {
                        if (childNode.FirstChild == null)
                        {
                            Logger.Info("Cluster child does not have child. No parse needed");
                        }
                        else if (childNode.FirstChild.Attributes["class"] == null)
                        {
                            Logger.Info("Cluster child does not have a class. No parse needed");
                        }
                        else if (childNode.FirstChild.Attributes["class"].Value == null)
                        {
                            Logger.Info("Cluster child class does not have a value. No parse needed");
                        }
                        else if (childNode.FirstChild.Attributes["class"].Value.ToLower() == "region")
                        {
                            Regions.Add(new RegionData(childNode, cde));
                        }
                        else if (childNode.FirstChild.Attributes["class"].Value.ToLower() == "sector")
                        {
                            Sectors.Add(new SectorData(childNode, cde));
                        }
                        else if (childNode.FirstChild.Attributes["class"].Value.ToLower() == "celestialbody")
                        {
                            Celestialbodys.Add(new CelestialbodyData(childNode, cde));
                        }
                        else if (childNode.FirstChild.Attributes["class"].Value.ToLower() == "highway")
                        {
                            Highways.Add(new HighwayData(childNode, cde));
                        }
                        else
                        {
                            Logger.Warning("Not a handled cluster child node type.");
                        }
                    }
                    catch (Exception ex)
                    {
                        Logger.Error("Unable to add cluster child node type.", ex);
                    }

                    childNode = childNode.NextSibling;
                }
                this.cde = cde;
            }
            catch (Exception ex)
            {
                throw new Exception("Unable to get ClusterNode data.", ex);
            }
        }
Ejemplo n.º 31
0
        public PlayerData(XmlNode playerNode, CatDatExtractor cde)
        {
            PlayerNode = playerNode;
            XmlNode childNode = null;

            this.cde = cde;

            try
            {
                childNode = XMLFunctions.FindChild(PlayerNode.FirstChild, "inventory").FirstChild;

                while (childNode != null)
                {
                    try
                    {
                        PlayerInventory.Add(new ShipInventoryItemData(childNode, cde));
                    }
                    catch (Exception ex)
                    {
                        Logger.Error("Unable to add player inventory item.", ex);
                    }
                    childNode = childNode.NextSibling;
                }
            }
            catch (Exception ex)
            {
                Logger.Error("Unable to parse inventory", ex);
            }

            try
            {
                childNode = XMLFunctions.FindChild(PlayerNode.FirstChild, "known").FirstChild;

                while (childNode != null)
                {
                    try
                    {
                        List <string> ids          = new List <string>();
                        XmlNode       childSubNode = childNode.FirstChild;
                        XmlAttribute  att          = childNode.Attributes["type"];
                        if (att == null)
                        {
                            Logger.Warning("The entry in the known list does not have a type.");
                        }
                        else
                        {
                            while (childSubNode != null)
                            {
                                try
                                {
                                    ids.Add(childSubNode.Attributes["id"].Value);
                                }
                                catch (Exception ex)
                                {
                                    Logger.Error("Unable to create known list item", ex);
                                }
                                childSubNode = childSubNode.NextSibling;
                            }
                            PlayerKnown.Add(childNode.Attributes["type"].Value, ids);
                        }
                    }
                    catch (Exception ex)
                    {
                        Logger.Error("Unable to create known list", ex);
                    }
                    childNode = childNode.NextSibling;
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Unable to parse known. This is a fatal error.", ex);
            }
        }