Beispiel #1
0
 public void ChangeCalculator(XElement currentElement,
                              ref XElement calculator)
 {
     //these analyzers use atts from calculators only
     if (this.GCCalculatorParams.AnalyzerParms.AnalyzerType
         == ME2AnalyzerHelper.ANALYZER_TYPES.mechangealt.ToString() ||
         this.GCCalculatorParams.AnalyzerParms.AnalyzerType
         == ME2AnalyzerHelper.ANALYZER_TYPES.meprogress1.ToString())
     {
         //don't change the starting calculator
         if (this.GCCalculatorParams.StartingDocToCalcNodeName
             == currentElement.Name.LocalName)
         {
             return;
         }
         bool bIsChildren
             = CalculatorHelpers.IsSelfOrChildNode(this.GCCalculatorParams, currentElement.Name.LocalName);
         bool bIsTPGrandChild =
             (currentElement.Name.LocalName == BudgetInvestment.BUDGET_TYPES.budgettimeperiod.ToString() ||
              currentElement.Name.LocalName == BudgetInvestment.INVESTMENT_TYPES.investmenttimeperiod.ToString())
             ? true : false;
         //need the alt or target type from mecalcs
         if (bIsChildren || bIsTPGrandChild)
         {
             bool   bIsMECalculator  = false;
             string sCurrentCalcType = string.Empty;
             if (calculator != null)
             {
                 sCurrentCalcType = CalculatorHelpers.GetAttribute(calculator, Calculator1.cCalculatorType);
             }
             if (!string.IsNullOrEmpty(sCurrentCalcType))
             {
                 //see if it matches a real me calctype
                 CalculatorHelpers.CALCULATOR_TYPES calcType
                     = CalculatorHelpers.GetCalculatorType(sCurrentCalcType);
                 if (calcType != CalculatorHelpers.CALCULATOR_TYPES.none)
                 {
                     bIsMECalculator = true;
                 }
             }
             if (calculator == null ||
                 bIsMECalculator == false)
             {
                 calculator = CalculatorHelpers.GetChildLinkedViewUsingAttribute(currentElement,
                                                                                 Calculator1.cCalculatorType, currentElement.Name.LocalName);
             }
         }
     }
 }
        private async Task <bool> RunBasicCalculationsAndSetUpdatesAsync(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
                CalculatorHelpers.AdjustSpecialtyLinkedViewElements(currentElement, linkedViewElement, this.GCCalculatorParams);
                //4. Set bool to update base node attributes in db
                this.GCCalculatorParams.AttributeNeedsDbUpdate
                    = CalculatorHelpers.NeedsUpdateAttribute(this.GCCalculatorParams);
                //5. raise event to carry out calculations
                //v180: no children xml doc changes when Overwrite = false and UseSameCalc = false
                bool bNeedsLVUpdate = CalculatorHelpers.NeedsLVUpdate(this.GCCalculatorParams);
                if (bNeedsLVUpdate)
                {
                    bHasCalculations
                        = await RunCalculationAsync(currentElement, linkedViewElement);
                }
                else
                {
                    //but if it's a child it might still need to be displayed
                    //will only be displayed by setting CalculatorId or AnalyzerType in currentEl
                    if (CalculatorHelpers.IsSelfOrChildNode(this.GCCalculatorParams, this.GCCalculatorParams.CurrentElementNodeName))
                    {
                        CalculatorHelpers.SetCalculatorId(linkedViewElement, currentElement);
                    }
                }
                if (bHasCalculations)
                {
                    //v182 added resetting because async starts next node (i.e. parent) and these change before the method is finished
                    //1. set parameters needed by updates collection
                    //this.GCCalculatorParams.CurrentElementNodeName
                    //    = currentElement.Name.LocalName;
                    //this.GCCalculatorParams.CurrentElementURIPattern
                    //    = CalculatorHelpers.MakeNewURIPatternFromElement(this.GCCalculatorParams.ExtensionDocToCalcURI.URIPattern,
                    //    currentElement);
                    //6. 100% Rules: don't allow analyzers to db update descendent calculators
                    CalculatorHelpers.ChangeLinkedViewCalculator(currentElement, linkedViewElement, this.GCCalculatorParams);
                    //7. replace the this.GCCalculatorParams.LinkedViewElement when
                    //the originating doctocalcuri node is processed
                    bool bHasReplacedCalculator = CalculatorHelpers.ReplaceCalculations(this.GCCalculatorParams,
                                                                                        currentElement, linkedViewElement);
                    //8. v180 SetXmlDocAttributes only set db updates (xmldoc lvs are automatically changed by RunCalcAsync)
                    CalculatorHelpers.SetXmlDocUpdates(this.GCCalculatorParams,
                                                       linkedViewElement, currentElement, this.GCCalculatorParams.Updates);
                }
            }
            else
            {
                //basic calculators don't need full collections that include ancestobrs
                bHasCalculations = true;
            }
            return(bHasCalculations);
        }
Beispiel #3
0
 private void ChangeLinkedViewCalculator(XElement currentElement, ref XElement linkedViewElement)
 {
     //v137 pattern allows analyzers to update descendents using dbupdates
     //i.e. need i/o calculators to get totals, but don't want to
     //overwrite those calculations in db
     if (this.GCCalculatorParams.ExtensionCalcDocURI.URIDataManager.HostName
         == DevTreks.Data.Helpers.AddInHelper.HOSTS.extensionanalyzersteps.ToString() &&
         this.GCCalculatorParams.NeedsCalculators &&
         CalculatorHelpers.IsSelfOrChildNode(this.GCCalculatorParams, currentElement.Name.LocalName))
     {
         //100% Rule 1: Analyzers never, ever, update calculators
         string sCalculatorType = CalculatorHelpers.GetAttribute(linkedViewElement,
                                                                 Calculator1.cCalculatorType);
         //pure calculators never have an analysis type
         string sAnalysisType = CalculatorHelpers.GetAttribute(linkedViewElement,
                                                               Calculator1.cAnalyzerType);
         if (!string.IsNullOrEmpty(sCalculatorType) &&
             string.IsNullOrEmpty(sAnalysisType))
         {
             //order of lv retrieval gets calulators before analyzers
             XElement analyzerLV = CalculatorHelpers.GetChildLinkedViewUsingAttribute(
                 currentElement, Calculator1.cAnalyzerType, this.GCCalculatorParams.AnalyzerParms.AnalyzerType);
             if (analyzerLV != null)
             {
                 if (this.GCCalculatorParams.LinkedViewElement != null)
                 {
                     //keep the id and calculatorid, but update the rest of the atts with new lv
                     string sId     = CalculatorHelpers.GetAttribute(analyzerLV, Calculator1.cId);
                     string sCalcId = CalculatorHelpers.GetAttribute(analyzerLV, Calculator1.cCalculatorId);
                     analyzerLV = new XElement(this.GCCalculatorParams.LinkedViewElement);
                     CalculatorHelpers.SetAttribute(analyzerLV, Calculator1.cId, sId);
                     CalculatorHelpers.SetAttribute(analyzerLV, Calculator1.cCalculatorId, sCalcId);
                 }
                 //use it to update db (not the calculator)
                 linkedViewElement = new XElement(analyzerLV);
             }
             else
             {
                 //use the base linked view standard pattern
                 //avoids updating the wrong lvs
                 linkedViewElement = CalculatorHelpers.GetNewCalculator(this.GCCalculatorParams, currentElement);
             }
         }
     }
     //100% Rule 2: Analyzers and Calculators never, ever, allow descendent lvs
     //to have parent Overwrite or UseSameCalc properties
     if (this.GCCalculatorParams.StartingDocToCalcNodeName
         != currentElement.Name.LocalName)
     {
         if (linkedViewElement != null)
         {
             string sAttValue = CalculatorHelpers.GetAttribute(linkedViewElement,
                                                               Calculator1.cUseSameCalculator);
             if ((!string.IsNullOrEmpty(sAttValue)) && sAttValue != Constants.NONE)
             {
                 CalculatorHelpers.SetAttribute(linkedViewElement,
                                                Calculator1.cUseSameCalculator, string.Empty);
             }
             sAttValue = CalculatorHelpers.GetAttribute(linkedViewElement,
                                                        Calculator1.cOverwrite);
             if ((!string.IsNullOrEmpty(sAttValue)) && sAttValue != Constants.NONE)
             {
                 CalculatorHelpers.SetAttribute(linkedViewElement,
                                                Calculator1.cOverwrite, string.Empty);
             }
         }
     }
 }
Beispiel #4
0
        private void ChangeCalculatorIdForUpdatedChildren(XElement currentElement,
                                                          ref XElement calculator, ME2Stock me2)
        {
            //alternatives are set using ME calculators (or input/output calculators)
            bool bIsChildrenUpdate
                = CalculatorHelpers.IsSelfOrChildNode(this.GCCalculatorParams, currentElement.Name.LocalName);

            if (bIsChildrenUpdate)
            {
                //don't change the starting calculator
                if (this.GCCalculatorParams.StartingDocToCalcNodeName
                    == currentElement.Name.LocalName)
                {
                    return;
                }
                XElement lv = CalculatorHelpers.GetChildLinkedViewUsingAttribute(currentElement,
                                                                                 Calculator1.cAnalyzerType, this.GCCalculatorParams.AnalyzerParms.AnalyzerType.ToString());
                //init with random calculator id
                if (this.GCCalculatorParams.RndGenerator == null)
                {
                    this.GCCalculatorParams.RndGenerator = new Random();
                }
                int iCalcId = this.GCCalculatorParams.RndGenerator.Next();
                if (lv != null)
                {
                    //switch to a calc that needs to be updated
                    iCalcId = CalculatorHelpers.GetAttributeInt(lv, Calculator1.cId);
                }
                else
                {
                    if (calculator != null)
                    {
                        //use the existing calc (gencalcsubscriber will replace with a new one anyway)
                        lv = new XElement(calculator);
                    }
                }
                if (lv != null)
                {
                    //change analyzer so that it can be inserted or updated (instead of the existing me calc)
                    CalculatorHelpers.SetAttributeInt(lv, Calculator1.cId, iCalcId);
                    CalculatorHelpers.SetAttributeInt(lv, Calculator1.cCalculatorId, iCalcId);
                    //important for updates that this get set to string.empty
                    CalculatorHelpers.SetAttribute(lv, Calculator1.cCalculatorType, string.Empty);
                    CalculatorHelpers.SetAttribute(lv, Calculator1.cAnalyzerType, this.GCCalculatorParams.AnalyzerParms.AnalyzerType);
                    //tells subscriber to update/insert child
                    calculator = new XElement(lv);
                }
                if (iCalcId != 0)
                {
                    me2.Id           = iCalcId;
                    me2.CalculatorId = iCalcId;
                    if (me2.Total1 != null)
                    {
                        me2.Total1.Id           = iCalcId;
                        me2.Total1.CalculatorId = iCalcId;
                    }
                    if (me2.Stat1 != null)
                    {
                        me2.Stat1.Id           = iCalcId;
                        me2.Stat1.CalculatorId = iCalcId;
                    }
                    if (me2.Change1 != null)
                    {
                        me2.Change1.Id           = iCalcId;
                        me2.Change1.CalculatorId = iCalcId;
                    }
                    if (me2.Progress1 != null)
                    {
                        me2.Progress1.Id           = iCalcId;
                        me2.Progress1.CalculatorId = iCalcId;
                    }
                }
            }
        }