public GetProgress ( ApplicationJob job ) : short | ||
job | ApplicationJob | |
Результат | short |
public override void Render(Graphics g, Rectangle r) { ApplicationJob job = RowObject as ApplicationJob; // Do not draw anything if the updater is not currently working if (m_Updater.GetProgress(job) == -1) { base.DrawBackground(g, r); return; } base.Render(g, r); long fileSize = m_Updater.GetDownloadSize(job); // No file size has been determined yet if (fileSize == -2) { return; } using (Brush fontBrush = new SolidBrush(SystemColors.WindowText)) { StringFormat format = new StringFormat(); format.Alignment = StringAlignment.Center; format.LineAlignment = StringAlignment.Center; string text = FormatFileSize.Format(fileSize); if (fileSize < 0) { text = "(unknown)"; } g.DrawString(text, new Font(this.Font, FontStyle.Bold), fontBrush, r, format); } }
public MainForm() { InitializeComponent(); olvJobs.Initialize(); olvJobs.ContextMenu = cmnuJobs; colName.AspectGetter = delegate(object x) { return(((ApplicationJob)x).Name); }; colName.GroupKeyGetter = delegate(object x) { ApplicationJob job = (ApplicationJob)x; if (job.Name.Length == 0) { return(string.Empty); } return(job.Name[0].ToString().ToUpper()); }; // Gray out disabled jobs olvJobs.RowFormatter = delegate(OLVListItem item) { if (!((ApplicationJob)item.RowObject).Enabled) { item.ForeColor = Color.Gray; } else { item.ForeColor = olvJobs.ForeColor; } }; colName.ImageGetter = delegate(object x) { ApplicationJob job = (ApplicationJob)x; // Gray icon if disabled if (!job.Enabled && !string.IsNullOrEmpty(job.CurrentLocation) && m_Updater.GetStatus(job) == Updater.Status.Idle) { try { string disabledKey = job.CurrentLocation + "|Disabled"; if (!imlStatus.Images.ContainsKey(disabledKey)) { // No icon if no file exists if (!File.Exists(job.CurrentLocation)) { return(0); } Icon programIcon = IconReader.GetFileIcon(job.CurrentLocation, IconReader.IconSize.Small, false); imlStatus.Images.Add(disabledKey, MakeGrayscale(programIcon.ToBitmap())); } return(disabledKey); } catch (ArgumentException) { // no icon could be determined, use default } } // If available and idle, use the program icon if (m_Updater.GetStatus(job) == Updater.Status.Idle && !string.IsNullOrEmpty(job.CurrentLocation)) { try { if (!imlStatus.Images.ContainsKey(job.CurrentLocation)) { // No icon if no file exists if (!File.Exists(job.CurrentLocation)) { return(0); } Icon programIcon = IconReader.GetFileIcon(job.CurrentLocation, IconReader.IconSize.Small, false); imlStatus.Images.Add(job.CurrentLocation, programIcon); } return(job.CurrentLocation); } catch (ArgumentException) { // no icon could be determined, use default } } return((int)m_Updater.GetStatus(job)); }; colStatus.AspectGetter = delegate(object x) { return(m_Updater.GetStatus(x as ApplicationJob)); }; colStatus.AspectToStringConverter = delegate(object x) { switch ((Updater.Status)x) { case Updater.Status.Downloading: return("Downloading"); case Updater.Status.Failure: return("Failed"); case Updater.Status.Idle: return("Idle"); case Updater.Status.NoUpdate: return("No update"); case Updater.Status.UpdateSuccessful: return("Updated"); case Updater.Status.UpdateAvailable: return("Update available"); } return(string.Empty); }; colTarget.AspectGetter = delegate(object x) { ApplicationJob job = x as ApplicationJob; return(job.Variables.ReplaceAllInString(job.TargetPath, DateTime.MinValue, null, true)); }; colTarget.GroupKeyGetter = delegate(object x) { return(((ApplicationJob)x).TargetPath.ToLower()); }; colLastUpdate.AspectGetter = delegate(object x) { return(((ApplicationJob)x).LastUpdated); }; colLastUpdate.AspectToStringFormat = "{0:g}"; colLastUpdate.GroupKeyGetter = delegate(object x) { ApplicationJob job = (ApplicationJob)x; if (job.LastUpdated == null) { return(DateTime.MinValue); } return(job.LastUpdated.Value.Date); }; colLastUpdate.GroupKeyToTitleConverter = delegate(object x) { if ((DateTime)x == DateTime.MinValue) { return(string.Empty); } return(((DateTime)x).ToString("d")); }; colProgress.AspectGetter = delegate(object x) { return(m_Updater.GetProgress(x as ApplicationJob)); }; colProgress.Renderer = new ApplicationJobsListView.ProgressRenderer(m_Updater, 0, 100); m_Updater.ProgressChanged += new EventHandler <Updater.JobProgressChangedEventArgs>(m_Updater_ProgressChanged); m_Updater.StatusChanged += new EventHandler <Updater.JobStatusChangedEventArgs>(m_Updater_StatusChanged); m_Updater.UpdateCompleted += new EventHandler(m_Updater_UpdateCompleted); m_Updater.UpdatesFound += new EventHandler <GenericEventArgs <string[]> >(m_Updater_UpdatesFound); LogDialog.Instance.VisibleChanged += new EventHandler(delegate(object sender, EventArgs e) { mnuLog.Checked = LogDialog.Instance.Visible; }); this.olvJobs.FilterChanged += new EventHandler(olvJobs_FilterChanged); imlStatus.Images.Add(Properties.Resources.Document); imlStatus.Images.Add(Properties.Resources.Import); imlStatus.Images.Add(Properties.Resources.New); imlStatus.Images.Add(Properties.Resources.NewDownloaded); imlStatus.Images.Add(Properties.Resources.Symbol_Check); imlStatus.Images.Add(Properties.Resources.Symbol_Delete); imlStatus.Images.Add(Properties.Resources.Document_Restricted); }