public static void RunLoadAsync(object background) { if (!IsReady) { return; } if ((bool)background) { bool back = System.Threading.ThreadPool.QueueUserWorkItem(RunLoadAsync, false); if (back) { return; } } try { IsReady = false; //initialize global values problemList = new List <ProblemInfo>(); problemId = new SortedDictionary <long, long>(); problemNum = new SortedDictionary <long, ProblemInfo>(); categoryRoot = new CategoryNode("Root", "All Categories"); //get object data from json data string text = File.ReadAllText(LocalDirectory.GetProblemInfoFile()); var data = JsonConvert.DeserializeObject <List <List <object> > >(text); if (data == null || data.Count == 0) { throw new NullReferenceException("Problem database was empty"); } //load all lists from object data LoadList(data); LoadOthers(); data.Clear(); IsAvailable = true; } catch (Exception ex) { Logger.Add(ex.Message, "Problem Database|RunLoadAsync()"); if (!IsAvailable) { Internet.Downloader.DownloadProblemDatabase(); } } //load categories LoadCategories(); //load default user LoadDefaultUser(); IsReady = true; Interactivity.CategoryDataUpdated(); Interactivity.ProblemDatabaseUpdated(); }
public static bool UpdateAll() { const double PROBLEM_ALIVE_DAY = 1; const double USER_SUB_ALIVE_DAY = 0.5; bool result = true; //if database file is too old redownload string file = LocalDirectory.GetProblemInfoFile(); if (LocalDirectory.GetFileSize(file) < 100 || (new TimeSpan( DateTime.Now.Ticks - new FileInfo(file).LastWriteTime.Ticks ).TotalDays > PROBLEM_ALIVE_DAY)) { UVA_Arena.Internet.Downloader.DownloadProblemDatabase(); result = false; } //update user submissions if not available if (LocalDatabase.ContainsUser(RegistryAccess.DefaultUsername)) { file = LocalDirectory.GetUserSubPath(RegistryAccess.DefaultUsername); if (LocalDirectory.GetFileSize(file) < 50 || (new TimeSpan( DateTime.Now.Ticks - new FileInfo(file).LastWriteTime.Ticks ).TotalDays > USER_SUB_ALIVE_DAY)) { long sid = 0; if (LocalDatabase.DefaultUser != null) { sid = LocalDatabase.DefaultUser.LastSID; } UVA_Arena.Internet.Downloader.DownloadDefaultUserInfo(sid); } } //download category index if too old UVA_Arena.Internet.Downloader.DownloadCategoryIndex(); return(result); }
private void DelayInitialize(object background) { //run in background if ((bool)background) { this.Cursor = Cursors.AppStarting; System.Threading.ThreadPool.QueueUserWorkItem(DelayInitialize, false); return; } //load problem database LocalDatabase.RunLoadAsync(false); //load controls bool _initialized = false; this.BeginInvoke((MethodInvoker) delegate { //add controls AddControls(); //add buttons to the top right beside control buttons //AddActiveButtons(); _initialized = true; this.Cursor = Cursors.Default; Logger.Add("Initialized all controls", "Main Form"); loadingPanel.Visible = false; }); //update problem database if not available if (LocalDirectory.GetFileSize(LocalDirectory.GetProblemInfoFile()) < 100) { while (!_initialized) { System.Threading.Thread.Sleep(1000); } System.Threading.Thread.Sleep(2000); this.BeginInvoke((MethodInvoker) delegate { UVA_Arena.Internet.Downloader.DownloadProblemDatabase(); }); } //update user submissions if not available if (LocalDatabase.ContainsUser(RegistryAccess.DefaultUsername)) { string file = LocalDirectory.GetUserSubPath(RegistryAccess.DefaultUsername); if (LocalDirectory.GetFileSize(file) < 50) { System.Threading.Thread.Sleep(1000); this.BeginInvoke((MethodInvoker) delegate { Interactivity.userstat.DownloadUserSubs(RegistryAccess.DefaultUsername); }); } } //check for updates System.Threading.Thread.Sleep(10000); UpdateCheck.CheckForUpdate(); }