Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Communication.Operators/CurrentStateInitializer.cs @ 584

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

merged communication framework to trunk (ticket #279)

File size: 1.8 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 CurrentStateInitializer : OperatorBase {
10    public override string Description {
11      get { return @"TODO\r\nOperator description still missing ..."; }
12    }
13
14    public CurrentStateInitializer()
15      : base() {
16      AddVariableInfo(new VariableInfo("Protocol", "", typeof(Protocol), VariableKind.In));
17      AddVariableInfo(new VariableInfo("CurrentState", "", typeof(ProtocolState), VariableKind.New | VariableKind.Out));
18    }
19
20    public override IOperation Apply(IScope scope) {
21      Protocol p = GetVariableValue<Protocol>("Protocol", scope, true);
22      ProtocolState currentState = GetVariableValue<ProtocolState>("CurrentState", scope, true, false);
23      IVariableInfo info = GetVariableInfo("CurrentState");
24      string actualName = "";
25      if (!info.Local)
26        actualName = scope.TranslateName(info.FormalName);
27      if (currentState == null) {
28        currentState = p.InitialState;
29        if (info.Local)
30          AddVariable(new Variable(info.ActualName, currentState));
31        else
32          scope.AddVariable(new Variable(actualName, currentState));
33      } else {
34        currentState = p.InitialState;
35        if (info.Local) {
36          if (GetVariable(info.ActualName) == null) AddVariable(new Variable(info.ActualName, currentState));
37          else GetVariable(info.ActualName).Value = currentState;
38        } else {
39          if (scope.GetVariable(actualName) == null) scope.AddVariable(new Variable(actualName, currentState));
40          else scope.GetVariable(actualName).Value = currentState;
41        }
42      }
43      return null;
44    }
45  }
46}
Note: See TracBrowser for help on using the repository browser.