Beispiel #1
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)
            ARSCalculatorHelper arsCalculatorHelper
                = new ARSCalculatorHelper(e.CalculatorParams);

            //run the calculations
            bHasCalculations = arsCalculatorHelper
                               .RunCalculations();
            //pass the bool back to the publisher
            //by setting the HasCalculations property of CustomEventArgs
            e.HasCalculations = bHasCalculations;
        }
Beispiel #2
0
        public async Task <bool> RunAnalyzerStep(
            ExtensionContentURI extDocToCalcURI, ExtensionContentURI extCalcDocURI,
            string stepNumber, IList <string> urisToAnalyze,
            IDictionary <string, string> updates, CancellationToken cancellationToken)
        {
            bool bHasAnalysis = false;
            CalculatorParameters arsCalcParams
                = CalculatorHelpers.SetCalculatorParameters(
                      extDocToCalcURI, extCalcDocURI, stepNumber, urisToAnalyze,
                      updates);
            ARSAnalyzerHelper arsAnalyzerHelper = new ARSAnalyzerHelper(arsCalcParams);

            //check to make sure the analyzer can be run
            arsAnalyzerHelper.SetOptions();
            if (arsAnalyzerHelper.ARSCalculatorParams.ErrorMessage != string.Empty)
            {
                extDocToCalcURI.ErrorMessage += arsAnalyzerHelper.ARSCalculatorParams.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.RefreshUpdatesUsingDocToCalc(arsCalcParams,
                                                                                   stepNumber, updates);

                if (arsAnalyzerHelper.AnalyzerType
                    == ARSAnalyzerHelper.ANALYZER_TYPES.resources01 ||
                    arsAnalyzerHelper.AnalyzerType.ToString().StartsWith(ARSAnalyzerHelper.ANALYZER_TYPES.resources02.ToString()))
                {
                    //linked view insertions needs some analysis parameters
                    SetAnalyzerParameters(arsAnalyzerHelper, arsCalcParams);
                    //the calculator pattern handles children linked view insertions
                    //better than the analyzer pattern
                    ARSCalculatorHelper arsCalculatorHelper
                        = new ARSCalculatorHelper(arsCalcParams);
                    if (arsCalcParams.SubApplicationType == Constants.SUBAPPLICATION_TYPES.devpacks)
                    {
                        bHasAnalysis = await arsCalculatorHelper.RunAnalysis(arsCalcParams.UrisToAnalyze);
                    }
                    else
                    {
                        bHasAnalysis = await arsCalculatorHelper.RunCalculations();
                    }
                }
                extDocToCalcURI.ErrorMessage = arsAnalyzerHelper.ARSCalculatorParams.ErrorMessage;
                if (!bHasAnalysis)
                {
                    extDocToCalcURI.ErrorMessage = (extDocToCalcURI.ErrorMessage == string.Empty) ?
                                                   Errors.MakeStandardErrorMsg("ANALYSES_URI_MISMATCH")
                            : extDocToCalcURI.ErrorMessage;
                    return(bHasAnalysis);
                }
                if (string.IsNullOrEmpty(extDocToCalcURI.ErrorMessage))
                {
                    //two step analyzers need to be saved now
                    ARSAnalyzerHelper.ANALYZER_TYPES eAnalyzerType
                        = arsAnalyzerHelper.GetAnalyzerType(
                              arsAnalyzerHelper.ARSCalculatorParams.AnalyzerParms.AnalyzerType);
                    //when 3+ step analyzers start being used
                    CheckForLastStepAnalyzer(eAnalyzerType,
                                             eStepNumber, extDocToCalcURI);
                    if (!CalculatorHelpers.IsSaveAction(extCalcDocURI))
                    {
                        //replace the old calculator with the new one
                        //and save the new calculations document
                        bool bHasReplacedCalcDoc
                            = await CalculatorHelpers.SaveNewCalculationsDocument(
                                  arsAnalyzerHelper.ARSCalculatorParams);

                        if (bHasReplacedCalcDoc)
                        {
                            //the resource01 app uses the calculator, rather
                            //than analyzer, pattern (i.e. children linked views
                            //can be inserted)
                            if (arsAnalyzerHelper.AnalyzerType
                                != ARSAnalyzerHelper.ANALYZER_TYPES.resources01 &&
                                (!arsAnalyzerHelper.AnalyzerType.ToString().StartsWith(ARSAnalyzerHelper.ANALYZER_TYPES.resources02.ToString())))
                            {
                                //and add xmldoc params to update collection
                                //only doctocalc gets updated
                                CalculatorHelpers.AddXmlDocAndXmlDocIdsToUpdates(
                                    arsAnalyzerHelper.ARSCalculatorParams);
                            }
                            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 (arsAnalyzerHelper.AnalyzerType
                    == ARSAnalyzerHelper.ANALYZER_TYPES.resources01)
                {
                    extDocToCalcURI.URIDataManager.NeedsFullView    = true;
                    extDocToCalcURI.URIDataManager.NeedsSummaryView = false;
                    extCalcDocURI.URIFileExtensionType = CalculatorHelpers.GetAttribute(arsCalcParams.LinkedViewElement,
                                                                                        Calculator1.cFileExtensionType);
                }
                else if (arsAnalyzerHelper.AnalyzerType
                         == ARSAnalyzerHelper.ANALYZER_TYPES.resources02a ||
                         arsAnalyzerHelper.AnalyzerType
                         == ARSAnalyzerHelper.ANALYZER_TYPES.resources02)
                {
                    extDocToCalcURI.URIDataManager.NeedsFullView    = true;
                    extDocToCalcURI.URIDataManager.NeedsSummaryView = false;
                    extCalcDocURI.URIFileExtensionType = CalculatorHelpers.GetAttribute(arsCalcParams.LinkedViewElement,
                                                                                        Calculator1.cFileExtensionType);
                }
                if (extDocToCalcURI.URIDataManager.TempDocSaveMethod
                    == Constants.SAVECALCS_METHOD.saveastext.ToString())
                {
                    //text files can be filtered by subscribers
                    ARSAnalyzerHelper.ANALYZER_TYPES eAnalyzerType
                        = arsAnalyzerHelper.GetAnalyzerType(
                              arsAnalyzerHelper.ARSCalculatorParams.AnalyzerParms.AnalyzerType);
                    ARSTextSubscriber npvTextSubscriber
                                 = new ARSTextSubscriber(arsCalcParams, eAnalyzerType);
                    bHasAnalysis = await npvTextSubscriber.BuildObservations(urisToAnalyze);

                    if (!bHasAnalysis ||
                        (!string.IsNullOrEmpty(npvTextSubscriber.ObsCalculatorParams.ErrorMessage)))
                    {
                        extDocToCalcURI.ErrorMessage = npvTextSubscriber.ObsCalculatorParams.ErrorMessage;
                        CalculatorHelpers.SetTempDocSaveNoneProperty(extDocToCalcURI);
                    }
                    else
                    {
                        //tells addinhelper to save calcs
                        CalculatorHelpers.SetTempDocSaveAnalysesProperty(extDocToCalcURI);
                    }
                }
                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 += arsCalcParams.ErrorMessage;
            extDocToCalcURI.ErrorMessage += arsAnalyzerHelper.ARSCalculatorParams.ErrorMessage;
            return(bHasAnalysis);
        }