Ejemplo n.º 1
0
        private void DownloadCompleted(Internet.DownloadTask task)
        {
            try
            {
                if (task.Status != Internet.ProgressStatus.Completed)
                {
                    throw task.Error;
                }

                RegistryAccess.DefaultUsername = username1.Text;
                this.DialogResult = System.Windows.Forms.DialogResult.OK;
                this.Close();

                Interactivity.DefaultUsernameChanged();
            }
            catch (Exception ex)
            {
                if (ex == null)
                {
                    ex = new Exception("Canceled");
                }
                Status.Text = string.Format("[Error: {0}]", ex.Message);
            }
            finally
            {
                username1.Enabled   = true;
                set_button1.Enabled = true;
                username1.Focus();
            }
        }
Ejemplo n.º 2
0
 private void cancelTaskToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (downloadQueue1.SelectedObject == null)
     {
         return;
     }
     Internet.DownloadTask task = (Internet.DownloadTask)downloadQueue1.SelectedObject;
     task.Cancel();
 }
Ejemplo n.º 3
0
        public static DownloadTask DownloadFileAsync(
            string url,
            string file,
            object token                  = null,
            Priority priority             = Priority.Normal,
            DownloadTaskHandler progress  = null,
            DownloadTaskHandler completed = null,
            int retry = 0)
        {
            DownloadTask task = new DownloadTask(url, file, token, retry);

            task.ProgressChangedEvent   += progress;
            task.DownloadCompletedEvent += completed;
            return(DownloadAsync(task, priority));
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
0
        private static void __DownloadProblemDatabaseProgress(DownloadTask task)
        {
            string msg = "Downloading problem list... [{0}/{1} completed]";

            if ((bool)task.Token)
            {
                msg = "Downloading category list... [{0}/{1} completed]";
            }
            msg = string.Format(msg, Functions.FormatMemory(task.Received), Functions.FormatMemory(task.Total));
            Interactivity.SetStatus(msg);

            int percent = task.ProgressPercentage;

            if ((bool)task.Token)
            {
                percent += 100;
            }
            Interactivity.SetProgress(task.ProgressPercentage, 200);
        }
Ejemplo n.º 7
0
        private void InitOthers()
        {
            TaskQueue.AddTask(RefreshList, 1000);

            nameINT.AspectGetter = delegate(object row)
            {
                if (row == null)
                {
                    return(null);
                }
                Internet.DownloadTask task = (Internet.DownloadTask)row;
                if (task.IsSaveToFile)
                {
                    return(System.IO.Path.GetFileName(task.FileName));
                }
                else
                {
                    return(task.Url.AbsolutePath);
                }
            };
            receiveINT.AspectToStringConverter   =
                totalINT.AspectToStringConverter = delegate(object key)
            {
                if (key == null)
                {
                    return("");
                }
                return(Functions.FormatMemory((long)key));
            };
            funcTask.AspectToStringConverter = delegate(object key)
            {
                if (key == null)
                {
                    return("");
                }
                TaskQueue.Function func   = (TaskQueue.Function)key;
                string             target = func.Target.ToString();
                string             name   = func.Method.ReturnType.Name.ToLower() + " " + func.Method.Name + "()";
                string             other  = func.Method.Attributes.ToString();
                return(target + " | " + name + " | " + other);
            };
        }
Ejemplo n.º 8
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);
        }
Ejemplo n.º 9
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);
        }
Ejemplo n.º 10
0
        public static void DownloadUserid(string name, Internet.DownloadTaskHandler complete)
        {
            string       url = "http://uhunt.felix-halim.net/api/uname2uid/" + name;
            DownloadTask dt  = new DownloadTask(url, null, name, 2);

            if (LocalDatabase.ContainsUser(name))
            {
                dt.Result = LocalDatabase.GetUserid(name);
                dt.Status = ProgressStatus.Completed;
                if (complete != null)
                {
                    complete(dt);
                }
            }
            else
            {
                dt.DownloadCompletedEvent += __DownloadUseridCompleted;
                if (complete != null)
                {
                    dt.DownloadCompletedEvent += complete;
                }
                DownloadAsync(dt, Priority.High);
            }
        }