コード例 #1
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
                }
            }
        }
コード例 #2
0
        public void ValidatePlanningFunction(ref IPlanningFunction _function, ref string validationResponse)
        {
            switch (_function.FunctionType)
            {
                #region CostPlan
            case PlanningFunctionType.CostPlan:
            {
                CostPlan costPlanFunction = (CostPlan)_function;

                try
                {
                    #region Check Period From, Period To Check
                    /// Check Period from greater than period to
                    int pFromInt = Convert.ToInt32(costPlanFunction.PeriodFrom);
                    int pToInt   = Convert.ToInt32(costPlanFunction.PeriodTo);
                    int diff     = pToInt - pFromInt;

                    if (diff < 0)
                    {
                        throw new Exception("Period From must be less than Period To");
                    }
                    else if (pFromInt < 1 || pFromInt > 12 || pToInt < 1 || pToInt > 12)
                    {
                        throw new Exception("Period From and Period To must be a numeric value between 1 and 12");
                    }
                    #endregion

                    #region Check Trial Version Restriction
                    //                        /// Check trial version restriction
                    //					    string productName = Excel4apps.Connector_SAP.Product.GetProductName(Excel4apps.Connector_SAP.Product.Code.PlanningWand);
                    //                        if (Excel4apps.Connector_SAP.Product.GetProductLicenseType(productName) == Excel4apps.Connector_SAP.Product.LicenseType.Trial)
                    //                        {
                    //	                        if ((pToInt < 1 || pToInt > 3) || (pFromInt < 1 || pFromInt > 3))
                    //                            {
                    //		                        throw new Exception("Trial version may only post from periods 1 to 3, please reduce difference between From and To periods");
                    //	                        }
                    //                        }
                    #endregion

                    #region Check Delta
                    /// Check Delta is empty or X
                    if (costPlanFunction.Delta != " " && costPlanFunction.Delta != "X")
                    {
                        costPlanFunction.Delta = " ";
                    }
                    #endregion

                    #region Check Fiscal Year is Numeric
                    //// Check Fiscal Year is Numeric
                    try
                    {
                        costPlanFunction.FiscalYear = costPlanFunction.FiscalYear.TrimStart(new char[] { '0', ' ' });
                        int.Parse(costPlanFunction.FiscalYear);
                    }
                    catch (Exception ex)
                    {
                        throw new Exception("Fiscal Year must be a valid numeric year");
                    }
                    #endregion

                    #region Check Planning Currency Type
                    try
                    {
                        if (costPlanFunction.PlanningCurrency.ToUpper() != "C" && costPlanFunction.PlanningCurrency.ToUpper() != "O" && costPlanFunction.PlanningCurrency.ToUpper() != "T")
                        {
                            throw new Exception("Planning Currency must be C, O or T");
                        }
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                    #endregion

                    #region Check Fixed Input is Numeric

                    try
                    {
                        Decimal.Parse(costPlanFunction.FixedInputValue);
                    }
                    catch (Exception ex)
                    {
                        throw new Exception("Fixed Value must be a numeric");
                    }

                    #endregion
                }
                catch (Exception e)
                {
                    costPlanFunction.ValidationResult = "mmError (" + e.Message + ")";
                    validationResponse = "mmError (" + e.Message + ")";
                }
            }
            break;
                #endregion


                #region ActivityPlan
            case PlanningFunctionType.ActivityPlan:
            {
                ActivityPlan activityPlanFunction = (ActivityPlan)_function;

                try
                {
                    #region Check Period From, Period To Check
                    /// Check Period from greater than period to
                    int pFromInt = Convert.ToInt32(activityPlanFunction.PeriodFrom);
                    int pToInt   = Convert.ToInt32(activityPlanFunction.PeriodTo);
                    int diff     = pToInt - pFromInt;

                    if (diff < 0)
                    {
                        throw new Exception("Period From must be less than Period To");
                    }
                    else if (pFromInt < 1 || pFromInt > 12 || pToInt < 1 || pToInt > 12)
                    {
                        throw new Exception("Period From and Period To must be a numeric value between 1 and 12");
                    }
                    #endregion

                    #region Check Trial Version Restriction
                    //                        /// Check trial version restriction
                    //					    string productName = Excel4apps.Connector_SAP.Product.GetProductName(Excel4apps.Connector_SAP.Product.Code.PlanningWand);
                    //                        if (Excel4apps.Connector_SAP.Product.GetProductLicenseType(productName) == Excel4apps.Connector_SAP.Product.LicenseType.Trial)
                    //                        {
                    //	                        if ((pToInt < 1 || pToInt > 3) || (pFromInt < 1 || pFromInt > 3))
                    //                            {
                    //		                        throw new Exception("Trial version may only post from periods 1 to 3, please reduce difference between From and To periods");
                    //	                        }
                    //                        }
                    #endregion

                    #region Check Delta
                    /// Check Delta is empty or X
                    if (activityPlanFunction.Delta != " " && activityPlanFunction.Delta != "X")
                    {
                        activityPlanFunction.Delta = " ";
                    }
                    #endregion

                    #region Check Fiscal Year is Numeric
                    //// Check Fiscal Year is Numeric
                    try
                    {
                        activityPlanFunction.FiscalYear = activityPlanFunction.FiscalYear.TrimStart(new char[] { '0', ' ' });
                        int.Parse(activityPlanFunction.FiscalYear);
                    }
                    catch (Exception ex)
                    {
                        throw new Exception("Fiscal Year must be a valid numeric year");
                    }
                    #endregion

                    #region Check Planning Currency Type
                    try
                    {
                        if (activityPlanFunction.PlanningCurrency.ToUpper() != "C" && activityPlanFunction.PlanningCurrency.ToUpper() != "O" && activityPlanFunction.PlanningCurrency.ToUpper() != "T")
                        {
                            throw new Exception("Planning Currency must be C, O or T");
                        }
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                    #endregion
                }
                catch (Exception e)
                {
                    activityPlanFunction.ValidationResult = "mmError (" + e.Message + ")";
                    validationResponse = "mmError (" + e.Message + ")";
                }
            }
            break;
                #endregion

            default:
                break;
            }
        }