예제 #1
1
        public static BitsJob CreateBitsJob( string jobName, BG_JOB_TYPE jobType, string description, long retryPeriod,
                                             long retryDelay )
        {
            BitsJobAdapter bitsJobAdapter = CreateBitsJobAdapter( jobName, jobType, description, retryPeriod,
                                                                  retryDelay );

            var bitsJob = new BitsJob( bitsJobAdapter );
            return bitsJob;
        }
예제 #2
0
        private void RegisterEvents(BitsJob job)
        {
            job.OnJobError += (s, e) =>
            {
                _status.NextVersion = new Version();
                _status.BitsJobId   = Guid.Empty;
                _status.Save();
                OnUpdateDownloadError(new UpdateErrorEventArgs(e.Error));
                job.Cancel();
                job.Dispose();
            };

            job.OnJobTransferred += (s, e) =>
            {
                job.Complete();
                job.Dispose();
                OnUpdateDownloaded(new UpdateDownloadedEventArgs());
            };

            job.OnJobModified += (s, e) =>
            {
                if (job != null && job.State == JobState.Transferring)
                {
                    if (job.Progress != null)
                    {
                        OnUpdateDownloadProgressChanged(new UpdateProgressEventArgs(job.Progress.BytesTransferred, job.Progress.BytesTotal));
                    }
                }
            };
        }
예제 #3
0
        private void RefreshList(Dictionary <Guid, BitsJob> jobs)
        {
            CheckAndAddNewJobs(jobs);

            for (int i = 0; i < lstDownloads.Items.Count; i++)
            {
                if (lstDownloads.Items[i] == null)
                {
                    continue;
                }
                Guid    g = (Guid)lstDownloads.Items[i].Tag;
                BitsJob j = jobs[g];
                lstDownloads.Items[i].SubItems[2] = new ListViewItem.ListViewSubItem(lstDownloads.Items[i], (j.PercentComplete).ToString("00.00 %", CultureInfo.InvariantCulture));
                lstDownloads.Items[i].SubItems[3] = new ListViewItem.ListViewSubItem(lstDownloads.Items[i], j.JobStateDescription);

                if (j.BytesTotal == ulong.MaxValue)
                {
                    lstDownloads.Items[i].SubItems[5] = new ListViewItem.ListViewSubItem(lstDownloads.Items[i], "?");
                }
                if ((lstDownloads.Items[i].SubItems[5].Text == "?") && (j.JobState == BitsJobState.TRANSFERRING))
                {
                    lstDownloads.Items[i].SubItems[5] = new ListViewItem.ListViewSubItem(lstDownloads.Items[i], (j.BytesTotal / 1048576.0).ToString("N", CultureInfo.InvariantCulture));
                }

                lstDownloads.Items[i].SubItems[6] = new ListViewItem.ListViewSubItem(lstDownloads.Items[i], (j.BytesTransferred / 1048576.0).ToString("N", CultureInfo.InvariantCulture));
                if (this.tsmiAutoRestart.Checked && ((j.JobState == BitsJobState.ERROR || (j.JobState == BitsJobState.TRANSIENT_ERROR))))
                {
                    BitsManager.ResumeJob(j.Guid);
                }
            }
            ColourJobs();
            AutoCompleteJobs();
            MakeFirstJobsActive();
            UpdateStatusInfo();
        }
예제 #4
0
        public override void UpdateControl()
        {
            BitsJob bitsJob = base.wrapper.BitsJob;

            this.chkAutoComplete.CheckedChanged -= new EventHandler(this.chkAutoComplete_CheckedChanged);
            this.chkAutoComplete.Checked         = base.wrapper.AutoComplete;
            this.chkAutoComplete.CheckedChanged += new EventHandler(this.chkAutoComplete_CheckedChanged);
            this.tbJobName.Text                   = bitsJob.DisplayName;
            this.tbJobDescription.Text            = bitsJob.Description;
            this.tbJobOwner.Text                  = bitsJob.OwnerName;
            this.tbJobState.Text                  = bitsJob.State.ToString();
            this.cbPriority.SelectedIndexChanged -= new EventHandler(this.cbPriority_SelectedIndexChanged);
            this.cbPriority.SelectedIndex         = (int)bitsJob.Priority;
            this.cbPriority.SelectedIndexChanged += new EventHandler(this.cbPriority_SelectedIndexChanged);
            this.tbJobDirection.Text              = bitsJob.JobType.ToString();
            this.DisplayTimestamp();
            this.tbJobFileCount.Text        = bitsJob.Progress.FilesTotal.ToString(CultureInfo.CurrentCulture);
            this.tbJobFilesCompleted.Text   = bitsJob.Progress.FilesTransferred.ToString();
            this.tbJobBytesTotal.Text       = Utils.Bytes2Size(bitsJob.Progress.BytesTotal);
            this.tbJobBytesTransferred.Text = Utils.Bytes2Size(bitsJob.Progress.BytesTransferred);
            if (this.lastState != bitsJob.State)
            {
                this.ControlsFromJobState();
                this.lastState = bitsJob.State;
            }
        }
예제 #5
0
        private void FillListViewItem(ListViewItem listItem, JobWrapper jobWrapper)
        {
            BitsJob bitsJob = jobWrapper.BitsJob;

            listItem.SubItems.Clear();
            listItem.ImageIndex  = (bitsJob.JobType == JobType.Download) ? 0 : 1;
            listItem.ToolTipText = string.IsNullOrEmpty(bitsJob.Description) ? bitsJob.DisplayName : bitsJob.Description;
            listItem.Text        = bitsJob.DisplayName;
            listItem.Name        = bitsJob.JobId.ToString();
            ListViewItem.ListViewSubItem item = new ListViewItem.ListViewSubItem(listItem, bitsJob.State.ToString());
            item.Name = ColumnNames.JobState;
            listItem.SubItems.Add(item);
            item      = new ListViewItem.ListViewSubItem(listItem, bitsJob.Progress.FilesTransferred.ToString() + "/" + bitsJob.Progress.FilesTotal.ToString());
            item.Name = ColumnNames.FileCount;
            listItem.SubItems.Add(item);
            item      = new ListViewItem.ListViewSubItem(listItem, Utils.Bytes2Size(bitsJob.Progress.BytesTransferred) + "/" + Utils.Bytes2Size(bitsJob.Progress.BytesTotal));
            item.Name = ColumnNames.ByteCount;
            listItem.SubItems.Add(item);
            item      = new ListViewItem.ListViewSubItem(listItem, Utils.Percentage(bitsJob.Progress.BytesTotal, bitsJob.Progress.BytesTransferred));
            item.Name = ColumnNames.Progress;
            listItem.SubItems.Add(item);
            if (bitsJob.JobType == JobType.Upload)
            {
                listItem.Group = this.lvJobList.Groups[1];
            }
            if (bitsJob.JobType == JobType.Download)
            {
                listItem.Group = this.lvJobList.Groups[0];
            }
            listItem.Tag = jobWrapper;
        }
예제 #6
0
        private void lstDownloads_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            Guid g = (Guid)lstDownloads.GetItemAt(e.X, e.Y).Tag;

            BitsJob j       = _bitsJobs[g];
            JobInfo jobInfo = new JobInfo(j);

            jobInfo.ShowDialog(this);
        }
예제 #7
0
 // Methods
 public JobDetailsForm(JobWrapper wrapper)
 {
     this.wrapper = wrapper;
     this.manager = wrapper.Manager;
     this.job     = wrapper.BitsJob;
     this.InitializeComponent();
     this.bitsJobDetails.InitControl(wrapper);
     this.Text = this.job.DisplayName;
 }
예제 #8
0
        public override void OnCreate(BitsJob jobToConfigure)
        {
            jobToConfigure.Description =
                string.Format("License verification for {0}", Name);

            jobToConfigure.AddFile(
                VerifyUrl,
                LocalFileName
                );
        }
예제 #9
0
        private void AddBitsJob2List(BitsJob j)
        {
            ListViewItem lvi = new ListViewItem(j.GetHashCode().ToString());

            lvi.SubItems[0].Text = j.FileName;

            lvi.SubItems.AddRange(new string[] { j.DisplayName, j.PercentComplete.ToString("P2", CultureInfo.InvariantCulture), j.JobStateDescription, j.Url, (j.BytesTotal / 1048576.0).ToString("N", CultureInfo.InvariantCulture), (j.BytesTransferred / 1048576.0).ToString("N", CultureInfo.InvariantCulture) });
            lvi.Tag = j.Guid;
            lstDownloads.Items.Add(lvi);
        }
예제 #10
0
        private void CreateNewJob(JobType jobType, string[] files)
        {
            BitsJob job = null;

            job = this.bitsManager.CreateJob(jobType.ToString(), jobType);
            this.lvJobList.Items[job.JobId.ToString()].Selected = true;
            JobWrapper wrapper = this.jobWrappers[job.JobId];

            wrapper.FileList = files;
            this.ShowJobDetails(wrapper, true);
        }
예제 #11
0
        /// <summary>Downloads the application updates.</summary>
        /// <param name="application">The Sui containing the update info.</param>
        /// <param name="bitsJob">The bits job that will download the update.</param>
        static void DownloadUpdates(Sui application, ref BitsJob bitsJob)
        {
            if (application == null)
            {
                throw new ArgumentNullException("application");
            }

            if (bitsJob == null)
            {
                throw new ArgumentNullException("bitsJob");
            }

            for (int y = 0; y < application.Updates.Count; y++)
            {
                // Create download directory consisting of application name and update title
                string downloadDir = Path.Combine(downloadDirectory, application.Updates[y].Name[0].Value);

                Directory.CreateDirectory(downloadDir);

                for (int z = 0; z < application.Updates[y].Files.Count; z++)
                {
                    if (application.Updates[y].Files[z].Action == FileAction.Delete ||
                        application.Updates[y].Files[z].Action == FileAction.UnregisterThenDelete ||
                        application.Updates[y].Files[z].Action == FileAction.CompareOnly)
                    {
                        continue;
                    }

                    string destination = Path.GetFileName(application.Updates[y].Files[z].Destination);
                    if (string.IsNullOrWhiteSpace(destination))
                    {
                        throw new InvalidOperationException();
                    }

                    if (Utilities.GetHash(Path.Combine(downloadDir, destination))
                        == application.Updates[y].Files[z].Hash)
                    {
                        continue;
                    }

                    try
                    {
                        File.Delete(Path.Combine(downloadDir, destination));
                    }
                    catch (IOException)
                    {
                    }

                    bitsJob.AddFile(
                        new Uri(application.Updates[y].Files[z].Source).AbsoluteUri,
                        Path.Combine(downloadDir, destination));
                }
            }
        }
예제 #12
0
        private void MakeFirstJobsActive()
        {
            if (_activeJobs == ActiveJobs.Manual)
            {
                return;
            }

            int activeJobsNum = 0;

            switch (_activeJobs)
            {
            case ActiveJobs.One:
                activeJobsNum = 1;
                break;

            case ActiveJobs.Three:
                activeJobsNum = 3;
                break;

            case ActiveJobs.Five:
                activeJobsNum = 5;
                break;

            case ActiveJobs.All:
                activeJobsNum = lstDownloads.Items.Count;
                break;
            }

            int counter = 0;

            for (int i = 0; i < lstDownloads.Items.Count; i++, counter++)
            {
                Guid g = (Guid)lstDownloads.Items[i].Tag;
                if (!_bitsJobs.ContainsKey(g))
                {
                    continue;
                }

                BitsJob j = _bitsJobs[g];

                if ((counter < activeJobsNum) && (j.JobState != BitsJobState.TRANSFERRING && j.JobState != BitsJobState.TRANSFERRED && j.JobState != BitsJobState.CONNECTING && j.JobState != BitsJobState.QUEUED))
                {
                    BitsManager.ResumeJob(g);
                }
                else
                {
                    if ((counter >= activeJobsNum) && (j.JobState != BitsJobState.SUSPENDED))
                    {
                        BitsManager.SuspendJob(g);
                    }
                }
            }
        }
예제 #13
0
        private static void ManageJobState(string button, BitsJob job)
        {
            switch (button)
            {
            case "Resume":
                job.Resume();
                break;

            case "Cancel":
                job.Cancel();
                break;
            }
        }
예제 #14
0
 private void ctxmiComplete_Click(object sender, EventArgs e)
 {
     if (this.lvJobList.SelectedItems.Count == 1)
     {
         JobWrapper tag     = this.lvJobList.SelectedItems[0].Tag as JobWrapper;
         BitsJob    bitsJob = tag.BitsJob;
         if ((((bitsJob.JobType == JobType.Download) && (bitsJob.State != JobState.Acknowledged)) && (bitsJob.State != JobState.Canceled)) || ((bitsJob.JobType == JobType.Upload) && (bitsJob.State == JobState.Transferred)))
         {
             bitsJob.Complete();
         }
         this.ControlsFromJobState();
     }
 }
예제 #15
0
 private void ctxmiCancel_Click(object sender, EventArgs e)
 {
     if (this.lvJobList.SelectedItems.Count == 1)
     {
         JobWrapper tag     = this.lvJobList.SelectedItems[0].Tag as JobWrapper;
         BitsJob    bitsJob = tag.BitsJob;
         if (((MessageBox.Show(string.Format("Are you sure to delete job '{0}''", bitsJob.DisplayName), "Confirmation", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) && (bitsJob.State != JobState.Acknowledged)) && (bitsJob.State != JobState.Canceled))
         {
             bitsJob.Cancel();
         }
         this.ControlsFromJobState();
     }
 }
예제 #16
0
 private void ctxmiResume_Click(object sender, EventArgs e)
 {
     if (this.lvJobList.SelectedItems.Count == 1)
     {
         JobWrapper tag     = this.lvJobList.SelectedItems[0].Tag as JobWrapper;
         BitsJob    bitsJob = tag.BitsJob;
         if ((bitsJob.State != JobState.Acknowledged) && (bitsJob.State != JobState.Canceled))
         {
             bitsJob.Resume();
         }
         this.ControlsFromJobState();
     }
 }
예제 #17
0
 private void notifyIcon_MouseClick(object sender, MouseEventArgs e)
 {
     if (e.Button == MouseButtons.Left)
     {
         BitsJob job = GetActiveJob();
         if (job != null)
         {
             notifyIcon.ShowBalloonTip(1000, "Download info", String.Format("job: {0} - {1}", job.DisplayName, job.PercentComplete.ToString("P2")), ToolTipIcon.Info);
         }
         else
         {
             notifyIcon.ShowBalloonTip(1000, "Download info", "There are no active jobs", ToolTipIcon.Info);
         }
     }
 }
예제 #18
0
        private string getButtonText(BitsJob job)
        {
            switch (job.State)
            {
            case JobState.Suspended:
                return("Resume");

            case JobState.Transferred:
            case JobState.Acknowledged:
                return("Done");

            default:
                return("Cancel");
            }
        }
예제 #19
0
        private DataGridViewRow MakeRow(BitsJob job)
        {
            var row = new DataGridViewRow();

            row.CreateCells(dataGridView1);
            row.Cells[_colIDs.FileName].Value = job.JobId; // TODO: change this to get the filename rather then the download ID
            row.Cells[_colIDs.Button].Value   = getButtonText(job);
            if (row.Cells[_colIDs.Button].Value.ToString() == "Done")
            {
                row.Cells[_colIDs.Button].ReadOnly = true;
            }
            row.Cells[_colIDs.Progress].Value = String.Format("{0}/{1}", job.Progress.BytesTransferred, job.Progress.BytesTotal);
            row.Cells[_colIDs.Status].Value   = job.State.ToString();
            row.Cells[_colIDs.ID].Value       = job.JobId.ToString();
            return(row);
        }
예제 #20
0
 private void AutoCompleteJobs( )
 {
     for (int i = 0; i < lstDownloads.Items.Count; i++)
     {
         Guid g = (Guid)lstDownloads.Items[i].Tag;
         if (!_bitsJobs.ContainsKey(g))
         {
             continue;
         }
         BitsJob j = _bitsJobs[g];
         if (j.JobState == BitsJobState.TRANSFERRED)
         {
             notifyIcon.ShowBalloonTip(1000, "Download complete", String.Format("Downloading job: {0} finished", j.DisplayName), ToolTipIcon.Info);
             BitsManager.CompleteJob(j.Guid);
         }
     }
     ShutdownWindows();
 }
예제 #21
0
        private BitsJob GetActiveJob()
        {
            BitsJob job     = null;
            BitsJob tempjob = null;
            Guid    g;

            for (int i = 0; i < lstDownloads.Items.Count; i++)
            {
                g = (Guid)lstDownloads.Items[i].Tag;
                if (!_bitsJobs.ContainsKey(g))
                {
                    continue;
                }
                tempjob = _bitsJobs[g];
                if (tempjob.JobState == BitsJobState.CONNECTING || tempjob.JobState == BitsJobState.TRANSFERRING)
                {
                    job = tempjob;
                    break;
                }
            }
            return(job);
        }
예제 #22
0
        private void ControlsFromJobState()
        {
            BitsJob bitsJob = null;

            if (this.lvJobList.SelectedItems.Count > 0)
            {
                JobWrapper tag = this.lvJobList.SelectedItems[0].Tag as JobWrapper;
                bitsJob = tag.BitsJob;
            }
            if (bitsJob == null)
            {
                this.ctxmiCancel.Visible        = false;
                this.ctxmiComplete.Visible      = false;
                this.ctxmiSuspend.Visible       = false;
                this.ctxmiResume.Visible        = false;
                this.ctxdlPriority.Visible      = false;
                this.ctxmiPriorityMap.Visible   = false;
                this.ctxmiJobProperties.Visible = false;
                this.ctxsepJob2.Visible         = this.ctxsepJob3.Visible = false;
            }
            else
            {
                this.ctxmiJobProperties.Visible = true;
                this.ctxmiCancel.Visible        = true;
                this.ctxmiComplete.Visible      = true;
                this.ctxmiSuspend.Visible       = true;
                this.ctxmiResume.Visible        = true;
                this.ctxmiPriorityMap.Visible   = true;
                this.ctxdlPriority.Visible      = true;
                this.ctxsepJob2.Visible         = this.ctxsepJob3.Visible = true;
                switch (bitsJob.State)
                {
                case JobState.Queued:
                    this.ctxmiResume.Enabled        = true;
                    this.ctxmiSuspend.Enabled       = true;
                    this.ctxmiCancel.Enabled        = true;
                    this.ctxmiComplete.Enabled      = true;
                    this.ctxdlPriority.Enabled      = true;
                    this.ctxmiJobProperties.Enabled = true;
                    break;

                case JobState.Connecting:
                    this.ctxmiResume.Enabled        = false;
                    this.ctxmiSuspend.Enabled       = true;
                    this.ctxmiCancel.Enabled        = true;
                    this.ctxmiComplete.Enabled      = true;
                    this.ctxdlPriority.Enabled      = true;
                    this.ctxmiJobProperties.Enabled = true;
                    break;

                case JobState.Transferring:
                    this.ctxmiResume.Enabled        = false;
                    this.ctxmiSuspend.Enabled       = true;
                    this.ctxmiCancel.Enabled        = true;
                    this.ctxmiComplete.Enabled      = true;
                    this.ctxdlPriority.Enabled      = true;
                    this.ctxmiJobProperties.Enabled = true;
                    break;

                case JobState.Suspended:
                    this.ctxmiResume.Enabled        = true;
                    this.ctxmiSuspend.Enabled       = false;
                    this.ctxmiCancel.Enabled        = true;
                    this.ctxmiComplete.Enabled      = true;
                    this.ctxdlPriority.Enabled      = true;
                    this.ctxmiJobProperties.Enabled = true;
                    break;

                case JobState.Error:
                    this.ctxmiResume.Enabled        = true;
                    this.ctxmiSuspend.Enabled       = true;
                    this.ctxmiCancel.Enabled        = true;
                    this.ctxmiComplete.Enabled      = true;
                    this.ctxdlPriority.Enabled      = true;
                    this.ctxmiJobProperties.Enabled = true;
                    break;

                case JobState.TransientError:
                    this.ctxmiResume.Enabled        = true;
                    this.ctxmiSuspend.Enabled       = false;
                    this.ctxmiCancel.Enabled        = true;
                    this.ctxmiComplete.Enabled      = true;
                    this.ctxdlPriority.Enabled      = true;
                    this.ctxmiJobProperties.Enabled = true;
                    break;

                case JobState.Transferred:
                    this.ctxmiResume.Enabled        = false;
                    this.ctxmiSuspend.Enabled       = false;
                    this.ctxmiCancel.Enabled        = true;
                    this.ctxmiComplete.Enabled      = true;
                    this.ctxdlPriority.Enabled      = true;
                    this.ctxmiJobProperties.Enabled = true;
                    break;

                case JobState.Acknowledged:
                    this.ctxmiCancel.Enabled        = false;
                    this.ctxmiComplete.Enabled      = false;
                    this.ctxmiSuspend.Enabled       = false;
                    this.ctxmiResume.Enabled        = false;
                    this.ctxdlPriority.Enabled      = false;
                    this.ctxmiJobProperties.Enabled = false;
                    break;

                case JobState.Canceled:
                    this.ctxmiCancel.Enabled        = false;
                    this.ctxmiComplete.Enabled      = false;
                    this.ctxmiSuspend.Enabled       = false;
                    this.ctxmiResume.Enabled        = false;
                    this.ctxdlPriority.Enabled      = false;
                    this.ctxmiJobProperties.Enabled = false;
                    break;
                }
                this.ctxdlPriority.SelectedIndexChanged -= new EventHandler(this.ctxdlPriority_SelectedIndexChanged);
                this.ctxdlPriority.SelectedIndex         = (int)bitsJob.Priority;
                this.ctxdlPriority.SelectedIndexChanged += new EventHandler(this.ctxdlPriority_SelectedIndexChanged);
            }
        }
예제 #23
0
 public static BitsJob GetJob( Guid jobId )
 {
     try
     {
         IBackgroundCopyJob bitsJob;
         _bitsManager.GetJob( ref jobId, out bitsJob );
         var job = new BitsJob( new BitsJobAdapter( bitsJob ) );
         return job;
     }
     catch ( COMException ex )
     {
         throw new BitsException( ex );
     }
 }
 /// <summary>Initializes a new instance of the <see cref="NotificationEventArgs" /> class.</summary>
 /// <param name="job">The job the event occurred for.</param>
 internal NotificationEventArgs(BitsJob job)
 {
     this.Job = job;
 }
예제 #25
0
        private void lvJobFiles_DrawSubItem(object sender, DrawListViewSubItemEventArgs e)
        {
            Rectangle       rectangle;
            Brush           gradientActiveCaption;
            BitsFile        tag        = (BitsFile)e.Item.Tag;
            BitsJob         bitsJob    = base.wrapper.BitsJob;
            Color           windowText = SystemColors.WindowText;
            Font            prototype  = this.lvJobFiles.Font;
            TextFormatFlags flags      = TextFormatFlags.LeftAndRightPadding | TextFormatFlags.EndEllipsis | TextFormatFlags.VerticalCenter;

            if (tag == null)
            {
                if ((bitsJob.State == JobState.Suspended) || (bitsJob.State == JobState.Queued))
                {
                    if (e.Item.Selected)
                    {
                        windowText = SystemColors.ActiveCaptionText;
                    }
                    else
                    {
                        windowText = SystemColors.InactiveCaptionText;
                    }
                    prototype = new Font(prototype, FontStyle.Italic);
                }
                else if ((bitsJob.State == JobState.Error) || (bitsJob.State == JobState.TransientError))
                {
                    windowText = Color.Red;
                }
                else if ((bitsJob.State == JobState.Transferred) || (bitsJob.State == JobState.Acknowledged))
                {
                    windowText = Settings.Default.ProgressCompletedColor;
                    prototype  = new Font(prototype, FontStyle.Strikeout);
                }
                else if (bitsJob.State == JobState.Canceled)
                {
                    if (e.Item.Selected)
                    {
                        windowText = SystemColors.ActiveCaptionText;
                    }
                    else
                    {
                        windowText = SystemColors.InactiveCaptionText;
                    }
                    prototype = new Font(prototype, FontStyle.Strikeout);
                }
                else if (bitsJob.State == JobState.Connecting)
                {
                    windowText = Color.YellowGreen;
                }
                else if (bitsJob.State == JobState.Transferring)
                {
                    windowText = Settings.Default.ProgressDoneColor;
                }
            }
            if (e.Item.Selected)
            {
                int num = (e.ColumnIndex == 0) ? 1 : 0;
                rectangle = new Rectangle(e.Bounds.X + num, e.Bounds.Y + 1, e.Bounds.Width - num, e.Bounds.Height - 2);
                if (this.lvJobFiles.Focused)
                {
                    gradientActiveCaption = SystemBrushes.GradientActiveCaption;
                }
                else
                {
                    gradientActiveCaption = SystemBrushes.GradientInactiveCaption;
                }
                e.Graphics.FillRectangle(gradientActiveCaption, rectangle);
            }
            if (e.SubItem.Name.Equals("BytesTotal"))
            {
                TextRenderer.DrawText(e.Graphics, e.SubItem.Text, prototype, e.Bounds, windowText, flags | TextFormatFlags.Right);
            }
            else if (e.SubItem.Name.Equals("BytesTransfered"))
            {
                TextRenderer.DrawText(e.Graphics, e.SubItem.Text, prototype, e.Bounds, windowText, flags | TextFormatFlags.Right);
            }
            else if (e.SubItem.Name == "Progress")
            {
                Rectangle    rectangle2;
                StringFormat format = new StringFormat();
                format.Alignment      = StringAlignment.Center;
                gradientActiveCaption = new SolidBrush(Settings.Default.ProgressLeftColor);
                rectangle             = new Rectangle(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height);
                e.Graphics.FillRectangle(gradientActiveCaption, rectangle);
                JobProgress progress = null;
                if (tag != null)
                {
                    FileProgress progress2 = null;
                    progress2  = tag.Progress;
                    rectangle2 = CalcProgress(e.Bounds, progress2.BytesTotal, progress2.BytesTransferred);
                    if (progress2.BytesTransferred > 0L)
                    {
                        if (progress2.Completed || (progress2.BytesTotal == progress2.BytesTransferred))
                        {
                            gradientActiveCaption = new SolidBrush(Settings.Default.ProgressCompletedColor);
                        }
                        else
                        {
                            gradientActiveCaption = new LinearGradientBrush(rectangle, Settings.Default.ProgressDoneColor, Settings.Default.ProgressCompletedColor, LinearGradientMode.Horizontal);
                        }
                    }
                    rectangle2 = Utils.CalculateProgress(rectangle, progress2.BytesTotal, progress2.BytesTransferred);
                }
                else
                {
                    progress   = bitsJob.Progress;
                    rectangle2 = CalcProgress(e.Bounds, progress.BytesTotal, progress.BytesTransferred);
                    if (progress.BytesTransferred > 0L)
                    {
                        if ((bitsJob.State == JobState.Transferred) || (bitsJob.State == JobState.Acknowledged))
                        {
                            gradientActiveCaption = new SolidBrush(Settings.Default.ProgressCompletedColor);
                        }
                        else
                        {
                            gradientActiveCaption = new LinearGradientBrush(rectangle, Settings.Default.ProgressDoneColor, Settings.Default.ProgressCompletedColor, LinearGradientMode.Horizontal);
                        }
                    }
                    rectangle2 = Utils.CalculateProgress(rectangle, progress.BytesTotal, progress.BytesTransferred);
                }
                e.Graphics.FillRectangle(gradientActiveCaption, rectangle2);
                ControlPaint.DrawBorder(e.Graphics, rectangle, SystemColors.ActiveBorder, ButtonBorderStyle.Solid);
                windowText = SystemColors.InactiveCaptionText;
                TextRenderer.DrawText(e.Graphics, e.SubItem.Text, prototype, rectangle, windowText, TextFormatFlags.VerticalCenter | TextFormatFlags.HorizontalCenter);
            }
            else
            {
                TextRenderer.DrawText(e.Graphics, e.SubItem.Text, prototype, e.Bounds, windowText, flags);
            }
        }
 /// <summary>Initializes a new instance of the <see cref="ErrorNotificationEventArgs" /> class.</summary>
 /// <param name="job">The job the notification is for.</param>
 /// <param name="error">The error that occurred.</param>
 internal ErrorNotificationEventArgs(BitsJob job, BitsError error) : base(job)
 {
     this.Error = error;
 }
예제 #27
0
 /// <summary>
 /// Sets the necessary flags on a BitsJob to fire the events we want.
 /// </summary>
 /// <param name="job">The BitsJob whom to apply the flags.</param>
 private static void AddJobFlags(BitsJob job)
 {
     job.NotificationFlags = NotificationFlags.JobModified | NotificationFlags.JobTransferred |
                             NotificationFlags.JobErrorOccured;
 }
예제 #28
0
        /// <summary>Downloads the updates using BITS.</summary>
        /// <param name="appUpdates">The application updates to download.</param>
        /// <param name="downloadName">The name of the job.</param>
        /// <param name="downloadLocation">The directory where the files are downloaded are stored.</param>
        /// <param name="isPriority">If set to <c>True</c> the updates will download with priority.</param>
        public static void DownloadUpdates(
            Collection <Sui> appUpdates, string downloadName, string downloadLocation, bool isPriority = false)
        {
            downloadDirectory = downloadLocation;
            jobName           = downloadName;
            if (appUpdates == null)
            {
                throw new ArgumentNullException(@"appUpdates");
            }

            if (appUpdates.Count < 1)
            {
                throw new ArgumentOutOfRangeException(@"appUpdates");
            }

            IsDownloading = true;

            // It's a new manager class
            manager = new BitsManager();

            // Assign the event handlers
            manager.OnJobTransferred -= ReportDownloadComplete;
            manager.OnJobError       -= ReportDownloadError;
            manager.OnJobModified    -= ReportDownloadProgress;
            manager.OnJobTransferred += ReportDownloadComplete;
            manager.OnJobError       += ReportDownloadError;
            manager.OnJobModified    += ReportDownloadProgress;

            // Load the BITS Jobs for the entire machine and current user
            manager.EnumJobs();
            manager.EnumJobs(JobOwner.AllUsers);

            int jobCount = 0;

            // Loops through the jobs, if a Seven Update job is found, try to resume, if not cancel it.
            foreach (var job in manager.Jobs.Values.Where(job => job.DisplayName == jobName).ToList())
            {
                jobCount++;
                job.EnumerateFiles();
                if (job.Files.Count < 1)
                {
                    job.Cancel();
                    jobCount--;
                }

                if (job.State == JobState.Suspended)
                {
                    job.Resume();
                }

                if (job.State == JobState.Transferred)
                {
                    job.Complete();
                    IsDownloading = false;
                    if (DownloadCompleted != null)
                    {
                        DownloadCompleted(null, new DownloadCompletedEventArgs(false));
                    }

                    return;
                }

                if ((job.State != JobState.Error && job.State != JobState.TransientError) && job.ErrorCount <= 0)
                {
                    continue;
                }

                Utilities.ReportError(
                    new WebException(job.Error.Description + " " + job.Error.ErrorCode), ErrorType.DownloadError);
                job.Cancel();
                jobCount--;
            }

            if (jobCount > 0)
            {
                return;
            }

            BitsJob bitsJob = manager.CreateJob(jobName, JobType.Download);

            bitsJob.Priority = isPriority ? JobPriority.Foreground : JobPriority.Normal;

            bitsJob.NotificationOptions = NotificationOptions.JobErrorOccurred | NotificationOptions.JobModified
                                          | NotificationOptions.JobTransferred;
            bitsJob.NoProgressTimeout = 60;
            bitsJob.MinimumRetryDelay = 60;
            foreach (var update in appUpdates)
            {
                DownloadUpdates(update, ref bitsJob);
            }

            bitsJob.EnumerateFiles();
            if (bitsJob.Files.Count > 0)
            {
                bitsJob.Resume();
            }
            else
            {
                bitsJob.Cancel();
                IsDownloading = false;
                if (DownloadCompleted != null)
                {
                    DownloadCompleted(null, new DownloadCompletedEventArgs(false));
                }
            }
        }
 /// <summary>Initializes a new instance of the <see cref="ErrorNotificationEventArgs" /> class.</summary>
 /// <param name="job">The job the notification is for.</param>
 /// <param name="error">The error that occurred.</param>
 internal ErrorNotificationEventArgs(BitsJob job, BitsError error)
     : base(job)
 {
     this.Error = error;
 }
예제 #30
0
 public JobInfo(BitsJob j)
 {
     InitializeComponent();
     this._job = j;
     InitializeComponentEx();
 }
 /// <summary>Initializes a new instance of the <see cref="NotificationEventArgs" /> class.</summary>
 /// <param name="job">The job the event occurred for.</param>
 internal NotificationEventArgs(BitsJob job)
 {
     this.Job = job;
 }
예제 #32
0
 /// <summary>
 /// Initializes a new instance of the <see cref="JobErrorEventArgs"/> class.
 /// </summary>
 /// <param name="eventBitsJob">The event bits job.</param>
 /// <param name="errorInfo">The error info.</param>
 protected internal JobErrorEventArgs( BitsJob eventBitsJob, BitsError errorInfo )
 {
     BitsJob = eventBitsJob;
     BitsError = errorInfo;
 }
예제 #33
0
        private void lvJobList_DrawSubItem(object sender, DrawListViewSubItemEventArgs e)
        {
            Rectangle  rectangle;
            Brush      gradientActiveCaption;
            JobWrapper tag        = e.Item.Tag as JobWrapper;
            BitsJob    bitsJob    = tag.BitsJob;
            Color      windowText = SystemColors.WindowText;
            Font       prototype  = this.lvJobList.Font;
            int        num        = 0;

            if (e.SubItem.Name == bitsJob.JobId.ToString())
            {
                num = 0;
            }
            TextFormatFlags flags = TextFormatFlags.LeftAndRightPadding | TextFormatFlags.EndEllipsis | TextFormatFlags.VerticalCenter;

            if ((bitsJob.State == JobState.Suspended) || (bitsJob.State == JobState.Queued))
            {
                if (e.Item.Selected)
                {
                    windowText = SystemColors.ActiveCaptionText;
                }
                else
                {
                    windowText = SystemColors.InactiveCaptionText;
                }
                prototype = new Font(prototype, FontStyle.Italic);
            }
            else if ((bitsJob.State == JobState.Error) || (bitsJob.State == JobState.TransientError))
            {
                windowText = Color.Red;
            }
            else if ((bitsJob.State == JobState.Transferred) || (bitsJob.State == JobState.Acknowledged))
            {
                windowText = Settings.Default.ProgressCompletedColor;
                prototype  = new Font(prototype, FontStyle.Strikeout);
            }
            else if (bitsJob.State == JobState.Canceled)
            {
                if (e.Item.Selected)
                {
                    windowText = SystemColors.ActiveCaptionText;
                }
                else
                {
                    windowText = SystemColors.InactiveCaptionText;
                }
                prototype = new Font(prototype, FontStyle.Strikeout);
            }
            else if (bitsJob.State == JobState.Connecting)
            {
                windowText = Color.YellowGreen;
            }
            else if (bitsJob.State == JobState.Transferring)
            {
                windowText = Settings.Default.ProgressDoneColor;
            }
            if (e.Item.Selected)
            {
                int num2 = (e.ColumnIndex == 0) ? 1 : 0;
                rectangle = new Rectangle((e.Bounds.X + num) + num2, e.Bounds.Y + 1, (e.Bounds.Width - num) - num2, e.Bounds.Height - 2);
                if (this.lvJobList.Focused)
                {
                    gradientActiveCaption = SystemBrushes.GradientActiveCaption;
                }
                else
                {
                    gradientActiveCaption = SystemBrushes.GradientInactiveCaption;
                }
                e.Graphics.FillRectangle(gradientActiveCaption, rectangle);
            }
            if (e.SubItem.Name == ColumnNames.Progress)
            {
                StringFormat format = new StringFormat();
                format.Alignment      = StringAlignment.Center;
                gradientActiveCaption = new SolidBrush(Settings.Default.ProgressLeftColor);
                rectangle             = new Rectangle(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height);
                e.Graphics.FillRectangle(gradientActiveCaption, rectangle);
                if (bitsJob.Progress.BytesTransferred > 0L)
                {
                    if ((bitsJob.State == JobState.Transferred) || (bitsJob.State == JobState.Acknowledged))
                    {
                        gradientActiveCaption = new SolidBrush(Settings.Default.ProgressCompletedColor);
                    }
                    else
                    {
                        gradientActiveCaption = new LinearGradientBrush(rectangle, Settings.Default.ProgressDoneColor, Settings.Default.ProgressCompletedColor, LinearGradientMode.Horizontal);
                    }
                    Rectangle rect = Utils.CalculateProgress(rectangle, bitsJob.Progress.BytesTotal, bitsJob.Progress.BytesTransferred);
                    e.Graphics.FillRectangle(gradientActiveCaption, rect);
                }
                ControlPaint.DrawBorder(e.Graphics, rectangle, SystemColors.ActiveBorder, ButtonBorderStyle.Solid);
                windowText = SystemColors.InactiveCaptionText;
                TextRenderer.DrawText(e.Graphics, e.SubItem.Text, prototype, rectangle, windowText, TextFormatFlags.VerticalCenter | TextFormatFlags.HorizontalCenter);
            }
            else if (e.SubItem.Name == bitsJob.JobId.ToString())
            {
                Image image = this.imglDirection.Images[e.Item.ImageIndex];
                rectangle = new Rectangle(e.Bounds.X + 2, e.Bounds.Y + 1, image.Width, image.Height);
                e.Graphics.DrawImage(image, rectangle);
                rectangle = new Rectangle((e.Bounds.X + 2) + this.textDelta, e.Bounds.Y + 1, (e.Bounds.Width - 2) - this.textDelta, e.Bounds.Height);
                TextRenderer.DrawText(e.Graphics, e.SubItem.Text, prototype, rectangle, windowText, flags);
            }
            else if (e.SubItem.Name == ColumnNames.JobState)
            {
                TextRenderer.DrawText(e.Graphics, e.SubItem.Text, prototype, e.Bounds, windowText, flags);
            }
            else
            {
                TextRenderer.DrawText(e.Graphics, e.SubItem.Text, prototype, e.Bounds, windowText, flags | TextFormatFlags.Right);
            }
        }