//allows derived classes to override the method
        protected virtual async Task <bool> RunCalculationAsync(XElement currentElement, XElement linkedViewElement)
        {
            bool bHasCalculations = false;

            SB1CalculatorHelper.CALCULATOR_TYPES eCalculatorType
                = SB1CalculatorHelper.GetCalculatorType(
                      this.GCCalculatorParams.CalculatorType);
            switch (eCalculatorType)
            {
            case SB1CalculatorHelper.CALCULATOR_TYPES.sb101:
                //serialize, run calcs, and deserialize
                SBC1Calculator sbc1 = new SBC1Calculator();
                bHasCalculations = await sbc1.SetSB1C1CalculationsAsync(eCalculatorType, this.GCCalculatorParams,
                                                                        linkedViewElement, currentElement);

                break;

            case SB1CalculatorHelper.CALCULATOR_TYPES.sb102:
                //serialize, run calcs, and deserialize
                SBB1Calculator sbb1 = new SBB1Calculator();
                bHasCalculations = await sbb1.SetSB1B1CalculationsAsync(eCalculatorType, this.GCCalculatorParams,
                                                                        linkedViewElement, currentElement);

                break;

            default:
                //should be running an analysis
                break;
            }
            return(bHasCalculations);
        }
Beispiel #2
0
 private static void CheckForLastStepCalculator(
     CalculatorParameters sb1CalcParams,
     ContractHelpers.EXTENSION_STEPS stepNumber,
     ExtensionContentURI extDocToCalcURI)
 {
     SB1CalculatorHelper.CALCULATOR_TYPES eCalculatorType
         = SB1CalculatorHelper.GetCalculatorType(
               sb1CalcParams.CalculatorType);
     //other projects have code for handling different
     //numbers of steps in calculators
 }
Beispiel #3
0
        //define the actions to take when the event is raised
        public void AddCalculations(object sender, CustomEventArgs e)
        {
            //pass a byref xelement from the publisher's data
            XElement statElement       = null;
            XElement linkedViewElement = null;

            if (e.CurrentElement != null)
            {
                statElement = new XElement(e.CurrentElement);
            }
            if (e.LinkedViewElement != null)
            {
                linkedViewElement = new XElement(e.LinkedViewElement);
            }
            //run the stats and add them to statelement
            SB1CalculatorHelper.CALCULATOR_TYPES eCalculatorType
                = SB1CalculatorHelper.GetCalculatorType(
                      this.GCCalculatorParams.CalculatorType);
            if (eCalculatorType == SB1CalculatorHelper.CALCULATOR_TYPES.sb101 ||
                eCalculatorType == SB1CalculatorHelper.CALCULATOR_TYPES.sb102)
            {
                e.HasCalculations = RunSB1Calculation(eCalculatorType,
                                                      statElement, linkedViewElement);
            }
            else
            {
                //run normally and save the same statelement and linkedviewelement
                e.HasCalculations = RunSB1Analysis(
                    statElement, linkedViewElement);
            }
            if (e.HasCalculations)
            {
                //pass the new statelement back to the publisher
                //by setting the CalculatedElement property of CustomEventArgs
                if (statElement != null)
                {
                    e.CurrentElement = new XElement(statElement);
                }
                if (linkedViewElement != null)
                {
                    e.LinkedViewElement = new XElement(linkedViewElement);
                }
            }
        }
Beispiel #4
0
        //define the actions to take when the event is raised
        public void AddDevPackCalculations(object sender, CustomEventArgs e)
        {
            bool bHasCalculations = false;
            //e.CalculatorParams = current devpack or devpackpart being processed
            //the file paths identify the document to run calcs on and the
            //uripattern identifies the node holding the linkedviews
            //note that e.CalcParams.ExtensionDoctoCalcURI.Resources[0] holds
            //parent contenturi used to start the extension
            //(with original doctocalc file that is used when the linkedview is needed)
            SB1CalculatorHelper fnCalculatorHelper
                = new SB1CalculatorHelper(e.CalculatorParams);

            //run the calculations
            //bHasCalculations = fnCalculatorHelper
            //    .RunCalculations();
            //pass the bool back to the publisher
            //by setting the HasCalculations property of CustomEventArgs
            e.HasCalculations = bHasCalculations;
        }
Beispiel #5
0
        public override async Task <bool> RunCalculatorStep(
            ExtensionContentURI extDocToCalcURI, ExtensionContentURI extCalcDocURI,
            string stepNumber, IList <string> urisToAnalyze,
            IDictionary <string, string> updates, CancellationToken cancellationToken)
        {
            bool bHasCalculation = false;
            CalculatorParameters SB1CalcParams
                = CalculatorHelpers.SetCalculatorParameters(
                      extDocToCalcURI, extCalcDocURI, stepNumber, urisToAnalyze,
                      updates);
            SB1CalculatorHelper sb1BudgetHelper
                = new SB1CalculatorHelper(SB1CalcParams);

            ContractHelpers.EXTENSION_STEPS eStepNumber
                = ContractHelpers.GetEnumStepNumber(stepNumber);
            switch (eStepNumber)
            {
            case ContractHelpers.EXTENSION_STEPS.stepzero:
                bHasCalculation = true;
                break;

            case ContractHelpers.EXTENSION_STEPS.stepone:
                bHasCalculation = true;
                break;

            case ContractHelpers.EXTENSION_STEPS.steptwo:
                //clear updates collection
                updates.Clear();
                if (SB1CalcParams != null)
                {
                    //set constants for this step
                    bHasCalculation
                        = SB1CalculatorHelper.SetConstants(SB1CalcParams);
                }
                extDocToCalcURI.URIDataManager.NeedsFullView    = false;
                extDocToCalcURI.URIDataManager.NeedsSummaryView = false;
                break;

            case ContractHelpers.EXTENSION_STEPS.stepthree:
                //get rid of any update member that was added after running the same step 2x
                CalculatorHelpers.RefreshUpdates(SB1CalcParams, stepNumber, updates);
                if (SB1CalcParams != null)
                {
                    //run the calculations
                    bHasCalculation = await sb1BudgetHelper.RunSB1CalculatorCalculationsAsync();

                    extDocToCalcURI.ErrorMessage  = SB1CalcParams.ErrorMessage;
                    extDocToCalcURI.ErrorMessage += SB1CalcParams.ExtensionDocToCalcURI.ErrorMessage;
                    if (!bHasCalculation)
                    {
                        extDocToCalcURI.ErrorMessage = (extDocToCalcURI.ErrorMessage == string.Empty) ?
                                                       Errors.MakeStandardErrorMsg("CALCULATORS_URI_MISMATCH")
                                : extDocToCalcURI.ErrorMessage;
                        return(bHasCalculation);
                    }
                    if (string.IsNullOrEmpty(extDocToCalcURI.ErrorMessage))
                    {
                        //two step calculators need to be saved now
                        CheckForLastStepCalculator(SB1CalcParams,
                                                   eStepNumber, extDocToCalcURI);
                        //replace the old calculator with the new one
                        //and save the new calculations document
                        bHasCalculation
                            = CalculatorHelpers.SaveNewCalculationsDocument(SB1CalcParams);
                    }
                    else
                    {
                        bHasCalculation = false;
                    }
                }
                extDocToCalcURI.URIDataManager.NeedsFullView    = true;
                extDocToCalcURI.URIDataManager.NeedsSummaryView = false;
                break;

            case ContractHelpers.EXTENSION_STEPS.stepfour:
                extDocToCalcURI.URIDataManager.NeedsFullView    = false;
                extDocToCalcURI.URIDataManager.NeedsSummaryView = true;
                extCalcDocURI.URIFileExtensionType = CalculatorHelpers.GetAttribute(SB1CalcParams.LinkedViewElement,
                                                                                    Calculator1.cFileExtensionType);
                bHasCalculation = true;
                //tells addinhelper to save calcs
                CalculatorHelpers.SetTempDocSaveCalcsProperty(extDocToCalcURI);
                break;

            default:
                //as many steps as needed can be added to this addin
                break;
            }
            extDocToCalcURI.ErrorMessage += SB1CalcParams.ErrorMessage;
            return(bHasCalculation);
        }