Example #1
0
        /// <summary>
        /// Select User Status tab page and show profile of the user
        /// </summary>
        /// <param name="user">User-name to show statistics </param>
        public static void ShowUserStat(string user)
        {
            if (!LocalDatabase.ContainsUser(user))
            {
                return;
            }

            userstat.BeginInvoke((MethodInvoker) delegate
            {
                try
                {
                    userstat.ShowUserSub(user);
                }
                catch (System.Exception ex)
                {
                    Logger.Add(ex.Message, "Interactivity|ShowUserStat()");
                }
            });

            mainForm.BeginInvoke((MethodInvoker) delegate
            {
                try
                {
                    mainForm.customTabControl1.SelectedTab = mainForm.profileTab;
                    mainForm.BringToFront();
                }
                catch (System.Exception ex)
                {
                    Logger.Add(ex.Message, "Interactivity|ShowUserStat()");
                }
            });
        }
Example #2
0
        /// <summary>
        /// Get path where user's submissions are stored.
        /// If user id doesn't found an empty string is returned.
        /// </summary>
        /// <param name="username">User-name of the user</param>
        /// <returns>Valid file with .json extension</returns>
        public static string GetUserSubPath(string username)
        {
            if (!LocalDatabase.ContainsUser(username))
            {
                return("");
            }
            string uid  = LocalDatabase.GetUserid(username);
            string name = uid.ToString() + ".json";
            string file = Path.Combine("Users", name);

            file = Path.Combine(DefaultPath, file);
            CreateFile(file);
            return(file);
        }
Example #3
0
 public void SetFormProperties()
 {
     string user = RegistryAccess.DefaultUsername;
     if (LocalDatabase.ContainsUser(user))
     {
         this.Text = string.Format(this.Tag.ToString(), user, LocalDatabase.GetUserid(user));
     }
     else
     {
         string msg = "Looks like you didn't set a default user-name." + Environment.NewLine;
         msg += "It is extremely important to set a default user-name to enable many features." + Environment.NewLine;
         msg += "Press OK to set it now. Or, you can set it later from the menu bar options.";
         if (MessageBox.Show(msg, Application.ProductName, MessageBoxButtons.OKCancel)
             == System.Windows.Forms.DialogResult.OK)
         {
             Interactivity.ShowUserNameForm();
         }
     }
 }
Example #4
0
        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);
        }
Example #5
0
        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();
        }