示例#1
0
        public SystemClass(string Name, int xi, int yi, int zi, long edsmid,
                           long eddbid, int eddbupdateat, long population, string faction,
                           EDGovernment g, EDAllegiance a, EDState s, EDSecurity security,
                           EDEconomy eco, string power, string powerstate, int needspermit,
                           int gridid = -1, SystemStatusEnum statusv = SystemStatusEnum.Unknown)
        {
            base.Name = Name;
            Xi        = xi; Yi = yi; Zi = zi;
            EDSMID    = edsmid;
            GridID    = gridid == -1 ? EliteDangerousCore.DB.GridId.Id(xi, zi) : gridid;

            EDDBID         = eddbid;
            Population     = population;
            Faction        = faction;
            Government     = g;
            Allegiance     = a;
            State          = s;
            Security       = security;
            PrimaryEconomy = eco;
            Power          = power;
            PowerState     = powerstate;
            NeedsPermit    = needspermit;
            EDDBUpdatedAt  = eddbupdateat;
            status         = statusv;
        }
示例#2
0
 public SystemClass(SystemSource statusv, string name, int xi, int yi, int zi, long edsmid,
                    long population, string faction,
                    EDGovernment g, EDAllegiance a, EDState s, EDSecurity security,
                    EDEconomy eco, string power, string powerstate, int needspermit,
                    int gridid = -1) : base(name, xi, yi, zi, edsmid, gridid)
 {
     Population     = population;
     Faction        = faction;
     Government     = g;
     Allegiance     = a;
     State          = s;
     Security       = security;
     PrimaryEconomy = eco;
     Power          = power;
     PowerState     = powerstate;
     NeedsPermit    = needspermit;
     source         = statusv;
 }
示例#3
0
 public SystemClass(string name, int xi, int yi, int zi, long edsmid,
                    long eddbid, int eddbupdateat, long population, string faction,
                    EDGovernment g, EDAllegiance a, EDState s, EDSecurity security,
                    EDEconomy eco, string power, string powerstate, int needspermit,
                    int gridid = -1, SystemStatusEnum statusv = SystemStatusEnum.Unknown) : base(name, xi, yi, zi, edsmid, gridid)
 {
     EDDBID         = eddbid;
     Population     = population;
     Faction        = faction;
     Government     = g;
     Allegiance     = a;
     State          = s;
     Security       = security;
     PrimaryEconomy = eco;
     Power          = power;
     PowerState     = powerstate;
     NeedsPermit    = needspermit;
     EDDBUpdatedAt  = eddbupdateat;
     status         = statusv;
 }
示例#4
0
        public StationClass(JObject jo, SystemInfoSource source)
        {
            if (source == SystemInfoSource.EDDB)
            {
                name = jo["name"].Value<string>();
                SearchName = name.ToLower();

                eddb_id = jo["id"].Value<int>();
                system_id = jo["system_id"].Value<int>();

                if (jo["max_landing_pad_size"].Type == JTokenType.String)
                    max_landing_pad_size = jo["max_landing_pad_size"].Value<string>();

                if (jo["distance_to_star"].Type == JTokenType.Integer)
                    distance_to_star = jo["distance_to_star"].Value<int>();

                faction = jo["faction"].Value<string>();

                government = EliteDangerous.Government2ID(jo["government"]);
                allegiance = EliteDangerous.Allegiance2ID(jo["allegiance"]);

                state = EliteDangerous.EDState2ID(jo["state"]);

                stationtype = EliteDangerous.EDStationType2ID(jo["type"]);

                if (jo["has_blackmarket"].Type == JTokenType.Integer)
                    has_blackmarket = jo["has_blackmarket"].Value<int>();
                else
                    has_blackmarket = -1;

                if (jo["has_commodities"].Type == JTokenType.Integer)
                    has_commodities = jo["has_commodities"].Value<int>();
                else
                    has_commodities = -1;

                if (jo["has_refuel"].Type == JTokenType.Integer)
                    has_refuel = jo["has_refuel"].Value<int>();
                else
                    has_refuel = -1;

                if (jo["has_repair"].Type == JTokenType.Integer)
                    has_repair = jo["has_repair"].Value<int>();
                else
                    has_repair = -1;

                if (jo["has_rearm"].Type == JTokenType.Integer)
                    has_rearm = jo["has_rearm"].Value<int>();
                else
                    has_rearm = -1;

                if (jo["has_outfitting"].Type == JTokenType.Integer)
                    has_outfitting = jo["has_outfitting"].Value<int>();
                else
                    has_outfitting = -1;

                if (jo["has_shipyard"].Type == JTokenType.Integer)
                    has_shipyard = jo["has_shipyard"].Value<int>();
                else
                    has_shipyard = -1;

                economies = EliteDangerous.EDEconomies2ID((JArray)jo["economies"]);
                import_commodities = EliteDangerous.EDCommodities2ID((JArray)jo["import_commodities"]);
                export_commodities = EliteDangerous.EDCommodities2ID((JArray)jo["export_commodities"]);
                prohibited_commodities = EliteDangerous.EDCommodities2ID((JArray)jo["prohibited_commodities"]);
                eddb_updated_at = jo["updated_at"].Value<int>();

            }
        }
示例#5
0
        private List <ISystem> GetSystemsByName(string systemName, bool uselike = false)     // Protect yourself against bad JSON
        {
            string query = String.Format("api-v1/systems?systemName={0}&showCoordinates=1&showId=1&showInformation=1&showPermit=1", Uri.EscapeDataString(systemName));

            var response = RequestGet(query, handleException: true);

            if (response.Error)
            {
                return(null);
            }

            var json = response.Body;

            if (json == null)
            {
                return(null);
            }

            JArray msg = JArray.Parse(json);

            List <ISystem> systems = new List <ISystem>();

            if (msg != null)
            {
                foreach (JObject sysname in msg)
                {
                    ISystem sys = new SystemClass();
                    sys.Name   = sysname["name"].Str("Unknown");
                    sys.EDSMID = sysname["id"].Long(0);
                    JObject co = (JObject)sysname["coords"];

                    if (co != null)
                    {
                        sys.X = co["x"].Double();
                        sys.Y = co["y"].Double();
                        sys.Z = co["z"].Double();
                    }

                    sys.NeedsPermit = sysname["requirePermit"].Bool(false) ? 1 : 0;

                    JObject info = sysname["information"] as JObject;

                    if (info != null)
                    {
                        sys.Population = info["population"].Long(0);
                        sys.Faction    = info["faction"].StrNull();
                        EDAllegiance allegiance = EDAllegiance.None;
                        EDGovernment government = EDGovernment.None;
                        EDState      state      = EDState.None;
                        EDEconomy    economy    = EDEconomy.None;
                        EDSecurity   security   = EDSecurity.Unknown;
                        sys.Allegiance     = Enum.TryParse(info["allegiance"].Str(), out allegiance) ? allegiance : EDAllegiance.None;
                        sys.Government     = Enum.TryParse(info["government"].Str(), out government) ? government : EDGovernment.None;
                        sys.State          = Enum.TryParse(info["factionState"].Str(), out state) ? state : EDState.None;
                        sys.PrimaryEconomy = Enum.TryParse(info["economy"].Str(), out economy) ? economy : EDEconomy.None;
                        sys.Security       = Enum.TryParse(info["security"].Str(), out security) ? security : EDSecurity.Unknown;
                    }

                    if (uselike ? sys.Name.StartsWith(systemName, StringComparison.InvariantCultureIgnoreCase) : sys.Name.Equals(systemName, StringComparison.InvariantCultureIgnoreCase))
                    {
                        systems.Add(sys);
                    }
                }
            }

            return(systems);
        }
示例#6
0
        public StationClass(JObject jo, SystemInfoSource source)
        {
            if (source == SystemInfoSource.EDDB)
            {
                name       = jo["name"].Value <string>();
                SearchName = name.ToLower();

                eddb_id   = jo["id"].Value <int>();
                system_id = jo["system_id"].Value <int>();

                if (jo["max_landing_pad_size"].Type == JTokenType.String)
                {
                    max_landing_pad_size = jo["max_landing_pad_size"].Value <string>();
                }

                if (jo["distance_to_star"].Type == JTokenType.Integer)
                {
                    distance_to_star = jo["distance_to_star"].Value <int>();
                }

                faction = jo["faction"].Value <string>();

                government = EliteDangerous.Government2ID(jo["government"]);
                allegiance = EliteDangerous.Allegiance2ID(jo["allegiance"]);

                state = EliteDangerous.EDState2ID(jo["state"]);

                stationtype = EliteDangerous.EDStationType2ID(jo["type"]);

                if (jo["has_blackmarket"].Type == JTokenType.Integer)
                {
                    has_blackmarket = jo["has_blackmarket"].Value <int>();
                }
                else
                {
                    has_blackmarket = -1;
                }

                if (jo["has_commodities"].Type == JTokenType.Integer)
                {
                    has_commodities = jo["has_commodities"].Value <int>();
                }
                else
                {
                    has_commodities = -1;
                }

                if (jo["has_refuel"].Type == JTokenType.Integer)
                {
                    has_refuel = jo["has_refuel"].Value <int>();
                }
                else
                {
                    has_refuel = -1;
                }

                if (jo["has_repair"].Type == JTokenType.Integer)
                {
                    has_repair = jo["has_repair"].Value <int>();
                }
                else
                {
                    has_repair = -1;
                }

                if (jo["has_rearm"].Type == JTokenType.Integer)
                {
                    has_rearm = jo["has_rearm"].Value <int>();
                }
                else
                {
                    has_rearm = -1;
                }

                if (jo["has_outfitting"].Type == JTokenType.Integer)
                {
                    has_outfitting = jo["has_outfitting"].Value <int>();
                }
                else
                {
                    has_outfitting = -1;
                }

                if (jo["has_shipyard"].Type == JTokenType.Integer)
                {
                    has_shipyard = jo["has_shipyard"].Value <int>();
                }
                else
                {
                    has_shipyard = -1;
                }

                economies              = EliteDangerous.EDEconomies2ID((JArray)jo["economies"]);
                import_commodities     = EliteDangerous.EDCommodities2ID((JArray)jo["import_commodities"]);
                export_commodities     = EliteDangerous.EDCommodities2ID((JArray)jo["export_commodities"]);
                prohibited_commodities = EliteDangerous.EDCommodities2ID((JArray)jo["prohibited_commodities"]);
                eddb_updated_at        = jo["updated_at"].Value <int>();
            }
        }
示例#7
0
        //public SystemClass(JObject jo, SystemInfoSource source)
        //{
        //    if (source == SystemInfoSource.RW)
        //    {
        //        try
        //        {
        //            x = jo["x"].Value<double>();
        //            y = jo["y"].Value<double>();
        //            z = jo["z"].Value<double>();

        //            name = jo["name"].Value<string>();
        //            SearchName = name.ToLower();


        //            cr = 1;
        //            status = SystemStatusEnum.RedWizzard;
        //        }
        //        catch
        //        {

        //        }


        //    }
        //    else if (source == SystemInfoSource.EDSC)
        //    {
        //        JArray ja = (JArray)jo["coord"];

        //        name = jo["name"].Value<string>();
        //        SearchName = name.ToLower();

        //        cr = jo["cr"].Value<int>();

        //        if (ja[0].Type == JTokenType.Float || ja[0].Type == JTokenType.Integer)
        //        {
        //            x = ja[0].Value<double>();
        //            y = ja[1].Value<double>();
        //            z = ja[2].Value<double>();
        //        }
        //        else
        //        {
        //            x = double.NaN;
        //            y = double.NaN;
        //            z = double.NaN;
        //        }


        //        CommanderCreate = jo["commandercreate"].Value<string>();
        //        CreateDate = jo["createdate"].Value<DateTime>();
        //        CommanderUpdate = jo["commanderupdate"].Value<string>();
        //        UpdateDate = jo["updatedate"].Value<DateTime>();
        //        status = SystemStatusEnum.EDSC;
        //    }
        //    else if (source == SystemInfoSource.EDSM)
        //    {
        //        JObject coords = (JObject)jo["coords"];

        //        name = jo["name"].Value<string>();
        //        SearchName = name.ToLower();

        //        //cr = jo["cr"].Value<int>();
        //        x = double.NaN;
        //        y = double.NaN;
        //        z = double.NaN;


        //        if (coords !=null &&  (coords["x"].Type == JTokenType.Float || coords["x"].Type == JTokenType.Integer))
        //        {
        //            x = coords["x"].Value<double>();
        //            y = coords["y"].Value<double>();
        //            z = coords["z"].Value<double>();
        //        }
        //        JArray submitted = (JArray)jo["submitted"];

        //        if (submitted.Count>0)
        //        {
        //            if (submitted[0]["cmdrname"]!=null)
        //                CommanderCreate = submitted[0]["cmdrname"].Value<string>();
        //            CreateDate = submitted[0]["date"].Value<DateTime>();

        //            if (submitted[submitted.Count - 1]["cmdrname"] != null)
        //                CommanderUpdate = submitted[submitted.Count-1]["cmdrname"].Value<string>();
        //            UpdateDate = submitted[submitted.Count-1]["date"].Value<DateTime>();

        //        }

        //        UpdateDate = jo["date"].Value<DateTime>();
        //        if (CreateDate.Year <= 1)
        //            CreateDate = UpdateDate;


        //        status = SystemStatusEnum.EDSC;
        //    }
        //    else if (source == SystemInfoSource.EDDB)
        //    {


        //        name = jo["name"].Value<string>();
        //        SearchName = name.ToLower();

        //        cr = 1;

        //        x = jo["x"].Value<double>();
        //        y = jo["y"].Value<double>();
        //        z = jo["z"].Value<double>();

        //        id_eddb = jo["id"].Value<int>();

        //        /*CommanderCreate = jo["commandercreate"].Value<string>();
        //        CreateDate = jo["createdate"].Value<DateTime>();
        //        CommanderUpdate = jo["commanderupdate"].Value<string>();
        //        UpdateDate = jo["updatedate"].Value<DateTime>();*/

        //        faction = jo["faction"].Value<string>();

        //        if (jo["population"].Type == JTokenType.Integer)
        //            population = jo["population"].Value<long>();


        //        government = EliteDangerous.Government2ID(jo["government"]);
        //        allegiance = EliteDangerous.Allegiance2ID(jo["allegiance"]);

        //        state = EliteDangerous.EDState2ID(jo["state"]);
        //        security = EliteDangerous.EDSecurity2ID(jo["security"]);



        //        primary_economy = EliteDangerous.EDEconomy2ID(jo["primary_economy"]);


        //        if (jo["needs_permit"].Type == JTokenType.Integer)
        //            needs_permit = jo["needs_permit"].Value<int>();

        //        eddb_updated_at = jo["updated_at"].Value<int>();

        //        status = SystemStatusEnum.EDDB;
        //    }



        //}



        public SystemClass(DataRow dr)
        {
            try
            {
                Object o;

                id   = (int)(long)dr["id"];
                name = (string)dr["name"];



                SearchName = name.ToLower();


                cr = (int)(long)dr["cr"];

                if (System.DBNull.Value == dr["x"])
                {
                    x = double.NaN;
                    y = double.NaN;
                    z = double.NaN;
                }
                else
                {
                    x = (double)dr["x"];
                    y = (double)dr["y"];
                    z = (double)dr["z"];
                    CommanderCreate = dr["commandercreate"].ToString();
                    if (CommanderCreate.Length > 0)
                    {
                        CreateDate = (DateTime)dr["createdate"];
                    }
                    else
                    {
                        CreateDate = new DateTime(1980, 1, 1);
                    }

                    CommanderUpdate = (string)dr["commanderupdate"].ToString();
                    if (CommanderUpdate.Length > 0)
                    {
                        UpdateDate = (DateTime)dr["updatedate"];
                    }
                    else
                    {
                        UpdateDate = new DateTime(1980, 1, 1);
                    }
                }

                status = (SystemStatusEnum)((long)dr["status"]);
                Note   = dr["Note"].ToString();

                o       = dr["id_eddb"];
                id_eddb = o == DBNull.Value ? 0 : (int)((long)o);

                o       = dr["faction"];
                faction = o == DBNull.Value ? null : (string)o;

                o          = dr["government_id"];
                government = o == DBNull.Value ? EDGovernment.Unknown : (EDGovernment)((long)o);

                o          = dr["allegiance_id"];
                allegiance = o == DBNull.Value ? EDAllegiance.Unknown : (EDAllegiance)((long)o);

                o = dr["primary_economy_id"];
                primary_economy = o == DBNull.Value ? EDEconomy.Unknown : (EDEconomy)((long)o);

                o        = dr["security"];
                security = o == DBNull.Value ? EDSecurity.Unknown : (EDSecurity)((long)o);

                o = dr["eddb_updated_at"];
                eddb_updated_at = o == DBNull.Value ? 0 : (int)((long)o);

                o     = dr["state"];
                state = o == DBNull.Value ? EDState.Unknown : (EDState)((long)o);

                o            = dr["needs_permit"];
                needs_permit = o == DBNull.Value ? 0 : (int)((long)o);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine("Exception SystemClass: " + ex.Message);
                System.Diagnostics.Trace.WriteLine("Trace: " + ex.StackTrace);
            }
        }
        public SystemClass(JObject jo, SystemInfoSource source)
        {
            if (source == SystemInfoSource.RW)
            {
                try
                {
                    x = jo["x"].Value<double>();
                    y = jo["y"].Value<double>();
                    z = jo["z"].Value<double>();

                    name = jo["name"].Value<string>();
                    SearchName = name.ToLower();

                    cr = 1;
                    status = SystemStatusEnum.RedWizzard;
                }
                catch
                {

                }

            }
            else if (source == SystemInfoSource.EDSC)
            {
                JArray ja = (JArray)jo["coord"];

                name = jo["name"].Value<string>();
                SearchName = name.ToLower();

                cr = jo["cr"].Value<int>();

                if (ja[0].Type == JTokenType.Float || ja[0].Type == JTokenType.Integer)
                {
                    x = ja[0].Value<double>();
                    y = ja[1].Value<double>();
                    z = ja[2].Value<double>();
                }
                else
                {
                    x = double.NaN;
                    y = double.NaN;
                    z = double.NaN;
                }

                CommanderCreate = jo["commandercreate"].Value<string>();
                CreateDate = jo["createdate"].Value<DateTime>();
                CommanderUpdate = jo["commanderupdate"].Value<string>();
                UpdateDate = jo["updatedate"].Value<DateTime>();
                status = SystemStatusEnum.EDSC;
            }
            else if (source == SystemInfoSource.EDSM)
            {
                JObject coords = (JObject)jo["coords"];

                name = jo["name"].Value<string>();
                SearchName = name.ToLower();

                //cr = jo["cr"].Value<int>();
                x = double.NaN;
                y = double.NaN;
                z = double.NaN;

                if (coords !=null &&  (coords["x"].Type == JTokenType.Float || coords["x"].Type == JTokenType.Integer))
                {
                    x = coords["x"].Value<double>();
                    y = coords["y"].Value<double>();
                    z = coords["z"].Value<double>();
                }
                JArray submitted = (JArray)jo["submitted"];

                if (submitted.Count>0)
                {
                    if (submitted[0]["cmdrname"]!=null)
                        CommanderCreate = submitted[0]["cmdrname"].Value<string>();
                    CreateDate = submitted[0]["date"].Value<DateTime>();

                    if (submitted[submitted.Count - 1]["cmdrname"] != null)
                        CommanderUpdate = submitted[submitted.Count-1]["cmdrname"].Value<string>();
                    UpdateDate = submitted[submitted.Count-1]["date"].Value<DateTime>();

                }
                status = SystemStatusEnum.EDSC;
            }
            else if (source == SystemInfoSource.EDDB)
            {

                name = jo["name"].Value<string>();
                SearchName = name.ToLower();

                cr = 1;

                x = jo["x"].Value<double>();
                y = jo["y"].Value<double>();
                z = jo["z"].Value<double>();

                id_eddb = jo["id"].Value<int>();

                /*CommanderCreate = jo["commandercreate"].Value<string>();
                CreateDate = jo["createdate"].Value<DateTime>();
                CommanderUpdate = jo["commanderupdate"].Value<string>();
                UpdateDate = jo["updatedate"].Value<DateTime>();*/

                faction = jo["faction"].Value<string>();

                if (jo["population"].Type == JTokenType.Integer)
                    population = jo["population"].Value<long>();

                government = EliteDangerous.Government2ID(jo["government"]);
                allegiance = EliteDangerous.Allegiance2ID(jo["allegiance"]);

                state = EliteDangerous.EDState2ID(jo["state"]);
                security = EliteDangerous.EDSecurity2ID(jo["security"]);

                primary_economy = EliteDangerous.EDEconomy2ID(jo["primary_economy"]);

                if (jo["needs_permit"].Type == JTokenType.Integer)
                    needs_permit = jo["needs_permit"].Value<int>();

                eddb_updated_at = jo["updated_at"].Value<int>();

                status = SystemStatusEnum.EDDB;
            }
        }
        public SystemClass(DataRow dr)
        {
            try
            {
                Object o;

                id = (int)(long)dr["id"];
                name = (string)dr["name"];

                SearchName = name.ToLower();

                cr = (int)(long)dr["cr"];

                if (System.DBNull.Value == dr["x"])
                {
                    x = double.NaN;
                    y = double.NaN;
                    z = double.NaN;

                }
                else
                {
                    x = (double)dr["x"];
                    y = (double)dr["y"];
                    z = (double)dr["z"];
                    CommanderCreate = dr["commandercreate"].ToString();
                    if (CommanderCreate.Length > 0)
                        CreateDate = (DateTime)dr["createdate"];
                    else
                        CreateDate = new DateTime(1980, 1, 1);

                    CommanderUpdate = (string)dr["commanderupdate"].ToString();
                    if (CommanderUpdate.Length > 0)
                        UpdateDate = (DateTime)dr["updatedate"];
                    else
                        UpdateDate = new DateTime(1980, 1, 1);

                }

                status = (SystemStatusEnum)((long)dr["status"]);
                Note = dr["Note"].ToString();

                o = dr["id_eddb"];
                id_eddb = o == DBNull.Value ? 0 : (int)((long)o);

                o = dr["faction"];
                faction = o == DBNull.Value ? null : (string)o;

                o = dr["government_id"];
                government = o == DBNull.Value ? EDGovernment.Unknown : (EDGovernment)((long)o);

                o = dr["allegiance_id"];
                allegiance = o == DBNull.Value ? EDAllegiance.Unknown : (EDAllegiance)((long)o);

                o = dr["primary_economy_id"];
                primary_economy = o == DBNull.Value ? EDEconomy.Unknown : (EDEconomy)((long)o);

                o = dr["security"];
                security = o == DBNull.Value ? EDSecurity.Unknown : (EDSecurity)((long)o);

                o = dr["eddb_updated_at"];
                eddb_updated_at = o == DBNull.Value ? 0 : (int)((long)o);

                o = dr["state"];
                state = o == DBNull.Value ? EDState.Unknown : (EDState)((long)o);

                o = dr["needs_permit"];
                needs_permit = o == DBNull.Value ? 0 : (int)((long)o);

            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine("Exception SystemClass: " + ex.Message);
                System.Diagnostics.Trace.WriteLine("Trace: " + ex.StackTrace);

            }
        }
        public static long ParseEDDBJSON(TextReader tr, Func <bool> cancelRequested)
        {
            long updated = 0;

            bool eof = false;

            while (!eof)
            {
                SystemsDatabase.Instance.ExecuteWithDatabase(usetxnlock: true, mode: SQLExtConnection.AccessMode.Writer, action: db =>
                {
                    var cn = db.Connection;

                    using (DbTransaction txn = cn.BeginTransaction())
                    {
                        DbCommand selectCmd  = null;
                        DbCommand replaceCmd = null;

                        try
                        {
                            selectCmd = cn.CreateSelect("EDDB", "eddbupdatedat", "edsmid = @edsmid", inparas: new string[] { "edsmid:int64" }, limit: "1", tx: txn);   // 1 return matching ID

                            string[] dbfields = { "edsmid",     "eddbid",         "eddbupdatedat", "population",
                                                  "faction",    "government",     "allegiance",    "state",
                                                  "security",   "primaryeconomy", "needspermit",   "power",
                                                  "powerstate", "properties" };
                            DbType[] dbfieldtypes = { DbType.Int64,  DbType.Int64, DbType.Int64, DbType.Int64,
                                                      DbType.String, DbType.Int64, DbType.Int64, DbType.Int64,
                                                      DbType.Int64,  DbType.Int64, DbType.Int64, DbType.String,
                                                      DbType.String, DbType.String };

                            replaceCmd = cn.CreateReplace("EDDB", dbfields, dbfieldtypes, txn);

                            while (!SQLiteConnectionSystem.IsReadWaiting)
                            {
                                string line = tr.ReadLine();

                                if (line == null)  // End of stream
                                {
                                    eof = true;
                                    break;
                                }

                                try
                                {
                                    JObject jo           = JObject.Parse(line);
                                    long jsonupdatedat   = jo["updated_at"].Int();
                                    long jsonedsmid      = jo["edsm_id"].Long();
                                    bool jsonispopulated = jo["is_populated"].Bool();

                                    if (jsonispopulated)        // double check that the flag is set - population itself may be zero, for some systems, but its the flag we care about
                                    {
                                        selectCmd.Parameters[0].Value = jsonedsmid;
                                        long dbupdated_at             = selectCmd.ExecuteScalar <long>(0);

                                        if (dbupdated_at == 0 || jsonupdatedat != dbupdated_at)
                                        {
                                            replaceCmd.Parameters["@edsmid"].Value        = jsonedsmid;
                                            replaceCmd.Parameters["@eddbid"].Value        = jo["id"].Long();
                                            replaceCmd.Parameters["@eddbupdatedat"].Value = jsonupdatedat;
                                            replaceCmd.Parameters["@population"].Value    = jo["population"].Long();
                                            replaceCmd.Parameters["@faction"].Value       = jo["controlling_minor_faction"].Str("Unknown");
                                            replaceCmd.Parameters["@government"].Value    = EliteDangerousTypesFromJSON.Government2ID(jo["government"].Str("Unknown"));
                                            replaceCmd.Parameters["@allegiance"].Value    = EliteDangerousTypesFromJSON.Allegiance2ID(jo["allegiance"].Str("Unknown"));

                                            EDState edstate = EDState.Unknown;

                                            try
                                            {
                                                if (jo["states"] != null && jo["states"].HasValues)
                                                {
                                                    JToken tk       = jo["states"].First; // we take the first one whatever
                                                    JObject jostate = (JObject)tk;
                                                    edstate         = EliteDangerousTypesFromJSON.EDState2ID(jostate["name"].Str("Unknown"));
                                                }
                                            }
                                            catch (Exception ex)
                                            {
                                                System.Diagnostics.Debug.WriteLine("EDDB JSON file exception for states " + ex.ToString());
                                            }

                                            replaceCmd.Parameters["@state"].Value          = edstate;
                                            replaceCmd.Parameters["@security"].Value       = EliteDangerousTypesFromJSON.EDSecurity2ID(jo["security"].Str("Unknown"));
                                            replaceCmd.Parameters["@primaryeconomy"].Value = EliteDangerousTypesFromJSON.EDEconomy2ID(jo["primary_economy"].Str("Unknown"));
                                            replaceCmd.Parameters["@needspermit"].Value    = jo["needs_permit"].Int(0);
                                            replaceCmd.Parameters["@power"].Value          = jo["power"].Str("None");
                                            replaceCmd.Parameters["@powerstate"].Value     = jo["power_state"].Str("N/A");
                                            replaceCmd.Parameters["@properties"].Value     = RemoveFieldsFromJSON(jo);
                                            replaceCmd.ExecuteNonQuery();
                                            updated++;
                                        }
                                    }
                                }
                                catch (Exception ex)
                                {
                                    System.Diagnostics.Debug.WriteLine("EDDB JSON file exception " + ex.ToString());
                                }
                            }

                            txn.Commit();
                        }
                        finally
                        {
                            if (selectCmd != null)
                            {
                                selectCmd.Dispose();
                            }

                            if (replaceCmd != null)
                            {
                                replaceCmd.Dispose();
                            }
                        }
                    }
                });
            }

            return(updated);
        }
示例#11
0
        public SystemClass(JObject jo, SystemInfoSource source)
        {
            if (source == SystemInfoSource.RW)
            {
                try
                {
                    x = jo["x"].Value <double>();
                    y = jo["y"].Value <double>();
                    z = jo["z"].Value <double>();

                    name       = jo["name"].Value <string>();
                    SearchName = name.ToLower();


                    cr     = 1;
                    status = SystemStatusEnum.RedWizzard;
                }
                catch
                {
                }
            }
            else if (source == SystemInfoSource.EDSC)
            {
                JArray ja = (JArray)jo["coord"];

                name       = jo["name"].Value <string>();
                SearchName = name.ToLower();

                cr = jo["cr"].Value <int>();

                if (ja[0].Type == JTokenType.Float || ja[0].Type == JTokenType.Integer)
                {
                    x = ja[0].Value <double>();
                    y = ja[1].Value <double>();
                    z = ja[2].Value <double>();
                }
                else
                {
                    x = double.NaN;
                    y = double.NaN;
                    z = double.NaN;
                }


                CommanderCreate = jo["commandercreate"].Value <string>();
                CreateDate      = jo["createdate"].Value <DateTime>();
                CommanderUpdate = jo["commanderupdate"].Value <string>();
                UpdateDate      = jo["updatedate"].Value <DateTime>();
                status          = SystemStatusEnum.EDSC;
            }
            else if (source == SystemInfoSource.EDSM)
            {
                JObject coords = (JObject)jo["coords"];

                name       = jo["name"].Value <string>();
                SearchName = name.ToLower();

                //cr = jo["cr"].Value<int>();
                x = double.NaN;
                y = double.NaN;
                z = double.NaN;


                if (coords != null && (coords["x"].Type == JTokenType.Float || coords["x"].Type == JTokenType.Integer))
                {
                    x = coords["x"].Value <double>();
                    y = coords["y"].Value <double>();
                    z = coords["z"].Value <double>();
                }
                JArray submitted = (JArray)jo["submitted"];

                if (submitted.Count > 0)
                {
                    if (submitted[0]["cmdrname"] != null)
                    {
                        CommanderCreate = submitted[0]["cmdrname"].Value <string>();
                    }
                    CreateDate = submitted[0]["date"].Value <DateTime>();

                    if (submitted[submitted.Count - 1]["cmdrname"] != null)
                    {
                        CommanderUpdate = submitted[submitted.Count - 1]["cmdrname"].Value <string>();
                    }
                    UpdateDate = submitted[submitted.Count - 1]["date"].Value <DateTime>();
                }
                status = SystemStatusEnum.EDSC;
            }
            else if (source == SystemInfoSource.EDDB)
            {
                name       = jo["name"].Value <string>();
                SearchName = name.ToLower();

                cr = 1;

                x = jo["x"].Value <double>();
                y = jo["y"].Value <double>();
                z = jo["z"].Value <double>();

                id_eddb = jo["id"].Value <int>();

                /*CommanderCreate = jo["commandercreate"].Value<string>();
                 * CreateDate = jo["createdate"].Value<DateTime>();
                 * CommanderUpdate = jo["commanderupdate"].Value<string>();
                 * UpdateDate = jo["updatedate"].Value<DateTime>();*/

                faction = jo["faction"].Value <string>();

                if (jo["population"].Type == JTokenType.Integer)
                {
                    population = jo["population"].Value <long>();
                }


                government = EliteDangerous.Government2ID(jo["government"]);
                allegiance = EliteDangerous.Allegiance2ID(jo["allegiance"]);

                state    = EliteDangerous.EDState2ID(jo["state"]);
                security = EliteDangerous.EDSecurity2ID(jo["security"]);



                primary_economy = EliteDangerous.EDEconomy2ID(jo["primary_economy"]);


                if (jo["needs_permit"].Type == JTokenType.Integer)
                {
                    needs_permit = jo["needs_permit"].Value <int>();
                }

                eddb_updated_at = jo["updated_at"].Value <int>();

                status = SystemStatusEnum.EDDB;
            }
        }