public LogProfile Clone() { LogProfile clone = new LogProfile(); clone.columns = new List <LogColumn>(this.columns); return(clone); }
/// <summary> /// Build the list of columns for the given profile /// </summary> private void AddColumnsAndDependents(IList <LogColumn> columns, LogProfile newProfile) { List <LogColumn> dependencies = new List <LogColumn>(); foreach (LogColumn column in newProfile.Columns) { Parameter parameter = column.Parameter; Conversion conversion = column.Conversion; DependencyMap dependencyMap = null; if (parameter.IsCalculated) { dependencyMap = new DependencyMap(); foreach (Parameter dependency in parameter.Dependencies) { string depencencyKey; Conversion dependencyConversion; InternalLogProfile.GetDependencyConversion( dependency, conversion, out dependencyConversion, out depencencyKey); this.VerifyParameter(dependency); LogColumn dependencyColumn = LogColumn.GetInstance( dependency, dependencyConversion, null, true); dependencyMap[depencencyKey] = dependencyColumn; dependencies.Add(dependencyColumn); } } this.VerifyParameter(parameter); LogColumn newColumn = LogColumn.GetInstance(parameter, conversion, dependencyMap, false); columns.Add(newColumn); } if (dependencies != null) { foreach (LogColumn dependency in dependencies) { columns.Add(dependency); } } }
/// <summary> /// Selects parameters to be logged /// </summary> public void SetProfile(LogProfile profile) { Trace.WriteLine("SsmRecordingLogger.SetProfile"); this.currentProfile = profile; if (this.currentProfile == null) { Trace.WriteLine("SsmRecordingLogger.SetProfile: profile set to null"); return; } this.internalProfile = this.currentProfile.Clone(); if (this.filter.Parameter != null && this.filter.Conversion != null) { this.internalProfile.Add(this.filter.Parameter, this.filter.Conversion); } this.logger.SetProfile(this.internalProfile, this.database); }
/// <summary> /// Private constructor, use factory instead /// </summary> /// <param name="profile"></param> private InternalLogProfile(LogProfile profile, ParameterDatabase database) { if (Debugger.IsAttached) { this.stackTrace = new StackTrace(); } this.profile = profile; this.database = database; List <LogColumn> columns = new List <LogColumn>(); this.AddColumnsAndDependents(columns, this.profile); this.addresses = BuildAddressList(columns); ReadOnlyCollection <LogColumn> readOnly = columns.AsReadOnly(); LogRow row = LogRow.GetInstance(readOnly); this.logEventArgs = new LogEventArgs(row, profile.UserData); }
/// <summary> /// Load parameter list from file. /// </summary> /// <remarks> /// TODO: indicate what parameters in the file are not supported by the current database. /// </remarks> public static LogProfile Load(string path, ParameterDatabase database) { Trace.WriteLine("LogProfile.Load"); if (database == null) { Trace.WriteLine("LogProfile.Load: no database? WTF?"); return(LogProfile.CreateInstance()); } LogProfile profile = null; using (Stream stream = File.OpenRead(path)) { XmlSerializer serializer = new XmlSerializer(typeof(SerializedColumn[])); SerializedColumn[] serializedColumns = (SerializedColumn[])serializer.Deserialize(stream); profile = LogProfile.CreateInstance(); foreach (SerializedColumn serializedColumn in serializedColumns) { Parameter parameter; Conversion conversion; if (serializedColumn == null) { Trace.WriteLine("LogProfile.Load: serializedColumn == null? WTF?"); continue; } if (database.TryGetParameterById(serializedColumn.ParameterId, out parameter) && parameter.TryGetConversionByUnits(serializedColumn.ConversionUnits, out conversion)) { profile.Add(parameter, conversion); } } } Trace.WriteLine("LogProfile.Load: done"); return(profile); }
/// <summary> /// Selects parameters to be logged /// </summary> public void SetProfile(LogProfile profile, ParameterDatabase database) { Trace.WriteLine("SsmBasicLogger.SetProfile"); this.internalProfile = InternalLogProfile.GetInstance(profile, database); }
/// <summary> /// Selects parameters to be logged /// </summary> public void SetProfile(LogProfile profile, ParameterDatabase database) { Trace.WriteLine("SsmLogger.SetProfile"); this.logger.SetProfile(profile, database); }
/// <summary> /// Factory /// </summary> public static InternalLogProfile GetInstance(LogProfile profile, ParameterDatabase database) { return(new InternalLogProfile(profile, database)); }