1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2008 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 |
|
---|
22 | using System;
|
---|
23 | using System.Collections.Generic;
|
---|
24 | using System.Linq;
|
---|
25 | using System.Text;
|
---|
26 | using HeuristicLab.Core;
|
---|
27 | using System.Xml;
|
---|
28 | using HeuristicLab.CEDMA.DB.Interfaces;
|
---|
29 | using HeuristicLab.Operators;
|
---|
30 |
|
---|
31 | namespace HeuristicLab.CEDMA.Core {
|
---|
32 | public class OperatorLink : OperatorBase {
|
---|
33 | private long id;
|
---|
34 | public long Id {
|
---|
35 | get { return id; }
|
---|
36 | }
|
---|
37 |
|
---|
38 | public IDatabase Database { get; set; }
|
---|
39 |
|
---|
40 | private IOperator myOperator;
|
---|
41 | public IOperator Operator {
|
---|
42 | get { return myOperator; }
|
---|
43 | set { myOperator = value; }
|
---|
44 | }
|
---|
45 |
|
---|
46 | public OperatorLink() : base() { } // for cloning and persistence
|
---|
47 |
|
---|
48 | public OperatorLink(long id, IOperator op)
|
---|
49 | : base() {
|
---|
50 | this.id = id;
|
---|
51 | this.myOperator = op;
|
---|
52 | Name = myOperator.Name;
|
---|
53 | }
|
---|
54 |
|
---|
55 | public override void Abort() {
|
---|
56 | throw new NotSupportedException();
|
---|
57 | }
|
---|
58 |
|
---|
59 | public override IOperation Apply(IScope scope) {
|
---|
60 | throw new NotSupportedException();
|
---|
61 | }
|
---|
62 |
|
---|
63 | public override object Clone(IDictionary<Guid, object> clonedObjects) {
|
---|
64 | OperatorLink clone = (OperatorLink)base.Clone(clonedObjects);
|
---|
65 | clone.id = id;
|
---|
66 | clone.myOperator = Operator;
|
---|
67 | return clone;
|
---|
68 | }
|
---|
69 |
|
---|
70 | public override IView CreateView() {
|
---|
71 | if(Operator == null) {
|
---|
72 | if(Database == null) return null;
|
---|
73 | OperatorEntry targetEntry = Database.GetOperator(Id);
|
---|
74 | IOperator target = (IOperator)PersistenceManager.RestoreFromGZip(targetEntry.RawData);
|
---|
75 | OperatorLinkPatcher.LinkDatabase(target, Database);
|
---|
76 | Operator = target;
|
---|
77 | }
|
---|
78 | return myOperator.CreateView();
|
---|
79 | }
|
---|
80 |
|
---|
81 | public override IOperation Execute(IScope scope) {
|
---|
82 | throw new NotSupportedException();
|
---|
83 | }
|
---|
84 |
|
---|
85 | public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {
|
---|
86 | XmlNode node = base.GetXmlNode(name, document, persistedObjects);
|
---|
87 | XmlAttribute idAttr = document.CreateAttribute("OperatorId");
|
---|
88 | idAttr.Value = id.ToString();
|
---|
89 | node.Attributes.Append(idAttr);
|
---|
90 | return node;
|
---|
91 | }
|
---|
92 |
|
---|
93 | public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) {
|
---|
94 | id = long.Parse(node.Attributes["OperatorId"].Value);
|
---|
95 | base.Populate(node, restoredObjects);
|
---|
96 | }
|
---|
97 | }
|
---|
98 | }
|
---|