Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.CEDMA.Core/OperatorLink.cs @ 644

Last change on this file since 644 was 513, checked in by gkronber, 16 years ago

Fixed the problem that sometimes an operator link was not patched before a view was created (which resulted in a NullException) by adding a property for the source database in OperatorLink! and updating this property recursively whenever an operator is loaded from the CEDMA DB.

The method for recursively setting the property is in static class OperatorLinkPatcher because the code is needed in Agent, DatabaseOperatorLibrary and OperatorLink.

(ticket #211)

File size: 3.1 KB
Line 
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
22using System;
23using System.Collections.Generic;
24using System.Linq;
25using System.Text;
26using HeuristicLab.Core;
27using System.Xml;
28using HeuristicLab.CEDMA.DB.Interfaces;
29using HeuristicLab.Operators;
30
31namespace 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}
Note: See TracBrowser for help on using the repository browser.