Пример #1
0
 private IEnumerable <XElement> StreamOperationComponent()
 {
     //loop through the descendants in document order
     while (this.GCCalculatorParams.DocToCalcReader.Read())
     {
         if (this.GCCalculatorParams.DocToCalcReader.NodeType
             == XmlNodeType.Element)
         {
             if (this.GCCalculatorParams.DocToCalcReader.Name
                 == BudgetInvestment.BUDGET_TYPES.budgetoperation.ToString() ||
                 this.GCCalculatorParams.DocToCalcReader.Name
                 == BudgetInvestment.INVESTMENT_TYPES.investmentcomponent.ToString())
             {
                 //use streaming techniques to process descendants
                 XElement currentElement
                     = CalculatorHelpers.GetCurrentElementWithAttributes(
                           this.GCCalculatorParams.DocToCalcReader);
                 //attach linked views separately (or the readdescendant syntax skips)
                 CalculatorHelpers.AddLinkedViewsToCurrentElementWithReader(
                     this.GCCalculatorParams.ExtensionDocToCalcURI,
                     this.GCCalculatorParams.AnalyzerParms.ObservationsPath, ref currentElement);
                 //don't process previously calculated nodes
                 bool bIsAnnuity = TimePeriod.IsAnnuity(currentElement);
                 if (!bIsAnnuity)
                 {
                     //set stateful ancestor objects (i.e. this.GCCalculatorParams.ParentBudget)
                     //that descendants use in their calculations
                     GCArguments.CurrentElement = currentElement;
                     OnSetAncestorObjects(GCArguments);
                     IEnumerable <XElement> childElements = null;
                     if (this.GCCalculatorParams.DocToCalcReader.Name
                         == BudgetInvestment.BUDGET_TYPES.budgetoperation.ToString())
                     {
                         childElements =
                             from childElement in StreamBudgetInput()
                             select childElement;
                     }
                     else if (this.GCCalculatorParams.DocToCalcReader.Name
                              == BudgetInvestment.INVESTMENT_TYPES.investmentcomponent.ToString())
                     {
                         childElements =
                             from childElement in StreamInvestmentInput()
                             select childElement;
                     }
                     if (currentElement != null)
                     {
                         if (childElements != null)
                         {
                             currentElement.Add(childElements);
                         }
                         this.RunCalculationsAndSetUpdates(ref currentElement);
                         yield return(currentElement);
                     }
                 }
             }
         }
         else if (this.GCCalculatorParams.DocToCalcReader.NodeType
                  == XmlNodeType.EndElement)
         {
             if (this.GCCalculatorParams.DocToCalcReader.Name
                 == BudgetInvestment.BUDGET_TYPES.budgetoperations.ToString() ||
                 this.GCCalculatorParams.DocToCalcReader.Name
                 == BudgetInvestment.INVESTMENT_TYPES.investmentcomponents.ToString())
             {
                 break;
             }
         }
     }
 }
Пример #2
0
 private IEnumerable <XElement> StreamInvestmentOutcome()
 {
     //not all calculations include outcomes, so use ReadToDescendent syntax
     //this works even without outcomes as long as the parent "outcomes" node
     //is yielded, and that node has no xmldoc calcs
     while (this.GCCalculatorParams.DocToCalcReader.ReadToDescendant(
                BudgetInvestment.INVESTMENT_TYPES.investmentoutcome.ToString()))
     {
         if (this.GCCalculatorParams.DocToCalcReader.NodeType
             == XmlNodeType.Element)
         {
             //use streaming techniques to process descendants
             XElement currentElement
                 = CalculatorHelpers.GetCurrentElementWithAttributes(
                       this.GCCalculatorParams.DocToCalcReader);
             //attach linked views separately (or the readdescendant syntax skips)
             CalculatorHelpers.AddLinkedViewsToCurrentElementWithReader(
                 this.GCCalculatorParams.ExtensionDocToCalcURI,
                 this.GCCalculatorParams.AnalyzerParms.ObservationsPath, ref currentElement);
             //don't process previously calculated nodes
             bool bIsAnnuity = TimePeriod.IsAnnuity(currentElement);
             if (!bIsAnnuity)
             {
                 //set stateful ancestor objects (i.e. this.GCCalculatorParams.ParentOutcome)
                 //that descendants use in their calculations
                 GCArguments.CurrentElement = currentElement;
                 OnSetAncestorObjects(GCArguments);
                 IEnumerable <XElement> childElements = null;
                 childElements =
                     from childElement in StreamInvestmentOutput()
                     select childElement;
                 if (currentElement != null)
                 {
                     if (childElements != null)
                     {
                         currentElement.Add(childElements);
                     }
                     this.RunCalculationsAndSetUpdates(ref currentElement);
                     yield return(currentElement);
                 }
             }
             //process sibling outcomes
             while (this.GCCalculatorParams.DocToCalcReader
                    .ReadToNextSibling(BudgetInvestment.INVESTMENT_TYPES.investmentoutcome.ToString()))
             {
                 if (this.GCCalculatorParams.DocToCalcReader.NodeType
                     == XmlNodeType.Element)
                 {
                     XElement siblingElement
                         = CalculatorHelpers.GetCurrentElementWithAttributes(
                               this.GCCalculatorParams.DocToCalcReader);
                     //attach linked views separately (or the readdescendant syntax skips)
                     CalculatorHelpers.AddLinkedViewsToCurrentElementWithReader(
                         this.GCCalculatorParams.ExtensionDocToCalcURI,
                         this.GCCalculatorParams.AnalyzerParms.ObservationsPath, ref siblingElement);
                     //don't process previously calculated nodes
                     bIsAnnuity = TimePeriod.IsAnnuity(siblingElement);
                     if (!bIsAnnuity)
                     {
                         //set stateful ancestor objects (i.e. this.GCCalculatorParams.ParentOutcome)
                         //that descendants use in their calculations
                         GCArguments.CurrentElement = siblingElement;
                         OnSetAncestorObjects(GCArguments);
                         IEnumerable <XElement> childElements = null;
                         childElements =
                             from childElement in StreamInvestmentOutput()
                             select childElement;
                         if (siblingElement != null)
                         {
                             if (childElements != null)
                             {
                                 siblingElement.Add(childElements);
                             }
                             this.RunCalculationsAndSetUpdates(ref siblingElement);
                             yield return(siblingElement);
                         }
                     }
                 }
                 else if (this.GCCalculatorParams.DocToCalcReader.NodeType
                          == XmlNodeType.EndElement)
                 {
                     if (this.GCCalculatorParams.DocToCalcReader.Name
                         == BudgetInvestment.BUDGET_TYPES.budgetoutcomes.ToString() ||
                         this.GCCalculatorParams.DocToCalcReader.Name
                         == BudgetInvestment.INVESTMENT_TYPES.investmentoutcomes.ToString())
                     {
                         break;
                     }
                 }
             }
         }
         else if (this.GCCalculatorParams.DocToCalcReader.NodeType
                  == XmlNodeType.EndElement)
         {
             if (this.GCCalculatorParams.DocToCalcReader.Name
                 == BudgetInvestment.BUDGET_TYPES.budgetoutcomes.ToString() ||
                 this.GCCalculatorParams.DocToCalcReader.Name
                 == BudgetInvestment.INVESTMENT_TYPES.investmentoutcomes.ToString())
             {
                 break;
             }
         }
     }
 }
Пример #3
0
 //set the class properties using the XElement
 public void SetInputProperties(CalculatorParameters calcParameters,
                                XElement currentCalculationsElement, XElement currentElement)
 {
     //several extensions store some calculator props in base element (observations, targettype)
     //no harm done in setting them but never set their attributes in base element
     this.SetCalculatorProperties(currentCalculationsElement);
     this.SetSharedObjectProperties(currentElement);
     this.SetTotalCostsProperties(currentElement);
     this.AnnuityType = TimePeriod.GetAnnuityType(currentElement);
     //input calcs can be run from group nodes
     if (currentElement.Name.LocalName
         != DataAppHelpers.Prices.INPUT_PRICE_TYPES.inputgroup.ToString())
     {
         //set this object's specific properties
         this.Date = CalculatorHelpers.GetAttributeDate(currentElement,
                                                        DataAppHelpers.Prices.INPUT_DATE);
         this.OCAmount = CalculatorHelpers.GetAttributeDouble(currentElement,
                                                              DataAppHelpers.Prices.OC_AMOUNT);
         this.OCPrice = CalculatorHelpers.GetAttributeDouble(currentElement,
                                                             DataAppHelpers.Prices.OC_PRICE);
         this.OCUnit = CalculatorHelpers.GetAttribute(currentElement,
                                                      DataAppHelpers.Prices.OC_UNIT);
         this.AOHAmount = CalculatorHelpers.GetAttributeDouble(currentElement,
                                                               DataAppHelpers.Prices.AOH_AMOUNT);
         this.AOHPrice = CalculatorHelpers.GetAttributeDouble(currentElement,
                                                              DataAppHelpers.Prices.AOH_PRICE);
         this.AOHUnit = CalculatorHelpers.GetAttribute(currentElement,
                                                       DataAppHelpers.Prices.AOH_UNIT);
         this.CAPAmount = CalculatorHelpers.GetAttributeDouble(currentElement,
                                                               DataAppHelpers.Prices.CAP_AMOUNT);
         this.CAPPrice = CalculatorHelpers.GetAttributeDouble(currentElement,
                                                              DataAppHelpers.Prices.CAP_PRICE);
         this.CAPUnit = CalculatorHelpers.GetAttribute(currentElement,
                                                       DataAppHelpers.Prices.CAP_UNIT);
         this.IncentiveAmount = CalculatorHelpers.GetAttributeDouble(currentElement,
                                                                     DataAppHelpers.General.INCENTIVE_AMOUNT);
         this.IncentiveRate = CalculatorHelpers.GetAttributeDouble(currentElement,
                                                                   DataAppHelpers.General.INCENTIVE_RATE);
         this.InputGroupId = CalculatorHelpers.GetAttributeInt(currentElement,
                                                               DataAppHelpers.Prices.INPUT_GROUP_ID);
         this.InputGroupName = CalculatorHelpers.GetAttribute(currentElement,
                                                              DataAppHelpers.Prices.INPUT_GROUP_NAME);
         this.Times = CalculatorHelpers.GetAttributeDouble(currentElement,
                                                           DataAppHelpers.Prices.INPUT_TIMES);
         this.UseAOH = CalculatorHelpers.GetAttributeBool(currentElement,
                                                          DataAppHelpers.Prices.USE_AOH);
         this.Local = new Local();
         string sCurrentNodeURIPattern
             = CalculatorHelpers.MakeNewURIPatternFromElement(
                   calcParameters.ExtensionDocToCalcURI.URIPattern, currentElement);
         this.Local = CalculatorHelpers.GetLocal(sCurrentNodeURIPattern, calcParameters,
                                                 currentCalculationsElement, currentElement);
     }
     else
     {
         //set this object's properties using calculator attributes
         this.Date = CalculatorHelpers.GetAttributeDate(currentCalculationsElement,
                                                        INPUT_DATE);
         this.OCAmount = CalculatorHelpers.GetAttributeDouble(currentCalculationsElement,
                                                              DataAppHelpers.Prices.OC_AMOUNT);
         this.OCPrice = CalculatorHelpers.GetAttributeDouble(currentCalculationsElement,
                                                             DataAppHelpers.Prices.OC_PRICE);
         this.OCUnit = CalculatorHelpers.GetAttribute(currentCalculationsElement,
                                                      DataAppHelpers.Prices.OC_UNIT);
         this.AOHAmount = CalculatorHelpers.GetAttributeDouble(currentCalculationsElement,
                                                               DataAppHelpers.Prices.AOH_AMOUNT);
         this.AOHPrice = CalculatorHelpers.GetAttributeDouble(currentCalculationsElement,
                                                              DataAppHelpers.Prices.AOH_PRICE);
         this.AOHUnit = CalculatorHelpers.GetAttribute(currentCalculationsElement,
                                                       DataAppHelpers.Prices.AOH_UNIT);
         this.CAPAmount = CalculatorHelpers.GetAttributeDouble(currentCalculationsElement,
                                                               DataAppHelpers.Prices.CAP_AMOUNT);
         this.CAPPrice = CalculatorHelpers.GetAttributeDouble(currentCalculationsElement,
                                                              DataAppHelpers.Prices.CAP_PRICE);
         this.CAPUnit = CalculatorHelpers.GetAttribute(currentCalculationsElement,
                                                       DataAppHelpers.Prices.CAP_UNIT);
         this.IncentiveAmount = CalculatorHelpers.GetAttributeDouble(currentCalculationsElement,
                                                                     DataAppHelpers.General.INCENTIVE_AMOUNT);
         this.IncentiveRate = CalculatorHelpers.GetAttributeDouble(currentCalculationsElement,
                                                                   DataAppHelpers.General.INCENTIVE_RATE);
         this.Times = CalculatorHelpers.GetAttributeDouble(currentCalculationsElement,
                                                           DataAppHelpers.Prices.INPUT_TIMES);
         this.UseAOH = CalculatorHelpers.GetAttributeBool(currentCalculationsElement,
                                                          DataAppHelpers.Prices.USE_AOH);
         //use the calculator params to set locals (they can be changed in calcor)
         this.Local = new Local();
         this.Local.SetLocalProperties(calcParameters,
                                       currentCalculationsElement, currentElement);
     }
     //joint input calcs can change this element
     this.XmlDocElement = currentCalculationsElement;
 }
Пример #4
0
 public TimePeriod(CalculatorParameters calcParameters, TimePeriod timePeriod)
 {
     //calcParams same pattern as other constructors
     this.CopyTimePeriod(timePeriod);
 }
Пример #5
0
 //copy constructors
 public TimePeriod(TimePeriod timePeriod)
 {
     this.CopyTimePeriod(timePeriod);
 }
Пример #6
0
 //set the class properties using the XElement
 public void SetOutputProperties(CalculatorParameters calcParameters,
                                 XElement currentCalculationsElement, XElement currentElement)
 {
     //several extensions store some calculator props in base element (observations, targettype)
     //no harm done in setting them but never set their attributes in base element
     this.SetCalculatorProperties(currentCalculationsElement);
     this.SetSharedObjectProperties(currentElement);
     this.SetTotalBenefitsProperties(currentElement);
     this.AnnuityType = TimePeriod.GetAnnuityType(currentElement);
     if (currentElement.Name.LocalName
         != DataAppHelpers.Prices.OUTPUT_PRICE_TYPES.outputgroup.ToString())
     {
         this.Date = CalculatorHelpers.GetAttributeDate(currentElement,
                                                        DataAppHelpers.Prices.OUTPUT_DATE);
         this.Amount = CalculatorHelpers.GetAttributeDouble(currentElement,
                                                            OUTPUT_AMOUNT);
         this.Price = CalculatorHelpers.GetAttributeDouble(currentElement,
                                                           OUTPUT_PRICE);
         this.Unit = CalculatorHelpers.GetAttribute(currentElement,
                                                    OUTPUT_BASE_UNIT);
         this.CompositionAmount = CalculatorHelpers.GetAttributeDouble(currentElement,
                                                                       COMPOSITION_AMOUNT);
         this.CompositionUnit = CalculatorHelpers.GetAttribute(currentElement,
                                                               COMPOSITION_UNIT);
         this.Times = CalculatorHelpers.GetAttributeDouble(currentElement,
                                                           OUTPUT_TIMES);
         this.IncentiveAmount = CalculatorHelpers.GetAttributeDouble(currentElement,
                                                                     DataAppHelpers.General.INCENTIVE_AMOUNT);
         this.IncentiveRate = CalculatorHelpers.GetAttributeDouble(currentElement,
                                                                   DataAppHelpers.General.INCENTIVE_RATE);
         this.OutputGroupId = CalculatorHelpers.GetAttributeInt(currentElement,
                                                                DataAppHelpers.Prices.OUTPUT_GROUP_ID);
         this.OutputGroupName = CalculatorHelpers.GetAttribute(currentElement,
                                                               DataAppHelpers.Prices.OUTPUT_GROUP_NAME);
         this.Local = new Local();
         string sCurrentNodeURIPattern
             = CalculatorHelpers.MakeNewURIPatternFromElement(
                   calcParameters.ExtensionDocToCalcURI.URIPattern, currentElement);
         this.Local = CalculatorHelpers.GetLocal(sCurrentNodeURIPattern, calcParameters,
                                                 currentCalculationsElement, currentElement);
     }
     else
     {
         this.Date = CalculatorHelpers.GetAttributeDate(currentCalculationsElement,
                                                        OUTPUT_DATE);
         this.Amount = CalculatorHelpers.GetAttributeDouble(currentCalculationsElement,
                                                            OUTPUT_AMOUNT);
         this.Price = CalculatorHelpers.GetAttributeDouble(currentCalculationsElement,
                                                           OUTPUT_PRICE);
         this.Unit = CalculatorHelpers.GetAttribute(currentCalculationsElement,
                                                    OUTPUT_BASE_UNIT);
         this.CompositionAmount = CalculatorHelpers.GetAttributeDouble(currentCalculationsElement,
                                                                       COMPOSITION_AMOUNT);
         this.CompositionUnit = CalculatorHelpers.GetAttribute(currentCalculationsElement,
                                                               COMPOSITION_UNIT);
         this.Times = CalculatorHelpers.GetAttributeDouble(currentCalculationsElement,
                                                           OUTPUT_TIMES);
         this.IncentiveAmount = CalculatorHelpers.GetAttributeDouble(currentCalculationsElement,
                                                                     DataAppHelpers.General.INCENTIVE_AMOUNT);
         this.IncentiveRate = CalculatorHelpers.GetAttributeDouble(currentCalculationsElement,
                                                                   DataAppHelpers.General.INCENTIVE_RATE);
         //use the calculator params to set locals (they can be changed in calcor)
         this.Local = new Local();
         this.Local.SetLocalProperties(calcParameters,
                                       currentCalculationsElement, currentElement);
     }
     //joint output calcs can change this element
     this.XmlDocElement = currentCalculationsElement;
 }
Пример #7
0
 private IEnumerable <XElement> StreamTimePeriods()
 {
     //loop through the descendants in document order
     while (this.GCCalculatorParams.DocToCalcReader.Read())
     {
         if (this.GCCalculatorParams.DocToCalcReader.NodeType
             == XmlNodeType.Element)
         {
             if (this.GCCalculatorParams.DocToCalcReader.Name
                 == Constants.ROOT_PATH)
             {
                 //skip using while
             }
             else if (this.GCCalculatorParams.DocToCalcReader.Name
                      == BudgetInvestment.BUDGET_TYPES.budgettimeperiod.ToString() ||
                      this.GCCalculatorParams.DocToCalcReader.Name
                      == BudgetInvestment.INVESTMENT_TYPES.investmenttimeperiod.ToString())
             {
                 //read currentElement including xmldocnodes
                 XElement currentElement
                     = CalculatorHelpers.GetCurrentElementWithAttributes(
                           this.GCCalculatorParams.DocToCalcReader);
                 //don't process previously calculated nodes
                 bool bIsAnnuity = TimePeriod.IsAnnuity(currentElement);
                 if (!bIsAnnuity)
                 {
                     //attach linked views separately (put in first position)
                     CalculatorHelpers.AddLinkedViewsToCurrentElementWithReader(
                         this.GCCalculatorParams.ExtensionDocToCalcURI,
                         this.GCCalculatorParams.AnalyzerParms.ObservationsPath, currentElement);
                     //set stateful ancestor objects (i.e. this.GCCalculatorParams.ParentBudget)
                     //that descendants use in their calculations
                     GCArguments.CurrentElement = currentElement;
                     OnSetAncestorObjects(GCArguments);
                     //use streaming techniques to process descendants
                     IEnumerable <XElement> childElements =
                         from childElement in StreamTimePeriodChildren()
                         select childElement;
                     if (currentElement != null)
                     {
                         if (childElements != null)
                         {
                             //add the child elements to the currentElement
                             currentElement.Add(childElements);
                         }
                         this.RunCalculationsAndSetUpdates(ref currentElement);
                         yield return(currentElement);
                     }
                 }
             }
         }
         else if (this.GCCalculatorParams.DocToCalcReader.NodeType
                  == XmlNodeType.EndElement)
         {
             if (this.GCCalculatorParams.DocToCalcReader.Name
                 == BudgetInvestment.BUDGET_TYPES.budget.ToString() ||
                 this.GCCalculatorParams.DocToCalcReader.Name
                 == BudgetInvestment.INVESTMENT_TYPES.investment.ToString())
             {
                 break;
             }
         }
     }
 }