public override void LoadLayout() { DateTime firstofmonth = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1); curmonth = SQLiteConnectionUser.GetSettingDate(DbDateSave, firstofmonth); string daynames = "Sun;Mon;Tue;Wed;Thu;Fri;Sat".T(EDTx.CaptainsLogDiary_Daysofweek); string[] daynamesplit = daynames.Split(';'); for (int i = 0; i < 7; i++) { Label lb = new Label(); lb.Text = daynamesplit[i]; lb.TextAlign = ContentAlignment.MiddleCenter; daynameslabels[i] = lb; Controls.Add(lb); } for (int i = 1; i <= 31; i++) { ExtendedControls.ExtButton b = new ExtendedControls.ExtButton(); b.Click += DayClick; Controls.Add(b); daybuttons[i - 1] = b; } layoutdone = true; }
public override void Init() { searchtimer = new Timer() { Interval = 500 }; searchtimer.Tick += Searchtimer_Tick; GlobalCaptainsLogList.Instance.OnLogEntryChanged += LogChanged; BaseUtils.Translator.Instance.Translate(this, new Control[] { }); BaseUtils.Translator.Instance.Translate(contextMenuStrip, this); BaseUtils.Translator.Instance.Translate(toolTip, this); ColNote.DefaultCellStyle.WrapMode = DataGridViewTriState.True; dataGridView.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells; dataGridView.DefaultCellStyle.Alignment = DataGridViewContentAlignment.TopLeft; dateTimePickerStartDate.Value = SQLiteConnectionUser.GetSettingDate(DbStartDate, new DateTime(2014, 12, 14)); dateTimePickerStartDate.Checked = SQLiteConnectionUser.GetSettingBool(DbStartDateOn, false); dateTimePickerEndDate.Value = SQLiteConnectionUser.GetSettingDate(DbEndDate, new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day)); dateTimePickerEndDate.Checked = SQLiteConnectionUser.GetSettingBool(DbEndDateOn, false); dateTimePickerStartDate.ValueChanged += (s, e) => { if (!updateprogramatically) { Display(); } }; dateTimePickerEndDate.ValueChanged += (s, e) => { if (!updateprogramatically) { Display(); } }; discoveryform.OnRefreshCommanders += Discoveryform_OnRefreshCommanders; }
private void FetcherThreadProc() { Trace.WriteLine($"EDSM Thread logs start"); DateTime lastCommentFetch = DateTime.MinValue; int waittime = 1000; // initial waittime, will be reestimated later DateTime curtime = DateTime.UtcNow; KeyName(out string latestdatekeyname, out string oldestdatekeyname); while (!ExitRequested.WaitOne(waittime)) { if (ExitRequested.WaitOne(0)) { return; } EDSMClass edsm = new EDSMClass(Commander); // logic checked 21/12/2018 RJP if (edsm.ValidCredentials && Commander.SyncFromEdsm) { if (DateTime.UtcNow > lastCommentFetch.AddHours(1)) { edsm.GetComments(l => Trace.WriteLine(l)); lastCommentFetch = DateTime.UtcNow; } DateTime latestentry = SQLiteConnectionUser.GetSettingDate(latestdatekeyname, GammaStart); // lastest entry DateTime oldestentry = SQLiteConnectionUser.GetSettingDate(oldestdatekeyname, DateTime.UtcNow); // oldest entry DateTime logstarttime = DateTime.MinValue; // return what we got.. DateTime logendtime = DateTime.MinValue; List <JournalFSDJump> edsmlogs = null; BaseUtils.ResponseData response = default(BaseUtils.ResponseData); int res = -1; if (DateTime.UtcNow.Subtract(latestentry).TotalMinutes >= EDSMMaxLogAgeMinutes) // is latest entry old? { DateTime askfor = DateTime.UtcNow; System.Diagnostics.Debug.WriteLine("Fetch latest since Curtime > lastestentry + gap " + askfor.ToStringZulu()); res = edsm.GetLogs(null, askfor, out edsmlogs, out logstarttime, out logendtime, out response); //res = 100; logstarttime = askfor.AddDays(-7); logendtime = askfor; // debug it } else if (oldestentry > GammaStart) // if oldest entry younger than gamma? { System.Diagnostics.Debug.WriteLine("Go back in time to gamma "); res = edsm.GetLogs(null, oldestentry, out edsmlogs, out logstarttime, out logendtime, out response); //res = 100; logstarttime = oldestentry.AddDays(-7); logendtime = oldestentry; // debug it } if (res == 100) // hunky dory - note if Anthor faults, we just retry again and again { System.Diagnostics.Debug.WriteLine("Data stored from " + oldestentry.ToStringZulu() + " -> " + latestentry.ToStringZulu()); System.Diagnostics.Debug.WriteLine("Process logs from " + logstarttime.ToStringZulu() + " => " + logendtime.ToStringZulu()); if (edsmlogs != null && edsmlogs.Count > 0) // if anything to process.. { Process(edsmlogs, logstarttime, logendtime); } if (logendtime > latestentry) { SQLiteConnectionUser.PutSettingDate(latestdatekeyname, logendtime); } if (logstarttime < oldestentry) { SQLiteConnectionUser.PutSettingDate(oldestdatekeyname, logstarttime); } } else if (res != -1) { System.Diagnostics.Debug.WriteLine("EDSM Log request rejected with " + res); } if (response.Headers != null && response.Headers["X-Rate-Limit-Limit"] != null && response.Headers["X-Rate-Limit-Remaining"] != null && response.Headers["X-Rate-Limit-Reset"] != null && Int32.TryParse(response.Headers["X-Rate-Limit-Limit"], out int ratelimitlimit) && Int32.TryParse(response.Headers["X-Rate-Limit-Remaining"], out int ratelimitremain) && Int32.TryParse(response.Headers["X-Rate-Limit-Reset"], out int ratelimitreset)) { if (ratelimitremain < ratelimitlimit * 2 / 4) // lets keep at least X remaining for other purposes later.. { waittime = 1000 * ratelimitreset / (ratelimitlimit - ratelimitremain); // slow down to its pace now.. example 878/(360-272) = 10 seconds per quota } else { waittime = 1000; // 1 second so we don't thrash } System.Diagnostics.Debug.WriteLine("EDSM Log Delay Parameters {0} {1} {2} => {3}ms", ratelimitlimit, ratelimitremain, ratelimitreset, waittime); } } } }