Пример #1
0
 private static void SetAnalyzerParameters(
     HCAnalyzerHelper hcAnalyzerHelper, CalculatorParameters hcCalcParams)
 {
     //only resources01 analyzers are available yet
     hcAnalyzerHelper.SetAnalysisParameters();
     hcCalcParams.FileExtensionType
         = hcAnalyzerHelper.HCCalculatorParams.FileExtensionType;
     hcCalcParams.Stylesheet2Name
         = hcAnalyzerHelper.HCCalculatorParams.Stylesheet2Name;
     hcCalcParams.Stylesheet2ObjectNS
         = hcAnalyzerHelper.HCCalculatorParams.Stylesheet2ObjectNS;
 }
        //define the actions to take when the event is raised
        public void SetLinkedView(object sender, CustomEventArgs e)
        {
            //pass a byref xelement from the publisher's data
            XElement         obsElement     = new XElement(e.CurrentElement);
            HCAnalyzerHelper analyzerHelper = new HCAnalyzerHelper();

            this.AnalyzerType = analyzerHelper.GetAnalyzerType(e.CalculatorParams.AnalyzerParms.AnalyzerType);
            //if observation documents need to differ depending on the analysis
            //use a switch (this.AnalyzerType) here
            SetLinkedViewAttributes(e.CalculatorParams,
                                    obsElement);
            //pass the new statelement back to the publisher
            //by setting the CalculatedElement property of CustomEventArgs
            e.CurrentElement = new XElement(obsElement);
        }
Пример #3
0
        public override async Task <bool> RunAnalyzerStep(
            ExtensionContentURI extDocToCalcURI, ExtensionContentURI extCalcDocURI,
            string stepNumber, IList <string> urisToAnalyze,
            IDictionary <string, string> updates, CancellationToken cancellationToken)
        {
            bool bHasAnalysis = false;
            CalculatorParameters hcCalcParams
                = CalculatorHelpers.SetCalculatorParameters(
                      extDocToCalcURI, extCalcDocURI, stepNumber, urisToAnalyze,
                      updates);
            HCAnalyzerHelper hcAnalyzerHelper = new HCAnalyzerHelper(hcCalcParams);

            //check to make sure the analyzer can be run
            hcAnalyzerHelper.SetOptions();
            if (hcAnalyzerHelper.HCCalculatorParams.ErrorMessage != string.Empty)
            {
                extDocToCalcURI.ErrorMessage += hcAnalyzerHelper.HCCalculatorParams.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
                CalculatorHelpers.RefreshUpdates(hcCalcParams, stepNumber, updates);
                if (hcAnalyzerHelper.AnalyzerType
                    == HCAnalyzerHelper.ANALYZER_TYPES.resources01)
                {
                    //linked view insertions needs some analysis parameters
                    SetAnalyzerParameters(hcAnalyzerHelper, hcCalcParams);
                    //the calculator pattern handles children linked view insertions
                    //better than the analyzer pattern
                    HCCalculatorHelper hcCalculatorHelper
                                 = new HCCalculatorHelper(hcCalcParams);
                    bHasAnalysis = hcCalculatorHelper
                                   .RunCalculations();
                }
                else
                {
                    //run the analysis (when analyses are available)
                    //bHasAnalysis = hcAnalyzerHelper
                    //    .RunAnalysis(urisToAnalyze);
                }
                extDocToCalcURI.ErrorMessage  = hcCalcParams.ErrorMessage;
                extDocToCalcURI.ErrorMessage += hcAnalyzerHelper.HCCalculatorParams.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
                    HCAnalyzerHelper.ANALYZER_TYPES eAnalyzerType
                        = hcAnalyzerHelper.GetAnalyzerType(
                              hcAnalyzerHelper.HCCalculatorParams.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
                            = CalculatorHelpers.SaveNewCalculationsDocument(
                                  hcAnalyzerHelper.HCCalculatorParams);
                        if (bHasReplacedCalcDoc)
                        {
                            //the resource01 app uses the calculator, rather
                            //than analyzer, pattern (i.e. children linked views
                            //can be inserted)
                            if (hcAnalyzerHelper.AnalyzerType
                                != HCAnalyzerHelper.ANALYZER_TYPES.resources01)
                            {
                                //and add xmldoc params to update collection
                                //only doctocalc gets updated
                                CalculatorHelpers.AddXmlDocAndXmlDocIdsToUpdates(
                                    hcAnalyzerHelper.HCCalculatorParams);
                            }
                            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 (hcAnalyzerHelper.AnalyzerType
                    == HCAnalyzerHelper.ANALYZER_TYPES.resources01)
                {
                    extDocToCalcURI.URIDataManager.NeedsFullView    = false;
                    extDocToCalcURI.URIDataManager.NeedsSummaryView = true;
                    extCalcDocURI.URIFileExtensionType = CalculatorHelpers.GetAttribute(hcCalcParams.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 += hcAnalyzerHelper.HCCalculatorParams.ErrorMessage;
            return(bHasAnalysis);
        }