[6134] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[9615] | 3 | * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[6134] | 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
| 22 | using System;
|
---|
[6133] | 23 | using System.Collections.Generic;
|
---|
| 24 | using System.Linq;
|
---|
| 25 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 26 |
|
---|
| 27 | namespace HeuristicLab.DataImporter.Data.Model {
|
---|
| 28 | [StorableClass]
|
---|
| 29 | public class DataSet {
|
---|
| 30 |
|
---|
| 31 | [Storable]
|
---|
| 32 | private List<ColumnGroup> columnGroups;
|
---|
| 33 | public IEnumerable<ColumnGroup> ColumnGroups {
|
---|
| 34 | get { return this.columnGroups; }
|
---|
| 35 | }
|
---|
[9614] | 36 | [StorableConstructor]
|
---|
| 37 | protected DataSet(bool deserializing) : base() { }
|
---|
[6133] | 38 | public DataSet() {
|
---|
| 39 | this.columnGroups = new List<ColumnGroup>();
|
---|
| 40 | }
|
---|
| 41 |
|
---|
| 42 | public event EventHandler Changed;
|
---|
| 43 | protected virtual void OnChanged() {
|
---|
| 44 | if (this.Changed != null)
|
---|
| 45 | this.Changed(this, EventArgs.Empty);
|
---|
| 46 | }
|
---|
| 47 | public void FireChanged() {
|
---|
| 48 | this.OnChanged();
|
---|
| 49 | }
|
---|
| 50 |
|
---|
| 51 | public void AddColumnGroup(ColumnGroup columnGroup) {
|
---|
| 52 | this.CheckColumnGroupName(columnGroup);
|
---|
| 53 | this.columnGroups.Add(columnGroup);
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | public void AddColumnGroups(IEnumerable<ColumnGroup> columnGroups) {
|
---|
| 57 | foreach (ColumnGroup columnGroup in columnGroups) {
|
---|
| 58 | this.CheckColumnGroupName(columnGroup);
|
---|
| 59 | }
|
---|
| 60 | this.columnGroups.AddRange(columnGroups);
|
---|
| 61 | }
|
---|
| 62 |
|
---|
| 63 | private void CheckColumnGroupName(ColumnGroup columnGroup) {
|
---|
| 64 | int i = 0;
|
---|
| 65 | string columnGroupName = columnGroup.Name;
|
---|
| 66 | while (this.ColumnGroups.Any(cg => cg.Name == columnGroupName && cg != columnGroup)) {
|
---|
| 67 | i++;
|
---|
| 68 | columnGroupName = columnGroup.Name + " " + i;
|
---|
| 69 | }
|
---|
| 70 | columnGroup.Name = columnGroupName;
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 | public void InsertColumnGroup(int position, ColumnGroup columnGroup) {
|
---|
| 74 | this.CheckColumnGroupName(columnGroup);
|
---|
| 75 | this.columnGroups.Insert(position, columnGroup);
|
---|
| 76 | }
|
---|
| 77 |
|
---|
| 78 | public void ReplaceColumnGroup(int position, ColumnGroup columnGroup) {
|
---|
| 79 | this.columnGroups[position] = columnGroup;
|
---|
| 80 | this.CheckColumnGroupName(columnGroup);
|
---|
| 81 | }
|
---|
| 82 |
|
---|
| 83 | public void RemoveColumnGroup(ColumnGroup columnGroup) {
|
---|
| 84 | this.columnGroups.Remove(columnGroup);
|
---|
| 85 | }
|
---|
| 86 |
|
---|
| 87 | public int IndexOfColumnGroup(ColumnGroup columnGroup) {
|
---|
| 88 | return this.columnGroups.IndexOf(columnGroup);
|
---|
| 89 | }
|
---|
| 90 |
|
---|
| 91 | public ColumnGroup GetColumnGroup(string columnGroupName) {
|
---|
| 92 | IEnumerable<ColumnGroup> groups = this.columnGroups.Where(g => g.Name == columnGroupName);
|
---|
| 93 | if (groups.Count() != 1)
|
---|
| 94 | throw new InvalidOperationException("Found 0 or more than 1 column group with the name \"" + columnGroupName + "\".");
|
---|
| 95 | return groups.First();
|
---|
| 96 |
|
---|
| 97 | }
|
---|
| 98 |
|
---|
| 99 | public IEnumerable<ColumnGroup> ActiveColumnGroups {
|
---|
| 100 | get {
|
---|
| 101 | return this.columnGroups.Where(cg => cg.Active);
|
---|
| 102 | }
|
---|
| 103 | }
|
---|
| 104 | }
|
---|
| 105 | }
|
---|