public void UpdateStatus(string statusStripMessage, bool incrementProgress = true) { //SyncLock ThreadLockObj bool stillAddingFunctions = MatManFunctionCollection.GetObject().StillAddingFunctions; //int functionsRemainingInQueue = PWFunctionCollection.GetObject().Count; int totalFunctionsAddedToQueue = MatManFunctionCollection.GetObject().TotalFunctionsAddedToQueue + 1; int totalProcessedBySAP = SAPRequest.GetObject().TotalProcessedBySAP; this.ElapsedTime = DateTime.Now - this.ProcessStartTime; if (totalProcessedBySAP < 1) { // report progress of RTD reading functions into batch if (ElapsedTime.TotalSeconds > 0) { // Update the CalculationCount text box this.uxCalculationCountTextBox.Text = totalFunctionsAddedToQueue.ToString() + " functions in processing queue..."; // Update the Balance Records Text Box this.uxBalanceRecordsSummedTextBox.Text = totalFunctionsAddedToQueue.ToString() + "...pending"; // Update the CalculationTimeTextBox decimal processRate = Convert.ToDecimal(totalFunctionsAddedToQueue / ElapsedTime.TotalSeconds); uxCalculationTimeTextBox.Text = ElapsedTime.Minutes.ToString() + " : " + ElapsedTime.Seconds.ToString() + " at " + processRate.ToString("0.00") + " cells/sec"; StatusStrip.Text = statusStripMessage; } } else if (totalProcessedBySAP >= 1) { if (ElapsedTime.TotalSeconds > 0) { //Update the CalculationCount text box this.uxCalculationCountTextBox.Text = totalFunctionsAddedToQueue.ToString() + " functions being processed by SAP..."; // Update the Balance Records Text Box this.uxBalanceRecordsSummedTextBox.Text = totalProcessedBySAP.ToString(); // Update the CalculationTimeTextBox decimal processRate = Convert.ToDecimal(totalProcessedBySAP / ElapsedTime.TotalSeconds); uxCalculationTimeTextBox.Text = ElapsedTime.Minutes.ToString() + " : " + ElapsedTime.Seconds.ToString() + " at " + processRate.ToString("0.00") + " cells/sec"; StatusStrip.Text = statusStripMessage; } } this.Refresh(); }
public static void ClearPreviousRun() { MatManFunctionCollection.GetObject().Clear(); MatManFunctionCollection.GetObject().TotalFunctionsAddedToQueue = 0; SAPRequest.GetObject().TotalProcessedBySAP = 0; SAPRequest.ReturnValuesList.Clear(); //MatManCalcEngine.GetObject().CurrentFunctionsByCellAddress.Clear(); //MatManCalcEngine.GetObject().ConnectDataCount = 0; //MatManCalcEngine.GetObject().TopicCount = 0; //MatManCalcEngine.GetObject().UserInitiatedCalc = true; }
/// <summary> /// Sends the Batch to SAP - This would be part of processing functions phase /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void myBackgroundWorker_DoWork(object sender, DoWorkEventArgs e) { this.ProcessStartTime = DateTime.Now; MatManFunctionCollection.GetObject().Clear(); MatManFunctionCollection.GetObject().TotalFunctionsAddedToQueue = 0; //SAPRequest.GetObject().FunctionBatch.Clear() SAPRequest.GetObject().TotalProcessedBySAP = 0; m_cancelOperation = false; Thread.Sleep(2000); while (true) { if ((MatManFunctionCollection.GetObject().Count > 0 && m_executeFunctions && !m_isRunning)) { m_isRunning = true; FunctionExecutionType functionType = (FunctionExecutionType)Properties.Settings.Default.FunctionExecutionType; SAPRequest.GetObject().ProcessSAPRequests(functionType, Settings.Default.MaximumBatchSize); } if (m_cancelOperation) { MatManFunctionCollection.GetObject().StillAddingFunctions = true; m_executeFunctions = false; m_isRunning = true; break; // TODO: might not be correct. Was : Exit While } System.Threading.Thread.Sleep(250); //' Breaks us out of while loop if ((SAPRequest.GetObject().TotalProcessedBySAP == MatManFunctionCollection.GetObject().TotalFunctionsAddedToQueue) && m_Progress == 100) { MatManFunctionCollection.GetObject().StillAddingFunctions = true; m_executeFunctions = false; break; } if ((MatManFunctionCollection.GetObject().Count == 0)) { break; } } }
/// <summary> /// OnLoad is overidden to provide localization strings for the form /// </summary> /// <param name="e"></param> protected override void OnLoad(EventArgs e) { // FunctionAdded & Function Removed EventHandlers MatManFunctionCollection.GetObject().OnFunctionAdded += functionCollection_OnFunctionAdded; MatManFunctionCollection.GetObject().OnFunctionRemoved += functionCollection_OnFunctionRemoved; //// FunctionProcessed and BatchCompleted EventHandlers SAPRequest.GetObject().FunctionProcessedBySAP += sapRequest_FunctionProcessedBySAP; m_connectDataCount = 0; this.uxCalculationTimeLabel.Text = iiiwave.MatManLib.Localization.Localize.ReturnProgressDataForm_uxCalculationTimeLabel_Text; this.uxBalanceRecordsSummedLabel.Text = iiiwave.MatManLib.Localization.Localize.ReturnProgressDataForm_uxBalanceRecordsSummedLabel_Text; this.uxCalculationCountLabel.Text = iiiwave.MatManLib.Localization.Localize.ReturnProgressDataForm_uxCalculationCountLabel_Text; this.uxCancelButton.Text = iiiwave.MatManLib.Localization.Localize.ReturnProgressDataForm_uxCancelButton_Text; if (Settings.Default.FunctionExecutionType == (int)FunctionExecutionType.RetrievingData) { this.Text = "Retrieving Data"; } else if (Settings.Default.FunctionExecutionType == (int)FunctionExecutionType.ValidateData) { this.Text = "Validating Data"; } else { this.Text = "Posting Data"; } this.uxCancelButton.Enabled = false; m_cancelOperation = false; // Initialize Form this.uxProgressBar.Value = 0; this.m_Progress = 0; // Initialize counters and booleans MatManFunctionCollection.GetObject().Clear(); // Start the background worker myBackgroundWorker.WorkerReportsProgress = true; myBackgroundWorker.WorkerSupportsCancellation = true; myBackgroundWorker.RunWorkerAsync(); }
protected override void OnFormClosing(FormClosingEventArgs e) { if (m_cancelOperation) { myBackgroundWorker.CancelAsync(); while ((myBackgroundWorker.IsBusy)) { Thread.Sleep(500); continue; } Thread.Sleep(500); OnDataFormClosing?.Invoke(); // Remove event listeners MatManFunctionCollection.GetObject().OnFunctionAdded -= functionCollection_OnFunctionAdded; MatManFunctionCollection.GetObject().OnFunctionRemoved -= functionCollection_OnFunctionRemoved; SAPRequest.GetObject().FunctionProcessedBySAP -= sapRequest_FunctionProcessedBySAP; Thread.Sleep(500); MessageBox.Show(this, "Process has been cancelled"); m_cancelOperation = false; // Clear out PWFunctionCollection completely MatManFunctionCollection.GetObject().Dispose(); // Clear out SAPRequest completely SAPRequest.GetObject().Dispose(); } else { this.uxProgressBar.Value = 100; this.Refresh(); Application.DoEvents(); Thread.Sleep(1000); this.uxProgressBar.Value = 100; this.uxToolStripStatusLabel.Text = "Done"; this.StatusStrip.BackColor = Color.FromArgb(80, 161, 216); this.Refresh(); Application.DoEvents(); OnDataFormClosing?.Invoke(); // Remove event listeners MatManFunctionCollection.GetObject().OnFunctionAdded -= functionCollection_OnFunctionAdded; MatManFunctionCollection.GetObject().OnFunctionRemoved -= functionCollection_OnFunctionRemoved; SAPRequest.GetObject().FunctionProcessedBySAP -= sapRequest_FunctionProcessedBySAP; // Clear out PWFunctionCollection completely MatManFunctionCollection.GetObject().Dispose(); // Clear out SAPRequest completely SAPRequest.GetObject().Dispose(); Thread.Sleep(2000); OnUpdateValues?.Invoke(); } base.OnFormClosing(e); //FileLogger.WriteEntry(System.Reflection.MethodBase.GetCurrentMethod().Name + " " + DateTime.Now.ToString("HH:mm:ss dd-MMM-yyyy") + " -- Trace Type: Stop ") }
private void myBackgroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e) { lock (ThreadLockObj) { bool stillAddingFunctions = MatManFunctionCollection.GetObject().StillAddingFunctions; int remainingInQueue = MatManFunctionCollection.GetObject().Count; int totalAddedToQueue = MatManFunctionCollection.GetObject().TotalFunctionsAddedToQueue; int totalProcessedBySAP = SAPRequest.GetObject().TotalProcessedBySAP; decimal progressDec = ((decimal)totalProcessedBySAP / (decimal)totalAddedToQueue) * 100; m_Progress = (int)progressDec; try { this.ElapsedTime = DateTime.Now - this.ProcessStartTime; if (m_cancelOperation) { this.uxProgressBar.Value = 100; this.Refresh(); Application.DoEvents(); } else if (stillAddingFunctions) { if (totalProcessedBySAP < totalAddedToQueue) { //this.uxToolStripStatusLabel.Text = Convert.ToString(e.UserState); this.uxCalculationCountTextBox.Text = "SAP is processing functions..."; this.uxBalanceRecordsSummedTextBox.Text = "Total Functions Queued: " + totalAddedToQueue.ToString() + " -- Processing: " + totalProcessedBySAP.ToString(); // Items being processed by SAP - Update the CalculationTimeTextBox decimal processRate = Convert.ToDecimal(totalProcessedBySAP / ElapsedTime.TotalSeconds); uxCalculationTimeTextBox.Text = totalProcessedBySAP.ToString() + " Functions processed by SAP at " + ElapsedTime.Minutes.ToString() + " : " + ElapsedTime.Seconds.ToString() + "- Process Rate: " + processRate.ToString("0.00") + " cells/sec"; this.uxProgressBar.Value = m_Progress; this.Refresh(); // (2) Done } else if (totalProcessedBySAP == totalAddedToQueue) { //this.uxToolStripStatusLabel.Text = Convert.ToString(e.UserState); this.uxCalculationCountTextBox.Text = "SAP is processing functions..."; this.uxBalanceRecordsSummedTextBox.Text = "Total Functions Queued: " + totalAddedToQueue.ToString() + " -- Complete: " + totalProcessedBySAP.ToString(); // Items being processed by SAP - Update the CalculationTimeTextBox decimal processRate = Convert.ToDecimal(totalProcessedBySAP / ElapsedTime.TotalSeconds); uxCalculationTimeTextBox.Text = totalProcessedBySAP.ToString() + " processed at " + ElapsedTime.Minutes.ToString() + " : " + ElapsedTime.Seconds.ToString() + "- Process Rate: " + processRate.ToString("0.00") + " cells/sec"; this.uxProgressBar.Value = m_Progress; this.Refresh(); Application.DoEvents(); } // RTD has COMPLETED adding functions to the queue. The background worker sends remaining functions to SAP to be processed // Excel is done reading functions - process the remaining batch } else if (!stillAddingFunctions) { this.uxCancelButton.Enabled = true; if (totalProcessedBySAP < totalAddedToQueue) { //this.uxToolStripStatusLabel.Text = Convert.ToString(e.UserState); this.uxCalculationCountTextBox.Text = "SAP is processing functions..."; this.uxBalanceRecordsSummedTextBox.Text = "Total Functions Queued: " + totalAddedToQueue.ToString() + " -- Complete: " + totalProcessedBySAP.ToString(); // Items being processed by SAP - Update the CalculationTimeTextBox decimal processRate = Convert.ToDecimal(totalProcessedBySAP / ElapsedTime.TotalSeconds); uxCalculationTimeTextBox.Text = totalProcessedBySAP.ToString() + " processed at " + ElapsedTime.Minutes.ToString() + " : " + ElapsedTime.Seconds.ToString() + "- Process Rate: " + processRate.ToString("0.00") + " cells/sec"; if ((m_Progress < 90)) { this.uxProgressBar.Value = m_Progress; } else { this.uxProgressBar.Value = 100; } this.Refresh(); //Application.DoEvents(); } else if (totalProcessedBySAP == totalAddedToQueue) { //this.uxToolStripStatusLabel.Text = Convert.ToString(e.UserState); this.uxCalculationCountTextBox.Text = "SAP is processing functions..."; this.uxBalanceRecordsSummedTextBox.Text = "Total Functions Queued: " + totalAddedToQueue.ToString() + " -- Complete: " + totalProcessedBySAP.ToString(); // Items being processed by SAP - Update the CalculationTimeTextBox decimal processRate = Convert.ToDecimal(totalProcessedBySAP / ElapsedTime.TotalSeconds); uxCalculationTimeTextBox.Text = totalProcessedBySAP.ToString() + " processed at " + ElapsedTime.Minutes.ToString() + " : " + ElapsedTime.Seconds.ToString() + "- Process Rate: " + processRate.ToString("0.00") + " cells/sec"; this.uxProgressBar.Value = 100; this.Refresh(); Application.DoEvents(); } } } catch (Exception ex) { //MessageBox.Show(ex.Message) } } }
public void ProcessSAPRequests(FunctionExecutionType _executionType, int _maxBatchSize) { lock (syncRoot) { //m_returnValuesDictionary.Clear(); m_executionType = _executionType; m_maximumBatchSize = _maxBatchSize; m_batchProcessTimeStart = DateTime.Now; m_functionCount = 0; //' reset to 0 for each batch //m_currentBatchNumberProcessed = 0 // reset to 0 for each batch m_updateBatchComplete = false; // reset for each batch m_batchNumber = 1; if (MatManFunctionCollection.GetObject().Count > 0) { // ToDo: Log entry here // Get all of the batched functions from the PWFunctionCollection lock (syncRoot) { m_functionBatchGroups = MatManFunctionCollection.GetObject().GetFunctionGroups(); } //For Each _functionGroup As FunctionGroup In m_planningFunctionBatchGroups for (int index = 0; index <= (m_functionBatchGroups.Count - 1); index++) { IFunctionGroup _functionGroup = m_functionBatchGroups[index]; // Start of Batch Process if (!m_operationCancelled) { if (_functionGroup.GetType() == typeof(PlanningFunctionGroup)) { switch (((PlanningFunctionGroup)_functionGroup).FunctionType) { case PlanningFunctionType.CostPlan: if (m_executionType == FunctionExecutionType.ValidateData) { CostPlan.ValidateSAPData(((PlanningFunctionGroup)_functionGroup), m_functionCount); } else { CostPlan.PostSAPData(((PlanningFunctionGroup)_functionGroup), m_functionCount); } break; case PlanningFunctionType.ActivityPlan: if (m_executionType == FunctionExecutionType.ValidateData) { ActivityPlan.ValidateSAPData(((PlanningFunctionGroup)_functionGroup), m_functionCount); } else { ActivityPlan.PostSAPData(((PlanningFunctionGroup)_functionGroup), m_functionCount); } break; default: break; } } else if (_functionGroup.GetType() == typeof(QueryFunctionGroup)) { } } else { //m_currentBatchNumberProcessed = 0; m_totalProcessedBySAP = 0; m_batchNumber = 1; MatManFunctionCollection.GetObject().TotalFunctionsAddedToQueue = 0; MatManFunctionCollection.GetObject().Clear(); FunctionProcessedBySAP?.Invoke(this, new FunctionProcessedBySAPEventArgs(1, 1)); break; } m_functionCount = m_functionCount + _functionGroup.FunctionList.Count - 1; //m_currentBatchNumberProcessed = m_currentBatchNumberProcessed + _functionGroup.FunctionList.Count; m_totalProcessedBySAP = m_totalProcessedBySAP + _functionGroup.FunctionList.Count; m_totalAddedToQueue = MatManFunctionCollection.GetObject().TotalFunctionsAddedToQueue; // Increment Batch Number m_batchNumber++; try { //Invoke the FunctionProcessed event FunctionProcessedBySAP?.Invoke(this, new FunctionProcessedBySAPEventArgs(m_totalAddedToQueue, m_totalProcessedBySAP)); } catch (Exception e1) { } } // end foreach // Re-assign the LAST BATCH UPDATE time to now. m_batchProcessTimeComplete = DateTime.Now; // Calculate the time to complete the batch process m_currentBatchProcessTime = (DateTime)m_batchProcessTimeComplete - (DateTime)m_batchProcessTimeStart; //Update the Batch to COMPLETE processing m_updateBatchComplete = true; } else { //PWCalculationEngine.AcceptNewCalcs = True } } }