Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Communication.Operators/MessageInjector.cs @ 1000

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

[TICKET #297] communication restructuring

File size: 1.7 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Text;
4using HeuristicLab.Core;
5using HeuristicLab.Data;
6using HeuristicLab.Communication.Data;
7
8namespace HeuristicLab.Communication.Operators {
9  public class MessageInjector : OperatorBase {
10    public override string Description {
11      get {
12        return @"Creates a message template for a communicator to send.";
13      }
14    }
15
16    public MessageInjector()
17      : base() {
18      AddVariableInfo(new VariableInfo("Protocol", "", typeof(Protocol), VariableKind.In));
19      AddVariableInfo(new VariableInfo("PeerName", "", typeof(StringData), VariableKind.In));
20      AddVariableInfo(new VariableInfo("CurrentState", "The current state which to create a message", typeof(ProtocolState), VariableKind.In));
21      AddVariableInfo(new VariableInfo("Message", "The message to inject", typeof(Message), VariableKind.New));
22    }
23
24    public override IOperation Apply(IScope scope) {
25      Protocol protocol = GetVariableValue<Protocol>("Protocol", scope, true);
26      ProtocolState currentState = GetVariableValue<ProtocolState>("CurrentState", scope, true);
27      string iPeer = GetVariableValue<StringData>("PeerName", scope, true).Data;
28      Message message = new Message();
29      message.Protocol = protocol.Name;
30      message.Source = iPeer;
31      message.Destination = "";
32      for (int i = 0; i < currentState.Give.Count; i++)
33        message.Give.Add((IVariable)currentState.Give[i].Clone());
34      for (int i = 0; i < currentState.Expect.Count; i++)
35        message.Expect.Add((IVariable)currentState.Expect[i].Clone());
36
37      scope.AddVariable(new Variable(scope.TranslateName("Message"),message));
38      return null;
39    }
40  }
41}
Note: See TracBrowser for help on using the repository browser.