//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) //NPVCalculatorHelper npvCalculatorHelper // = new NPVCalculatorHelper(); NPVCalculatorHelper npvCalculatorHelper = new NPVCalculatorHelper(e.CalculatorParams); //run the calculations bHasCalculations = npvCalculatorHelper .RunCalculations(); //pass the bool back to the publisher //by setting the HasCalculations property of CustomEventArgs e.HasCalculations = bHasCalculations; }
public override async Task <bool> RunCalculatorStep( ExtensionContentURI extDocToCalcURI, ExtensionContentURI extCalcDocURI, string stepNumber, IList <string> urisToAnalyze, IDictionary <string, string> updates, CancellationToken cancellationToken) { bool bHasCalculation = false; CalculatorHelpers eCalcHelpers = new CalculatorHelpers(); CalculatorParameters npvCalcParams = CalculatorHelpers.SetCalculatorParameters( extDocToCalcURI, extCalcDocURI, stepNumber, urisToAnalyze, updates); if (!CalculatorHelpers.URIAbsoluteExists(extDocToCalcURI, extDocToCalcURI.URIDataManager.TempDocPath)) { //this calculator requires the base document to be built first extDocToCalcURI.ErrorMessage = Errors.MakeStandardErrorMsg("CALCULATORS_MISSINGBASEDOC"); return(false); } NPVCalculatorHelper npvBudgetHelpers = new NPVCalculatorHelper(npvCalcParams); 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: updates.Clear(); if (npvCalcParams != null) { //set constants for this step bHasCalculation = NPVCalculatorHelper.SetConstants(npvCalcParams); //this step does not generate 3rd htmldocs 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(npvCalcParams, stepNumber, updates); if (npvCalcParams != null) { if (npvCalcParams.CalculatorType == CalculatorHelpers.CALCULATOR_TYPES.operation2.ToString() || npvCalcParams.CalculatorType == CalculatorHelpers.CALCULATOR_TYPES.component2.ToString()) { //run the scheduling calculations bHasCalculation = NPVCalculatorHelper.RunSchedulingCalculations(npvCalcParams); } else { //run the calculations bHasCalculation = npvBudgetHelpers.RunCalculations(); } extDocToCalcURI.ErrorMessage = npvCalcParams.ErrorMessage; extDocToCalcURI.ErrorMessage += npvCalcParams.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(npvCalcParams, eStepNumber, extDocToCalcURI); //replace the old calculator with the new one //and save the new calculations document bHasCalculation = CalculatorHelpers.SaveNewCalculationsDocument(npvCalcParams); } else { bHasCalculation = false; } } //this step needs a full 3rd htmldocs extDocToCalcURI.URIDataManager.NeedsFullView = true; extDocToCalcURI.URIDataManager.NeedsSummaryView = false; break; case ContractHelpers.EXTENSION_STEPS.stepfour: if (npvCalcParams.ExtensionDocToCalcURI.URIDataManager.SubAppType == Constants.SUBAPPLICATION_TYPES.componentprices.ToString() || npvCalcParams.ExtensionDocToCalcURI.URIDataManager.SubAppType == Constants.SUBAPPLICATION_TYPES.operationprices.ToString()) { if (npvCalcParams.CalculatorType == CalculatorHelpers.CALCULATOR_TYPES.operation2.ToString() || npvCalcParams.CalculatorType == CalculatorHelpers.CALCULATOR_TYPES.component2.ToString()) { //get rid of any update member that was added after running the same step 2x CalculatorHelpers.RefreshUpdates(npvCalcParams, stepNumber, updates); //run the scheduling calculations bHasCalculation = npvBudgetHelpers.RunCalculations(); bHasCalculation = CalculatorHelpers.SaveNewCalculationsDocument(npvCalcParams); //this step needs a full 3rd htmldocs extDocToCalcURI.URIDataManager.NeedsFullView = true; extDocToCalcURI.URIDataManager.NeedsSummaryView = false; } else { //save the calculations bHasCalculation = SaveCalculations(extDocToCalcURI, extCalcDocURI, npvCalcParams); } } else { //save the calculations bHasCalculation = SaveCalculations(extDocToCalcURI, extCalcDocURI, npvCalcParams); } break; case ContractHelpers.EXTENSION_STEPS.stepfive: if (npvCalcParams.ExtensionDocToCalcURI.URIDataManager.SubAppType == Constants.SUBAPPLICATION_TYPES.componentprices.ToString() || npvCalcParams.ExtensionDocToCalcURI.URIDataManager.SubAppType == Constants.SUBAPPLICATION_TYPES.operationprices.ToString()) { //save the calculations bHasCalculation = SaveCalculations(extDocToCalcURI, extCalcDocURI, npvCalcParams); } break; default: //as many steps as needed can be added to this addin break; } extDocToCalcURI.ErrorMessage += npvCalcParams.ErrorMessage; return(bHasCalculation); }