public TravelHistoryControl()
 {
     InitializeComponent();
     static_richTextBox = richTextBox_History;
     edsc = new EDSCClass();
 }
        private void SubmitToEDSC()
        {
            var travelHistoryControl = _discoveryForm.TravelControl;
            string commanderName = travelHistoryControl.GetCommanderName();

            if (string.IsNullOrEmpty(commanderName))
            {
                MessageBox.Show("Please enter commander name before submitting the system!");
                UnfreezeTrilaterationUI();
                return;
            }

            var distances = new Dictionary<string, double>();
            foreach (var item in lastTrilatelationEntries)
            {
                var system = item.Key;
                var entry = item.Value;
                distances.Add(system.name, entry.Distance);
            }

            var edsc = new EDSCClass();
            var edsm = new EDSMClass();
            //if (!EDSCClass.UseTest)
            //{
            //    Invoke((MethodInvoker) delegate
            //    {
            //        // TODO temporarily mess with EDSC in test mode only
            //        LogText("Forcibly switching to EDSC UseTest mode." + Environment.NewLine, Color.OrangeRed);
            //    });
            //    EDSCClass.UseTest = true;
            //}

            var responseC = edsc.SubmitDistances(commanderName, TargetSystem.name, distances);
            var responseM = edsm.SubmitDistances(commanderName, TargetSystem.name, distances);

            Console.WriteLine(responseC);
            Console.WriteLine(responseM);

            string infoC, infoM;
            bool trilaterationOkC;
            bool trilaterationOkM;
            var responseOkC = edsc.ShowDistanceResponse(responseC, out infoC);
            var responseOkM = edsm.ShowDistanceResponse(responseM, out infoM, out trilaterationOkM);

            trilaterationOkC = infoC.IndexOf("Trilateration succesful") != -1; // FIXME this is ugly
            Console.WriteLine(infoC);

            Invoke((MethodInvoker) delegate
            {
                if (responseOkC && trilaterationOkC)
                {
                    LogText("EDSC submission succeeded, trilateration successful." + Environment.NewLine, Color.Green);
                }
                else if (responseOkC)
                {
                    LogText("EDSC submission succeeded, but trilateration failed. Try adding more distances." + Environment.NewLine, Color.Orange);
                }
                else
                {
                    LogText("EDSC submission failed." + Environment.NewLine, Color.Red);
                }

                if (responseOkM && trilaterationOkM)
                {
                    LogText("EDSM submission succeeded, trilateration successful." + Environment.NewLine, Color.Green);
                }
                else if (responseOkM)
                {
                    LogText("EDSM submission succeeded, but trilateration failed. Try adding more distances." + Environment.NewLine, Color.Orange);
                }
                else
                {
                    LogText("EDSM submission failed." + Environment.NewLine, Color.Red);
                }

            });

            if (responseOkC && trilaterationOkC)
            {
                Invoke((MethodInvoker) delegate
                {
                    //Visible = false;
                    travelHistoryControl.TriggerEDSCRefresh(); // TODO we might eventually avoid this by further parsing EDSC response
                    travelHistoryControl.RefreshHistory();
                });
            }
            else
            {
                Invoke((MethodInvoker) UnfreezeTrilaterationUI);
                lastTrilatelationResult = null;
                lastTrilatelationEntries = null;
            }
        }
        private void button2_Click(object sender, EventArgs e)
        {
            EDSCClass edsc = new EDSCClass();

            //string json = edsc.SubmitDistances("Finwen", "19 Geminorum", "HIP 30687", (float)19.26);

            FormMap map2 = new FormMap();
            map2.visitedSystems = visitedSystems;
            map2.Show();
        }
        private void buttonSync_Click(object sender, EventArgs e)
        {
            if (textBoxCmdrName.Text.Equals(""))
            {
                MessageBox.Show("Please enter commander name before sending distances!");
                return;
            }

            var dists = from p in SQLiteDBClass.globalDistances where p.Status == DistancsEnum.EDDiscovery  orderby p.CreateTime  select p;

            EDSCClass edsc = new EDSCClass();

            foreach (var dist in dists)
            {
                string json;

                if (dist.Dist > 0)
                {
                    LogText("Add distance: " + dist.NameA + " => " + dist.NameB + " :" + dist.Dist.ToString("0.00") + "ly" + Environment.NewLine);
                    json = edsc.SubmitDistances(textBoxCmdrName.Text, dist.NameA, dist.NameB, dist.Dist);
                }
                else
                {
                    dist.Delete();
                    return;
                }
                if (json != null)
                {
                    string str="";
                    if (edsc.ShowDistanceResponse(json, out str))
                    {
                        LogText(str);
                        dist.Status = DistancsEnum.EDDiscoverySubmitted;
                        dist.Update();
                    }
                    else
                    {
                        LogText(str);
                    }
                }
            }
        }
 public void InitControl(EDDiscoveryForm discoveryForm)
 {
     _discoveryForm = discoveryForm;
     edsc           = new EDSCClass(); // Init here to avoid UI editor errors.
 }
        private void GetEDSCDistances()
        {
            try
            {
                SQLiteDBClass db = new SQLiteDBClass();
                EDSCClass edsc = new EDSCClass();
                string lstdist = db.GetSettingString("EDSCLastDist", "2010-01-01 00:00:00");
                string json;

                // Get distances
                string rwdisttime = db.GetSettingString("RWLastDist", "2000-01-01 00:00:00"); // Latest time from RW file.
                string rwdistfiletime = "";
                lstdist = db.GetSettingString("EDSCLastDist", "2010-01-01 00:00:00");
                List<DistanceClass> dists = new List<DistanceClass>();

                json = LoadJsonArray(fileTgcDistances);
                dists = DistanceClass.ParseEDSC(json, ref rwdistfiletime);

                if (!rwdisttime.Equals(rwdistfiletime))  // New distance file from Redwizzard
                {
                    DistanceClass.Delete(DistancsEnum.EDSC); // Remove all EDSC distances.
                    lstdist = "2010-01-01 00:00:00";
                    db.PutSettingString("RWLastDist", rwdistfiletime);
                }

                if (lstdist.Equals("2010-01-01 00:00:00"))
                {
                    LogText("Adding data from tgcdistances.json " + Environment.NewLine);

                    lstdist = rwdistfiletime;

                    if (json == null)
                        LogText("Couldn't read file." + Environment.NewLine);

                    else
                    {
                        LogText("Found " + dists.Count.ToString() + " new distances." + Environment.NewLine);

                        DistanceClass.Store(dists);
                        db.PutSettingString("EDSCLastDist", lstdist);
                    }

                }

                LogText("Checking for new distances from EDSC. ");

                Application.DoEvents();
                json = edsc.RequestDistances(lstdist);

                dists = new List<DistanceClass>();
                dists = DistanceClass.ParseEDSC(json, ref lstdist);

                if (json == null)
                    LogText("No response from server." + Environment.NewLine);

                else
                    LogText("Found " + dists.Count.ToString() + " new distances." + Environment.NewLine);

                Application.DoEvents();
                DistanceClass.Store(dists);
                db.PutSettingString("EDSCLastDist", lstdist);
                db.GetAllDistances();
                OnDistancesLoaded();

                // Check for a new installer
                CheckForNewInstaller();

            }
            catch (Exception ex)
            {
                LogText("GetEDSCDistances exception:" + ex.Message + Environment.NewLine);

            }
        }
 public void InitControl(EDDiscoveryForm discoveryForm)
 {
     _discoveryForm = discoveryForm;
     edsc = new EDSCClass();  // Init here to avoid UI editor errors.
 }
示例#8
0
        private void SubmitToEDSC()
        {
            var    travelHistoryControl = _discoveryForm.TravelControl;
            string commanderName        = travelHistoryControl.GetCommanderName();

            if (string.IsNullOrEmpty(commanderName))
            {
                MessageBox.Show("Please enter commander name before submitting the system!");
                UnfreezeTrilaterationUI();
                return;
            }

            var distances = new Dictionary <string, double>();

            foreach (var item in lastTrilatelationEntries)
            {
                var system = item.Key;
                var entry  = item.Value;
                distances.Add(system.name, entry.Distance);
            }

            var edsc = new EDSCClass();
            var edsm = new EDSMClass();
            //if (!EDSCClass.UseTest)
            //{
            //    Invoke((MethodInvoker) delegate
            //    {
            //        // TODO temporarily mess with EDSC in test mode only
            //        LogText("Forcibly switching to EDSC UseTest mode." + Environment.NewLine, Color.OrangeRed);
            //    });
            //    EDSCClass.UseTest = true;
            //}

            var responseC = edsc.SubmitDistances(commanderName, TargetSystem.name, distances);
            var responseM = edsm.SubmitDistances(commanderName, TargetSystem.name, distances);

            Console.WriteLine(responseC);
            Console.WriteLine(responseM);

            string infoC, infoM;
            bool   trilaterationOkC;
            bool   trilaterationOkM;
            var    responseOkC = edsc.ShowDistanceResponse(responseC, out infoC);
            var    responseOkM = edsm.ShowDistanceResponse(responseM, out infoM, out trilaterationOkM);

            trilaterationOkC = infoC.IndexOf("Trilateration succesful") != -1; // FIXME this is ugly
            Console.WriteLine(infoC);

            Invoke((MethodInvoker) delegate
            {
                if (responseOkC && trilaterationOkC)
                {
                    LogText("EDSC submission succeeded, trilateration successful." + Environment.NewLine, Color.Green);
                }
                else if (responseOkC)
                {
                    LogText("EDSC submission succeeded, but trilateration failed. Try adding more distances." + Environment.NewLine, Color.Orange);
                }
                else
                {
                    LogText("EDSC submission failed." + Environment.NewLine, Color.Red);
                }

                if (responseOkM && trilaterationOkM)
                {
                    LogText("EDSM submission succeeded, trilateration successful." + Environment.NewLine, Color.Green);
                }
                else if (responseOkM)
                {
                    LogText("EDSM submission succeeded, but trilateration failed. Try adding more distances." + Environment.NewLine, Color.Orange);
                }
                else
                {
                    LogText("EDSM submission failed." + Environment.NewLine, Color.Red);
                }
            });

            if (responseOkC && trilaterationOkC)
            {
                Invoke((MethodInvoker) delegate
                {
                    //Visible = false;
                    travelHistoryControl.TriggerEDSCRefresh(); // TODO we might eventually avoid this by further parsing EDSC response
                    travelHistoryControl.RefreshHistory();
                });
            }
            else
            {
                Invoke((MethodInvoker)UnfreezeTrilaterationUI);
                lastTrilatelationResult  = null;
                lastTrilatelationEntries = null;
            }
        }
示例#9
0
        private void GetEDSCSystems()
        {
            try
            {
                SQLiteDBClass db = new SQLiteDBClass();
                EDSCClass edsc = new EDSCClass();

                string json;

                string rwsystime = db.GetSettingString("RWLastSystems", "2000-01-01 00:00:00"); // Latest time from RW file.
                string rwsysfiletime = "";

                CommanderName = db.GetSettingString("CommanderName", "");
                Invoke((MethodInvoker) delegate {
                    travelHistoryControl1.textBoxCmdrName.Text = CommanderName;
                });

                json = LoadJsonArray(fileTgcSystems);
                List<SystemClass> systems = SystemClass.ParseEDSC(json, ref rwsysfiletime);

                if (!rwsystime.Equals(rwsysfiletime))  // New distance file from Redwizzard
                {
                    SystemClass.Delete(SystemStatusEnum.EDSC); // Remove all EDSC systems.

                    db.PutSettingString("RWLastSystems", rwsysfiletime);
                    db.PutSettingString("EDSCLastSystems", rwsysfiletime);
                    Invoke((MethodInvoker) delegate {
                        TravelHistoryControl.LogText("Adding data from tgcsystems.json " + Environment.NewLine);
                    });
                    SystemClass.Store(systems);
                    EDDBClass eddb = new EDDBClass();
                    DBUpdateEDDB(eddb);
                }

                string retstr = edsc.EDSCGetNewSystems(db);
                Invoke((MethodInvoker)delegate
                {
                    TravelHistoryControl.LogText(retstr);
                });

                db.GetAllSystemNotes();
                db.GetAllSystems();

                SystemNames.Clear();
                foreach (SystemClass system in SystemData.SystemList)
                {
                    SystemNames.Add(system.name);
                }

            }
            catch (Exception ex)
            {
                Invoke((MethodInvoker) delegate {
                    TravelHistoryControl.LogText("GetEDSCSystems exception:" + ex.Message + Environment.NewLine);
                });
            }
        }