Free cookie consent management tool by TermsFeed Policy Generator

source: addons/HeuristicLab.DataImporter/HeuristicLab.DataImporter.DataProcessor/Command/LoadColumnGroupsFromDBCommand.cs @ 16567

Last change on this file since 16567 was 16567, checked in by gkronber, 5 years ago

#2520: changed StorableConstructors and added StorableType attributes in HeuristicLab.DataImporter addon

File size: 2.7 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
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
22using System.Collections.Generic;
23using HeuristicLab.DataImporter.Data.CommandBase;
24using HeuristicLab.DataImporter.Data.Model;
25using HeuristicLab.DataImporter.DbExplorer.Interfaces;
26using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
27using HEAL.Attic;
28
29namespace HeuristicLab.DataImporter.DataProcessor.Command {
30  [StorableType("09770133-379E-4DE3-AC5D-7A3A358B550D")]
31  public class LoadColumnGroupsFromDBCommand : DatabaseCommandBase {
32    [Storable]
33    private List<DbTable> tables;
34
35    private List<ColumnGroup> newColumnGroups;
36
37    [StorableConstructor]
38    protected LoadColumnGroupsFromDBCommand(StorableConstructorFlag _) : base(_) {
39      this.newColumnGroups = new List<ColumnGroup>();
40    }
41
42    public LoadColumnGroupsFromDBCommand(DataSet dataSet, IDbExplorer dbExplorer, IEnumerable<DbTable> tables)
43      : base(dataSet, dbExplorer) {
44      this.tables = new List<DbTable>(tables);
45      this.newColumnGroups = new List<ColumnGroup>();
46    }
47
48    public override string Description {
49      get { return "Load ColumnGroups from database"; }
50    }
51
52    public override void Execute() {
53      base.Execute();
54      if (DbExplorer == null || !DbExplorer.IsConnected)
55        throw new CommandExecutionException("Could not load data because no connection to the database exists", this);
56      ColumnGroup columnGroup;
57      foreach (DbTable table in tables) {
58        columnGroup = DbExplorer.CreateColumnGroup(table);
59        this.DataSet.AddColumnGroup(columnGroup);
60        newColumnGroups.Add(columnGroup);
61      }
62      this.DataSet.FireChanged();
63    }
64
65    public override void UndoExecute() {
66      base.UndoExecute();
67      foreach (ColumnGroup columnGroup in newColumnGroups)
68        this.DataSet.RemoveColumnGroup(columnGroup);
69      newColumnGroups.Clear();
70      this.DataSet.FireChanged();
71    }
72  }
73}
Note: See TracBrowser for help on using the repository browser.