Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Communication.Operators/SubscopeCurrentStateLooseDataCollector.cs @ 591

Last change on this file since 591 was 591, checked in by abeham, 16 years ago

Put the GPL license in the files from the communication framework and simulation optimization project

File size: 2.9 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.Text;
25using System.Xml;
26using HeuristicLab.Core;
27using HeuristicLab.Data;
28using HeuristicLab.Communication.Data;
29
30namespace HeuristicLab.Communication.Operators {
31  public class SubscopeCurrentStateLooseDataCollector : OperatorBase {
32    public override string Description {
33      get {
34        return @"Browses through all subscopes and collects the data defined under ""Send"" in the current state of the protocol";
35      }
36    }
37
38    public SubscopeCurrentStateLooseDataCollector() {
39      AddVariableInfo(new VariableInfo("CurrentState", "The current state in the execution of the protocol", typeof(ProtocolState), VariableKind.In));
40      AddVariableInfo(new VariableInfo("CombinedData", "The combinedData to be sent", typeof(StringData), VariableKind.New));
41    }
42
43    public override IOperation Apply(IScope scope) {
44      ProtocolState currentState = GetVariableValue<ProtocolState>("CurrentState", scope, true);
45
46      if (currentState.SendingData.Count > 0) {
47        XmlDocument document = new XmlDocument();
48        XmlNode root = document.CreateNode(XmlNodeType.Element, "COMBINED_DATA", null);
49        document.AppendChild(root);
50        foreach (IScope subScope in scope.SubScopes) {
51          ConstrainedItemList sendingData = (ConstrainedItemList)currentState.SendingData.Clone();
52          for (int i = 0; i < sendingData.Count; i++) {
53            Variable tmp = (Variable)sendingData[i];
54            tmp.Value = subScope.GetVariableValue(tmp.Name, true);
55          }
56
57          XmlNode node = sendingData.GetXmlNode("DATA", document, new Dictionary<Guid, IStorable>());
58          root.AppendChild(node);
59        }
60
61        IVariableInfo info = GetVariableInfo("CombinedData");
62        if (info.Local) {
63          AddVariable(new Variable(info.ActualName, new StringData(document.OuterXml)));
64        } else {
65          scope.AddVariable(new Variable(scope.TranslateName(info.FormalName), new StringData(document.OuterXml)));
66        }
67      }
68      return null;
69    }
70  }
71}
Note: See TracBrowser for help on using the repository browser.