public void Merge(ProjectInfo project, ChannelMergeMode mergeMode) { if (this.Id != project.Id) { throw new Exception("The project to be merged has a different ID."); } // merge channels List <ChannelInfo> newChannels = new List <ChannelInfo>(); foreach (var channel in project.Channels) { var referenceChannel = this.Channels.FirstOrDefault(current => current.Id == channel.Id); if (referenceChannel != null) { referenceChannel.Merge(channel, mergeMode); } else { newChannels.Add(channel); } channel.Parent = this; } this.Channels.AddRange(newChannels); // merge other data if (this.ProjectStart == DateTime.MinValue) { this.ProjectStart = project.ProjectStart; } else { this.ProjectStart = new DateTime(Math.Min(this.ProjectStart.Ticks, project.ProjectStart.Ticks)); } if (this.ProjectEnd == DateTime.MinValue) { this.ProjectEnd = project.ProjectEnd; } else { this.ProjectEnd = new DateTime(Math.Max(this.ProjectEnd.Ticks, project.ProjectEnd.Ticks)); } }
public void Merge(ChannelInfo channel, ChannelMergeMode mergeMode) { if (this.Parent.Id != channel.Parent.Id) { throw new Exception("The channel to be merged has a different parent."); } // merge properties switch (mergeMode) { case ChannelMergeMode.OverwriteMissing: if (string.IsNullOrWhiteSpace(this.Name)) { this.Name = channel.Name; } if (string.IsNullOrWhiteSpace(this.Group)) { this.Group = channel.Group; } if (string.IsNullOrWhiteSpace(this.Unit)) { this.Unit = channel.Unit; } if (string.IsNullOrWhiteSpace(this.Description)) { this.Description = channel.Description; } break; case ChannelMergeMode.NewWins: this.Name = channel.Name; this.Group = channel.Group; this.Unit = channel.Unit; this.Description = channel.Description; break; default: throw new NotSupportedException(); } // merge datasets var newDatasets = new List <DatasetInfo>(); foreach (var dataset in channel.Datasets) { var referenceDataset = this.Datasets.FirstOrDefault(current => current.Id == dataset.Id); if (referenceDataset != null) { referenceDataset.Merge(dataset); } else { newDatasets.Add(dataset); } dataset.Parent = this; } this.Datasets.AddRange(newDatasets); }