Example #1
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);
        }
Example #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.");
                }
            }
        }
Example #3
0
        /// <summary>
        /// Expand up to path of given problem number and select top file inside that folder
        /// Prompt for new file if none exist
        /// </summary>
        /// <param name="pnum">Problem number</param>
        public void ShowCode(object pnum)
        {
            if (!Directory.Exists(RegistryAccess.CodesPath))
            {
                return;
            }
            if (!IsReady || folderTreeView.Nodes.Count == 0)
            {
                if (this.IsDisposed)
                {
                    return;
                }
                TaskQueue.AddTask(ShowCode, pnum, 1000);
                return;
            }

            //create code file if doesn't exist
            string path = LocalDirectory.GetCodesPath((long)pnum);

            if (!Directory.Exists(path) || Directory.GetFiles(path).Length == 0)
            {
                this.BeginInvoke((MethodInvoker)(() => AddProblem((long)pnum)));
                return;
            }

            this.BeginInvoke((MethodInvoker) delegate
            {
                //select code file path
                TreeNode tn = GetNode(new DirectoryInfo(path));
                CodesBrowser.ExpandAndSelect(tn, CodesBrowser.ExpandSelectType.SelecFirstChild);
            });
        }
Example #4
0
 public ApplicationDefault(string tempDir)
 {
     _exitTaskQueue = new TaskQueue(_progressTracker);
     //_temporalFileManager = new TemporalFileManager(tempDir);
     _recentUsedFilesMgr = new RecentUsedFiles(20, tempDir);
     _exitTaskQueue.AddTask(_temporalFileManager);
 }
        public IXmppConnection AddConnection(long rid, IXmppConnection connection)
        {
            Args.NotNull(connection, "connection");

            lock (connections)
            {
                if (hold == connections.Count)
                {
                    throw new JabberStreamException(StreamErrorCondition.PolicyViolation);
                }
                foreach (var pair in connections)
                {
                    if (window < Math.Abs(rid - pair.Key))
                    {
                        throw new JabberStreamException(StreamErrorCondition.PolicyViolation);
                    }
                }

                // cancel inactivity
                TaskQueue.RemoveTask(SessionId);

                connection.SessionId = SessionId;
                connections.Add(rid, connection);
                // add wait timeout
                TaskQueue.AddTask(rid.ToString(), () => SendAndClose(rid, new Body(), null), waitTimeout);
            }
            return(this);
        }
        private void SendBody(Body body, Action <Element> onerror)
        {
            var timeout = TimeSpan.Zero;

            lock (connections)
            {
                if (connections.Count == 0)
                {
                    timeout = sendTimeout;
                }
            }

            Action send = () =>
            {
                var minrid = 0L;
                lock (connections)
                {
                    minrid = connections.Any() ? connections.Min(p => p.Key) : 0;
                }
                // cancel wait timeout
                TaskQueue.RemoveTask(minrid.ToString());

                SendAndClose(minrid, body, onerror);
            };

            TaskQueue.AddTask(Guid.NewGuid().ToString(), send, timeout);
        }
Example #7
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);
            }
        }
Example #8
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);
            }
        }
Example #9
0
        public bool Send()
        {
            var task = _queue.AddTask(this.Key, SendInternall);

            if (task != null)
            {
                this._logger.WriteEvent(
                    string.Format("Add task SendPrice. key:{0}, total:{1} wait:{2} active:{3}", this.Key, _queue.TotalTaskCount, _queue.WaitTasksCount, _queue.ActiveTaskCount));
            }

            return(task != null);
        }
Example #10
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);
            }
        }
        public void ProjectModified(ILuaIntellisenseProject project)
        {
            if (project != m_project)
            {
                return;
            }

            if (project == null)
            {
                Database.Clear();
                Database.LoadStandardLibrary();
            }
            else
            {
                Database.Rebuild(project);
            }

            TaskQueue.AddTask(ReparseOpenDocuments, TaskQueue.Thread.UI);
        }
Example #12
0
    private void DoOnPrimaryClick()
    {
        var ray = Camera.main.ScreenPointToRay(Input.mousePosition);

        RaycastHit[] hits           = Physics.RaycastAll(ray, checkDistance);
        Clickable    firstClickable = hits
                                      .Where(x => x.transform.GetComponent <Clickable>() != null)
                                      .Select(x => x.transform.GetComponent <Clickable>())
                                      .FirstOrDefault();

        if (firstClickable != null)
        {
            // First set selection properties on object
            firstClickable.TriggerIt();

            // Then inform queue system (add task will deal with deselection)
            queue.AddTask(firstClickable.gameObject);
        }
    }
Example #13
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            //load volume and problems data at once
            if (LocalDatabase.IsReady)
            {
                Interactivity.ProblemDatabaseUpdated();
                Interactivity.CategoryDataUpdated();
            }

            Stylish.SetGradientBackground(plistPanel,
                                          new Stylish.GradientStyle(Color.LightCyan, Color.PaleTurquoise, -90F));

            if (Properties.Settings.Default.ProblemViewExpandCollapse)
            {
                CollapsePanel2View();
            }

            // check category
            TaskQueue.AddTask(updateListIfEmpty, 5000);
        }
 private void SendAndClose(long rid, Body body, Action <Element> onerror)
 {
     try
     {
         IXmppConnection c;
         lock (connections)
         {
             if (connections.TryGetValue(rid, out c))
             {
                 connections.Remove(rid);
             }
             if (connections.Count == 0)
             {
                 // set inactivity callback
                 TaskQueue.RemoveTask(SessionId);
                 TaskQueue.AddTask(SessionId, () => Close(), inactivityTimeout);
             }
         }
         if (c != null)
         {
             c.Send(body, onerror);
         }
         else if (onerror != null)
         {
             onerror(body);
         }
     }
     catch (Exception ex)
     {
         Log.Error(ex);
         if (onerror != null)
         {
             onerror(body);
         }
     }
 }