Esempio n. 1
0
        public ActionResult SyncEDDB(string key)
        {
            var eddb_systems_path = Server.MapPath("/app_data/eddb/systems.json");

            var prevSyncDate = DateTime.MinValue;

            if (System.IO.File.Exists(eddb_systems_path))
            {
                prevSyncDate = System.IO.File.GetLastWriteTimeUtc(eddb_systems_path).AddHours(-25);
            }

            using (WebClient wc = new WebClient())
            {
                try
                {
                    wc.DownloadFile(new Uri("https://eddb.io/archive/v5/systems_populated.json"), eddb_systems_path);
                }
                catch {
                    throw new Exception("Unable to download station data from eddb.");
                }
            }

            var systems = new List <EDDBSystem>();

            using (var eddb_systems = new Models.Json.JsonStreamReader <EDDBSystem>(eddb_systems_path))
            {
                while (eddb_systems.Next())
                {
                    //Updated?
                    if (eddb_systems.Current.Updated_At > prevSyncDate)
                    {
                        //Add additional data
                        if (eddb_systems.Current.Population.HasValue && eddb_systems.Current.Population.Value > 0)
                        {
                            eddb_systems.Current.CCIncome = (int)Math.Round(0.4343f * Math.Log(eddb_systems.Current.Population.Value) + 1);
                        }

                        //Store
                        systems.Add(eddb_systems.Current);
                        if (systems.Count > 149)
                        {
                            StoreSystems(systems);
                            systems.Clear();
                        }
                    }
                }
            }

            StoreSystems(systems);

            return(new JsonResult {
                Data = new { status = "ok" }, JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
Esempio n. 2
0
        public ActionResult SyncFactions(string key)
        {
            if (!key.Equals(ConfigurationManager.AppSettings["jobkey"], StringComparison.CurrentCulture))
            {
                return(new JsonResult {
                    Data = new { status = "unauthorized" }, JsonRequestBehavior = JsonRequestBehavior.AllowGet
                });
            }

            //Sync Factions
            var eddb_factions_path = Server.MapPath("/app_data/eddb/factions.json");

            using (WebClient wc = new WebClient())
            {
                try
                {
                    wc.DownloadFile(new Uri("https://eddb.io/archive/v5/factions.json"), eddb_factions_path);
                }
                catch
                {
                    throw new Exception("Unable to download station data from eddb.");
                }
            }

            List <EDDBFaction> factions = new List <EDDBFaction>();

            using (var eddb_factions = new Models.Json.JsonStreamReader <EDDBFaction>(eddb_factions_path))
            {
                while (eddb_factions.Next())
                {
                    factions.Add(eddb_factions.Current);
                    if (factions.Count > 149)
                    {
                        StoreFactions(factions);
                        factions.Clear();
                    }
                }
            }

            return(new JsonResult {
                Data = new { status = "ok" }, JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }