コード例 #1
0
        public SuggestedReferences(double x, double y, double z)
        {
            EstimatedPosition = new SystemClass();

            EstimatedPosition.x = x;
            EstimatedPosition.y = y;
            EstimatedPosition.z = z;
            EstimatedPosition.name = "Estimated position";

            Stopwatch sw = new Stopwatch();
            sw.Start();


            CreateSectors();
            AddSystemsToSectors();
            sw.Stop();
            System.Diagnostics.Trace.WriteLine("FindCandidates time " + sw.Elapsed.TotalSeconds.ToString("0.000s"));

            for (int i = 0; i < sections; i++)
            {
                for (int j = 0; j < sections/2; j++)
                {
                    System.Diagnostics.Trace.WriteLine(i.ToString() + ":" + j.ToString() + "  " + sectors[i, j].Name + "  " + sectors[i, j].CandidatesCount.ToString());
                }
            }
        }
コード例 #2
0
 public ReferenceSystem(SystemClass refsys, SystemClass EstimatedPosition)
 {
     this.refSys = refsys;
     Azimuth = Math.Atan2(refSys.y - EstimatedPosition.y, refSys.x - EstimatedPosition.x);
     Distance = SystemData.Distance(refSys, EstimatedPosition);
     Altitude= Math.Acos((refSys.z-EstimatedPosition.z)/Distance);
 }
コード例 #3
0
        public static double DistanceX2(SystemClass s1, SystemClass s2)
        {
            if (s1 == null || s2 == null)
                return -1;

            //return Math.Sqrt(Math.Pow(s1.x - s2.x, 2) + Math.Pow(s1.y - s2.y, 2) + Math.Pow(s1.z - s2.z, 2));
            return ((s1.x - s2.x) * (s1.x - s2.x) + (s1.y - s2.y) * (s1.y - s2.y) + (s1.z - s2.z) * (s1.z - s2.z));
        }
コード例 #4
0
ファイル: Node.cs プロジェクト: vendolis/EDDiscovery
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="PositionX">X coordinate.</param>
 /// <param name="PositionY">Y coordinate.</param>
 /// <param name="PositionZ">Z coordinate.</param>
 /// <param name="si">Node name.</param>
 public Node(double PositionX, double PositionY, double PositionZ, SystemClass si)
 {
     _Position = new Point3D(PositionX, PositionY, PositionZ);
     _Passable = true;
     _IncomingArcs = new ArrayList();
     _OutgoingArcs = new ArrayList();
     _si = si;
 }
コード例 #5
0
        private void AddSystemToDataGridViewDistances(SystemClass system)
        {
            for (int i = 0, count = dataGridViewDistances.Rows.Count - 1; i < count; i++)
            {
                var cell = dataGridViewDistances[0, i];
                if (cell.Tag != null && (SystemClass)cell.Tag == system)
                {
                    return;
                }
            }

            var index = dataGridViewDistances.Rows.Add(system.name);
            dataGridViewDistances[0, index].Tag = system;
        }
コード例 #6
0
        /* Adds a system to the grid if it's not already in there */
        public void AddSystemToDataGridViewDistances(SystemClass system)
        {
            for (int i = 0, count = dataGridViewDistances.Rows.Count - 1; i < count; i++)
            {
                var cell = dataGridViewDistances[0, i];
                SystemClass s2 = cell.Tag as SystemClass;
                if (s2 != null && s2.SearchName.Equals(system.SearchName))
                {
                    return;
                }
                /* Should we fall-back on comparing cell.Value if call.Tag is null? */
            }

            var index = dataGridViewDistances.Rows.Add(system.name);
            newSystemAdded(dataGridViewDistances[0, index], system);
        }
コード例 #7
0
ファイル: FormMap.cs プロジェクト: Red13x3/EDDiscovery
        private void buttonCenter_Click(object sender, EventArgs e)
        {
            if (CenterSystem == null)
                    CenterSystem = SystemData.GetSystem("sol");
                SystemClass sys = SystemData.GetSystem(textBox_From.Text);

                if (sys != null)
                {
                    CenterSystem = sys;
                    ShowCenterSystem();
                }
                else
                {
                    ShowCenterSystem();
                }

                glControl1.Invalidate();
        }
コード例 #8
0
        public string AddSystem(SystemClass system)
        {
            string query;
            JObject jo = new JObject();

            jo["id"] = system.id;
            jo["name"] = system.name;
            jo["x"] = system.x;
            jo["y"] = system.y;
            jo["z"] = system.z;
            jo["cr"] = system.cr;
            jo["commandercreate"] = system.CommanderCreate;
            jo["createdate"] = system.CreateDate;
            jo["commanderupdate"] = system.CommanderUpdate;
            jo["updatedate"] = system.UpdateDate;

            query = jo.ToString();
            return Post(query, "system");
        }
コード例 #9
0
        static public double Distance(SystemClass s1, SystemClass s2)
        {
            List <DistanceClass> dists = new List <DistanceClass>();

            if (s1 == null || s2 == null)
            {
                return(-1);
            }

            string key = SQLiteDBClass.GetDistanceCacheKey(s1.SearchName, s2.SearchName);

            DistanceClass distance;

            if (SQLiteDBClass.dictDistances.TryGetValue(key, out distance))
            {
                return(distance.Dist);
            }
            else
            {
                return(-1);
            }

            /*
             * var obj3 = from p in SQLiteDBClass.globalDistances where (p.NameA.ToLower() == name2 && p.NameB.ToLower() == name1) || (p.NameA.ToLower() == name1 && p.NameB.ToLower() == name2) orderby p.CreateTime descending select p;
             *
             *
             * foreach (DistanceClass dist in obj3)
             * {
             *  dists.Add(dist);
             * }
             *
             * if (dists.Count < 1)
             *  return -1;
             *
             * return dists.First().Dist;
             * */
        }
コード例 #10
0
        private void buttonCenter_Click(object sender, EventArgs e)
        {
            SystemClass sys = SystemData.GetSystem(textBox_From.Text);
            if (sys == null) return;

            CenterSystem = sys;
            ShowCenterSystem();

            GenerateDataSets();
            glControl1.Invalidate();
        }
コード例 #11
0
 private void AddSystem(SystemClass system, Data3DSetClass<PointData> dataset)
 {
     if (system != null && system.HasCoordinate)
     {
         dataset.Add(new PointData(system.x - CenterSystem.x, system.y - CenterSystem.y, CenterSystem.z - system.z));
     }
 }
コード例 #12
0
        public void AddWantedSystem(string sysName)
        {
            if (wanted == null)
                PopulateLocalWantedSystems();

            WantedSystemClass entry = wanted.Where(x => x.system == sysName).FirstOrDefault();  //duplicate?

            if (entry == null)
            {
                WantedSystemClass toAdd = new WantedSystemClass(sysName);       // make one..
                toAdd.Add();                                                    // add to db.

                wanted.Add(toAdd);

                SystemClass star = SystemClass.GetSystem(sysName);
                if (star == null)
                    star = new SystemClass(sysName);

                var index = dataGridViewClosestSystems.Rows.Add("Local");
                dataGridViewClosestSystems[1, index].Value = sysName;
                dataGridViewClosestSystems[1, index].Tag = star;
            }
        }
コード例 #13
0
        public static double DistanceDB(SystemClass s1, SystemClass s2)
        {
            List<DistanceClass> dists = new List<DistanceClass>();
            try
            {
                using (SQLiteConnection cn = new SQLiteConnection(SQLiteDBClass.ConnectionString))
                {
                    using (SQLiteCommand cmd = new SQLiteCommand())
                    {
                        DataSet ds = null;
                        DataSet ds2 = null;
                        cmd.Connection = cn;
                        cmd.CommandType = CommandType.Text;
                        cmd.CommandTimeout = 30;
                        cmd.CommandText = "SELECT * FROM Distances WHERE NameA = @NameA COLLATE NOCASE  and NameB = @NameB COLLATE NOCASE ";

                        cmd.Parameters.AddWithValue("@NameA", s1.name);
                        cmd.Parameters.AddWithValue("@NameB", s2.name);

                        ds = SqlQueryText(cn, cmd);

                        cmd.Parameters.Clear();
                        cmd.Parameters.AddWithValue("@NameA", s2.name);
                        cmd.Parameters.AddWithValue("@NameB", s1.name);
                        ds2 = SqlQueryText(cn, cmd);

                        if (ds.Tables.Count > 0)
                        {
                            if (ds.Tables[0].Rows.Count > 0)
                            {
                                foreach (DataRow dr in ds.Tables[0].Rows)
                                {
                                    DistanceClass dist = new DistanceClass(dr);
                                    dists.Add(dist);
                                }

                            }
                        }

                        if (ds2.Tables.Count > 0)
                        {
                            if (ds2.Tables[0].Rows.Count > 0)
                            {
                                foreach (DataRow dr in ds2.Tables[0].Rows)
                                {
                                    DistanceClass dist = new DistanceClass(dr);
                                    dists.Add(dist);
                                }

                            }
                        }

                        if (dists.Count == 0)
                            return -1;

                        return dists[0].Dist;

                    }
                }

            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine("Exception : " + ex.Message);
                System.Diagnostics.Trace.WriteLine(ex.StackTrace);
                return -1;
            }
        }
コード例 #14
0
        public static List<SystemClass> ParseEDSC(string json, ref string date)
        {
            JObject edsc = null;
            if (json != null)
                edsc = (JObject)JObject.Parse(json);

            List<SystemClass> listSystems = new List<SystemClass>();

            if (edsc == null)
                return listSystems;

            JObject edscdata = (JObject)edsc["d"];

            if (edscdata == null)
                edscdata = edsc;

            JArray systems = (JArray)edscdata["systems"];

            date = edscdata["date"].Value<string>();

            foreach (JObject jo in systems)
            {
                string name = jo["name"].Value<string>();

                SystemClass system = new SystemClass(jo, SystemInfoSource.EDSC);

                if (system.HasCoordinate)
                    listSystems.Add(system);
            }
            return listSystems;
        }
コード例 #15
0
ファイル: SystemClass.cs プロジェクト: amatos/EDDiscovery
        public static long ParseEDDBUpdateSystems(string filename, Action<string> logline)
        {
            StreamReader sr = new StreamReader(filename);         // read directly from file..

            if (sr == null)
                return 0;

            JsonTextReader jr = new JsonTextReader(sr);

            if (jr == null)
                return 0;

            int updated = 0;
            int inserted = 0;

            using (SQLiteConnectionSystem cn = new SQLiteConnectionSystem())  // open the db
            {
                DbCommand selectCmd = null;
                DbCommand insertCmd = null;
                DbCommand updateCmd = null;
                DbCommand updateSysCmd = null;

                using (DbTransaction txn = cn.BeginTransaction())
                {
                    try
                    {
                        selectCmd = cn.CreateCommand("SELECT EddbId, Population, EddbUpdatedAt FROM EddbSystems WHERE EdsmId = @EdsmId LIMIT 1", txn);   // 1 return matching ID
                        selectCmd.AddParameter("@Edsmid", DbType.Int64);

                        insertCmd = cn.CreateCommand("INSERT INTO EddbSystems (EdsmId, EddbId, Name, Faction, Population, GovernmentId, AllegianceId, State, Security, PrimaryEconomyId, NeedsPermit, EddbUpdatedAt) " +
                                                                      "VALUES (@EdsmId, @EddbId, @Name, @Faction, @Population, @GovernmentId, @AllegianceId, @State, @Security, @PrimaryEconomyid, @NeedsPermit, @EddbUpdatedAt)", txn);
                        insertCmd.AddParameter("@EdsmId", DbType.Int64);
                        insertCmd.AddParameter("@EddbId", DbType.Int64);
                        insertCmd.AddParameter("@Name", DbType.String);
                        insertCmd.AddParameter("@Faction", DbType.String);
                        insertCmd.AddParameter("@Population", DbType.Int64);
                        insertCmd.AddParameter("@GovernmentId", DbType.Int64);
                        insertCmd.AddParameter("@AllegianceId", DbType.Int64);
                        insertCmd.AddParameter("@State", DbType.Int64);
                        insertCmd.AddParameter("@Security", DbType.Int64);
                        insertCmd.AddParameter("@PrimaryEconomyId", DbType.Int64);
                        insertCmd.AddParameter("@NeedsPermit", DbType.Int64);
                        insertCmd.AddParameter("@EddbUpdatedAt", DbType.Int64);

                        updateCmd = cn.CreateCommand("UPDATE EddbSystems SET EddbId=@EddbId, Name=@Name, Faction=@Faction, Population=@Population, GovernmentId=@GovernmentId, AllegianceId=@AllegianceId, State=@State, Security=@Security, PrimaryEconomyId=@PrimaryEconomyId, NeedsPermit=@NeedsPermit, EddbUpdatedAt=@EddbUpdatedAt WHERE EdsmId=@EdsmId", txn);
                        updateCmd.AddParameter("@EdsmId", DbType.Int64);
                        updateCmd.AddParameter("@EddbId", DbType.Int64);
                        updateCmd.AddParameter("@Name", DbType.String);
                        updateCmd.AddParameter("@Faction", DbType.String);
                        updateCmd.AddParameter("@Population", DbType.Int64);
                        updateCmd.AddParameter("@GovernmentId", DbType.Int64);
                        updateCmd.AddParameter("@AllegianceId", DbType.Int64);
                        updateCmd.AddParameter("@State", DbType.Int64);
                        updateCmd.AddParameter("@Security", DbType.Int64);
                        updateCmd.AddParameter("@PrimaryEconomyId", DbType.Int64);
                        updateCmd.AddParameter("@NeedsPermit", DbType.Int64);
                        updateCmd.AddParameter("@EddbUpdatedAt", DbType.Int64);

                        updateSysCmd = cn.CreateCommand("UPDATE EdsmSystems SET EddbId=@EddbId WHERE EdsmId=@EdsmId");
                        updateSysCmd.AddParameter("@EdsmId", DbType.Int64);
                        updateSysCmd.AddParameter("@EddbId", DbType.Int64);

                        int c = 0;
                        int hasinfo = 0;
                        int lasttc = Environment.TickCount;

                        while (jr.Read())
                        {
                            if (jr.TokenType == JsonToken.StartObject)
                            {
                                JObject jo = JObject.Load(jr);

                                SystemClass system = new SystemClass(jo, SystemInfoSource.EDDB);

                                if (system.HasEDDBInformation)                                  // screen out for speed any EDDB data with empty interesting fields
                                {
                                    hasinfo++;

                                    selectCmd.Parameters["@EdsmId"].Value = system.id_edsm;     // EDDB carries EDSM ID, so find entry in dB

                                    //DEBUGif ( c > 30000 )  Console.WriteLine("EDDB ID " + system.id_eddb + " EDSM ID " + system.id_edsm + " " + system.name + " Late info system");

                                    long updated_at = 0;
                                    long population = 0;
                                    long eddbid = 0;

                                    using (DbDataReader reader1 = selectCmd.ExecuteReader())         // if found (if not, we ignore EDDB system)
                                    {
                                        if (reader1.Read())                                     // its there.. check its got the right stuff in it.
                                        {
                                            eddbid = (long)reader1["EddbId"];
                                            updated_at = (long)reader1["EddbUpdatedAt"];
                                            population = (long)reader1["Population"];
                                        }
                                    }

                                    updateSysCmd.Parameters["@EdsmId"].Value = system.id_edsm;
                                    updateSysCmd.Parameters["@EddbId"].Value = system.id_eddb;
                                    updateSysCmd.ExecuteNonQuery();

                                    if (eddbid != 0)
                                    {
                                        if (updated_at != system.eddb_updated_at || population != system.population)
                                        {
                                            updateCmd.Parameters["@EddbId"].Value = system.id_eddb;
                                            updateCmd.Parameters["@Name"].Value = system.name;
                                            updateCmd.Parameters["@Faction"].Value = system.faction;
                                            updateCmd.Parameters["@Population"].Value = system.population;
                                            updateCmd.Parameters["@GovernmentId"].Value = system.government;
                                            updateCmd.Parameters["@AllegianceId"].Value = system.allegiance;
                                            updateCmd.Parameters["@State"].Value = system.state;
                                            updateCmd.Parameters["@Security"].Value = system.security;
                                            updateCmd.Parameters["@PrimaryEconomyId"].Value = system.primary_economy;
                                            updateCmd.Parameters["@NeedsPermit"].Value = system.needs_permit;
                                            updateCmd.Parameters["@EddbUpdatedAt"].Value = system.eddb_updated_at;
                                            updateCmd.Parameters["@EdsmId"].Value = system.id_edsm;
                                            updateCmd.ExecuteNonQuery();
                                            updated++;
                                        }
                                    }
                                    else
                                    {
                                        insertCmd.Parameters["@EdsmId"].Value = system.id_edsm;
                                        insertCmd.Parameters["@EddbId"].Value = system.id_eddb;
                                        insertCmd.Parameters["@Name"].Value = system.name;
                                        insertCmd.Parameters["@Faction"].Value = system.faction;
                                        insertCmd.Parameters["@Population"].Value = system.population;
                                        insertCmd.Parameters["@GovernmentId"].Value = system.government;
                                        insertCmd.Parameters["@AllegianceId"].Value = system.allegiance;
                                        insertCmd.Parameters["@State"].Value = system.state;
                                        insertCmd.Parameters["@Security"].Value = system.security;
                                        insertCmd.Parameters["@PrimaryEconomyId"].Value = system.primary_economy;
                                        insertCmd.Parameters["@NeedsPermit"].Value = system.needs_permit;
                                        insertCmd.Parameters["@EddbUpdatedAt"].Value = system.eddb_updated_at;
                                        insertCmd.ExecuteNonQuery();
                                        inserted++;
                                    }
                                }
                                else
                                {
                                    //Console.WriteLine("EDDB ID " + system.id_eddb + " EDSM ID " + system.id_edsm + " " + system.name + " No info reject");
                                }

                                if (++c % 10000 == 0)
                                {
                                    Console.WriteLine("EDDB Count " + c + " Delta " + (Environment.TickCount - lasttc) + " info " + hasinfo + " update " + updated + " new " + inserted);
                                    lasttc = Environment.TickCount;
                                }
                            }
                        }

                        txn.Commit();
                    }
                    catch
                    {
                        MessageBox.Show("There is a problem using the EDDB systems file." + Environment.NewLine +
                                        "Please perform a manual EDDB sync (see Admin menu) next time you run the program ", "EDDB Sync Error");
                    }
                    finally
                    {
                        if (selectCmd != null) selectCmd.Dispose();
                        if (updateCmd != null) updateCmd.Dispose();
                        if (insertCmd != null) insertCmd.Dispose();
                    }
                }
            }

            return updated + inserted;
        }
コード例 #16
0
        // Runs as a thread.
        private void ViewPushedSystems()
        {
            try
            {
                List<String> systems = edsm.GetPushedSystems();

                foreach (String system in systems)
                {
                    SystemClass star = SystemClass.GetSystem(system);
                    if (star == null)
                        star = new SystemClass(system);

                    this.BeginInvoke(new MethodInvoker(() =>
                    {
                        var index = dataGridViewClosestSystems.Rows.Add("EDSM");
                        dataGridViewClosestSystems[1, index].Value = system;
                        dataGridViewClosestSystems[1, index].Tag = star;
                    }));
                }
            }
            catch (Exception ex)
            {
                this.BeginInvoke(new MethodInvoker(() =>
                {
                    LogTextHighlight("ViewPushedSystems Exception:" + ex.Message);
                    LogText(ex.StackTrace);
                }));
            }
        }
コード例 #17
0
        public void AddWantedSystem(string sysName)
        {
            if (wanted == null) wanted = new List<WantedSystemClass>();
            WantedSystemClass entry = wanted.Where(x => x.system == sysName).FirstOrDefault();
            if (entry == null)
            {
                WantedSystemClass toAdd = new WantedSystemClass(sysName);
                wanted.Add(toAdd);
                SystemClass star = SystemClass.GetSystem(sysName);
                if (star == null)
                    star = new SystemClass(sysName);

                var index = dataGridViewClosestSystems.Rows.Add("Local");
                dataGridViewClosestSystems[1, index].Value = sysName;
                dataGridViewClosestSystems[1, index].Tag = star;
            }
        }
コード例 #18
0
        private void PopulateLocalWantedSystems()
        {
            wanted = WantedSystemClass.GetAllWantedSystems();

            if (wanted != null && wanted.Any())
            {
                foreach (WantedSystemClass sys in wanted)
                {
                    SystemClass star = SystemClass.GetSystem(sys.system);
                    if (star == null)
                        star = new SystemClass(sys.system);

                    var index = dataGridViewClosestSystems.Rows.Add("Local");
                    dataGridViewClosestSystems[1, index].Value = sys.system;
                    dataGridViewClosestSystems[1, index].Tag = star;
                }
            }
            else
            {
                wanted = new List<WantedSystemClass>();
            }
        }
コード例 #19
0
        public static double DistanceDB(SystemClass s1, SystemClass s2)
        {
            List <DistanceClass> dists = new List <DistanceClass>();

            try
            {
                using (SQLiteConnection cn = new SQLiteConnection(SQLiteDBClass.ConnectionString))
                {
                    using (SQLiteCommand cmd = new SQLiteCommand())
                    {
                        DataSet ds  = null;
                        DataSet ds2 = null;
                        cmd.Connection     = cn;
                        cmd.CommandType    = CommandType.Text;
                        cmd.CommandTimeout = 30;
                        cmd.CommandText    = "SELECT * FROM Distances WHERE NameA = @NameA COLLATE NOCASE  and NameB = @NameB COLLATE NOCASE ";

                        cmd.Parameters.AddWithValue("@NameA", s1.name);
                        cmd.Parameters.AddWithValue("@NameB", s2.name);

                        ds = SqlQueryText(cn, cmd);

                        cmd.Parameters.Clear();
                        cmd.Parameters.AddWithValue("@NameA", s2.name);
                        cmd.Parameters.AddWithValue("@NameB", s1.name);
                        ds2 = SqlQueryText(cn, cmd);


                        if (ds.Tables.Count > 0)
                        {
                            if (ds.Tables[0].Rows.Count > 0)
                            {
                                foreach (DataRow dr in ds.Tables[0].Rows)
                                {
                                    DistanceClass dist = new DistanceClass(dr);
                                    dists.Add(dist);
                                }
                            }
                        }

                        if (ds2.Tables.Count > 0)
                        {
                            if (ds2.Tables[0].Rows.Count > 0)
                            {
                                foreach (DataRow dr in ds2.Tables[0].Rows)
                                {
                                    DistanceClass dist = new DistanceClass(dr);
                                    dists.Add(dist);
                                }
                            }
                        }


                        if (dists.Count == 0)
                        {
                            return(-1);
                        }


                        return(dists[0].Dist);
                    }
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine("Exception : " + ex.Message);
                System.Diagnostics.Trace.WriteLine(ex.StackTrace);
                return(-1);
            }
        }
コード例 #20
0
 /* Callback for when a new system has been added to the grid.
  * Performs some additional setup such as clearing data and setting the status. */
 private void newSystemAdded(DataGridViewCell cell, SystemClass system)
 {
     if (!cell.Value.Equals(system.name))            // if cell value is not the same as system name
     {
         cell.Value = system.name;
     }
     cell.Tag = system;
     // reset any calculated distances
     dataGridViewDistances[2, cell.RowIndex].Value = null;
     // (re)set status
     if (system.HasCoordinate)
     {
         dataGridViewDistances[3, cell.RowIndex].Value = null;
     }
     else
     {
         dataGridViewDistances[3, cell.RowIndex].Value = "Position unknown";
         dataGridViewDistances[3, cell.RowIndex].Style.ForeColor = _discoveryForm.theme.NonVisitedSystemColor;
     }
 }
コード例 #21
0
        /* Tries to load the system data for the given name. If no system data is available, but the system is known,
         * it creates a new System entity, otherwise logs it and returns null. */
        private SystemClass getSystemForTrilateration(string systemName)
        {
            var system = SystemClass.GetSystem(systemName);

            if (system == null)
            {
                if (!edsm.IsKnownSystem(systemName))
                {
                    LogTextHighlight("Only systems with coordinates or already known to EDSM can be added" + Environment.NewLine);
                }
                else
                {
                    system = new SystemClass(systemName);
                }
            }
            return system;
        }
コード例 #22
0
        public List<SystemClass> ReadSystems()
        {
            List<SystemClass> eddbsystems = new List<SystemClass>();
            string json;

            json = ReadJson(systemFileName);

            if (json == null)
                return eddbsystems;

            JArray systems = (JArray)JArray.Parse(json);

            if (systems!=null)
            {
                foreach (JObject jo in systems)
                {
                    SystemClass sys = new SystemClass(jo, EDDiscovery.SystemInfoSource.EDDB);
                    
                    if (sys != null)
                        eddbsystems.Add(sys);

                }
            }
            systems = null;
            json = null;
            return eddbsystems;
        }
コード例 #23
0
ファイル: SQLiteDBClass.cs プロジェクト: Udomyr/EDDiscovery
        public bool GetAllSystems()
        {
            try
            {
                using (SQLiteConnection cn = new SQLiteConnection(ConnectionString))
                {
                    using (SQLiteCommand cmd = new SQLiteCommand())
                    {
                        DataSet ds = null;
                        cmd.Connection = cn;
                        cmd.CommandType = CommandType.Text;
                        cmd.CommandTimeout = 30;
                        cmd.CommandText = "select * from Systems Order By name";

                        ds = SqlQueryText(cn, cmd);
                        if (ds.Tables.Count == 0)
                        {
                            return false;
                        }
                        //
                        if (ds.Tables[0].Rows.Count == 0)
                        {
                            return false;
                        }

                        //globalSystems.Clear();
                        //dictSystems.Clear();

                        foreach (DataRow dr in ds.Tables[0].Rows)
                        {
                            SystemClass sys = new SystemClass(dr);

                            if (globalSystemNotes.ContainsKey(sys.SearchName))
                            {
                                sys.Note = globalSystemNotes[sys.SearchName].Note;
                            }

                            dictSystems[sys.SearchName] = sys;
                        }

                        globalSystems = dictSystems.Values.ToList<SystemClass>();

                        return true;

                    }
                }
            }
            catch
            {
                return false;
            }
        }
コード例 #24
0
        public void Set(SystemClass system)
        {
            if (TargetSystem == null || !TargetSystem.Equals(system))
            {
                TargetSystem = system;
                ClearDataGridViewDistancesRows();
            }

            if (TargetSystem == null) return;

            textBoxSystemName.Text = TargetSystem.name;
            labelStatus.Text = "Enter Distances";
            labelStatus.BackColor = Color.LightBlue;

            UnfreezeTrilaterationUI();
            dataGridViewDistances.Focus();

            PopulateSuggestedSystems();
            PopulateClosestSystems();
        }
コード例 #25
0
ファイル: SystemClass.cs プロジェクト: amatos/EDDiscovery
        // using an id
        public static SystemClass GetSystem(long id,  SQLiteConnectionSystem cn = null, SystemIDType idtype = SystemIDType.id)
        {
            SystemClass sys = null;
            bool closeit = false;

            try
            {
                if (cn == null)
                {
                    closeit = true;
                    cn = new SQLiteConnectionSystem();
                }

                using (DbCommand cmd = cn.CreateCommand("SELECT * FROM EdsmSystems WHERE " + idtype.ToString() + "=@id LIMIT 1"))   // 1 return matching name
                {
                    cmd.AddParameterWithValue("id", id);
                    using (DbDataReader reader = cmd.ExecuteReader())
                    {
                        if (reader.Read())
                        {
                            long edsmid = (long)reader["EdsmId"];

                            sys = new SystemClass
                            {
                                id = (long)reader["id"],
                                id_edsm = (long)reader["EdsmId"],
                                id_eddb = reader["EddbId"] == System.DBNull.Value ? 0 : (long)reader["EddbId"],
                                CreateDate = new DateTime(2015, 1, 1, 0, 0, 0, DateTimeKind.Utc) + TimeSpan.FromSeconds((long)reader["CreateTimestamp"]),
                                UpdateDate = new DateTime(2015, 1, 1, 0, 0, 0, DateTimeKind.Utc) + TimeSpan.FromSeconds((long)reader["UpdateTimestamp"]),
                                cr = 0,
                                status = SystemStatusEnum.EDSC,
                                gridid = (int)(long)reader["GridId"],
                                randomid = (int)(long)reader["RandomId"]
                            };

                            if (System.DBNull.Value == reader["x"])
                            {
                                sys.x = double.NaN;
                                sys.y = double.NaN;
                                sys.z = double.NaN;
                            }
                            else
                            {
                                sys.x = ((double)(long)reader["x"]) / XYZScalar;
                                sys.y = ((double)(long)reader["y"]) / XYZScalar;
                                sys.z = ((double)(long)reader["z"]) / XYZScalar;
                            }
                        }
                    }
                }

                if (sys != null && sys.id_edsm != 0)
                {
                    using (DbCommand cmd = cn.CreateCommand("SELECT Name FROM SystemNames WHERE EdsmId = @EdsmId LIMIT 1"))
                    {
                        cmd.AddParameterWithValue("@EdsmId", sys.id_edsm);
                        using (DbDataReader reader = cmd.ExecuteReader())
                        {
                            if (reader.Read())
                            {
                                sys.name = (string)reader["Name"];
                            }
                        }
                    }
                }

                if (sys != null && sys.id_eddb != 0)
                {
                    using (DbCommand cmd = cn.CreateCommand("SELECT * FROM EddbSystems WHERE EddbId = @EddbId LIMIT 1"))
                    {
                        cmd.AddParameterWithValue("EddbId", sys.id_eddb);
                        using (DbDataReader reader = cmd.ExecuteReader())
                        {
                            if (reader.Read())
                            {
                                object o;

                                o = reader["Population"];
                                sys.population = o == DBNull.Value ? 0 : (long)o;

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

                                o = reader["GovernmentId"];
                                sys.government = o == DBNull.Value ? EDGovernment.Unknown : (EDGovernment)((long)o);

                                o = reader["AllegianceId"];
                                sys.allegiance = o == DBNull.Value ? EDAllegiance.Unknown : (EDAllegiance)((long)o);

                                o = reader["PrimaryEconomyId"];
                                sys.primary_economy = o == DBNull.Value ? EDEconomy.Unknown : (EDEconomy)((long)o);

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

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

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

                                o = reader["NeedsPermit"];
                                sys.needs_permit = o == DBNull.Value ? 0 : (int)((long)o);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine("Exception : " + ex.Message);
                System.Diagnostics.Trace.WriteLine(ex.StackTrace);
            }
            finally
            {
                if (closeit && cn != null)
                {
                    cn.Dispose();
                }
            }

            return sys;
        }
コード例 #26
0
        private void ShowCenterSystem()
        {
            if (CenterSystem == null)
            {
                CenterSystem = SystemData.GetSystem("sol") ?? new SystemClass { name = "Sol", SearchName = "sol", x = 0, y = 0, z = 0 };
            }

            label1.Text = string.Format("{0} x:{1} y:{2} z:{3}", CenterSystem.name, CenterSystem.x.ToString("0.00"), CenterSystem.y.ToString("0.00"), CenterSystem.z.ToString("0.00"));
        }
コード例 #27
0
        public static List<SystemClass> ParseEDSM(string json, ref string date)
        {
            JArray edsc = null;
            if (json != null)
                edsc = (JArray)JArray.Parse(json);

            List<SystemClass> listSystems = new List<SystemClass>();

            if (edsc == null)
                return listSystems;

            DateTime maxdate = DateTime.Parse(date);

            //            date = edscdata["date"].Value<string>();

            foreach (JObject jo in edsc)
            {
                string name = jo["name"].Value<string>();

                SystemClass system = new SystemClass(jo, SystemInfoSource.EDSM);

                if (system.UpdateDate.Subtract(maxdate).TotalSeconds>0)
                    maxdate = system.UpdateDate;

                if (system.HasCoordinate)
                    listSystems.Add(system);
            }

            date = maxdate.ToString("yyyy-MM-dd HH:mm:ss");
            return listSystems;
        }
コード例 #28
0
 public FormMap(SystemClass centerSystem, AutoCompleteStringCollection SystemNames)
     : this(SystemNames)
 {
     if (centerSystem != null && centerSystem.HasCoordinate) CenterSystem = centerSystem;
 }
コード例 #29
0
        public static double Distance(SystemClass s1, SystemClass s2)
        {
            List<DistanceClass> dists = new List<DistanceClass>();

            if (s1 == null || s2 == null)
                return -1;

            string key = SQLiteDBClass.GetDistanceCacheKey(s1.SearchName, s2.SearchName);

            DistanceClass distance;
            if (SQLiteDBClass.dictDistances.TryGetValue(key, out distance))
                return distance.Dist;
            else
                return -1;

            /*
            var obj3 = from p in SQLiteDBClass.globalDistances where (p.NameA.ToLower() == name2 && p.NameB.ToLower() == name1) || (p.NameA.ToLower() == name1 && p.NameB.ToLower() == name2) orderby p.CreateTime descending select p;

            foreach (DistanceClass dist in obj3)
            {
                dists.Add(dist);
            }

            if (dists.Count < 1)
                return -1;

            return dists.First().Dist;
             * */
        }
コード例 #30
0
 private void DrawLine(Graphics gfx, Pen pen, SystemClass sys1, SystemClass sys2)
 {
     gfx.DrawLine(pen, Transform2Screen(currentFGEImage.TransformCoordinate(new Point((int)sys1.x, (int)sys1.z))), Transform2Screen(currentFGEImage.TransformCoordinate(new Point((int)sys2.x, (int)sys2.z))));
 }
コード例 #31
0
        private void AddSuggestedSystem(SystemClass system)
        {
            for (int i = 0, count = dataGridViewDistances.Rows.Count - 1; i < count; i++)
            {
                var systemCell = dataGridViewDistances[0, i];
                if (systemCell.Value!=null)
                    if (systemCell.Value.Equals(system.name))  // Dont add list thats already in distances.
                        return;
            }

                var index = dataGridViewSuggestedSystems.Rows.Add(system.name);
            dataGridViewSuggestedSystems[0, index].Tag = system;
        }
コード例 #32
0
        // this is a split in two version with the same code of AddHistoryRow..
        public static void UpdateVisitedSystemsEntries(VisitedSystemsClass item, VisitedSystemsClass item2, bool usedistancedb)
        {
            SystemClass sys1 = SystemClass.GetSystem(item.Name);
            if (sys1 == null)
            {
                sys1 = new SystemClass(item.Name);

                if (item.HasTravelCoordinates)
                {
                    sys1.x = item.X;
                    sys1.y = item.Y;
                    sys1.z = item.Z;
                }
            }

            SystemClass sys2 = null;

            if (item2 != null)
            {
                sys2 = SystemClass.GetSystem(item2.Name);
                if (sys2 == null)
                {
                    sys2 = new SystemClass(item2.Name);
                    if (item2.HasTravelCoordinates)
                    {
                        sys2.x = item2.X;
                        sys2.y = item2.Y;
                        sys2.z = item2.Z;
                    }
                }
            }
            else
                sys2 = null;

            item.curSystem = sys1;
            item.prevSystem = sys2;

            string diststr = "";
            if (sys2 != null)
            {
                double dist = usedistancedb ? SystemClass.DistanceIncludeDB(sys1, sys2) : SystemClass.Distance(sys1, sys2);
                if (dist > 0)
                    diststr = dist.ToString("0.00");
            }

            item.strDistance = diststr;
        }