Example #1
0
        static public VisitedSystemsClass GetLast()
        {
            List <VisitedSystemsClass> list = new List <VisitedSystemsClass>();


            using (SQLiteConnection cn = new SQLiteConnection(SQLiteDBClass.ConnectionString))
            {
                using (SQLiteCommand cmd = new SQLiteCommand())
                {
                    DataSet ds = null;
                    cmd.Connection     = cn;
                    cmd.CommandType    = CommandType.Text;
                    cmd.CommandTimeout = 30;
                    cmd.CommandText    = "select * from VisitedSystems Order by Time DESC Limit 1";


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

                    VisitedSystemsClass sys = new VisitedSystemsClass(ds.Tables[0].Rows[0]);

                    return(sys);
                }
            }
        }
Example #2
0
        static public List <VisitedSystemsClass> GetAll(int commander)
        {
            List <VisitedSystemsClass> list = new List <VisitedSystemsClass>();

            using (SQLiteConnectionUser cn = new SQLiteConnectionUser())
            {
                using (DbCommand cmd = cn.CreateCommand("select * from VisitedSystems where commander=@commander Order by Time "))
                {
                    cmd.AddParameterWithValue("@commander", commander);

                    DataSet ds = SQLiteDBClass.SQLQueryText(cn, cmd);
                    if (ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
                    {
                        return(list);
                    }

                    foreach (DataRow dr in ds.Tables[0].Rows)
                    {
                        VisitedSystemsClass sys = new VisitedSystemsClass(dr);
                        list.Add(sys);
                    }

                    return(list);
                }
            }
        }
Example #3
0
        public static ISystem FindSystem(List <VisitedSystemsClass> visitedSystems, GalacticMapping glist, string name)         // in system or name
        {
            EDDiscovery2.DB.ISystem ds1 = SystemClass.GetSystem(name);

            if (ds1 == null)
            {
                VisitedSystemsClass vs = VisitedSystemsClass.FindByName(visitedSystems, name);

                if (vs != null && vs.HasTravelCoordinates)
                {
                    ds1 = vs.curSystem;
                }
                else
                {
                    GalacticMapObject gmo = glist.Find(name, true, true);

                    if (gmo != null && gmo.points.Count > 0)
                    {
                        return(new SystemClass(gmo.name, gmo.points[0].X, gmo.points[0].Y, gmo.points[0].Z));        // fudge it into a system
                    }
                }
            }

            return(ds1);
        }
Example #4
0
        static public List <VisitedSystemsClass> GetAll()
        {
            List <VisitedSystemsClass> list = new List <VisitedSystemsClass>();

            using (SQLiteConnectionED cn = new SQLiteConnectionED())
            {
                using (DbCommand cmd = cn.CreateCommand("select * from VisitedSystems Order by Time "))
                {
                    DataSet ds = SQLiteDBClass.SQLQueryText(cn, cmd);

                    if (ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
                    {
                        return(list);
                    }

                    foreach (DataRow dr in ds.Tables[0].Rows)
                    {
                        VisitedSystemsClass sys = new VisitedSystemsClass(dr);
                        list.Add(sys);
                    }

                    return(list);
                }
            }
        }
Example #5
0
 public static VisitedSystemsClass FindByName(List <VisitedSystemsClass> visitedSystems, string name)
 {
     if (visitedSystems != null)
     {
         VisitedSystemsClass vs = visitedSystems.FindLast(x => x.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase));
         return(vs);
     }
     else
     {
         return(null);
     }
 }
Example #6
0
        public static void UpdateVisitedSystemsEntries(VisitedSystemsClass item, VisitedSystemsClass item2, bool usedistancedb)           // this is a split in two version with the same code of AddHistoryRow..
        {
            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;
        }
Example #7
0
 public static VisitedSystemsClass FindByPos(List <VisitedSystemsClass> visitedSystems, Point3D p, double limit)     // go thru setting the lastknowsystem
 {
     if (visitedSystems != null)
     {
         VisitedSystemsClass vs = visitedSystems.FindLast(x => x.curSystem.HasCoordinate &&
                                                          Math.Abs(x.curSystem.x - p.X) < limit &&
                                                          Math.Abs(x.curSystem.y - p.Y) < limit &&
                                                          Math.Abs(x.curSystem.z - p.Z) < limit);
         return(vs);
     }
     else
     {
         return(null);
     }
 }
Example #8
0
 public static double Distance(VisitedSystemsClass s1, double x, double y, double z)
 {
     if (s1 != null && s1.HasTravelCoordinates)
     {
         return(Math.Sqrt((s1.X - x) * (s1.X - x) + (s1.Y - y) * (s1.Y - y) + (s1.Z - z) * (s1.Z - z)));
     }
     else if (s1.curSystem.HasCoordinate)
     {
         return(Math.Sqrt((s1.curSystem.x - x) * (s1.curSystem.x - x) + (s1.curSystem.y - y) * (s1.curSystem.y - y) + (s1.curSystem.z - z) * (s1.curSystem.z - z)));
     }
     else
     {
         return(-1);
     }
 }
Example #9
0
        static public VisitedSystemsClass GetLast()
        {
            List <VisitedSystemsClass> list = new List <VisitedSystemsClass>();

            using (SQLiteConnectionUser cn = new SQLiteConnectionUser())
            {
                using (DbCommand cmd = cn.CreateCommand("select * from VisitedSystems Order by Time DESC Limit 1"))
                {
                    DataSet ds = SQLiteDBClass.SQLQueryText(cn, cmd);
                    if (ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
                    {
                        return(null);
                    }

                    VisitedSystemsClass sys = new VisitedSystemsClass(ds.Tables[0].Rows[0]);
                    return(sys);
                }
            }
        }
        static public List <VisitedSystemsClass> GetAll(int commander)
        {
            List <VisitedSystemsClass> list = new List <VisitedSystemsClass>();


            using (SQLiteConnection cn = new SQLiteConnection(SQLiteDBClass.ConnectionString))
            {
                using (SQLiteCommand cmd = new SQLiteCommand())
                {
                    DataSet ds = null;
                    cmd.Connection     = cn;
                    cmd.CommandType    = CommandType.Text;
                    cmd.CommandTimeout = 30;
                    cmd.CommandText    = "select * from VisitedSystems where commander=@commander Order by Time ";
                    cmd.Parameters.AddWithValue("@commander", commander);

                    ds = SQLiteDBClass.QueryText(cn, cmd);
                    if (ds.Tables.Count == 0)
                    {
                        return(null);
                    }
                    //
                    if (ds.Tables[0].Rows.Count == 0)
                    {
                        return(list);
                    }

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

                        list.Add(sys);
                    }

                    return(list);
                }
            }
        }
        public AssignTravelLogSystemForm(TravelHistoryControl travelHistory, VisitedSystemsClass vsc)
        {
            InitializeComponent();
            this._travelHistory = travelHistory;
            this._travelLogEntry = vsc;
            this._linkSystem = vsc.curSystem;

            this.tbLogSystemName.Text = vsc.Name;
            this.tbDateVisited.Text = vsc.Time.ToString();
            this.tbLogCoordX.Text = vsc.HasTravelCoordinates ? vsc.X.ToString("0.000") : "?";
            this.tbLogCoordY.Text = vsc.HasTravelCoordinates ? vsc.Y.ToString("0.000") : "?";
            this.tbLogCoordZ.Text = vsc.HasTravelCoordinates ? vsc.Z.ToString("0.000") : "?";
            this.tbLogCoordX.TextAlign = vsc.HasTravelCoordinates ? HorizontalAlignment.Right : HorizontalAlignment.Center;
            this.tbLogCoordY.TextAlign = vsc.HasTravelCoordinates ? HorizontalAlignment.Right : HorizontalAlignment.Center;
            this.tbLogCoordZ.TextAlign = vsc.HasTravelCoordinates ? HorizontalAlignment.Right : HorizontalAlignment.Center;

            UpdateLinkedSystemList(vsc.curSystem);
            tbManualSystemName.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
            tbManualSystemName.AutoCompleteSource = AutoCompleteSource.CustomSource;
            AutoCompleteStringCollection autocomplete = new AutoCompleteStringCollection();
            SystemClass.GetSystemNames(ref autocomplete);
            tbManualSystemName.AutoCompleteCustomSource = autocomplete;
        }
Example #12
0
        public static List<VisitedSystemsClass> GetAll(int commander)
        {
            List<VisitedSystemsClass> list = new List<VisitedSystemsClass>();

            using (SQLiteConnection cn = new SQLiteConnection(SQLiteDBClass.ConnectionString))
            {
                using (SQLiteCommand cmd = new SQLiteCommand())
                {
                    DataSet ds = null;
                    cmd.Connection = cn;
                    cmd.CommandType = CommandType.Text;
                    cmd.CommandTimeout = 30;
                    cmd.CommandText = "select * from VisitedSystems where commander=@commander Order by Time ";
                    cmd.Parameters.AddWithValue("@commander", commander);

                    ds = SQLiteDBClass.QueryText(cn, cmd);
                    if (ds.Tables.Count == 0)
                    {
                        return null;
                    }
                    //
                    if (ds.Tables[0].Rows.Count == 0)
                    {
                        return list;
                    }

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

                        list.Add(sys);
                    }

                    return list;
                }
            }
        }
Example #13
0
 public static double Distance(VisitedSystemsClass s1, Point3D p)
 {
     return Distance(s1, p.X, p.Y, p.Z);
 }
Example #14
0
 public static double Distance(VisitedSystemsClass s1, double x, double y, double z)
 {
     if (s1 != null && s1.HasTravelCoordinates)
         return Math.Sqrt((s1.X - x) * (s1.X - x) + (s1.Y - y) * (s1.Y - y) + (s1.Z - z) * (s1.Z - z));
     else if (s1.curSystem.HasCoordinate)
         return Math.Sqrt((s1.curSystem.x - x) * (s1.curSystem.x - x) + (s1.curSystem.y - y) * (s1.curSystem.y - y) + (s1.curSystem.z - z) * (s1.curSystem.z - z));
     else
         return -1;
 }
Example #15
0
        private string DistToStar(VisitedSystemsClass vscentry, Point3D tpos)
        {
            string res = "";
            if (!double.IsNaN(tpos.X))
            {
                double dist = VisitedSystemsClass.Distance(vscentry, tpos);
                if (dist >= 0)
                    res = dist.ToString("0.00");
            }

            return res;
        }
Example #16
0
 public void UpdateHistorySystem(VisitedSystemsClass historysel)
 {
     _formMap.UpdateHistorySystem(historysel);
 }
Example #17
0
        public void Sync()
        {
            try
            {
                SQLiteDBClass db = new SQLiteDBClass();
                EDSMClass edsm = new EDSMClass();

                edsm.apiKey = db.GetSettingString("EDSMApiKey", "");
                edsm.commanderName = db.GetSettingString("CommanderName", "");

                //string comments =  edsm.GetComments(new DateTime(2015, 1, 1));
                List<SystemPosition> log;
                int ret = edsm.GetLogs(new DateTime(2011, 1, 1), out log);

                if (log == null)
                    log = new List<SystemPosition>();

                // Send Unsynced system to EDSM.

                List<SystemPosition> systems = (from s in mainForm.VisitedSystems where s.vs !=null && s.vs.EDSM_sync == false select s).ToList<SystemPosition>();
                mainForm.LogLine("EDSM: Sending " +  systems.Count.ToString() + " flightlog entries", Color.Black);
                foreach (var system in systems)
                {
                    string json = null;

                    if (Exit)
                    {
                        running = false;
                        return;
                    }

                    if (system.vs != null && system.vs.EDSM_sync == false)
                    {
                        // check if it exist in EDSM
                        SystemPosition ps2 = (from c in log where c.Name == system.Name && c.time.Ticks == system.time.Ticks select c).FirstOrDefault<SystemPosition>();
                        if (ps2 != null)
                        {
                            system.vs.EDSM_sync = true;
                            system.Update();

                        }
                        else
                            json = edsm.SetLog(system.Name, system.time);

                        if (json != null)
                        {
                            JObject msg = (JObject)JObject.Parse(json);

                            int msgnum = msg["msgnum"].Value<int>();
                            string msgstr = msg["msg"].Value<string>();


                            if (msgnum == 100 || msgnum == 401 || msgnum == 402 || msgnum == 403)
                            {
                                if (msgnum == 100)
                                    System.Diagnostics.Trace.WriteLine("New");

                                system.vs.EDSM_sync = true;
                                system.Update();
                            }
                            else
                            {
                                mainForm.LogLine("EDSM sync ERROR:" + msgnum.ToString() +":" + msgstr, Color.Red);
                                System.Diagnostics.Trace.WriteLine("Error sync:" + msgnum.ToString() + " : " + system.Name);
                                break;
                            }


                        }
                    }
                }

                TravelLogUnit tlu = null;

                // Check for new systems from EDSM
                bool newsystem = false;
                int defaultColour = db.GetSettingInt("DefaultMap", Color.Red.ToArgb());
                foreach (var system in log)
                {
                    SystemPosition ps2 = (from c in mainForm.VisitedSystems where c.Name == system.Name && c.time.Ticks == system.time.Ticks select c).FirstOrDefault<SystemPosition>();
                    if (ps2 == null)  // Add to local DB...
                    {
                        if (tlu == null) // If we dontt have a travellogunit yet then create it. 
                        {
                            tlu = new TravelLogUnit();

                            tlu.type = 2;  // EDSM
                            tlu.Path = "http://www.edsm.net/api-logs-v1/get-logs";
                            tlu.Name = "EDSM-" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture);
                            tlu.Size = 0;

                            tlu.Add();  // Add to Database
                        }

                        VisitedSystemsClass vs = new VisitedSystemsClass();

                        vs.Source = tlu.id;
                        vs.Unit = tlu.Name;

                        vs.Name = system.Name;
                        vs.Time = system.time;
                        vs.MapColour = defaultColour;
                        vs.EDSM_sync = true;
                        

                        vs.Add();  // Add to DB;
                        System.Diagnostics.Trace.WriteLine("New from EDSM");
                        newsystem = true;
                        
                    }
                }
                mainForm.LogLine("EDSM sync Done", Color.Black);

                if (newsystem)
                    OnNewEDSMTravelLog(this);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine("Exception ex:" + ex.Message);
                mainForm.LogLine("EDSM sync Exception " + ex.Message, Color.Red);
            }

        }
Example #18
0
 public bool MoveToSystem(VisitedSystemsClass system)
 {
     return _formMap.SetCenterSystemTo(system);
 }
Example #19
0
 public void Prepare(VisitedSystemsClass historysel, string homesys, ISystem centersys, float zoom,
     AutoCompleteStringCollection sysname, List<VisitedSystemsClass> visited)
 {
     _formMap.Prepare(historysel, homesys, centersys, zoom, sysname, visited);
 }
Example #20
0
        internal static bool SendTravelLog(EDSMClass edsm, VisitedSystemsClass system, EDDiscoveryForm mainform)
        {
            string json;

            if (!system.HasTravelCoordinates)
                json = edsm.SetLog(system.Name, system.Time);
            else
                json = edsm.SetLogWithPos(system.Name, system.Time, system.X, system.Y, system.Z);

            if (json != null)
            {
                JObject msg = (JObject)JObject.Parse(json);

                int msgnum = msg["msgnum"].Value<int>();
                string msgstr = msg["msg"].Value<string>();

                if (msgnum == 100 || msgnum == 401 || msgnum == 402 || msgnum == 403)
                {
                    system.EDSM_sync = true;
                    system.Update();
                    return true;
                }
                else
                {
                    if (mainform!=null)
                        mainform.LogLine("EDSM sync ERROR:" + msgnum.ToString() + ":" + msgstr);

                    System.Diagnostics.Trace.WriteLine("Error sync:" + msgnum.ToString() + " : " + system.Name);
                    return false;
                }

            }
            else
                return false;
        }
Example #21
0
        public void Sync()
        {
            try
            {
                EDSMClass edsm = new EDSMClass();

                edsm.apiKey =  EDDiscoveryForm.EDDConfig.CurrentCommander.APIKey;
                edsm.commanderName = EDDiscoveryForm.EDDConfig.CurrentCommander.Name;

                //string comments =  edsm.GetComments(new DateTime(2015, 1, 1));
                List<VisitedSystemsClass> log;
                List<SystemNoteClass> notes;
                int ret = edsm.GetLogs(new DateTime(2011, 1, 1), out log);
                int nret = edsm.GetComments(new DateTime(2011, 1, 1), out notes);

                if (log == null)
                    log = new List<VisitedSystemsClass>();

                if (_syncTo)
                {
                    // Send Unsynced system to EDSM.

                    List<VisitedSystemsClass> systems = (from s in mainForm.VisitedSystems where s.EDSM_sync == false && s.Commander == EDDiscoveryForm.EDDConfig.CurrentCommander.Nr select s).ToList<VisitedSystemsClass>();
                    mainForm.LogLine("EDSM: Sending " + systems.Count.ToString() + " flightlog entries");
                    foreach (var system in systems)
                    {
                        if (Exit)
                        {
                            running = false;
                            return;
                        }

                        if ( system.EDSM_sync == false)
                        {
                            // check if it exist in EDSM
                            VisitedSystemsClass ps2 = (from c in log where c.Name == system.Name && c.Time.Ticks == system.Time.Ticks select c).FirstOrDefault<VisitedSystemsClass>();
                            if (ps2 != null)
                            {
                                system.EDSM_sync = true;
                                system.Update();

                            }
                            else
                            {
                                SendTravelLog(edsm, system, mainForm);

                            }
                        }
                    }
                }

                TravelLogUnit tlu = null;

                bool newsystem = false;
                if (_syncFrom)
                {
                    // Check for new systems from EDSM
                    foreach (var system in log)
                    {
                        VisitedSystemsClass ps2 = mainForm?.VisitedSystems == null ? null :
                            (from c in mainForm.VisitedSystems where c.Name == system.Name && c.Time.Ticks == system.Time.Ticks select c).FirstOrDefault<VisitedSystemsClass>();
                        if (ps2 == null)  // Add to local DB...
                        {
                            if (tlu == null) // If we dontt have a travellogunit yet then create it.
                            {
                                tlu = new TravelLogUnit();

                                tlu.type = 2;  // EDSM
                                tlu.Path = "https://www.edsm.net/api-logs-v1/get-logs";
                                tlu.Name = "EDSM-" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture);
                                tlu.Size = 0;

                                tlu.Add();  // Add to Database
                            }

                            VisitedSystemsClass vs = new VisitedSystemsClass();

                            vs.Source = tlu.id;
                            vs.Unit = tlu.Name;

                            vs.Name = system.Name;
                            vs.Time = system.Time;
                            vs.MapColour = _defmapcolour;
                            vs.EDSM_sync = true;
                            vs.Commander = EDDiscoveryForm.EDDConfig.CurrentCommander.Nr;

                            vs.Add();  // Add to DB;
                            System.Diagnostics.Trace.WriteLine("New from EDSM");
                            newsystem = true;

                        }
                    }

                    // Sync comments from EDSM
                    foreach (var note in notes)
                    {
                        SystemNoteClass dbnote = SystemNoteClass.GetSystemNoteClass(note.Name.ToLower());

                        if ( dbnote != null )       // if there..
                        {
                            if (note.Time > dbnote.Time)
                            {
                                dbnote.Time = note.Time;
                                dbnote.Note = note.Note;
                                dbnote.Update();
                            }
                        }
                        else
                        {
                            note.Add();
                        }
                    }
                }
                mainForm.LogLine("EDSM sync Done");

                if (newsystem)
                    OnNewEDSMTravelLog(this);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine("Exception ex:" + ex.Message);
                mainForm.LogLineHighlight("EDSM sync Exception " + ex.Message);
            }
        }
Example #22
0
 public static double Distance(VisitedSystemsClass s1, Point3D p)
 {
     return(Distance(s1, p.X, p.Y, p.Z));
 }
Example #23
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;
        }
Example #24
0
        public static List<VisitedSystemsClass> GetAll(int commander)
        {
            List<VisitedSystemsClass> list = new List<VisitedSystemsClass>();

            using (SQLiteConnectionUser cn = new SQLiteConnectionUser())
            {
                using (DbCommand cmd = cn.CreateCommand("select * from VisitedSystems where commander=@commander Order by Time "))
                {
                    cmd.AddParameterWithValue("@commander", commander);

                    DataSet ds = SQLiteDBClass.SQLQueryText(cn, cmd);
                    if (ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
                        return list;

                    foreach (DataRow dr in ds.Tables[0].Rows)
                    {
                        VisitedSystemsClass sys = new VisitedSystemsClass(dr);
                        list.Add(sys);
                    }

                    return list;
                }
            }
        }
Example #25
0
        protected bool ParseVisitedSystem(DateTime time, TimeSpan tzoffset, string line, out VisitedSystemsClass sp)
        {
            sp = new VisitedSystemsClass();

            try
            {
                Regex pattern;

                /* MKW: Use regular expressions to parse the log; much more readable and robust.
                 * Example log entry:

                From  ED  2.1 /1.6
                   {19:21:15} System:"Ooscs Fraae JR-L d8-112" StarPos:(-11609.469,639.594,20141.875)ly  NormalFlight
                string rgexpstr = "{(?<Hour>\\d+):(?<Minute>\\d+):(?<Second>\\d+)} System:\"(?<SystemName>[^\"]+)\" StarPos:\\((?<Pos>.*?)\\)ly( +(?<TravelMode>\\w+))?";

                new from beta3?
                {18:15:14} System:"Pleiades Sector HR-W d1-41" StarPos:(-83.969,-146.156,-334.219)ly Body:0 RelPos:(-1.19887e+07,-9.95573e+06,2.55124e+06)km Supercruise
                string rgexpstr = "{(?<Hour>\\d+):(?<Minute>\\d+):(?<Second>\\d+)} System:\"(?<SystemName>[^\"]+)\" StarPos:\\((?<Pos>.*?)\\)ly Body:(?<Body>\d+) StarPos:\\((?<Pos>.*?)\\)ly( +(?<TravelMode>\\w+))?";

                Pre ED 2.1/1.6
                    {09:36:16} System:0(Thuechea JE-O b11-0) Body:1 Pos:(-6.67432e+009,7.3151e+009,-1.19125e+010) Supercruise

                 * Also, please note that due to E:D bugs, these entries can be at the end of a line as well, not just on a line of their own.
                 * The RegExp below actually just finds the pattern somewhere in the line, so it caters for rubbish at the end too.
                 */

                if (line.Contains("StarPos:")) // new  ED 2.1 format
                {

                    //{(?<Hour>\d+):(?<Minute>\d+):(?<Second>\d+)} System:"(?<SystemName>[^"]+)" StarPos:\((?<Pos>.*?)\)ly( +(?<TravelMode>\w+))?
                    //{(?<Hour>\d+):(?<Minute>\d+):(?<Second>\d+)} System:"(?<SystemName>[^"]+)" StarPos:\((?<Pos>.*?)\)ly( +(?<TravelMode>\w+))?
                    //string rgexpstr = "{(?<Hour>\\d+):(?<Minute>\\d+):(?<Second>\\d+)} System:\"(?<SystemName>[^\"]+)\" StarPos:\\((?<Pos>.*?)\\)ly( +(?<TravelMode>\\w+))?";
                    string rgexpstr;

                    if (line.Contains("Body:"))
                        rgexpstr = "System:\"(?<SystemName>[^\"]+)\" StarPos:\\((?<Pos>.*?)\\)ly Body:(?<Body>\\d+) RelPos:\\((?<RelPos>.*?)\\)km( +(?<TravelMode>\\w+))?";
                    else
                        rgexpstr = "System:\"(?<SystemName>[^\"]+)\" StarPos:\\((?<Pos>.*?)\\)ly( +(?<TravelMode>\\w+))?";

                    pattern = new Regex(rgexpstr);

                    Match match = pattern.Match(line);

                    if (match != null && match.Success)
                    {
                        //sp.Nr = int.Parse(match.Groups["Body"].Value);
                        sp.Name = match.Groups["SystemName"].Value;
                        string pos = match.Groups["Pos"].Value;
                        try
                        {
                            string[] xyzpos = pos.Split(',');
                            var culture = new System.Globalization.CultureInfo("en-US");
                            sp.X = double.Parse(xyzpos[0], culture);
                            sp.Y = double.Parse(xyzpos[1], culture);
                            sp.Z = double.Parse(xyzpos[2], culture);
                        }
                        catch
                        {
                            sp.X = double.NaN;
                            sp.Y = double.NaN;
                            sp.Z = double.NaN;
                        }

                    }
                    else
                    {
                        System.Diagnostics.Trace.WriteLine("System parse error 1:" + line);
                        return false;
                    }

                }
                else
                {
                    pattern = new Regex(@"System:\d+\((?<SystemName>.*?)\) Body:(?<Body>\d+) Pos:\(.*?\)( (?<TravelMode>\w+))?");
                    Match match = pattern.Match(line);

                    if (match != null && match.Success)
                    {
                        //sp.Nr = int.Parse(match.Groups["Body"].Value);
                        sp.Name = match.Groups["SystemName"].Value;
                        sp.X = Double.NaN;
                        sp.Y = Double.NaN;
                        sp.Z = Double.NaN;
                    }
                    else
                    {
                        System.Diagnostics.Trace.WriteLine("System parse error 2:" + line);
                        return false;
                    }
                }

                sp.Time = time + tzoffset;

                return true;
            }
            catch
            {
                // MKW TODO: should we log bad lines?
                return false;
            }
        }
Example #26
0
        public bool ReadNetLogSystem(out VisitedSystemsClass vsc, Func<bool> cancelRequested = null, Stream stream = null, bool ownstream = false)
        {
            if (cancelRequested == null)
                cancelRequested = () => false;

            string line;
            try
            {
                if (stream == null)
                {
                    stream = File.Open(this.FileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                    ownstream = true;
                }
                while (!cancelRequested() && this.ReadLine(out line, stream))
                {
                    ParseLineTime(line);

                    if (line.Contains("[PG]"))
                    {
                        if (line.Contains("[PG] [Notification] Left a playlist lobby"))
                            this.CQC = false;

                        if (line.Contains("[PG] Destroying playlist lobby."))
                            this.CQC = false;

                        if (line.Contains("[PG] [Notification] Joined a playlist lobby"))
                            this.CQC = true;
                        if (line.Contains("[PG] Created playlist lobby"))
                            this.CQC = true;
                        if (line.Contains("[PG] Found matchmaking lobby object"))
                            this.CQC = true;
                    }

                    int offset = line.IndexOf("} System:") - 8;
                    if (offset >= 1 && ParseTime(line.Substring(offset, 8)) && this.CQC == false)
                    {
                        //Console.WriteLine(" RD:" + line );
                        if (line.Contains("ProvingGround"))
                            continue;

                        VisitedSystemsClass ps;
                        if (ParseVisitedSystem(this.LastLogTime, this.TimeZoneOffset, line.Substring(offset + 10), out ps))
                        {   // Remove some training systems
                            if (ps.Name.Equals("Training"))
                                continue;
                            if (ps.Name.Equals("Destination"))
                                continue;
                            if (ps.Name.Equals("Altiris"))
                                continue;
                            ps.Source = TravelLogUnit.id;
                            ps.Unit = TravelLogUnit.Name;
                            vsc = ps;
                            return true;
                        }
                    }
                }
            }
            finally
            {
                if (ownstream)
                {
                    stream.Dispose();
                }
            }

            vsc = null;
            return false;
        }
Example #27
0
        public static VisitedSystemsClass GetLast()
        {
            List<VisitedSystemsClass> list = new List<VisitedSystemsClass>();

            using (SQLiteConnectionUser cn = new SQLiteConnectionUser())
            {
                using (DbCommand cmd = cn.CreateCommand("select * from VisitedSystems Order by Time DESC Limit 1"))
                {
                    DataSet ds = SQLiteDBClass.SQLQueryText(cn, cmd);
                    if (ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
                    {
                        return null;
                    }

                    VisitedSystemsClass sys = new VisitedSystemsClass(ds.Tables[0].Rows[0]);
                    return sys;
                }
            }
        }
Example #28
0
        public List<SystemPosition> ParseFiles(RichTextBox richTextBox_History, int defaultMapColour, int commander)
        {
            string datapath;
            datapath = GetNetLogPath();

            if (datapath == null)
            {
                AppendText(richTextBox_History, "Netlog directory not found!" + Environment.NewLine + "Specify location in settings tab" + Environment.NewLine, Color.Red);
                return null;
            }
            DirectoryInfo dirInfo = new DirectoryInfo(datapath);

            if (!Directory.Exists(datapath))   // if logfiles directory is not found
            {
                if (richTextBox_History != null)
                {
                    richTextBox_History.Clear();
                    AppendText(richTextBox_History, "Netlog directory not found!" + Environment.NewLine + "Specify location in settings tab" + Environment.NewLine, Color.Red);
                    //MessageBox.Show("Netlog directory not found!" + Environment.NewLine + "Specify location in settings tab", "EDDiscovery Error", MessageBoxButtons.OK);
                }
                return null;
            }

            // Get TravelLogUnits;

            tlUnits =  TravelLogUnit.GetAll();

            List<VisitedSystemsClass> vsSystemsList = VisitedSystemsClass.GetAll(commander);

            visitedSystems.Clear();
            // Add systems in local DB.
            if (vsSystemsList != null)
                foreach (VisitedSystemsClass vs in vsSystemsList)
                {
                    if (visitedSystems.Count==0)
                        visitedSystems.Add(new SystemPosition(vs));
                    else if (!visitedSystems.Last<SystemPosition>().Name.Equals(vs.Name))  // Avoid duplicate if times exist in same system from different files.
                        visitedSystems.Add(new SystemPosition(vs));
                }

            FileInfo[] allFiles = dirInfo.GetFiles("netLog.*.log", SearchOption.AllDirectories).OrderBy(p => p.Name).ToArray();

            NoEvents = true;

            foreach (FileInfo fi in allFiles)
            {
                TravelLogUnit lu = null;
                bool parsefile = true;

                if (fi.Name.Equals("netLog.1510280152.01.log"))
                    parsefile = true;

                // Check if we alreade have parse the file and stored in DB.
                if (tlUnits!=null)
                    lu= (from c in tlUnits where c.Name == fi.Name select c).FirstOrDefault<TravelLogUnit>();

                if (lu != null)
                {
                    if (lu.Size == fi.Length)  // File is already in DB:
                        parsefile = false;
                }
                else
                {
                    lu = new TravelLogUnit();
                    lu.Name = fi.Name;
                    lu.Path = Path.GetDirectoryName(fi.FullName);
                    lu.Size = 0;  // Add real size after data is in DB //;(int)fi.Length;
                    lu.type = 1;
                    lu.Add();
                }

                if (parsefile)
                {
                    int nr = 0;
                    List<SystemPosition> tempVisitedSystems = new List<SystemPosition>();
                    ParseFile(fi, tempVisitedSystems);

                    foreach (SystemPosition ps in tempVisitedSystems)
                    {
                        SystemPosition ps2;
                        ps2 = (from c in visitedSystems where c.Name == ps.Name && c.time == ps.time select c).FirstOrDefault<SystemPosition>();
                        if (ps2 == null)
                        {
                            VisitedSystemsClass dbsys = new VisitedSystemsClass();

                            dbsys.Name = ps.Name;
                            dbsys.Time = ps.time;
                            dbsys.Source = lu.id;
                            dbsys.EDSM_sync = false;
                            dbsys.Unit = fi.Name;
                            dbsys.MapColour = defaultMapColour;

                            if (!lu.Beta)  // dont store  history in DB for beta (YET)
                            {
                                dbsys.Add();
                                nr++;
                            }
                            visitedSystems.Add(ps);
                        }

                    }

                    lu.Size = (int)fi.Length;
                    lu.Update();
                    AppendText(richTextBox_History, fi.Name + " " + nr.ToString() + " added to local database." + Environment.NewLine, Color.Black);
                }
            }
            NoEvents = false;

            //var result = visitedSystems.OrderByDescending(a => a.time).ToList<SystemPosition>();

            return visitedSystems;
        }
Example #29
0
        public int GetLogs(DateTime starttime, out List<VisitedSystemsClass> log)
        {
            log = new List<VisitedSystemsClass>();

            string query = "get-logs?startdatetime=" + HttpUtility.UrlEncode(starttime.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture)) + "&apiKey=" + apiKey + "&commanderName=" + HttpUtility.UrlEncode(commanderName);
            //string query = "get-logs?apiKey=" + apiKey + "&commanderName=" + HttpUtility.UrlEncode(commanderName);
            var response = RequestGet("api-logs-v1/" + query);
            var json = response.Body;

            if (json == null)
                return 0;

            JObject msg = JObject.Parse(json);
            int msgnr = msg["msgnum"].Value<int>();

            JArray logs = (JArray)msg["logs"];

            if (logs != null)
            {
                foreach (JObject jo in logs)
                {
                    VisitedSystemsClass pos = new VisitedSystemsClass();

                    pos.Name = jo["system"].Value<string>();
                    string str = jo["date"].Value<string>();

                    pos.Time = DateTime.ParseExact(str, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal).ToLocalTime();

                    log.Add(pos);

                }
            }

            return msgnr;
        }
Example #30
0
        private void NetLogMain()
        {
            try
            {
                m_Watcher = new System.IO.FileSystemWatcher();

                if (Directory.Exists(GetNetLogPath()))
                {
                    m_Watcher.Path = GetNetLogPath() + "\\";
                    m_Watcher.Filter = "netLog*.log";
                    m_Watcher.IncludeSubdirectories = true;
                    m_Watcher.NotifyFilter = NotifyFilters.FileName; // | NotifyFilters.Size;

                    m_Watcher.Changed += new FileSystemEventHandler(OnChanged);
                    m_Watcher.Created += new FileSystemEventHandler(OnChanged);
                    m_Watcher.Deleted += new FileSystemEventHandler(OnChanged);
                    m_Watcher.EnableRaisingEvents = true;
                }
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("Net log watcher exception : " + ex.Message, "EDDiscovery Error");
                System.Diagnostics.Trace.WriteLine("NetlogMAin exception : " + ex.Message);
                System.Diagnostics.Trace.WriteLine(ex.StackTrace);

            }

            List<TravelLogUnit> travelogUnits;
            // Get TravelLogUnits;
            travelogUnits = null;
            TravelLogUnit  tlUnit=null;
            SQLiteDBClass db = new SQLiteDBClass();

            int ii =0;

            while (!Exit)
            {
                try
                {

                    ii++;
                    Thread.Sleep(2000);

                    EliteDangerous.CheckED();

                    if (NoEvents == false)
                    {
                        if (lastnfi != null)
                        {
                            FileInfo fi = new FileInfo(lastnfi.FileName);

                            if (fi.Length != lastnfi.fileSize || ii % 5 == 0)
                            {
                                if (tlUnit == null || !tlUnit.Name.Equals(Path.GetFileName(lastnfi.FileName)))  // Create / find new travellog unit
                                {
                                    travelogUnits = TravelLogUnit.GetAll();
                                    // Check if we alreade have parse the file and stored in DB.
                                    if (tlUnit == null)
                                        tlUnit = (from c in travelogUnits where c.Name == fi.Name select c).FirstOrDefault<TravelLogUnit>();

                                    if (tlUnit == null)
                                    {
                                        tlUnit = new TravelLogUnit();
                                        tlUnit.Name = fi.Name;
                                        tlUnit.Path = Path.GetDirectoryName(fi.FullName);
                                        tlUnit.Size = 0;  // Add real size after data is in DB //;(int)fi.Length;
                                        tlUnit.type = 1;
                                        tlUnit.Add();
                                        travelogUnits.Add(tlUnit);
                                    }
                                }

                                int nrsystems = visitedSystems.Count;
                                ParseFile(fi, visitedSystems);
                                if (nrsystems < visitedSystems.Count) // Om vi har fler system
                                {
                                    System.Diagnostics.Trace.WriteLine("New systems " + nrsystems.ToString() + ":" + visitedSystems.Count.ToString());
                                    for (int nr = nrsystems; nr < visitedSystems.Count; nr++)  // Lägg till nya i locala databaslogen
                                    {
                                        VisitedSystemsClass dbsys = new VisitedSystemsClass();

                                        dbsys.Name = visitedSystems[nr].Name;
                                        dbsys.Time = visitedSystems[nr].time;
                                        dbsys.Source = tlUnit.id;
                                        dbsys.EDSM_sync = false;
                                        dbsys.Unit = fi.Name;
                                        dbsys.MapColour = db.GetSettingInt("DefaultMap", Color.Red.ToArgb());
                                        dbsys.Unit = fi.Name;

                                        if (!tlUnit.Beta)  // dont store  history in DB for beta (YET)
                                        {
                                            dbsys.Add();
                                        }
                                        visitedSystems[nr].vs = dbsys;
                                    }
                                }
                                else
                                {
                                    //System.Diagnostics.Trace.WriteLine("No change");
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Trace.WriteLine("NetlogMAin exception : " + ex.Message);
                    System.Diagnostics.Trace.WriteLine(ex.StackTrace);
                }

            }
        }