private void buttonUpdate_Click(object sender, EventArgs e) { var dist = DistanceAsDouble(textBoxDistance.Text.Trim()); if (!dist.HasValue) { MessageBox.Show("Distance in wrong format!"); } else { DistanceClass distance = new DistanceClass(); distance.Dist = dist.Value; distance.CreateTime = DateTime.UtcNow; distance.CommanderCreate = EDDiscoveryForm.EDDConfig.CurrentCommander.Name.Trim(); distance.NameA = textBoxSystem.Text; distance.NameB = textBoxPrevSystem.Text; distance.Status = DistancsEnum.EDDiscovery; distance.Store(); SQLiteDBClass.AddDistanceToCache(distance); if (dataGridViewTravel.SelectedCells.Count > 0) // if we have selected (we should!) { dataGridViewTravel.Rows[dataGridViewTravel.SelectedCells[0].OwningRow.Index].Cells[2].Value = textBoxDistance.Text.Trim(); } } }
private void buttonUpdate_Click(object sender, EventArgs e) { var dist = DistanceAsDouble(textBoxDistance.Text.Trim()); if (!dist.HasValue) { MessageBox.Show("Distance in wrong format!"); } else { DistanceClass distance = new DistanceClass(); distance.Dist = dist.Value; distance.CreateTime = DateTime.UtcNow; distance.CommanderCreate = textBoxCmdrName.Text.Trim(); distance.NameA = textBoxSystem.Text; distance.NameB = textBoxPrevSystem.Text; distance.Status = DistancsEnum.EDDiscovery; distance.Store(); SQLiteDBClass.AddDistanceToCache(distance); dataGridView1.Rows[lastRowIndex].Cells[2].Value = textBoxDistance.Text.Trim(); } }
internal void NewPosition(object source) { try { string name = netlog.visitedSystems.Last().Name; Invoke((MethodInvoker) delegate { LogText("Arrived to system: "); SystemClass sys1 = SystemData.GetSystem(name); if (sys1 == null || sys1.HasCoordinate == false) { LogTextHighlight(name); } else { LogText(name); } int count = GetVisitsCount(name); LogText(" : Vist nr " + count.ToString() + Environment.NewLine); System.Diagnostics.Trace.WriteLine("Arrived to system: " + name + " " + count.ToString() + ":th visit."); var result = visitedSystems.OrderByDescending(a => a.time).ToList <SystemPosition>(); //if (TrilaterationControl.Visible) //{ // CloseTrilateration(); // MessageBox.Show("You have arrived to another system while trilaterating." // + " As a pre-caution to prevent any mistakes with submitting wrong systems or distances" // + ", your trilateration was aborted."); //} SystemPosition item = result[0]; SystemPosition item2; if (result.Count > 1) { item2 = result[1]; } else { item2 = null; } // grab distance to next (this) system textBoxDistanceToNextSystem.Enabled = false; if (textBoxDistanceToNextSystem.Text.Length > 0 && item2 != null) { SystemClass currentSystem = null, previousSystem = null; SystemData.SystemList.ForEach(s => { if (s.name == item.Name) { currentSystem = s; } if (s.name == item2.Name) { previousSystem = s; } }); if (currentSystem == null || previousSystem == null || !currentSystem.HasCoordinate || !previousSystem.HasCoordinate) { var presetDistance = DistanceAsDouble(textBoxDistanceToNextSystem.Text.Trim(), 45); if (presetDistance.HasValue) { var distance = new DistanceClass { Dist = presetDistance.Value, CreateTime = DateTime.UtcNow, CommanderCreate = EDDiscoveryForm.EDDConfig.CurrentCommander.Name, NameA = item.Name, NameB = item2.Name, Status = DistancsEnum.EDDiscovery }; Console.Write("Pre-set distance " + distance.NameA + " -> " + distance.NameB + " = " + distance.Dist); distance.Store(); SQLiteDBClass.AddDistanceToCache(distance); } } } textBoxDistanceToNextSystem.Clear(); textBoxDistanceToNextSystem.Enabled = true; AddHistoryRow(true, item, item2); StoreSystemNote(); }); } catch (Exception ex) { System.Diagnostics.Trace.WriteLine("Exception NewPosition: " + ex.Message); System.Diagnostics.Trace.WriteLine("Trace: " + ex.StackTrace); } }
private void GetEDSCDistances() { try { SQLiteDBClass db = new SQLiteDBClass(); //EDSCClass edsc = new EDSCClass(); EDSMClass edsm = new EDSMClass(); 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 EDSM. "); Application.DoEvents(); json = edsm.RequestDistances(lstdist); dists = new List <DistanceClass>(); dists = DistanceClass.ParseEDSM(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); } }
private void GetEDSMDistances() { try { if (EDDConfig.UseDistances) { EDSMClass edsm = new EDSMClass(); EDDBClass eddb = new EDDBClass(); string lstdist = _db.GetSettingString("EDSCLastDist", "2010-01-01 00:00:00"); string json; // Get distances lstdist = _db.GetSettingString("EDSCLastDist", "2010-01-01 00:00:00"); List <DistanceClass> dists = new List <DistanceClass>(); if (lstdist.Equals("2010-01-01 00:00:00")) { LogText("Downloading mirrored EDSM distance data. (Might take some time)" + Environment.NewLine); eddb.GetEDSMDistances(); json = LoadJsonFile(_fileEDSMDistances); if (json != null) { LogText("Adding mirrored EDSM distance data." + Environment.NewLine); dists = new List <DistanceClass>(); dists = DistanceClass.ParseEDSM(json, ref lstdist); LogText("Found " + dists.Count.ToString() + " distances." + Environment.NewLine); Application.DoEvents(); DistanceClass.Store(dists); _db.PutSettingString("EDSCLastDist", lstdist); } } LogText("Checking for new distances from EDSM. "); Application.DoEvents(); json = edsm.RequestDistances(lstdist); dists = new List <DistanceClass>(); dists = DistanceClass.ParseEDSM(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(EDDConfig.UseDistances); // Load user added distances updateMapData(); OnDistancesLoaded(); GC.Collect(); } catch (Exception ex) { LogText("GetEDSMDistances exception:" + ex.Message + Environment.NewLine); LogText(ex.StackTrace + Environment.NewLine); } }