public ProgressUpdateStateBlock(ProgressUpdateStateBlock rhs) { // Copy constructor this.what = rhs.what; this.pageSum = rhs.pageSum; this.pageCurrent = rhs.pageCurrent; this.pageInfo = rhs.pageInfo; this.stagePercent = rhs.stagePercent; this.stageInfo = rhs.stageInfo; }
private void RollbackAnimation() { int progressPageValue = progressPage.Value; int progressStageValue = progressStage.Value; ProgressUpdateStateBlock state = new ProgressUpdateStateBlock(); state.what = ProgressUpdateState.Page; state.pageInfo = @"Canceling..."; state.pageCurrent = progressPageValue; state.pageSum = ProgressHandler.NumPages; state.stageInfo = @""; ProgressChanged(state); for (int i = progressStageValue; i >= 0; --i) { if (progressStageValue > 0) { if (i > 5) { // Sleeping helps with human comprehension (but let's not over do it) Thread.Sleep(1); } else { // Sleeping helps with human comprehension Thread.Sleep(2); } state.what = ProgressUpdateState.Stage; state.stagePercent = i; ProgressChanged(state); } } for (int i = progressPageValue; i >= 0; --i) { if (progressPageValue > 0) { if (i > 50) { // Sleeping helps with human comprehension (but let's not over do it) Thread.Sleep(1); } else { // Sleeping helps with human comprehension Thread.Sleep(2); } state.what = ProgressUpdateState.Page; state.pageCurrent = i; state.pageSum = ProgressHandler.NumPages; ProgressChanged(state); } } this.Close(); }
public void ProgressStageAssign(ProgressUpdateStateBlock state) { // Transfer the state (block) information to the control(s)... // Updates (of the UI) will happen automatically (after assignment, per each) if (state.stageInfo != null) { labelStageInfo.Text = state.stageInfo; } if (state.stagePercent > 0.0 && state.stagePercent <= 1.0) { progressStage.Value = (int)Math.Floor(progressStage.Maximum * state.stagePercent); labelStagePercent.Text = String.Format("{0}%", progressStage.Value); } else { progressStage.Value = 0; labelStagePercent.Text = @""; } }
public void ProgressPageAssign(ProgressUpdateStateBlock state) { // Transfer the state (block) information to the control(s)... // Updates (of the UI) will happen automatically (after assignment, per each) if (state.pageSum > 0 && progressPage.Maximum != state.pageSum) { progressPage.Maximum = state.pageSum; } if (state.pageInfo != null) { labelPageInfo.Text = state.pageInfo; } if (state.pageCurrent > 0) { if (state.pageCurrent > progressPage.Maximum) { state.pageCurrent = progressPage.Maximum; } progressPage.Value = state.pageCurrent; } }
public void ProgressChanged(ProgressUpdateStateBlock state) { switch (state.what) { case ProgressUpdateState.Page: { if (this.InvokeRequired) { // Consult: https://msdn.microsoft.com/en-us/library/2e08f6yc%28v=vs.110%29.aspx object[] myArray = new object[1]; myArray[0] = new ProgressUpdateStateBlock(state); progressPage.BeginInvoke(new ProgressDelegate(ProgressPageAssign), myArray); } else { // This needs to be present (albeit unlikely to ever execute) if (state.pageInfo != null) { labelPageInfo.Text = state.pageInfo; } if (state.pageCurrent > 0) { if (state.pageCurrent > progressPage.Maximum) { state.pageCurrent = progressPage.Maximum; } progressPage.Value = state.pageCurrent; } } break; } case ProgressUpdateState.Stage: { if (this.InvokeRequired) { // Consult: https://msdn.microsoft.com/en-us/library/2e08f6yc%28v=vs.110%29.aspx object[] myArray = new object[1]; myArray[0] = new ProgressUpdateStateBlock(state); progressStage.BeginInvoke(new ProgressDelegate(ProgressStageAssign), myArray); } else { // This needs to be present (albeit unlikely to ever execute) if (state.stageInfo != null) { labelStageInfo.Text = state.stageInfo; } if (state.stagePercent > 0.0 && state.stagePercent <= 1.0) { progressStage.Value = (int)Math.Floor(progressStage.Maximum * state.stagePercent); labelStagePercent.Text = String.Format("{0}%", state.stagePercent); } else { progressStage.Value = 0; labelStagePercent.Text = @""; } } break; } } }
private void ReportProgress(int page, int totalPages, float stagePercent, string info, PrintProgressStage stage) { // The primary progress update handler... switch (stage) { // // If all one wants is a simple, per page progress bar ALL THAT NEEDS BE DONE // is to switch on the PrintPage enumeration and present page count information. // When doing so, do not forget to change the page from 0-based to 1-based notation. // A value of -1 for either value means "not applicable". If one encounters -1, // simply ignore the update process for page/NumPages during that encounter. // // // APDFL cannot know how long things will take. So, any desire for an accurate // or trivial 0-100% progress bar is a bit of a misnomer. The closest one can // come to that sort of thing is to show page-level tracking (e.g., Page X of Y). // NONE of the percentage (or page progression) values can ever be equated // to any notion of time, remaining or otherwise. // // Performing simple math like: // // ((page / totalPages) * 100) * <median page time consumption thus far> // // ...will NOT accurately predict remaining time. // // Attempting to provide an estimate of time remaining (when printing or rendering) // a PDF is a futile process. Unlike network transmission times for a known quantity, // APDFL *cannot know* (and cannot be altered to know) how long the next page will // take to process. // // // TIP: When working on a solution that drives commercial digital print devices or // a similar high throughput 24/7/365 "keep the planes in the air, not on the ground" // environment... // // Flattening transparent artwork within the (greater) context of printing can be // a bad idea. // // One should investigate structuring the solution so that artwork to be printed // is pre-flattened (see FlattenPDF sample) and saved to a completely non-transparent // PDF *first* (separately). Then, simply print the pre-flattened (temp) file for // best performance. Separating these activities can greatly improve overall solution // performance and (printing) predictability. // case PrintProgressStage.PrintPage: { // Happens twice... // Once just before a page begins. Then again, just after the page ends. // This is the case where one should update Page progress... ProgressUpdateStateBlock state = new ProgressUpdateStateBlock(); if (state.stagePercent < 1.0) { // Start page... state.what = ProgressUpdateState.Page; state.pageCurrent = ((page > 1) ? page : 1); state.pageSum = ((NumPages > 1) ? NumPages : 1); state.pageInfo = String.Format("Page {0} of {1}", state.pageCurrent, state.pageSum); ProgressUI.ProgressChanged(state); Console.WriteLine(String.Format("Printing {0}.", state.pageInfo)); } else { // End page... // Reset the stage info at page end state.what = ProgressUpdateState.Stage; state.stageInfo = @""; state.stagePercent = 0; ProgressUI.ProgressChanged(state); } break; } // // ALL of the remaining enumeration values are optional. // If not interested is presenting stage information to a human, // the remaining case block(s) can be omitted entirely. // case PrintProgressStage.PrintProg_StreamingDocumentResource: case PrintProgressStage.PrintProg_StreamingDocumentProcset: { // Downloading a (document level) PostScript dictionary (%%BeginProlog)... ProgressUpdateStateBlock state = new ProgressUpdateStateBlock(); state.what = ProgressUpdateState.Stage; state.stageInfo = "Preparing Document"; state.stagePercent = stagePercent; ProgressUI.ProgressChanged(state); // // Sleeping here helps with human comprehension // of UI updates but slows printing throughput. // Thread.Sleep(10); break; } case PrintProgressStage.PrintProg_StreamingDocumentFont: case PrintProgressStage.PrintProg_StreamingPageFont: { // Downloading a font (info will contain the font name)... ProgressUpdateStateBlock state = new ProgressUpdateStateBlock(); state.what = ProgressUpdateState.Stage; if (info.Length > 0) { state.stageInfo = String.Format("Downloading Font: {0}", info); } else { state.stageInfo = @"Downloading Font"; } state.stagePercent = stagePercent; ProgressUI.ProgressChanged(state); // // Sleeping here helps with human comprehension // of UI updates but slows printing throughput. // Thread.Sleep(10); break; } case PrintProgressStage.PrintProg_StreamingPageContent: { // Sending miscellaneous, page content... ProgressUpdateStateBlock state = new ProgressUpdateStateBlock(); state.what = ProgressUpdateState.Stage; state.stageInfo = @"Streaming Page Content"; state.stagePercent = stagePercent; ProgressUI.ProgressChanged(state); // // Sleeping here helps with human comprehension // of UI updates but slows printing throughput. // Thread.Sleep(10); break; } case PrintProgressStage.PrintProg_StreamingPageResource: { // Downloading a (page level) PostScript dictionary... ProgressUpdateStateBlock state = new ProgressUpdateStateBlock(); state.what = ProgressUpdateState.Stage; state.stageInfo = @"Streaming Page Resource"; state.stagePercent = stagePercent; ProgressUI.ProgressChanged(state); // // Sleeping here helps with human comprehension // of UI updates but slows printing throughput. // Thread.Sleep(10); break; } case PrintProgressStage.PrintProg_StreamingPageGradient: { // Downloading a gradient... ProgressUpdateStateBlock state = new ProgressUpdateStateBlock(); state.what = ProgressUpdateState.Stage; state.stageInfo = @"Streaming Page Gradient"; state.stagePercent = stagePercent; ProgressUI.ProgressChanged(state); // // Sleeping here helps with human comprehension // of UI updates but slows printing throughput. // Thread.Sleep(10); break; } case PrintProgressStage.PrintProg_StreamingPageImage: case PrintProgressStage.PrintProg_StreamingPageImageProgressPercent: { // Downloading raster image data... ProgressUpdateStateBlock state = new ProgressUpdateStateBlock(); state.what = ProgressUpdateState.Stage; state.stageInfo = @"Streaming Page Image"; state.stagePercent = stagePercent; ProgressUI.ProgressChanged(state); // // Sleeping here helps with human comprehension // of UI updates but slows printing throughput. // Thread.Sleep(10); break; } case PrintProgressStage.PrintProg_StreamingPageImageOPI: { // Replacing an OPI proxy (only occurs when client provides additional OPI replacement callbacks)... ProgressUpdateStateBlock state = new ProgressUpdateStateBlock(); state.what = ProgressUpdateState.Stage; state.stageInfo = @"Replacing Open Prepress Interface (OPI) Proxy Image"; state.stagePercent = stagePercent; ProgressUI.ProgressChanged(state); // // Sleeping here helps with human comprehension // of UI updates but slows printing throughput. // Thread.Sleep(10); break; } case PrintProgressStage.PrintProg_StreamingPageSeparation: { // Sending a color separation (plate)... ProgressUpdateStateBlock state = new ProgressUpdateStateBlock(); state.what = ProgressUpdateState.Stage; state.stageInfo = @"Streaming Page Separation"; state.stagePercent = stagePercent; ProgressUI.ProgressChanged(state); // // Sleeping here helps with human comprehension // of UI updates but slows printing throughput. // Thread.Sleep(10); break; } case PrintProgressStage.PrintProg_StreamingPageCSA: case PrintProgressStage.PrintProg_StreamingPageCRD: { // (Converting a ICC profile to and) Downloading (PostScript) ColorSpace Array or Color Rendering Dictionary... ProgressUpdateStateBlock state = new ProgressUpdateStateBlock(); state.what = ProgressUpdateState.Stage; state.stageInfo = @"Streaming Page Content (CSA/CRD)"; state.stagePercent = stagePercent; ProgressUI.ProgressChanged(state); // // Sleeping here helps with human comprehension // of UI updates but slows printing throughput. // Thread.Sleep(10); break; } case PrintProgressStage.PrintFlat_EnterInFlattener: // Start of flattener (0%) case PrintProgressStage.PrintFlat_IdentifyingComplexityRegion: case PrintProgressStage.PrintFlat_ComputingComplexityRegionClippath: case PrintProgressStage.PrintFlat_EnterInPlanarMap: case PrintProgressStage.PrintFlat_FlattenAtomicRegions: { // Flattener preparation activities... ProgressUpdateStateBlock state = new ProgressUpdateStateBlock(); state.what = ProgressUpdateState.Stage; state.stageInfo = "Flattening..."; state.stagePercent = stagePercent; ProgressUI.ProgressChanged(state); // // Sleeping here helps with human comprehension // of UI updates but slows printing throughput. // Thread.Sleep(10); break; } case PrintProgressStage.PrintFlat_FindObjectsInvolvedInTransparency: { // (Flattener) Searching for Transparency... ProgressUpdateStateBlock state = new ProgressUpdateStateBlock(); state.what = ProgressUpdateState.Stage; state.stageInfo = "Searching for Transparent Art..."; state.stagePercent = stagePercent; ProgressUI.ProgressChanged(state); // // Sleeping here helps with human comprehension // of UI updates but slows printing throughput. // Thread.Sleep(10); break; } case PrintProgressStage.PrintFlat_TextHeuristics: { // (Flattener) Calculating Text Interactions... ProgressUpdateStateBlock state = new ProgressUpdateStateBlock(); state.what = ProgressUpdateState.Stage; state.stageInfo = "Searching for Transparent Text..."; state.stagePercent = stagePercent; ProgressUI.ProgressChanged(state); // // Sleeping here helps with human comprehension // of UI updates but slows printing throughput. // Thread.Sleep(10); break; } case PrintProgressStage.PrintFlat_RasterizingComplexityRegion: { // (Flattener) Rasterizing... ProgressUpdateStateBlock state = new ProgressUpdateStateBlock(); state.what = ProgressUpdateState.Stage; state.stageInfo = "Rasterizing Transparent Art..."; state.stagePercent = stagePercent; ProgressUI.ProgressChanged(state); // // Sleeping here helps with human comprehension // of UI updates but slows printing throughput. // Thread.Sleep(10); break; } case PrintProgressStage.PrintProg_OnHostTrapBeginPage: case PrintProgressStage.PrintProg_BeginStreamingTraps: { // On-Host (not in-RIP) trapping activities... ProgressUpdateStateBlock state = new ProgressUpdateStateBlock(); state.what = ProgressUpdateState.Stage; state.stageInfo = "On-Host Trapping"; state.stagePercent = stagePercent; ProgressUI.ProgressChanged(state); // // Sleeping here helps with human comprehension // of UI updates but slows printing throughput. // Thread.Sleep(10); break; } case PrintProgressStage.PrintProg_StreamingPageEpilogue: { // End of page activities (i.e., %%PageTrailer)... ProgressUpdateStateBlock state = new ProgressUpdateStateBlock(); state.what = ProgressUpdateState.Stage; state.stageInfo = "Finalizing Page"; for (float i = 0.0F; i <= 1.0F; i += 0.25F) { // Emulate stage progression (when we only get a single call) state.stagePercent = i; ProgressUI.ProgressChanged(state); // // Sleeping here helps with human comprehension // of UI updates but slows printing throughput. // Thread.Sleep(2); } // // Sleeping here helps with human comprehension // of UI updates but slows printing throughput. // Thread.Sleep(10); break; } case PrintProgressStage.PrintProg_StreamingDocumentEpilogue: { // End of file activities (i.e., %%Trailer)... ProgressUpdateStateBlock state = new ProgressUpdateStateBlock(); state.what = ProgressUpdateState.Stage; state.pageInfo = "Finalizing Document"; for (float i = 0.0F; i <= 1.0F; i += 0.25F) { // Eemulate stage progression (when we only get a single call) state.stagePercent = i; ProgressUI.ProgressChanged(state); // // Sleeping here helps with human comprehension // of UI updates but slows printing throughput. // Thread.Sleep(2); } // // Sleeping here helps with human comprehension // of UI updates but slows printing throughput. // Thread.Sleep(10); // Conclude the progress UI... state.what = ProgressUpdateState.Page; state.stageInfo = "Printing Complete"; state.pageCurrent = 0; state.pageSum = 0; break; } } }