Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Communication.Operators/3.2/SubScopeMessageComposer.cs @ 2273

Last change on this file since 2273 was 1529, checked in by gkronber, 16 years ago

Moved source files of plugins AdvancedOptimizationFrontEnd ... Grid into version-specific sub-folders. #576

File size: 1.4 KB
RevLine 
[704]1using System;
2using System.Collections.Generic;
3using System.Text;
4using HeuristicLab.Core;
5using HeuristicLab.Communication.Data;
6
7namespace HeuristicLab.Communication.Operators {
8  public class SubScopeMessageComposer : OperatorBase {
9    public override string Description {
10      get {
11        return @"Takes a message skeleton and fills it with variables from the subscope";
12      }
13    }
14
15    public SubScopeMessageComposer()
16      : base() {
17      AddVariableInfo(new VariableInfo("Message", "The message to fill", typeof(Message), VariableKind.In | VariableKind.Out));
18    }
19
20    public override IOperation Apply(IScope scope) {
21      Message message = GetVariableValue<Message>("Message", scope, false);
22      foreach (IVariable var in message.Give) {
23        int done = 0;
24        foreach (IScope subscope in scope.SubScopes) {
25          IItem item = subscope.GetVariableValue(var.Name, false, false);
26          if (item != null) {
27            done = 1;
28            if (var.Value.GetType().Equals(item.GetType())) {
29              var.Value = (IItem)item.Clone();
30              done = 2;
31            }
32          }
33        }
34        if (done == 0) throw new InvalidOperationException("ERROR in SubScopeMessageComposer: Parameter not found");
35        if (done == 1) throw new InvalidOperationException("ERROR in SubScopeMessageComposer: Parameter did not have the right type");
36      }
37      return null;
38    }
39  }
40}
Note: See TracBrowser for help on using the repository browser.