private static void CheckForLastStepAnalyzer( NPV1AnalyzerHelper.ANALYZER_TYPES analyzerType, ContractHelpers.EXTENSION_STEPS stepNumber, ExtensionContentURI extDocToCalcURI) { //this release only includes three step analyzers }
//implement the interface, but this is not an analyzers addin public override async Task <bool> RunAnalyzerStep( ExtensionContentURI extDocToCalcURI, ExtensionContentURI extCalcDocURI, string stepNumber, IList <string> urisToAnalyze, IDictionary <string, string> updates, CancellationToken cancellationToken) { return(false); }
private static void CheckForLastStepCalculator( CalculatorParameters npv1CalcParams, ContractHelpers.EXTENSION_STEPS stepNumber, ExtensionContentURI extDocToCalcURI) { NPV1CalculatorHelper.CALCULATOR_TYPES eCalculatorType = NPV1CalculatorHelper.GetCalculatorType( npv1CalcParams.CalculatorType); //other projects have code for handling different //numbers of steps in calculators }
private static void CheckForLastStepCalculator( AgBudgetingHelpers.CALCULATOR_TYPES calculatorType, ContractHelpers.EXTENSION_STEPS stepNumber, ExtensionContentURI extDocToCalcURI) { //if (calculatorType // == AgBudgetingHelpers.CALCULATOR_TYPES.locals) //{ // if (stepNumber == ContractHelpers.EXTENSION_STEPS.stepthree) // { // //locals use 2 steps // saveTempDocInDb = true; // } //} //else -remaining calculators in this extension use 4 steps }
private static void CheckForLastStepCalculator( CalculatorParameters npvCalcParams, ContractHelpers.EXTENSION_STEPS stepNumber, ExtensionContentURI extDocToCalcURI) { CalculatorHelpers.CALCULATOR_TYPES eCalculatorType = CalculatorHelpers.GetCalculatorType( npvCalcParams.CalculatorType); //keep for code sample but Locals moved to Locals Extension if (eCalculatorType == CalculatorHelpers.CALCULATOR_TYPES.locals) { if (stepNumber == ContractHelpers.EXTENSION_STEPS.stepthree) { //tells addinhelper to save calcs CalculatorHelpers.SetTempDocSaveCalcsProperty(extDocToCalcURI); } } }
private static async Task <bool> SaveCalculations( ExtensionContentURI extDocToCalcURI, ExtensionContentURI extCalcDocURI, CalculatorParameters npvCalcParams) { extDocToCalcURI.URIDataManager.NeedsFullView = false; extDocToCalcURI.URIDataManager.NeedsSummaryView = true; extCalcDocURI.URIFileExtensionType = CalculatorHelpers.GetAttribute(npvCalcParams.LinkedViewElement, Calculator1.cFileExtensionType); bool bHasCalculation = true; if (extDocToCalcURI.URIDataManager.TempDocSaveMethod == Constants.SAVECALCS_METHOD.saveastext.ToString()) { //text files can be filtered by subscribers KeyValuePair <string, string> kvp = new KeyValuePair <string, string>( extDocToCalcURI.URIPattern, extDocToCalcURI.URIDataManager.TempDocPath); npvCalcParams.AnalyzerParms.FileOrFolderPaths.Add(kvp); NPVCalcsTextSubscriber obsTextSubscriber = new NPVCalcsTextSubscriber(npvCalcParams); bHasCalculation = await obsTextSubscriber.BuildObservations(); if (!bHasCalculation || (!string.IsNullOrEmpty(obsTextSubscriber .ObsCalculatorParams.ErrorMessage))) { extDocToCalcURI.ErrorMessage = obsTextSubscriber.ObsCalculatorParams.ErrorMessage; CalculatorHelpers.SetTempDocSaveNoneProperty(extDocToCalcURI); } else { //tells addinhelper to save calcs CalculatorHelpers.SetTempDocSaveCalcsProperty(extDocToCalcURI); } } else { //tells addinhelper to save calcs CalculatorHelpers.SetTempDocSaveCalcsProperty(extDocToCalcURI); } return(bHasCalculation); }
public ExtensionContentURI(ExtensionContentURI uri) { //make a copy of uri this.URIName = uri.URIName; this.URIId = uri.URIId; this.URINetworkPartName = uri.URINetworkPartName; this.URINodeName = uri.URINodeName; this.URIFileExtensionType = uri.URIFileExtensionType; this.URIPattern = uri.URIPattern; this.URIFull = uri.URIFull; this.URIClub = new ExtensionClub(uri.URIClub); this.URIMember = new ExtensionMember(uri.URIMember); this.URINetwork = new ExtensionNetwork(uri.URINetwork); this.URIService = new ExtensionService(uri.URIService); this.URIDataManager = new ExtensionContentURI.DataManager(uri.URIDataManager); this.ErrorMessage = string.Empty; this.Message = uri.Message; this.Json = uri.Json; this.SchemaPath = uri.SchemaPath; }
//kept for consistency with Extension pattern, but NPV calculators use the NPVCalcs extension public 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 NPV1CalcParams = CalculatorHelpers.SetCalculatorParameters( extDocToCalcURI, extCalcDocURI, stepNumber, urisToAnalyze, updates); NPV1CalculatorHelper npv1BudgetHelper = new NPV1CalculatorHelper(NPV1CalcParams); ContractHelpers.EXTENSION_STEPS eStepNumber = ContractHelpers.GetEnumStepNumber(stepNumber); bool bHasUpdates = false; 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 (NPV1CalcParams != null) { //set constants for this step bHasCalculation = await NPV1CalculatorHelper.SetConstants(NPV1CalcParams); } 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 bHasUpdates = await CalculatorHelpers.RefreshUpdates(NPV1CalcParams, stepNumber, updates); if (NPV1CalcParams != null) { //no constants; just an xml edit of NRImpacts bHasCalculation = true; } extDocToCalcURI.URIDataManager.NeedsFullView = false; extDocToCalcURI.URIDataManager.NeedsSummaryView = false; break; case ContractHelpers.EXTENSION_STEPS.stepfour: //get rid of any update member that was added after running the same step 2x bHasUpdates = await CalculatorHelpers.RefreshUpdates(NPV1CalcParams, stepNumber, updates); if (NPV1CalcParams != null) { if (NPV1CalcParams.ExtensionDocToCalcURI.URIDataManager.SubAppType != Constants.SUBAPPLICATION_TYPES.devpacks.ToString()) { //run the calculations bHasCalculation = await npv1BudgetHelper.RunNPV1CalculatorCalculations(); } else { //run custom document calculations bHasCalculation = await npv1BudgetHelper.RunDevPacksCalculations(NPV1CalcParams); } extDocToCalcURI.ErrorMessage = NPV1CalcParams.ErrorMessage; extDocToCalcURI.ErrorMessage += NPV1CalcParams.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(NPV1CalcParams, eStepNumber, extDocToCalcURI); //replace the old calculator with the new one //and save the new calculations document bHasCalculation = await CalculatorHelpers.SaveNewCalculationsDocument(NPV1CalcParams); } else { bHasCalculation = false; } } extDocToCalcURI.URIDataManager.NeedsFullView = true; extDocToCalcURI.URIDataManager.NeedsSummaryView = false; break; case ContractHelpers.EXTENSION_STEPS.stepfive: extDocToCalcURI.URIDataManager.NeedsFullView = false; extDocToCalcURI.URIDataManager.NeedsSummaryView = true; extCalcDocURI.URIFileExtensionType = CalculatorHelpers.GetAttribute(NPV1CalcParams.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 += NPV1CalcParams.ErrorMessage; return(bHasCalculation); }
public async Task <bool> RunAnalyzerStep( ExtensionContentURI extDocToCalcURI, ExtensionContentURI extCalcDocURI, string stepNumber, IList <string> urisToAnalyze, IDictionary <string, string> updates, CancellationToken cancellationToken) { bool bHasAnalysis = false; CalculatorParameters npv1CalcParams = CalculatorHelpers.SetCalculatorParameters( extDocToCalcURI, extCalcDocURI, stepNumber, urisToAnalyze, updates); NPV1AnalyzerHelper npv1AnalyzerHelper = new NPV1AnalyzerHelper(npv1CalcParams); //check to make sure the analyzer can be run npv1AnalyzerHelper.SetOptions(); bool bHasUpdates = false; if (npv1AnalyzerHelper.NPV1CalculatorParams.ErrorMessage != string.Empty) { extDocToCalcURI.ErrorMessage += npv1AnalyzerHelper.NPV1CalculatorParams.ErrorMessage; return(false); } ContractHelpers.EXTENSION_STEPS eStepNumber = ContractHelpers.GetEnumStepNumber(stepNumber); switch (eStepNumber) { case ContractHelpers.EXTENSION_STEPS.stepzero: bHasAnalysis = true; break; case ContractHelpers.EXTENSION_STEPS.stepone: bHasAnalysis = true; break; case ContractHelpers.EXTENSION_STEPS.steptwo: //clear updates collection updates.Clear(); //just need the html form edits in this step bHasAnalysis = true; 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 bHasUpdates = await CalculatorHelpers.RefreshUpdates(npv1CalcParams, stepNumber, updates); //linked view insertions needs some analysis parameters SetAnalyzerParameters(npv1AnalyzerHelper, npv1CalcParams); if (npv1CalcParams.SubApplicationType == Constants.SUBAPPLICATION_TYPES.devpacks) { bHasAnalysis = await npv1AnalyzerHelper.RunAnalysis(npv1CalcParams.UrisToAnalyze); } else { bHasAnalysis = await npv1AnalyzerHelper.RunAnalysis(); } extDocToCalcURI.ErrorMessage = npv1CalcParams.ErrorMessage; extDocToCalcURI.ErrorMessage += npv1AnalyzerHelper.NPV1CalculatorParams.ErrorMessage; if (!bHasAnalysis) { extDocToCalcURI.ErrorMessage = (extDocToCalcURI.ErrorMessage == string.Empty) ? Errors.MakeStandardErrorMsg("CALCULATORS_URI_MISMATCH") : extDocToCalcURI.ErrorMessage; return(bHasAnalysis); } if (string.IsNullOrEmpty(extDocToCalcURI.ErrorMessage)) { //two step analyzers need to be saved now NPV1AnalyzerHelper.ANALYZER_TYPES eAnalyzerType = npv1AnalyzerHelper.GetAnalyzerType( npv1AnalyzerHelper.NPV1CalculatorParams.AnalyzerParms.AnalyzerType); //when 3+ step analyzers start being used CheckForLastStepAnalyzer(eAnalyzerType, eStepNumber, extDocToCalcURI); if (!CalculatorHelpers.IsSaveAction(extDocToCalcURI)) { //replace the old calculator with the new one //and save the new calculations document bool bHasReplacedCalcDoc = await CalculatorHelpers.SaveNewCalculationsDocument( npv1AnalyzerHelper.NPV1CalculatorParams); if (bHasReplacedCalcDoc) { bHasAnalysis = true; } else { extDocToCalcURI.ErrorMessage = Errors.MakeStandardErrorMsg("ANALYSES_ID_MISMATCH"); } } } else { bHasAnalysis = false; } extDocToCalcURI.URIDataManager.NeedsFullView = true; extDocToCalcURI.URIDataManager.NeedsSummaryView = false; break; case ContractHelpers.EXTENSION_STEPS.stepfour: bHasAnalysis = true; if (npv1AnalyzerHelper.AnalyzerType == NPV1AnalyzerHelper.ANALYZER_TYPES.npvtotal1 || npv1AnalyzerHelper.AnalyzerType == NPV1AnalyzerHelper.ANALYZER_TYPES.npvstat1 || npv1AnalyzerHelper.AnalyzerType == NPV1AnalyzerHelper.ANALYZER_TYPES.npvchangeyr || npv1AnalyzerHelper.AnalyzerType == NPV1AnalyzerHelper.ANALYZER_TYPES.npvchangeid || npv1AnalyzerHelper.AnalyzerType == NPV1AnalyzerHelper.ANALYZER_TYPES.npvchangealt || npv1AnalyzerHelper.AnalyzerType == NPV1AnalyzerHelper.ANALYZER_TYPES.npvprogress1) { if (npv1CalcParams.NeedsFullView) { extDocToCalcURI.URIDataManager.NeedsFullView = true; extDocToCalcURI.URIDataManager.NeedsSummaryView = false; } else { extDocToCalcURI.URIDataManager.NeedsFullView = false; extDocToCalcURI.URIDataManager.NeedsSummaryView = true; } extCalcDocURI.URIFileExtensionType = CalculatorHelpers.GetAttribute(npv1CalcParams.LinkedViewElement, Calculator1.cFileExtensionType); } if (extDocToCalcURI.URIDataManager.TempDocSaveMethod == Constants.SAVECALCS_METHOD.saveastext.ToString()) { //analyzers aren't yet available } else { //tells addinhelper to save calcs CalculatorHelpers.SetTempDocSaveAnalysesProperty(extDocToCalcURI); } break; default: //as many steps as needed can be added to this addin break; } extDocToCalcURI.ErrorMessage += npv1AnalyzerHelper.NPV1CalculatorParams.ErrorMessage; return(bHasAnalysis); }
public async Task <bool> RunAnalyzerStep( ExtensionContentURI extDocToCalcURI, ExtensionContentURI extCalcDocURI, string stepNumber, IList <string> urisToAnalyze, IDictionary <string, string> updates, CancellationToken cancellationToken) { bool bHasAnalysis = false; CalculatorParameters fnCalcParams = CalculatorHelpers.SetCalculatorParameters( extDocToCalcURI, extCalcDocURI, stepNumber, urisToAnalyze, updates); FNAnalyzerHelper fnAnalyzerHelper = new FNAnalyzerHelper(fnCalcParams); //check to make sure the analyzer can be run fnAnalyzerHelper.SetOptions(); if (fnAnalyzerHelper.FNCalculatorParams.ErrorMessage != string.Empty) { extDocToCalcURI.ErrorMessage += fnAnalyzerHelper.FNCalculatorParams.ErrorMessage; return(false); } ContractHelpers.EXTENSION_STEPS eStepNumber = ContractHelpers.GetEnumStepNumber(stepNumber); bool bHasUpdates = false; switch (eStepNumber) { case ContractHelpers.EXTENSION_STEPS.stepzero: bHasAnalysis = true; break; case ContractHelpers.EXTENSION_STEPS.stepone: bHasAnalysis = true; break; case ContractHelpers.EXTENSION_STEPS.steptwo: //clear updates collection updates.Clear(); //just need the html form edits in this step bHasAnalysis = true; 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 bHasUpdates = await CalculatorHelpers.RefreshUpdates(fnCalcParams, stepNumber, updates); if (fnAnalyzerHelper.AnalyzerType == FNAnalyzerHelper.ANALYZER_TYPES.resources01) { //linked view insertions needs some analysis parameters SetAnalyzerParameters(fnAnalyzerHelper, fnCalcParams); //the calculator pattern handles children linked view insertions //better than the analyzer pattern FNCalculatorHelper fnCalculatorHelper = new FNCalculatorHelper(fnCalcParams); bHasAnalysis = await fnCalculatorHelper.RunCalculations(); } else { //run the analysis (when analyses are available) //bHasAnalysis = fnAnalyzerHelper // .RunAnalysis(urisToAnalyze); } extDocToCalcURI.ErrorMessage = fnCalcParams.ErrorMessage; extDocToCalcURI.ErrorMessage += fnAnalyzerHelper.FNCalculatorParams.ErrorMessage; if (!bHasAnalysis) { extDocToCalcURI.ErrorMessage = (extDocToCalcURI.ErrorMessage == string.Empty) ? Errors.MakeStandardErrorMsg("CALCULATORS_URI_MISMATCH") : extDocToCalcURI.ErrorMessage; return(bHasAnalysis); } if (string.IsNullOrEmpty(extDocToCalcURI.ErrorMessage)) { //two step analyzers need to be saved now FNAnalyzerHelper.ANALYZER_TYPES eAnalyzerType = fnAnalyzerHelper.GetAnalyzerType( fnAnalyzerHelper.FNCalculatorParams.AnalyzerParms.AnalyzerType); //when 3+ step analyzers start being used CheckForLastStepAnalyzer(eAnalyzerType, eStepNumber, extDocToCalcURI); if (!CalculatorHelpers.IsSaveAction(extDocToCalcURI)) { //replace the old calculator with the new one //and save the new calculations document bool bHasReplacedCalcDoc = await CalculatorHelpers.SaveNewCalculationsDocument( fnAnalyzerHelper.FNCalculatorParams); if (bHasReplacedCalcDoc) { //the resource01 app uses the calculator, rather //than analyzer, pattern (i.e. children linked views //can be inserted) if (fnAnalyzerHelper.AnalyzerType != FNAnalyzerHelper.ANALYZER_TYPES.resources01) { //and add xmldoc params to update collection //only doctocalc gets updated CalculatorHelpers.AddXmlDocAndXmlDocIdsToUpdates( fnAnalyzerHelper.FNCalculatorParams); } bHasAnalysis = true; } else { extDocToCalcURI.ErrorMessage = Errors.MakeStandardErrorMsg("ANALYSES_ID_MISMATCH"); } } } else { bHasAnalysis = false; } extDocToCalcURI.URIDataManager.NeedsFullView = true; extDocToCalcURI.URIDataManager.NeedsSummaryView = false; break; case ContractHelpers.EXTENSION_STEPS.stepfour: bHasAnalysis = true; if (fnAnalyzerHelper.AnalyzerType == FNAnalyzerHelper.ANALYZER_TYPES.resources01) { extDocToCalcURI.URIDataManager.NeedsFullView = false; extDocToCalcURI.URIDataManager.NeedsSummaryView = true; extCalcDocURI.URIFileExtensionType = CalculatorHelpers.GetAttribute(fnCalcParams.LinkedViewElement, Calculator1.cFileExtensionType); } if (extDocToCalcURI.URIDataManager.TempDocSaveMethod == Constants.SAVECALCS_METHOD.saveastext.ToString()) { //analyzers aren't yet available } else { //tells addinhelper to save calcs CalculatorHelpers.SetTempDocSaveAnalysesProperty(extDocToCalcURI); } break; default: //as many steps as needed can be added to this addin break; } extDocToCalcURI.ErrorMessage += fnAnalyzerHelper.FNCalculatorParams.ErrorMessage; return(bHasAnalysis); }
//allows derived classes to override the default streaming //and save method protected virtual bool RunDevPackCalculations() { bool bHasCalculation = false; IDictionary <string, string> fileOrFolderPaths = CalculatorHelpers.GetDevPackState(this.GCCalculatorParams); if (string.IsNullOrEmpty(this.GCCalculatorParams.ErrorMessage)) { if (fileOrFolderPaths != null) { if (fileOrFolderPaths.Count > 0) { string sId = string.Empty; string sDocToCalcFilePath = string.Empty; string sTempDocToCalcPath = string.Empty; int i = 0; foreach (KeyValuePair <string, string> kvp in fileOrFolderPaths) { bHasCalculation = false; sId = kvp.Key; sDocToCalcFilePath = kvp.Value; if (CalculatorHelpers.URIAbsoluteExists( this.GCCalculatorParams.ExtensionDocToCalcURI, sDocToCalcFilePath)) { //make new calcparams using sDocToCalcFilePath ExtensionContentURI devPackCalcURI = CalculatorHelpers.GetDevPackCalcURI(this.GCCalculatorParams.ExtensionDocToCalcURI, this.GCCalculatorParams.ExtensionCalcDocURI, sDocToCalcFilePath, ref sTempDocToCalcPath); //copy the doctocalc to tempdoctocalcpath CalculatorHelpers.CopyFiles(this.GCCalculatorParams.ExtensionDocToCalcURI, sDocToCalcFilePath, sTempDocToCalcPath); //reset calculatorparams to reflect devPackCalcURI CalculatorParameters devPackCalcParameters = new CalculatorParameters(this.GCCalculatorParams); devPackCalcParameters.CurrentElementNodeName = devPackCalcURI.URINodeName; devPackCalcParameters.CurrentElementURIPattern = devPackCalcURI.URIPattern; //reset the calcparams.extdoctocalcuri devPackCalcParameters.ExtensionDocToCalcURI = devPackCalcURI; //currentDevPackElement has current db-generated linked views //and is more reliable for updating linked views in db XElement currentDevPackElement = null; XElement linkedViewElement = null; CalculatorHelpers.GetDevPackCalculator(this.GCCalculatorParams, devPackCalcParameters, out currentDevPackElement, out linkedViewElement); //4. raise event to carry out calculations GCArguments.CurrentElement = currentDevPackElement; GCArguments.LinkedViewElement = linkedViewElement; GCArguments.CalculatorParams = devPackCalcParameters; GCArguments.CalculatorParams.CurrentElement = currentDevPackElement; GCArguments.CalculatorParams.LinkedViewElement = linkedViewElement; OnRunDevPackCalculation(GCArguments); bHasCalculation = GCArguments.HasCalculations; currentDevPackElement = GCArguments.CurrentElement; linkedViewElement = GCArguments.LinkedViewElement; //5. SetXmlDocAttributes (using devPackElement) if (bHasCalculation) { //updates for children CalculatorHelpers.SetXmlDocUpdates(devPackCalcParameters, linkedViewElement, ref currentDevPackElement, this.GCCalculatorParams.Updates); //add the tempdoctocalcpath to updates for potential saving later string sErrorMsg = string.Empty; CalculatorHelpers.SetDevPackUpdatesState( devPackCalcURI, this.GCCalculatorParams.ExtensionCalcDocURI, this.GCCalculatorParams.Updates, ref sErrorMsg); if (i == 0) { //set the parent devpack this.GCCalculatorParams.CurrentElementNodeName = this.GCCalculatorParams.ExtensionDocToCalcURI.URINodeName; this.GCCalculatorParams.CurrentElementURIPattern = this.GCCalculatorParams.ExtensionDocToCalcURI.URIPattern; //currentDevPackElement has current db-generated linked views //and is reliable for updating linked views in db CalculatorHelpers.GetDevPackCalculator(this.GCCalculatorParams, this.GCCalculatorParams, out currentDevPackElement, out linkedViewElement); //update the parent this.GCCalculatorParams.NeedsXmlDocOnly = true; CalculatorHelpers.SetXmlDocUpdates(this.GCCalculatorParams, linkedViewElement, ref currentDevPackElement, this.GCCalculatorParams.Updates); //show them the first calculated document as feedback //refactor for future to show a summary of all calculated custom docs //move the doctocalc to tempdoctocalcpath CalculatorHelpers.CopyFiles( this.GCCalculatorParams.ExtensionDocToCalcURI, sTempDocToCalcPath, this.GCCalculatorParams.ExtensionDocToCalcURI.URIDataManager.TempDocPath); } } } i++; } } } } return(bHasCalculation); }
public 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 ME2CalcParams = CalculatorHelpers.SetCalculatorParameters( extDocToCalcURI, extCalcDocURI, stepNumber, urisToAnalyze, updates); ME2CalculatorHelper me2CalcHelper = new ME2CalculatorHelper(ME2CalcParams); ContractHelpers.EXTENSION_STEPS eStepNumber = ContractHelpers.GetEnumStepNumber(stepNumber); bool bHasUpdates = false; 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(); //just save this step's edits bHasCalculation = true; 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 bHasUpdates = await CalculatorHelpers.RefreshUpdates(ME2CalcParams, stepNumber, updates); if (ME2CalcParams != null) { bHasCalculation = await me2CalcHelper.RunME2CalculatorCalculations(); extDocToCalcURI.ErrorMessage = ME2CalcParams.ErrorMessage; extDocToCalcURI.ErrorMessage += ME2CalcParams.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(ME2CalcParams, eStepNumber, extDocToCalcURI); //replace the old calculator with the new one //and save the new calculations document bHasCalculation = await CalculatorHelpers.SaveNewCalculationsDocument(ME2CalcParams); } else { bHasCalculation = false; } } extDocToCalcURI.URIDataManager.NeedsFullView = true; extDocToCalcURI.URIDataManager.NeedsSummaryView = false; break; case ContractHelpers.EXTENSION_STEPS.stepfour: //show all indicators (unlike most calculators) extDocToCalcURI.URIDataManager.NeedsFullView = true; extDocToCalcURI.URIDataManager.NeedsSummaryView = false; extCalcDocURI.URIFileExtensionType = CalculatorHelpers.GetAttribute(ME2CalcParams.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 += ME2CalcParams.ErrorMessage; return(bHasCalculation); }
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); }
private async Task <bool> RunStepAsync(ContentURI docToCalcURI, ContentURI calcDocURI, string step, IDoStepsHostMetaData hostview, IList <string> urisToAnalyze, IDictionary <string, string> updates, CancellationToken cancellationToken) { bool bIsStepDone = false; //convert DevTreks' base model to the Extensions base model ExtensionContentURI extDocToCalcURI = new ExtensionContentURI(docToCalcURI); //extensions sets html view needed for each step extDocToCalcURI.URIDataManager.NeedsFullView = false; extDocToCalcURI.URIDataManager.NeedsSummaryView = false; ExtensionContentURI extCalcDocURI = new ExtensionContentURI(calcDocURI); //always display calculator extCalcDocURI.URIDataManager.NeedsFullView = true; //return Task.Run(() => //{ // cancellationToken.ThrowIfCancellationRequested(); //}, cancellationToken); if (calcDocURI.URIDataManager.HostName.ToLower() == DataHelpers.AddInHelper.HOSTS.extensioncalculatorsteps.ToString()) { //compute bound and mostly run synchronously bIsStepDone = await hostview.RunCalculatorStep( extDocToCalcURI, extCalcDocURI, step, urisToAnalyze, updates, cancellationToken); //set any new general display parameters docToCalcURI.URIDataManager.NeedsFullView = extDocToCalcURI.URIDataManager.NeedsFullView; docToCalcURI.URIDataManager.NeedsSummaryView = extDocToCalcURI.URIDataManager.NeedsSummaryView; docToCalcURI.URIDataManager.TempDocSaveMethod = extDocToCalcURI.URIDataManager.TempDocSaveMethod; docToCalcURI.ErrorMessage += extDocToCalcURI.ErrorMessage; } else if (calcDocURI.URIDataManager.HostName.ToLower() == DataHelpers.AddInHelper.HOSTS.extensionanalyzersteps.ToString()) { //compute bound and mostly run synchronously bIsStepDone = await hostview.RunAnalyzerStep( extDocToCalcURI, extCalcDocURI, step, urisToAnalyze, updates, cancellationToken); //set any new general display parameters docToCalcURI.URIDataManager.NeedsFullView = extDocToCalcURI.URIDataManager.NeedsFullView; docToCalcURI.URIDataManager.NeedsSummaryView = extDocToCalcURI.URIDataManager.NeedsSummaryView; docToCalcURI.URIDataManager.TempDocSaveMethod = extDocToCalcURI.URIDataManager.TempDocSaveMethod; docToCalcURI.ErrorMessage += extDocToCalcURI.ErrorMessage; } //newly inserted calculators usually set new fileextensiontypes if (extCalcDocURI.URIFileExtensionType != calcDocURI.URIFileExtensionType && (!string.IsNullOrEmpty(extCalcDocURI.URIFileExtensionType)) && extCalcDocURI.URIFileExtensionType != Constants.NONE) { //note: nothing more should be done with this parameter //linked view authors must manually set this property on //the LinkedView html form (previously ran unnecessary db updates) calcDocURI.URIFileExtensionType = extCalcDocURI.URIFileExtensionType; } if (docToCalcURI.ErrorMessage == string.Empty) { //set new stylesheet parameters //note that the sshelper looks for ssname2, which could be passed to it here IContentRepositoryEF contentRepository = new DevTreks.Data.SqlRepositories.ContentRepository(docToCalcURI); //i/o bound and run async await contentRepository.SetLinkedViewStateAsync(docToCalcURI, docToCalcURI); contentRepository.Dispose(); } return(bIsStepDone); }
//run analyzer extensions public abstract Task <bool> RunAnalyzerStep( ExtensionContentURI docToCalcURI, ExtensionContentURI calcDocURI, string stepNumber, IList <string> urisToAnalyze, IDictionary <string, string> updates, CancellationToken cancellationToken);