/// <summary> /// Initializes the object based on the serialized data. /// </summary> /// <param name="info">The SerializationInfo that holds the serialized object data.</param> /// <param name="context">The StreamingContext that contains contextual /// information about the source.</param> public ModelParameterDateSequence(SerializationInfo info, StreamingContext context) : base(info, context) { // Set the default for GenerateSequenceFromStartDate and FollowFrequency GenerateSequenceFromStartDate = true; FollowFrequency = true; int serialializedVersion; try { serialializedVersion = info.GetInt32("_VersionDateSequence"); } catch { serialializedVersion = 0; } if (serialializedVersion < 2) { #region No expressions try { this.StartDate = new DateTime(info.GetInt64("_StartDate")); this.EndDate = new DateTime(info.GetInt64("_EndDate")); } catch (Exception) { // In case the calibration time was serialized in a different way. this.StartDate = info.GetDateTime("_StartDate"); this.EndDate = info.GetDateTime("_EndDate"); } int frequency = info.GetInt32("_Frequency"); Array enumValues = Enum.GetValues(typeof(DateFrequency)); foreach (DateFrequency value in enumValues) { if ((int)value == frequency) { Frequency = value; break; } } if (serialializedVersion >= 1) { // Introduction of ExcludeStartDate bool exclude = info.GetBoolean("_ExcludeStartDate"); SkipPeriods = exclude ? new ModelParameter(1) : new ModelParameter((double)0); } else { SkipPeriods = new ModelParameter((double)0); } #endregion // No expressions } else { if (serialializedVersion < 4) { string tmpS = info.GetString("_StartDateExpression"); DateTime tmpD; if (DateTime.TryParseExact(tmpS, "yyyy-MM-dd", CultureInfo.CurrentCulture, DateTimeStyles.None, out tmpD)) { StartDate = tmpD; } else { StartDateExpression = new ModelParameter(tmpS); } tmpS = info.GetString("_EndDateExpression"); if (DateTime.TryParseExact(tmpS, "yyyy-MM-dd", CultureInfo.CurrentCulture, DateTimeStyles.None, out tmpD)) { EndDate = tmpD; } else { EndDateExpression = new ModelParameter(tmpS); } } else { StartDateExpression = (ModelParameter)info.GetValue("_StartDateExpression", typeof(ModelParameter)); EndDateExpression = (ModelParameter)info.GetValue("_EndDateExpression", typeof(ModelParameter)); SetupExportedIDs(); } FrequencyExpression = info.GetString("_FrequencyExpression"); if (serialializedVersion >= 3) { // FollowFrequency and GenerateSequenceFromStartDate in version 3 FollowFrequency = info.GetBoolean("_FollowFrequency"); GenerateSequenceFromStartDate = info.GetBoolean("_GenerateSequenceFromStartDate"); } // Skip Periods introduced in version 5 if (serialializedVersion < 5) { bool exclude = info.GetBoolean("_ExcludeStartDate"); SkipPeriods = exclude ? new ModelParameter(1) : new ModelParameter((double)0); } else { SkipPeriods = (ModelParameter)info.GetValue("_SkipPeriods", typeof(ModelParameter)); } if (serialializedVersion < 6) { VectorReferenceExpr = string.Empty; } else { VectorReferenceExpr = info.GetString("_VectorReferenceExpr"); SkipPeriodsArray = ObjectSerialization.GetValue <ModelParameter>(info, "_SkipPeriodsArray", new ModelParameter(0.0)); } } }