Пример #1
0
        private bool RunIOTechCalculationsAndSetUpdates(ref XElement currentElement)
        {
            bool bHasCalculations = false;

            if (!currentElement.HasAttributes)
            {
                return(true);
            }
            //1. set parameters needed by updates collection
            this.GCCalculatorParams.CurrentElementNodeName
                = currentElement.Name.LocalName;
            this.GCCalculatorParams.CurrentElementURIPattern
                = CalculatorHelpers.MakeNewURIPatternFromElement(this.GCCalculatorParams.ExtensionDocToCalcURI.URIPattern,
                                                                 currentElement);
            //2. don't run calcs on ancestors
            bool bIsSelfOrDescendentNode = CalculatorHelpers.IsSelfOrDescendentNode(
                this.GCCalculatorParams, this.GCCalculatorParams.CurrentElementNodeName);

            if (bIsSelfOrDescendentNode)
            {
                //3. get the calculator to use
                //(this.GCCalculatorParams.CalculationEl, or currentElement.xmldoc)
                XElement linkedViewElement       = null;
                bool     bNeedsRelatedCalculator = NeedsRelatedCalculator();
                if (bNeedsRelatedCalculator)
                {
                    //no db updates -potential to continually have to update in/outs in db
                    linkedViewElement
                        = CalculatorHelpers.GetRelatedCalculator(this.GCCalculatorParams,
                                                                 currentElement);
                }
                else
                {
                    //216: bug with feasible penalties needs to find a calculator using GetAllyCalc
                    linkedViewElement
                        = CalculatorHelpers.GetCalculator(this.GCCalculatorParams,
                                                          currentElement);
                    //216: mach stock calcs rely on at least default calculators or buggy
                    if (linkedViewElement == null)
                    {
                        linkedViewElement = new XElement(this.GCCalculatorParams.LinkedViewElement);
                    }
                    //pre 216 code
                    //don't use calctype = input; prefer using stronger relatedcalctype=agmachinery
                    //string sCalculatorType = this.GCCalculatorParams.CalculatorType;
                    //this.GCCalculatorParams.CalculatorType = string.Empty;
                    //linkedViewElement
                    //   = CalculatorHelpers.GetCalculator(this.GCCalculatorParams,
                    //        currentElement);
                    //this.GCCalculatorParams.CalculatorType = sCalculatorType;
                }
                //4. Set bool to update base node attributes in db
                this.GCCalculatorParams.AttributeNeedsDbUpdate
                    = CalculatorHelpers.NeedsUpdateAttribute(this.GCCalculatorParams);
                //5. raise event to carry out calculations
                GCArguments.CurrentElement    = currentElement;
                GCArguments.LinkedViewElement = linkedViewElement;
                OnRunCalculation(GCArguments);
                currentElement    = GCArguments.CurrentElement;
                linkedViewElement = GCArguments.LinkedViewElement;
                bHasCalculations  = GCArguments.HasCalculations;
                //6. 100% Rules: don't allow analyzers to db update descendent calculators
                ChangeLinkedViewCalculator(currentElement, ref linkedViewElement);
                //inputs have a join-side xmldoc that may need to be updated
                //to current calculator results (i.e. Input.Times can change
                //the amount of fuel, labor, and other resources for this input)
                //note that the base npvcalculator does not always adjust
                //resource calculator amounts, such as fuel and labor, when
                //Input.Times change (if it did, the following would not be needed).
                bool bHasReplacedCalculator = false;
                if (CalculatorHelpers.IsLinkedViewXmlDoc(
                        this.GCCalculatorParams.CurrentElementURIPattern,
                        this.GCCalculatorParams.ExtensionDocToCalcURI))
                {
                    //7. replace the this.GCCalculatorParams.CalculationsElement when
                    //the originating doctocalcuri node is processed
                    bHasReplacedCalculator = CalculatorHelpers.ReplaceCalculations(
                        this.GCCalculatorParams, currentElement,
                        linkedViewElement);
                    //8. this pattern combines analyzer and calculator patterns
                    CalculatorHelpers.SetAnalyzerParameters(
                        this.GCCalculatorParams, linkedViewElement);
                }
                //9. SetXmlDocAttributes
                CalculatorHelpers.SetXmlDocUpdates(this.GCCalculatorParams,
                                                   linkedViewElement, currentElement,
                                                   this.GCCalculatorParams.Updates);
                //10. 210 new rule: replace calcs when they've changed but no db work (210 stopped working because of byref changes)
                if ((!bHasReplacedCalculator) && bHasCalculations)
                {
                    bHasReplacedCalculator = CalculatorHelpers.ReplaceOrInsertLinkedViewElement(
                        linkedViewElement, currentElement);
                }
            }
            else
            {
                //version 1.3.0 added this so that ancestors are always added to collections
                //to make analyses consistent (i.e. always start with group)
                GCArguments.CurrentElement = currentElement;
                //ancestors can never update or use a linkedview element
                GCArguments.LinkedViewElement = null;
                //but we want the ancestor current element added to the underlying collections
                OnRunCalculation(GCArguments);
                //always return true, so no error msg is generated
                bHasCalculations = true;
            }
            return(bHasCalculations);
        }
Пример #2
0
        private bool RunBasicCalculationsAndSetUpdates(ref XElement currentElement)
        {
            bool bHasCalculations = false;

            if (!currentElement.HasAttributes)
            {
                return(true);
            }
            //1. set parameters needed by updates collection
            this.GCCalculatorParams.CurrentElementNodeName
                = currentElement.Name.LocalName;
            this.GCCalculatorParams.CurrentElementURIPattern
                = CalculatorHelpers.MakeNewURIPatternFromElement(this.GCCalculatorParams.ExtensionDocToCalcURI.URIPattern,
                                                                 currentElement);
            //2. don't run calcs on ancestors
            bool bIsSelfOrDescendentNode = CalculatorHelpers.IsSelfOrDescendentNode(
                this.GCCalculatorParams, this.GCCalculatorParams.CurrentElementNodeName);

            if (bIsSelfOrDescendentNode)
            {
                //3. get the calculator to use
                //(this.GCCalculatorParams.CalculationEl, or currentElement.xmldoc)
                XElement linkedViewElement = null;
                linkedViewElement = CalculatorHelpers.GetCalculator(
                    this.GCCalculatorParams, currentElement);
                //some apps, such as locals, work differently
                AdjustSpecialtyLinkedViewElements(currentElement, ref linkedViewElement);
                //4. Set bool to update base node attributes in db
                this.GCCalculatorParams.AttributeNeedsDbUpdate
                    = CalculatorHelpers.NeedsUpdateAttribute(this.GCCalculatorParams);
                //5. raise event to carry out calculations
                GCArguments.CurrentElement    = currentElement;
                GCArguments.LinkedViewElement = linkedViewElement;
                OnRunCalculation(GCArguments);
                currentElement    = GCArguments.CurrentElement;
                linkedViewElement = GCArguments.LinkedViewElement;
                bHasCalculations  = GCArguments.HasCalculations;
                if (bHasCalculations)
                {
                    //6. 100% Rules: don't allow analyzers to db update descendent calculators
                    ChangeLinkedViewCalculator(currentElement, ref linkedViewElement);
                    //7. replace the this.GCCalculatorParams.LinkedViewElement when
                    //the originating doctocalcuri node is processed
                    bool bHasReplacedCalculator = CalculatorHelpers.ReplaceCalculations(this.GCCalculatorParams,
                                                                                        currentElement, linkedViewElement);
                    //8. SetXmlDocAttributes
                    CalculatorHelpers.SetXmlDocUpdates(this.GCCalculatorParams,
                                                       linkedViewElement, currentElement,
                                                       this.GCCalculatorParams.Updates);
                    //9. 210 new rule: replace calcs when they've changed but no db work (210 stopped working because of byref changes)
                    if ((!bHasReplacedCalculator) && bHasCalculations)
                    {
                        bHasReplacedCalculator = CalculatorHelpers.ReplaceOrInsertLinkedViewElement(
                            linkedViewElement, currentElement);
                    }
                }
            }
            else
            {
                //basic calculators don't need full collections that include ancestors
                bHasCalculations = true;
            }
            return(bHasCalculations);
        }
Пример #3
0
        private bool RunBasicAnalysisAndSetUpdates(ref XElement currentElement)
        {
            bool bHasCalculations = false;

            if (!currentElement.HasAttributes)
            {
                return(true);
            }
            //1. set parameters needed by updates collection
            this.GCCalculatorParams.CurrentElementNodeName
                = currentElement.Name.LocalName;
            this.GCCalculatorParams.CurrentElementURIPattern
                = CalculatorHelpers.MakeNewURIPatternFromElement(this.GCCalculatorParams.ExtensionDocToCalcURI.URIPattern,
                                                                 currentElement);
            //2. don't run calcs on ancestors
            bool bIsSelfOrDescendentNode = CalculatorHelpers.IsSelfOrDescendentNode(
                this.GCCalculatorParams, this.GCCalculatorParams.CurrentElementNodeName);

            if (bIsSelfOrDescendentNode)
            {
                //3. get the calculator to use
                //(this.GCCalculatorParams.CalculationEl, or currentElement.xmldoc)
                XElement linkedViewElement = null;
                linkedViewElement = CalculatorHelpers.GetCalculator(
                    this.GCCalculatorParams, currentElement);
                //4. Set bool to update base node attributes in db
                this.GCCalculatorParams.AttributeNeedsDbUpdate
                    = CalculatorHelpers.NeedsUpdateAttribute(this.GCCalculatorParams);
                //5. raise event to carry out calculations
                GCArguments.CurrentElement    = currentElement;
                GCArguments.LinkedViewElement = linkedViewElement;
                OnRunCalculation(GCArguments);
                currentElement = GCArguments.CurrentElement;
                //subscriber sets the lv to update
                linkedViewElement = GCArguments.LinkedViewElement;
                bHasCalculations  = GCArguments.HasCalculations;
                if (bHasCalculations)
                {
                    //6. allow analyzers to db update descendent analyzers
                    CalculatorHelpers.ChangeLinkedViewCalculatorForAnalysis(this.GCCalculatorParams, currentElement,
                                                                            linkedViewElement);
                    //7. replace the this.GCCalculatorParams.LinkedViewElement when
                    //the originating doctocalcuri node is processed
                    bool bHasReplacedCalculator = CalculatorHelpers.ReplaceCalculations(this.GCCalculatorParams,
                                                                                        currentElement, linkedViewElement);
                    //8. SetXmlDocAttributes
                    CalculatorHelpers.SetXmlDocUpdates(this.GCCalculatorParams,
                                                       linkedViewElement, currentElement,
                                                       this.GCCalculatorParams.Updates);
                    //9. 210 new rule: replace calcs when they've changed but no db work (210 stopped working because of byref changes)
                    if ((!bHasReplacedCalculator) && bHasCalculations)
                    {
                        bHasReplacedCalculator = CalculatorHelpers.ReplaceOrInsertLinkedViewElement(
                            linkedViewElement, currentElement);
                    }
                }
            }
            else
            {
                //version 1.3.6 added this so that ancestors are always added to collections
                //to make analyses consistent (i.e. always start with group)
                GCArguments.CurrentElement = currentElement;
                //ancestors can never update or use a linkedview element
                GCArguments.LinkedViewElement = null;
                //but we want the ancestor current element added to the underlying collections
                OnRunCalculation(GCArguments);
                //always return true, so no error msg is generated
                bHasCalculations = true;
            }
            return(bHasCalculations);
        }