Esempio n. 1
0
        /// <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;
                }
            }
        }
Esempio n. 2
0
        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
                }
            }
        }