/// <summary> /// Initializes the object based on the current expressions using the given object as /// context. /// </summary> /// <param name="context">The context for the expressions.</param> /// <returns>false if the initialization is unsuccessfull; otherwise false.</returns> private bool InitializeObject(Project context) { try { startDate = GetDate(context as Project, StartDateExpression.Expr.GetValue(0, 0).ToString()).Date; } catch (Exception ex) { context.AddError("Start date is not valid. Details: " + ex.Message); return(true); } try { endDate = GetDate(context as Project, EndDateExpression.Expr.GetValue(0, 0).ToString()).Date; } catch (Exception ex) { context.AddError("End date is not valid. Details: " + ex.Message); return(true); } try { frequency = GetDateFrequency((Project)context, FrequencyExpression); } catch (Exception ex) { context.AddError("Frequency is not valid. Details: " + ex.Message); return(true); } try { skipPeriodsParsed = (int)SkipPeriods.V(); } catch (Exception ex) { context.AddError("The number of periods to skip is not valid. Details: " + ex.Message); return(true); } try { double v = SkipPeriodsArray?.V() ?? 0.0f; skipPeriodsArrayParsed = (int)v; } catch (Exception ex) { context.AddError("The number of periods to skip is not valid. Details: " + ex.Message); return(true); } return(false); }
/// <summary> /// Parses the object. /// </summary> /// <param name="p_Context">The project in which to parse the object.</param> /// <returns>true if an error occurred during the parsing, false otherwise.</returns> public override bool Parse(IProject p_Context) { if (StartDateExpression.Parse(p_Context)) { return(true); } if (EndDateExpression.Parse(p_Context)) { return(true); } if (SkipPeriods.Parse(p_Context)) { return(true); } if (InitializeObject(p_Context as Project)) { return(true); } if (Validation(p_Context)) { if (ValidVectorRef()) { if (SkipPeriodsArray.Parse(p_Context)) { return(true); } var arrayReference = GetVectorRef(); this.Values = new List <RightValue>(); this.Values.AddRange(arrayReference.Values.Skip(skipPeriodsArrayParsed)); return(false); } else { List <RightValue> dates; if (GenerateSequenceFromStartDate) { dates = GenerateForward(); } else { dates = GenerateBackward(); } if (dates.Count == 0) { return(true); } // Set the model parameter array values this.Values = dates; return(base.Parse(p_Context)); } } return(true); }