예제 #1
0
 public static void LoadDefaultUser()
 {
     try
     {
         string user = RegistryAccess.DefaultUsername;
         if (!ContainsUser(user)) throw new KeyNotFoundException();
         string file = LocalDirectory.GetUserSubPath(user);
         string data = File.ReadAllText(file);
         DefaultUser = JsonConvert.DeserializeObject<UserInfo>(data);
         if (DefaultUser != null) DefaultUser.Process();
         else DefaultUser = new UserInfo(RegistryAccess.DefaultUsername);
     }
     catch (Exception ex)
     {
         DefaultUser = new UserInfo(RegistryAccess.DefaultUsername);
         Logger.Add(ex.Message, "LocalDatabase|LoadDefaultUser()");
     }
 }
예제 #2
0
 public void ShowUserInfo(UserInfo uinfo)
 {
     currentUser = uinfo;
     LoadCurrentUser(true);
 }
예제 #3
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;
            }
        }
예제 #4
0
        private void ProcessList()
        {
            if (currentUser == null)
            {
                //currentUser = LocalDatabase.DefaultUser;
                currentUser = new UserInfo();
                currentUser.uid = currentUser.uname = currentUser.name = "[-]";
                currentUser.subs = new List<List<long>>();
                currentUser.Process();
            }

            userRank = RegistryAccess.GetUserRank(currentUser.uname);
            if (userRank == null)
            {
                userRank = new UserRanklist();
                userRank.username = currentUser.uname;
                userRank.rank = 0;
                userRank.activity = new List<long>();
                for (int i = 0; i < 5; ++i) userRank.activity.Add(0);
            }

            _acOverTime.Clear();
            _subOverTime.Clear();
            _RankCount.Clear();

            _firstSub = long.MaxValue;
            _solvedCount = _unsolvedCount = _tryCount = _totalSubmission = 0;
            _subInAnsiC = _subInCPP = _subInCPP11 = _subInJava = _subInPascal = 0;
            _acCount = _waCount = _tleCount = _reCount = _peCount = 0;
            _ceCount = _oleCount = _subeCount = _mleCount = 0;

            List<long> solved = new List<long>();

            foreach (UserSubmission usub in currentUser.submissions)
            {
                //total submission count
                _totalSubmission++;

                //age meter
                if (_firstSub > usub.sbt)
                    _firstSub = usub.sbt;

                //add rank count
                if (usub.IsAccepted())
                {
                    _RankCount.Add(usub.rank, usub.pid);

                    //solve count
                    if (!solved.Contains(usub.pnum))
                    {
                        _solvedCount++;
                        solved.Add(usub.pnum);
                    }
                }

                //language
                switch ((Language)usub.lan)
                {
                    case Language.C: _subInAnsiC++; break;
                    case Language.Java: _subInJava++; break;
                    case Language.Pascal: _subInPascal++; break;
                    case Language.CPP: _subInCPP++; break;
                    case Language.CPP11: _subInCPP11++; break;
                }

                //submissionPerTime
                double xval = new ZedGraph.XDate(UnixTimestamp.FromUnixTime(usub.sbt));
                if (_totalSubmission == 1) _subOverTime.Add(xval, 0);

                _subOverTime.Add(xval, _totalSubmission);
                _acOverTime.Add(xval, _solvedCount);

                //verdict
                switch ((Verdict)usub.ver)
                {
                    case Structures.Verdict.CompileError: _ceCount++; break;
                    case Structures.Verdict.RuntimeError: _reCount++; break;
                    case Structures.Verdict.OutputLimit: _oleCount++; break;
                    case Structures.Verdict.TimLimit: _tleCount++; break;
                    case Structures.Verdict.MemoryLimit: _mleCount++; break;
                    case Structures.Verdict.WrongAnswer: _waCount++; break;
                    case Structures.Verdict.PresentationError: _peCount++; break;
                    case Structures.Verdict.Accepted: _acCount++; break;
                }
            }

            //finalize
            _tryCount = currentUser.TryList.Count;
            _unsolvedCount = _tryCount - _solvedCount;
            _subOverTime.Add(new ZedGraph.XDate(DateTime.Now), _totalSubmission);
            _acOverTime.Add(new ZedGraph.XDate(DateTime.Now), _solvedCount);
        }
예제 #5
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)");
            }
        }