Exemplo n.º 1
0
        public static string GetInputdata(UserInput user)
        {
            Interactivity.SetStatus("Loading user input data...");

            var url     = "https://www.udebug.com/udebug-custom-get-selected-input-ajax";
            var request = (HttpWebRequest)WebRequest.Create(url);

            var postData = "input_nid=" + user.InputNID;
            var data     = Encoding.ASCII.GetBytes(postData);

            request.Method        = "POST";
            request.ContentType   = "application/x-www-form-urlencoded";
            request.ContentLength = data.Length;

            using (var stream = request.GetRequestStream())
            {
                stream.Write(data, 0, data.Length);
            }
            var response       = (HttpWebResponse)request.GetResponse();
            var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();

            var result = Newtonsoft.Json.JsonConvert.DeserializeObject <InputValue>(responseString);

            Interactivity.SetStatus("User's input data downloaded.");
            return(result.input_value);
        }
Exemplo n.º 2
0
        private void ShowDeepSearchStatus()
        {
            if (this.IsDisposed)
            {
                return;
            }

            if (_InDeepSearch)
            {
                int total = LocalDatabase.problemList.Count;
                Interactivity.SetProgress(_DeepSearchProgress, total);
                string msg = "Searching for problems... [{0} of {1} problems completed.]";
                Interactivity.SetStatus(string.Format(msg, _DeepSearchProgress, total));

                _SetObjects(_deepSearchRes);
                problemListView.Sort(priorityProb, SortOrder.Descending);

                TaskQueue.AddTask(ShowDeepSearchStatus, 1000);
            }
            else
            {
                Interactivity.SetProgress(0);
                if (_CancelSearch)
                {
                    Interactivity.SetStatus("Deep search cancelled.");
                }
                else
                {
                    Interactivity.SetStatus("Deep search completed.");
                }
            }
        }
Exemplo n.º 3
0
        private static void __DownloadUseridCompleted(DownloadTask task)
        {
            string uid  = (string)task.Result;
            string name = (string)task.Token;

            task.Status = ProgressStatus.Failed;
            if (string.IsNullOrEmpty(uid))
            {
                task.Error = new Exception("Connection error. Retry please.");
            }
            else if (uid.Trim() == "0")
            {
                task.Error = new Exception(name + " doesn't exist.");
            }
            else if (task.Error == null)
            {
                task.Status = ProgressStatus.Completed;
            }

            if (task.Status == ProgressStatus.Completed)
            {
                RegistryAccess.SetUserid(name, uid);
                string msg = "Username downloaded : {0} = {1}";
                Interactivity.SetStatus(string.Format(msg, name, uid));
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Runs a background thread to download and show world rank data.
        /// </summary>
        /// <param name="from">Integer type objects </param>
        private void ShowWorldRank(object from)
        {
            if (currentUser == null)
            {
                return;
            }

            if (webClient2.IsBusy)
            {
                webClient2.CancelAsync();
                TaskQueue.AddTask(new TaskQueue.Function2(ShowWorldRank), from, 500);
                return;
            }

            string url;

            if ((int)from <= 0)
            {
                //get current user's ranklist
                string format = "http://uhunt.felix-halim.net/api/ranklist/{0}/{1}/{2}";
                url = string.Format(format, currentUser.uid, 100, 100);
                Interactivity.SetStatus("Downloading " + currentUser.uname + "'s rank-list...");
            }
            else
            {
                //get ranklist from a specific rank
                string format = "http://uhunt.felix-halim.net/api/rank/{0}/{1}";
                url = string.Format(format, from, 200);
                Interactivity.SetStatus("Downloading rank-list from " + from.ToString() + "...");
            }

            webClient2.DownloadDataAsync(new Uri(url), from);
        }
Exemplo n.º 5
0
        private static void __DownloadProblemDatabaseCompleted(DownloadTask task)
        {
            _DownloadingProblemDatabase = false;

            string msg = "Failed to update problem list.";

            if (task.Status == ProgressStatus.Completed)
            {
                LocalDatabase.LoadDatabase();
                msg = "Problem list is successfully updated.";
                Logger.Add("Downloaded problem database file", "__DownloadProblemDatabaseCompleted");
            }
            else if (task.Error != null)
            {
                if (task.Token == null)
                {
                    LocalDatabase.LoadDatabase();
                    Logger.Add(task.Error.Message, "__DownloadProblemDatabaseCompleted");
                }
                else
                {
                    DownloadFileAsync((string)task.Token, task.FileName, null, Priority.High,
                                      __DownloadProblemDatabaseProgress, __DownloadProblemDatabaseCompleted, 0);
                }
            }

            Interactivity.SetStatus(msg);
            Interactivity.SetProgress(0);
        }
Exemplo n.º 6
0
        void webClient1_DownloadDataCompleted(object sender, DownloadDataCompletedEventArgs e)
        {
            try
            {
                string result = System.Text.Encoding.UTF8.GetString(e.Result);

                //update or add last submission id
                JudgeStatus[] statuslist = JsonConvert.DeserializeObject <JudgeStatus[]>(result);
                foreach (JudgeStatus status in statuslist)
                {
                    SetStatus(status);
                    if (status.id > LastSubID)
                    {
                        LastSubID = status.id;
                    }
                }

                Interactivity.SetProgress();
                Interactivity.SetStatus("Judge status update finished.");

                //set submission status
                submissionStatus.SetObjects(StatusList, false);
                submissionStatus.Sort(sidSUB, SortOrder.Descending);
                submissionStatus.EnsureVisible(0);
            }
            catch (Exception ex)
            {
                Interactivity.SetStatus("Judge status update failed.");
                Logger.Add(ex.Message, "Judge Status | webClient1_DownloadDataCompleted");
            }
            finally
            {
                LastUpdate = DateTime.Now;
            }
        }
Exemplo n.º 7
0
        private void ShowDataByTab()
        {
            Interactivity.SetStatus();
            if (currentUser == null)
            {
                return;
            }

            //change view and looks
            userNameTitle.Text = string.Format(userNameTitle.Tag.ToString(),
                                               currentUser.name, currentUser.uname);

            if (tabControl1.SelectedTab == submissionTab)
            {
                SetSubmissionToListView();
            }
            else if (tabControl1.SelectedTab == progtrackerTab)
            {
                Interactivity.progTracker.ShowUserInfo(currentUser);
            }
            else if (tabControl1.SelectedTab == worldrankTab)
            {
                ShowWorldRank(-1);
            }
        }
Exemplo n.º 8
0
        void webClient2_DownloadDataCompleted(object sender, DownloadDataCompletedEventArgs e)
        {
            if (this.IsDisposed)
            {
                return;
            }
            if (e.Cancelled)
            {
                return;
            }

            UserRanklist currentRank = null;

            try
            {
                if (e.Error != null)
                {
                    throw e.Error;
                }

                string result = System.Text.Encoding.UTF8.GetString(e.Result);

                if (worldRanks != null)
                {
                    worldRanks.Clear();
                }
                worldRanks = JsonConvert.DeserializeObject <List <UserRanklist> >(result);

                foreach (UserRanklist usub in worldRanks)
                {
                    if (LocalDatabase.ContainsUser(usub.username))
                    {
                        RegistryAccess.SetUserRank(usub);
                        if (usub.username == currentUser.uname)
                        {
                            currentRank = usub;
                        }
                    }
                }

                worldRanklist.SetObjects(worldRanks);
                worldRanklist.Sort(rankRANK, SortOrder.Ascending);


                Interactivity.SetStatus(currentUser.uname + "'s rank-list downloaded.");
                Logger.Add("World rank downloaded - " + currentUser.uname, "World Rank | webClient2_DownloadDataCompleted");
            }
            catch (Exception ex)
            {
                TaskQueue.AddTask(new TaskQueue.Function2(ShowWorldRank), e.UserState, 500);
                Interactivity.SetStatus("Rank-list download failed due to an error. Please try again.");
                Logger.Add(ex.Message, "World Rank | webClient2_DownloadDataCompleted");
            }

            if ((int)e.UserState == -1)
            {
                BringUserToMiddle(currentRank);
            }
        }
Exemplo n.º 9
0
        private void dt_progressChanged(DownloadTask task)
        {
            string status = string.Format("Downloading submission data on problem... [{0} of {1} received]",
                                          Functions.FormatMemory(task.Received), Functions.FormatMemory(task.Total));

            Interactivity.SetStatus(status);
            Interactivity.SetProgress(task.ProgressPercentage);
        }
Exemplo n.º 10
0
        void webClient1_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
        {
            Interactivity.SetProgress(e.ProgressPercentage);
            string msg = "Downloading {0}'s submissions... [{1} out of {2}]";

            Interactivity.SetStatus(string.Format(msg, e.UserState,
                                                  Functions.FormatMemory(e.BytesReceived), Functions.FormatMemory(e.TotalBytesToReceive), true));
        }
Exemplo n.º 11
0
        private void ProgressChanged(Internet.DownloadTask task)
        {
            string file = Path.GetFileName(task.FileName);
            string text = string.Format("Downloading file : \"{0}\"... {1}% [{2} out of {3}] completed.",
                                        file, task.ProgressPercentage, Functions.FormatMemory(task.Received), Functions.FormatMemory(task.Total));

            Interactivity.SetStatus(text);
            Interactivity.SetProgress(task.Received, task.Total);
        }
Exemplo n.º 12
0
        void webClient1_DownloadDataCompleted(object sender, DownloadDataCompletedEventArgs e)
        {
            if (this.IsDisposed)
            {
                return;
            }
            try
            {
                Interactivity.SetProgress();
                if (e.Cancelled)
                {
                    throw new OperationCanceledException();
                }
                if (e.Error != null)
                {
                    throw e.Error;
                }

                string result = System.Text.Encoding.UTF8.GetString(e.Result);

                if (currentUser != null)
                {
                    if (currentUser.uname != (string)e.UserState)
                    {
                        return;
                    }
                    currentUser.AddSubmissions(result);
                }
                else
                {
                    currentUser = JsonConvert.DeserializeObject <UserInfo>(result);
                    currentUser.Process();
                }

                string file = LocalDirectory.GetUserSubPath(currentUser.uname);
                string data = currentUser.GetJSONData();
                File.WriteAllText(file, data);

                ShowDataByTab();

                string msg = string.Format("Downloaded {0}'s submissions", e.UserState);
                Interactivity.SetStatus(msg);
                if (currentUser.LastSID == 0)
                {
                    Logger.Add(msg, "User Statistics");
                }
            }
            catch (Exception ex)
            {
                Interactivity.SetStatus(string.Format("Error while downloading {0}'s submissions.", e.UserState));
                Logger.Add(ex.Message, "UserStat | webClient1_DownloadDataCompleted");
            }
            finally
            {
                LastUpdate = DateTime.Now;
            }
        }
Exemplo n.º 13
0
        private static void __DownloadCategoryIndexProgress(DownloadTask task)
        {
            string msg = msg = "Downloading category index... [{0}/{1} completed]";

            msg = string.Format(msg, Functions.FormatMemory(task.Received), Functions.FormatMemory(task.Total));
            Interactivity.SetStatus(msg);

            int percent = task.ProgressPercentage;

            Interactivity.SetProgress(task.ProgressPercentage);
        }
Exemplo n.º 14
0
        private static void __DownloadProblemDatabaseProgress(DownloadTask task)
        {
            string msg = "Downloading problem list... [{0}/{1} completed]";

            msg = string.Format(msg, Functions.FormatMemory(task.Received), Functions.FormatMemory(task.Total));
            Interactivity.SetStatus(msg);

            int percent = task.ProgressPercentage;

            Interactivity.SetProgress(task.ProgressPercentage);
        }
Exemplo n.º 15
0
        /// <summary>
        /// Formats the code directory with default files and folders
        /// </summary>
        /// <param name="background">True to run this process on background</param>
        public void FormatCodeDirectory(object background)
        {
            if (!IsReady)
            {
                return;
            }

            //gather all files
            string path = RegistryAccess.CodesPath;

            if (!Directory.Exists(path))
            {
                return;
            }

            if ((bool)background)
            {
                System.Threading.ThreadPool.QueueUserWorkItem(FormatCodeDirectory, false);
                return;
            }

            IsReady = false;

            Interactivity.SetStatus("Formatting code directory started...");

            this.BeginInvoke((MethodInvoker) delegate
            {
                selectDirectoryPanel.Visible = false;
                folderTreeView.UseWaitCursor = true;
            });

            //create codes-path and check them
            if (!LocalDatabase.IsReady)
            {
                Logger.Add("Problem Database is not ready.", "Codes | FormatCodeDirectory()");
                return;
            }

            //just call codesPath. it will create directory automatically
            foreach (Structures.ProblemInfo prob in LocalDatabase.problemList)
            {
                LocalDirectory.GetCodesPath(prob.pnum);
            }

            //now create files for precode
            LocalDirectory.GetPrecode(Structures.Language.C);
            LocalDirectory.GetPrecode(Structures.Language.CPP);
            LocalDirectory.GetPrecode(Structures.Language.Java);
            LocalDirectory.GetPrecode(Structures.Language.Pascal);

            IsReady = true;
            LoadCodeFolder(false);
            Interactivity.SetStatus("Formatting code directory finished.");
        }
Exemplo n.º 16
0
        private static void __DownloadUserInfoProgress(DownloadTask task)
        {
            string msg = "Downloading {0}'s submissions... [{1}/{2} completed]";

            msg = string.Format(msg, task.Token,
                                Functions.FormatMemory(task.Received), Functions.FormatMemory(task.Total));
            Interactivity.SetStatus(msg);

            int percent = task.ProgressPercentage;

            Interactivity.SetProgress(task.ProgressPercentage);
        }
Exemplo n.º 17
0
        //
        // Timer
        //


        private void JudgeStatusRefresh()
        {
            _taskRunning = false;
            if (this.IsDisposed || !AutoUpdateStatus)
            {
                return;
            }
            TaskQueue.AddTask(JudgeStatusRefresh, 800);
            _taskRunning = true;

            //check if this is focused
            if (Interactivity.mainForm.customTabControl1.SelectedTab
                != Interactivity.mainForm.statusTab)
            {
                return;
            }

            //refresh items
            submissionStatus.SetObjects(StatusList);
            submissionStatus.SelectedObject = null;

            //check if update needed
            if (!AutoUpdateStatus)
            {
                return;
            }

            //update
            TimeSpan span = DateTime.Now.Subtract(LastUpdate);
            long     diff = (long)span.TotalMilliseconds;

            if (diff >= UpdateInterval)
            {
                if (webClient1.IsBusy)
                {
                    if (diff > 25000)
                    {
                        webClient1.CancelAsync();
                    }
                }
                else
                {
                    UpdateSubmissions();
                }
            }
            else
            {
                //show status about when to update
                long   inv = (long)Math.Ceiling((UpdateInterval - diff) / 1000.0);
                string msg = Functions.FormatTimeSpan(inv);
                Interactivity.SetStatus("Updating judge status in " + msg);
            }
        }
Exemplo n.º 18
0
        public void DownloadUserSubs(string user)
        {
            if (webClient1.IsBusy || currentUser == null || currentUser.uname != user)
            {
                return;
            }
            string format = "http://uhunt.felix-halim.net/api/subs-user/{0}/{1}";
            string url    = string.Format(format, currentUser.uid, currentUser.LastSID);

            Interactivity.SetStatus("Downloading " + user + "'s submissions...");
            webClient1.DownloadDataAsync(new Uri(url), currentUser.uname);
        }
Exemplo n.º 19
0
        public void UpdateSubmissions()
        {
            if (webClient1.IsBusy)
            {
                return;
            }

            ClearSome();
            Interactivity.SetStatus("Judge status update started...");
            string url = string.Format("http://uhunt.felix-halim.net/api/poll/{0}.", LastSubID);

            webClient1.DownloadDataAsync(new Uri(url));
        }
Exemplo n.º 20
0
        private static void __DownloadUserInfoCompleted(DownloadTask task)
        {
            string msg = "Failed to downloaded user submissions.";

            if (task.Status == ProgressStatus.Completed)
            {
                LocalDatabase.LoadDefaultUser();
                msg = "Downloaded user submissions.";
            }
            else if (task.Error != null)
            {
                Logger.Add(task.Error.Message, "__DownloadUserInfoCompleted");
            }

            Interactivity.SetStatus(msg);
            Interactivity.SetProgress(0);
        }
Exemplo n.º 21
0
        //
        // Timer
        //
        private void UserStatRefresh()
        {
            _taskRunning = false;
            if (this.IsDisposed || !AutoUpdateStatus)
            {
                return;
            }
            TaskQueue.AddTask(UserStatRefresh, 800);
            _taskRunning = true;

            //check if this is focused
            if (this.tabControl1.SelectedTab != submissionTab)
            {
                return;
            }
            if (Interactivity.mainForm.customTabControl1.SelectedTab
                != Interactivity.mainForm.profileTab)
            {
                return;
            }

            //refresh list
            lastSubmissions1.Refresh();

            //check if update needed
            if (webClient1.IsBusy || !AutoUpdateStatus || currentUser == null)
            {
                return;
            }

            //update
            TimeSpan span = DateTime.Now.Subtract(LastUpdate);
            long     diff = (long)span.TotalMilliseconds;

            if (diff >= UpdateInterval)
            {
                DownloadUserSubs(currentUser.uname);
            }
            else
            {
                //show status about when to update
                long   inv = (long)Math.Ceiling((UpdateInterval - diff) / 1000.0);
                string msg = Functions.FormatTimeSpan(inv);
                Interactivity.SetStatus("Updating user submissions in " + msg);
            }
        }
Exemplo n.º 22
0
        public static string GetOutputData(string input, FormData form)
        {
            Interactivity.SetStatus("Loading user's output data...");

            var url     = "https://www.udebug.com/UVa/" + form.pnum;
            var request = (HttpWebRequest)WebRequest.Create(url);


            // build request data
            var postData = "problem_nid=" + form.ProblemNID +
                           "&input_data=" + input +
                           "&node_nid=&op=Get+Accepted+Output&output_data=&user_output=" +
                           "&form_build_id=" + form.BuildID +
                           "&form_id=udebug_custom_problem_view_input_output_form";
            var data = Encoding.ASCII.GetBytes(postData);

            // send request and read response
            request.Method        = "POST";
            request.ContentType   = "application/x-www-form-urlencoded";
            request.ContentLength = data.Length;

            using (var stream = request.GetRequestStream())
            {
                stream.Write(data, 0, data.Length);
            }
            var response       = (HttpWebResponse)request.GetResponse();
            var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();

            // Parse page
            var htmlDoc = new HtmlDocument();

            htmlDoc.LoadHtml(responseString);

            // Read Accepted output data
            var node = htmlDoc.GetElementbyId("edit-output-data");

            string output = "";

            if (node != null)
            {
                output = node.InnerText;
            }

            Interactivity.SetStatus("Download output data from uDebug.");
            return(output);
        }
Exemplo n.º 23
0
        private static void __DownloadProblemCategoryCompleted(DownloadTask task)
        {
            string msg = "Failed to downloaded category list.";

            if (task.Status == ProgressStatus.Completed)
            {
                LocalDatabase.LoadCategories();
                msg = "Downloaded category list.";
                Logger.Add("Downloaded problem's categories.", "Downloader");
            }
            else if (task.Error != null)
            {
                Logger.Add(task.Error.Message, "Downloader");
            }

            Interactivity.SetStatus(msg);
            Interactivity.SetProgress(0);
        }
Exemplo n.º 24
0
        private static void __DownloadCategoryFileCompleted(DownloadTask task)
        {
            string msg = "Failed to downloaded category list.";

            if (task.Status == ProgressStatus.Completed)
            {
                LocalDatabase.LoadCategoryData((string)task.Token);
                Interactivity.CategoryDataUpdated();

                msg = "Downloaded Category file: " + (string)task.Token;
                Logger.Add(msg, "__DownloadCategoryFileCompleted");
            }
            else if (task.Error != null)
            {
                Logger.Add(task.Error.Message, "__DownloadCategoryFileCompleted");
            }

            Interactivity.SetStatus(msg);
            Interactivity.SetProgress(0);
        }
Exemplo n.º 25
0
        private static void __DownloadProblemDatabaseCompleted(DownloadTask task)
        {
            _DownloadingProblemDatabase = false;

            string msg = "Failed to update problem list.";

            if (task.Status == ProgressStatus.Completed)
            {
                LocalDatabase.LoadDatabase();
                msg = "Problem list is successfully updated.";
                Logger.Add("Downloaded problem database file", "Downloader");
            }
            else if (task.Error != null)
            {
                Logger.Add(task.Error.Message, "Downloader");
            }

            Interactivity.SetStatus(msg);
            Interactivity.SetProgress(0);
        }
Exemplo n.º 26
0
        private void dt_taskCompleted(DownloadTask task)
        {
            //check validity of result
            if (task.Status != ProgressStatus.Completed)
            {
                if (task.Error != null)
                {
                    Interactivity.SetStatus("Failed to download submission data on problem.");
                    Logger.Add(task.Error.Message, "Problem Viewer | dt_taskCompleted(DownloadTask task)");
                }
                return;
            }

            try
            {
                string user = (string)task.Token;

                //set result to listview
                if (_curSubType == SubViewType.UsersSub)
                {
                    task.Result = task.Result.Remove(0, task.Result.IndexOf(":") + 1);
                    task.Result = task.Result.Remove(task.Result.Length - 1);
                    UserInfo uinfo = JsonConvert.DeserializeObject <UserInfo>(task.Result);
                    uinfo.Process();
                    submissionStatus.SetObjects(uinfo.submissions);
                }
                else if (_curSubType == SubViewType.Comapre)
                {
                    List <UserSubmission> allsubs = new List <UserSubmission>();

                    string data = task.Result.Substring(1, task.Result.Length - 2);
                    do
                    {
                        int i = data.IndexOf("{");
                        if (i < 0)
                        {
                            break;
                        }
                        int j = data.IndexOf("}", i);
                        if (j < 0)
                        {
                            break;
                        }

                        string   tmp   = data.Substring(i, j - i + 1);
                        UserInfo uinfo = JsonConvert.DeserializeObject <UserInfo>(tmp);
                        uinfo.Process();
                        allsubs.AddRange(uinfo.submissions.ToArray());

                        data = data.Substring(j + 1);
                    }while (data.Length > 0);
                    submissionStatus.SetObjects(allsubs);
                }
                else
                {
                    List <SubmissionMessage> lsm =
                        JsonConvert.DeserializeObject <List <SubmissionMessage> >(task.Result);
                    if (lsm == null)
                    {
                        return;
                    }
                    submissionStatus.SetObjects(lsm);
                }

                //sort listview and set other flags
                submissionStatus.ShowGroups = false;
                switch (_curSubType)
                {
                case SubViewType.LastSubmission:
                    submissionStatus.Sort(sidSUB, SortOrder.Descending);
                    subListLabel.Text = "Last submissions on this problem from " +
                                        dateTimePicker1.Value.ToString();
                    break;

                case SubViewType.Ranklist:
                    submissionStatus.Sort(rankSUB, SortOrder.Ascending);
                    subListLabel.Text = "Rank-list of this problem displaying first " +
                                        numericUpDown1.Value.ToString() + "' users.";
                    break;

                case SubViewType.UsersRank:
                    submissionStatus.Sort(rankSUB, SortOrder.Ascending);
                    subListLabel.Text = user + "'s nearby users on this problem";
                    break;

                case SubViewType.UsersSub:
                    submissionStatus.Sort(sidSUB, SortOrder.Descending);
                    subListLabel.Text = user + "'s submissions on this problem";
                    break;

                case SubViewType.Comapre:
                    submissionStatus.BuildGroups(unameSUB, SortOrder.Ascending);
                    subListLabel.Text = "Comparison between all users in this problem";
                    break;
                }
            }
            catch (Exception ex)
            {
                Interactivity.SetStatus("Failed to download submission data on problem.");
                Logger.Add(ex.Message, "Problem Viewer | dt_taskCompleted(DownloadTask task)");
            }
        }
Exemplo n.º 27
0
 void webClient1_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
 {
     Interactivity.SetStatus("Judge status updating...");
     Interactivity.SetProgress(e.ProgressPercentage);
 }
Exemplo n.º 28
0
        private void LoadSubmission()
        {
            if (current == null)
            {
                return;
            }

            string user = (string)usernameList1.Tag;
            string uid  = LocalDatabase.GetUserid(user);

            submissionStatus.ClearObjects();

            long   start, stop;
            string url = "", format;

            switch (_curSubType)
            {
            case SubViewType.LastSubmission:
                start  = UnixTimestamp.ToUnixTime(dateTimePicker1.Value);
                stop   = UnixTimestamp.ToUnixTime(DateTime.Now);
                format = "http://uhunt.felix-halim.net/api/p/subs/{0}/{1}/{2}";     //pid, unix time start, stop
                url    = string.Format(format, current.pid, start, stop);
                Interactivity.SetStatus("Downloading last submissions on current problem...");
                break;

            case SubViewType.Ranklist:
                start  = 1;
                stop   = (long)numericUpDown1.Value;
                format = "http://uhunt.felix-halim.net/api/p/rank/{0}/{1}/{2}";     //pid, rank start, rank count
                url    = string.Format(format, current.pid, start, stop);
                Interactivity.SetStatus("Downloading ranks on current problem...");
                break;

            case SubViewType.UsersRank:
                start = stop = 10;
                if (string.IsNullOrEmpty(uid) || uid == "-")
                {
                    return;
                }
                format = "http://uhunt.felix-halim.net/api/p/ranklist/{0}/{1}/{2}/{3}";     //pid, uid, before_count, after_count
                url    = string.Format(format, current.pid, uid, start, stop);
                Interactivity.SetStatus("Downloading " + user + "'s rank-data on current problem...");
                break;

            case SubViewType.UsersSub:
                if (string.IsNullOrEmpty(uid) || uid == "-")
                {
                    return;
                }
                format = "http://uhunt.felix-halim.net/api/subs-nums/{0}/{1}/{2}";     //uid, pnum, last sid
                url    = string.Format(format, uid, current.pnum, 0);
                Interactivity.SetStatus("Downloading " + user + "'s submission on current problem...");
                break;

            case SubViewType.Comapre:
                List <string> uidcol = new List <string>();
                foreach (var val in LocalDatabase.usernames.Values)
                {
                    uidcol.Add(val);
                }
                if (uidcol.Count == 0)
                {
                    return;
                }
                format = "http://uhunt.felix-halim.net/api/subs-nums/{0}/{1}/0";     //uids(sep = comma), pnum
                url    = string.Format(format, string.Join(",", uidcol.ToArray()), current.pnum);
                Interactivity.SetStatus("Comparing user's on current problem...");
                break;
            }

            Downloader.DownloadStringAsync(url, user, Priority.Normal, dt_progressChanged, dt_taskCompleted, 1);
        }
Exemplo n.º 29
0
 void webClient2_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
 {
     Interactivity.SetProgress(e.ProgressPercentage);
     Interactivity.SetStatus(string.Format("Downloading rank-list... [{0} out of {1}]",
                                           Functions.FormatMemory(e.BytesReceived), Functions.FormatMemory(e.TotalBytesToReceive)));
 }
Exemplo n.º 30
0
        /// <summary>
        /// Load user submissions information to currentUser
        /// </summary>
        /// <param name="user">Username to load</param>
        public void LoadUserSub(string user)
        {
            //if 'user' is already loaded then do nothing
            if (currentUser != null && currentUser.uname == user)
            {
                return;
            }
            if (!LocalDatabase.ContainsUser(user))
            {
                return;
            }

            worldRanklist.ClearObjects();
            lastSubmissions1.ClearObjects();
            Interactivity.progTracker.ShowUserInfo(null);

            try
            {
                Interactivity.SetStatus();

                //if current user is default user then get it from LocalDatabase
                if (user == RegistryAccess.DefaultUsername)
                {
                    currentUser = LocalDatabase.DefaultUser;
                }
                else
                {
                    //load current user from json data stored on documents
                    string file = LocalDirectory.GetUserSubPath(user);
                    string json = File.ReadAllText(file);
                    currentUser = JsonConvert.DeserializeObject <UserInfo>(json);
                }

                //if no data could found, create a new instance
                if (currentUser == null)
                {
                    currentUser = new UserInfo(user);
                    if (user == RegistryAccess.DefaultUsername)
                    {
                        LocalDatabase.DefaultUser = currentUser;
                    }
                }

                //process loaded data
                //-> this is very important
                currentUser.Process();

                //if no previous data exist
                if (currentUser.LastSID == 0)
                {
                    DownloadUserSubs(user);
                }
                else
                {
                    //show list
                    ShowDataByTab();
                }

                //if auto update is off download once
                if (!AutoUpdateStatus)
                {
                    DownloadUserSubs(user);
                }

                //select user
                SelectUsername(user);
            }
            catch (Exception ex)
            {
                Interactivity.SetStatus("Error while loading user submissions.");
                Logger.Add(ex.Message, "User Statistics | LoadUserSub(string user)");
            }
        }