/// <summary> /// the client can cancel the job /// </summary> /// <param name="AClientID"></param> static public bool CancelJob(string AClientID) { lock (ProgressLockObject) { if (FProgressStates.ContainsKey(AClientID)) { TProgressState state = FProgressStates[AClientID]; if (state.JobFinished == true) { if (TLogging.DebugLevel >= DEBUG_PROGRESS) { TLogging.Log("Cannot cancel the job for " + AClientID + " because the job has already finished"); } } else { state.CancelJob = true; if (TLogging.DebugLevel >= DEBUG_PROGRESS) { TLogging.Log("Cancelled the job for " + AClientID); } return(true); } } return(false); } }
/// <summary> /// the client can cancel the job /// </summary> /// <param name="AClientID"></param> static public bool CancelJob(string AClientID) { if (TSession.HasVariable(PROGRESSTRACKER + AClientID)) { TProgressState state = ((JObject)TSession.GetVariable(PROGRESSTRACKER + AClientID)).ToObject <TProgressState>(); TLogging.SetStatusBarProcedure(null); if (state.JobFinished == true) { if (TLogging.DebugLevel >= DEBUG_PROGRESS) { TLogging.Log("Cannot cancel the job for " + AClientID + " because the job has already finished"); } } else { state.CancelJob = true; if (TLogging.DebugLevel >= DEBUG_PROGRESS) { TLogging.Log("Cancelled the job for " + AClientID); } TSession.SetVariable(PROGRESSTRACKER + AClientID, state); return(true); } } return(false); }
public static bool GetCurrentState(out string ACaption, out string AStatusMessage, out int APercentageDone, out bool AJobFinished) { TProgressState state = TProgressTracker.GetCurrentState(DomainManager.GClientID.ToString()); ACaption = state.Caption; AStatusMessage = state.StatusMessage; APercentageDone = state.PercentageDone; AJobFinished = state.JobFinished; return(state.PercentageDone != -1 || state.StatusMessage != string.Empty); }
/// <summary> /// add or reuse a tracker for the given clientID /// </summary> /// <param name="AClientID"></param> /// <param name="ACaption"></param> /// <param name="AAbsoluteOverallAmount"></param> /// <returns></returns> static public TProgressState InitProgressTracker(string AClientID, string ACaption, decimal AAbsoluteOverallAmount = 100.0m) { TProgressState state = new TProgressState(); state.AbsoluteOverallAmount = AAbsoluteOverallAmount; state.Caption = ACaption; TSession.SetVariable(PROGRESSTRACKER + AClientID, state); return(state); }
/// <summary> /// add or reuse a tracker for the given clientID /// </summary> /// <param name="AClientID"></param> /// <param name="ACaption"></param> /// <param name="AAbsoluteOverallAmount"></param> /// <returns></returns> static public TProgressState InitProgressTracker(string AClientID, string ACaption, decimal AAbsoluteOverallAmount = 100.0m) { TProgressState state = new TProgressState(); state.AbsoluteOverallAmount = AAbsoluteOverallAmount; state.Caption = ACaption; // First clear all progress trackers. We cannot have too many variables in the session. We only work with one progress tracker per session. TSession.ClearVariables(PROGRESSTRACKER); TSession.SetVariable(PROGRESSTRACKER + AClientID, state); return(state); }
/// <summary> /// the server will set the job to finished /// </summary> static public bool FinishJob(string AClientID) { if (FProgressStates.ContainsKey(AClientID)) { TProgressState state = FProgressStates[AClientID]; state.JobFinished = true; if (TLogging.DebugLevel >= DEBUG_PROGRESS) { TLogging.Log("Finished the job for " + AClientID); } return(true); } return(false); }
private void AsyncProgressCheckThread() { String OldLoggingText; DateTime startTime; OldLoggingText = ""; startTime = DateTime.Now; while (FKeepUpProgressCheck) { TProgressState state = FReportingGenerator.Progress; if (state.JobFinished) { this.Duration = DateTime.Now - startTime; if (FReportingGenerator.GetSuccess() == true) { this.Parameters.LoadFromDataTable(FReportingGenerator.GetParameter()); this.Results.LoadFromDataTable(FReportingGenerator.GetResult()); this.Results.SetMaxDisplayColumns(this.Parameters.Get("MaxDisplayColumns").ToInt()); } else { TLogging.Log(FReportingGenerator.GetErrorMessage()); } FKeepUpProgressCheck = false; } else { if ((state.StatusMessage != null) && (!OldLoggingText.Equals(state.StatusMessage))) { TLogging.Log(state.StatusMessage, TLoggingType.ToStatusBar); OldLoggingText = state.StatusMessage; } } if (FKeepUpProgressCheck) { // Sleep for some time. Then check again for latest progress information Thread.Sleep(500); } } }
/// <summary> /// get the current state, by clientID /// </summary> /// <param name="AClientID"></param> /// <returns></returns> static public TProgressState GetCurrentState(string AClientID) { TSession.RefreshFromDatabase(); if ((AClientID != null) && TSession.HasVariable(PROGRESSTRACKER + AClientID)) { TProgressState state = ((JObject)TSession.GetVariable(PROGRESSTRACKER + AClientID)).ToObject <TProgressState>(); if (state.PercentageDone > 100) { TLogging.Log("invalid percentage: " + state.PercentageDone.ToString()); state.PercentageDone = 99; } return(state); } return(new TProgressState()); }
/// <summary> /// add or reuse a tracker for the given clientID /// </summary> /// <param name="AClientID"></param> /// <param name="ACaption"></param> /// <param name="AAbsoluteOverallAmount"></param> /// <returns></returns> static public TProgressState InitProgressTracker(string AClientID, string ACaption, decimal AAbsoluteOverallAmount = 100.0m) { TProgressState state = new TProgressState(); state.AbsoluteOverallAmount = AAbsoluteOverallAmount; state.Caption = ACaption; if (FProgressStates.ContainsKey(AClientID)) { FProgressStates[AClientID] = state; } else { FProgressStates.Add(AClientID, state); } return(state); }
/// <summary> /// set the current state /// </summary> /// <param name="AClientID"></param> /// <param name="AStatusMessage"></param> /// <param name="ACurrentAbsoluteAmount"></param> static public void SetCurrentState(string AClientID, string AStatusMessage, Decimal ACurrentAbsoluteAmount) { if (TSession.HasVariable(PROGRESSTRACKER + AClientID)) { TProgressState state = ((JObject)TSession.GetVariable(PROGRESSTRACKER + AClientID)).ToObject <TProgressState>(); if (AStatusMessage.Length > 0) { state.StatusMessage = AStatusMessage; } state.PercentageDone = Convert.ToInt32((ACurrentAbsoluteAmount / state.AbsoluteOverallAmount) * 100.0m); if (TLogging.DebugLevel >= DEBUG_PROGRESS) { // avoid recursive calls, especially during report calculation Console.WriteLine(state.PercentageDone.ToString() + "%: " + state.StatusMessage); } TSession.SetVariable(PROGRESSTRACKER + AClientID, state); } }
/// <summary> /// the server will set the job to finished /// </summary> static public bool FinishJob(string AClientID) { if (TSession.HasVariable(PROGRESSTRACKER + AClientID)) { TProgressState state = ((JObject)TSession.GetVariable(PROGRESSTRACKER + AClientID)).ToObject <TProgressState>(); state.JobFinished = true; if (TLogging.DebugLevel >= DEBUG_PROGRESS) { TLogging.Log("Finished the job for " + AClientID); } TSession.SetVariable(PROGRESSTRACKER + AClientID, state); TLogging.SetStatusBarProcedure(null); return(true); } return(false); }
/// <summary> /// set the current state /// </summary> /// <param name="AClientID"></param> /// <param name="AStatusMessage"></param> /// <param name="ACurrentAbsolutAmount"></param> static public void SetCurrentState(string AClientID, string AStatusMessage, Decimal ACurrentAbsolutAmount) { if (AClientID == null) { // see https://tracker.openpetra.org/view.php?id=1789 // this should not happen??? TLogging.Log("TProgressTracker.SetCurrentState: ClientID is null: " + (DomainManager.GClientID.ToString() == null).ToString()); return; } if (FProgressStates.ContainsKey(AClientID)) { TProgressState state = FProgressStates[AClientID]; state.StatusMessage = AStatusMessage; state.PercentageDone = Convert.ToInt32((ACurrentAbsolutAmount / state.AbsoluteOverallAmount) * 100.0m); if (TLogging.DebugLevel >= DEBUG_PROGRESS) { TLogging.Log(state.PercentageDone.ToString() + "%: " + state.StatusMessage); } } }
/// <summary> /// set the current state /// </summary> /// <param name="AClientID"></param> /// <param name="AStatusMessage"></param> /// <param name="ACurrentAbsoluteAmount"></param> static public void SetCurrentState(string AClientID, string AStatusMessage, Decimal ACurrentAbsoluteAmount) { lock (ProgressLockObject) { if (FProgressStates.ContainsKey(AClientID)) { TProgressState state = FProgressStates[AClientID]; if (AStatusMessage.Length > 0) { state.StatusMessage = AStatusMessage; } state.PercentageDone = Convert.ToInt32((ACurrentAbsoluteAmount / state.AbsoluteOverallAmount) * 100.0m); if (TLogging.DebugLevel >= DEBUG_PROGRESS) { // avoid recursive calls, especially during report calculation Console.WriteLine(state.PercentageDone.ToString() + "%: " + state.StatusMessage); } } } }
/// <summary> /// This polls the server until the search has finished, /// </summary> /// <returns>void</returns> private void TimerSearchResults_Tick(System.Object sender, System.EventArgs e) { TProgressState state = FLocationFindObject.Progress; if (state.JobFinished) { /* we are finished: */ /* prevent further calls */ timerSearchResults.Enabled = false; FKeepUpSearchFinishedCheck = false; /* Fetch the first page of data */ try { // For speed reasons we must add the necessary amount of emtpy Rows only *after* .AutoSizeCells() // has already been run! See XML Comment on the called Method // TSgrdDataGridPaged.LoadFirstDataPage for details! FPagedDataTable = grdResult.LoadFirstDataPage(@GetDataPagedResult, false); } catch (Exception E) { MessageBox.Show(E.ToString()); } EnableDisableUI(true); } else if (state.CancelJob) { /* we are finished: */ /* prevent further calls */ timerSearchResults.Enabled = false; FKeepUpSearchFinishedCheck = false; EnableDisableUI(true); } }
private void AsyncProgressCheckThread() { String OldLoggingText; DateTime startTime; String ErrorMessage = null; Exception ServersideException; OldLoggingText = ""; startTime = DateTime.Now; while (FKeepUpProgressCheck) { TProgressState state = FReportingGenerator.Progress; if (state.JobFinished) { this.Duration = DateTime.Now - startTime; if (FReportingGenerator.GetSuccess() == true) { this.Parameters.LoadFromDataTable(FReportingGenerator.GetParameter()); this.Results.LoadFromDataTable(FReportingGenerator.GetResult()); this.Results.SetMaxDisplayColumns(this.Parameters.Get("MaxDisplayColumns").ToInt()); } else { ErrorMessage = FReportingGenerator.GetErrorMessage(out ServersideException); if (ErrorMessage != null) { if (ErrorMessage != String.Empty) { if (!ErrorMessage.StartsWith( SharedConstants.NO_PARALLEL_EXECUTION_OF_XML_REPORTS_PREFIX, StringComparison.InvariantCulture)) { TLogging.Log(ErrorMessage, FStatusBarProcedure); } else { FStatusBarProcedure(ErrorMessage.Substring( SharedConstants.NO_PARALLEL_EXECUTION_OF_XML_REPORTS_PREFIX.Length)); } } else { // We get here e.g. when Report Generation was cancelled: this clears anything that the // Status Bar has previously shown. FStatusBarProcedure(String.Empty); } // Let any Exception that happened server-side escalate to the 'Unhandled Exception Handler' // to give it visibility if (ServersideException != null) { throw ServersideException; } } } FKeepUpProgressCheck = false; } else { if ((state.StatusMessage != null) && (!OldLoggingText.Equals(state.StatusMessage))) { TLogging.Log(state.StatusMessage, TLoggingType.ToStatusBar, FStatusBarProcedure); OldLoggingText = state.StatusMessage; } } if (FKeepUpProgressCheck) { // Sleep for some time. Then check again for latest progress information Thread.Sleep(500); } } }
/// <summary> /// Enables and disables the UI. Invokes setting up of the Grid after a /// successful search operation. /// </summary> /// <returns>void</returns> private void EnableDisableUI(System.Object AEnable) { object[] Args; TMyUpdateDelegate MyUpdateDelegate; // Since this procedure is called from a separate (background) Thread, it is // necessary to execute this procedure in the Thread of the GUI if (btnSearch.InvokeRequired) { Args = new object[1]; try { MyUpdateDelegate = new TMyUpdateDelegate(EnableDisableUI); Args[0] = AEnable; btnSearch.Invoke(MyUpdateDelegate, new object[] { AEnable }); } finally { Args = new object[0]; } } else { // Enable/disable according to how the search operation ended if (Convert.ToBoolean(AEnable)) { TProgressState ThreadStatus = FGLTransactionFindObject.Progress; if (ThreadStatus.JobFinished) { // Search operation ended without interruption if (FPagedDataTable.Rows.Count > 0) { btnSearch.Enabled = false; // At least one result was found by the search operation lblSearchInfo.Text = ""; // // Setup result DataGrid // if (grdResult.Columns.Count < 1) { SetupGrid(); } SetupDataGridDataBinding(); grdResult.AutoSizeCells(); grdResult.Selection.SelectRow(1, true); // Scroll grid to first line (the grid might have been scrolled before to another position) grdResult.ShowCell(new Position(1, 1), true); // For speed reasons we must add the necessary amount of emtpy Rows only here (after .AutoSizeCells() has already // been run! See XML Comment on the called Method TSgrdDataGridPaged.AddEmptyRows() for details! grdResult.AddEmptyRows(); grdResult.BringToFront(); // set tooltips grdResult.SetHeaderTooltip(3, MFinanceConstants.BATCH_POSTED); grdResult.SetHeaderTooltip(5, Catalog.GetString("Confidential")); // Make the Grid respond on updown keys grdResult.Focus(); // Display the number of found gift details UpdateRecordNumberDisplay(); Application.DoEvents(); btnSearch.Enabled = true; this.Cursor = Cursors.Default; } else { // Search operation has found nothing this.Cursor = Cursors.Default; lblSearchInfo.Text = Catalog.GetString("No GL Transactions found."); Application.DoEvents(); btnSearch.Enabled = true; UpdateRecordNumberDisplay(); } } else { // Search operation interrupted by user // used to release server System.Object here // (It isn't currently possible for the user to stop the search. I don't think this functionality is necessary) this.Cursor = Cursors.Default; lblSearchInfo.Text = Catalog.GetString("Search stopped!"); btnSearch.Enabled = true; Application.DoEvents(); } // enable or disable btnView if (FPagedDataTable.Rows.Count > 0) { btnView.Enabled = true; } else { btnView.Enabled = false; } } } }