Free cookie consent management tool by TermsFeed Policy Generator

Changeset 704


Ignore:
Timestamp:
10/29/08 16:01:41 (15 years ago)
Author:
abeham
Message:

[TICKET #297] communication restructuring

Location:
trunk/sources
Files:
9 added
8 deleted
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Communication.Data/HeuristicLab.Communication.Data.csproj

    r584 r704  
    5959  -->
    6060  <ItemGroup>
     61    <Compile Include="Message.cs" />
    6162    <Compile Include="DummyDriverConfiguration.cs" />
    6263    <Compile Include="HeuristicLabCommunicationDataPlugin.cs" />
     
    109110      <DependentUpon>TcpNetworkDriverConfigurationView.cs</DependentUpon>
    110111    </Compile>
     112    <Compile Include="WindowedView.cs">
     113      <SubType>Form</SubType>
     114    </Compile>
     115    <Compile Include="WindowedView.Designer.cs">
     116      <DependentUpon>WindowedView.cs</DependentUpon>
     117    </Compile>
    111118  </ItemGroup>
    112119  <ItemGroup>
     
    134141      <DependentUpon>TcpNetworkDriverConfigurationView.cs</DependentUpon>
    135142      <SubType>Designer</SubType>
     143    </EmbeddedResource>
     144    <EmbeddedResource Include="WindowedView.resx">
     145      <DependentUpon>WindowedView.cs</DependentUpon>
    136146    </EmbeddedResource>
    137147  </ItemGroup>
  • trunk/sources/HeuristicLab.Communication.Data/ProcessData.cs

    r591 r704  
    8888    public void Initialize(IDriverConfiguration configuration) {
    8989      Configuration = configuration;
    90       StartProcess();
    9190    }
    9291
    93     public bool Connect() { 
    94       return true;
     92    public bool Connect() {
     93      StartProcess();
     94      return process != null && !process.HasExited;
    9595    }
    9696
     
    104104      StreamWriter writer = process.StandardInput;
    105105      writer.WriteLine(s);
    106       writer.WriteLine(".");
     106      writer.WriteLine(((char)4).ToString());
    107107    }
    108108
     
    113113      do {
    114114        line = reader.ReadLine();
    115         if (line.Equals(".")) break;
     115        if (line.Equals(((char)4).ToString())) break;
    116116        buffer.AppendLine(line);
    117117      } while (true);
  • trunk/sources/HeuristicLab.Communication.Data/Protocol.cs

    r591 r704  
    3030namespace HeuristicLab.Communication.Data {
    3131  public class Protocol : ItemBase, IEditable {
    32     private StringData name;
    33     public StringData Name {
     32    private string name;
     33    public string Name {
    3434      get { return name; }
    3535      set {
     
    3838      }
    3939    }
    40     private ItemList<ProtocolState> states;
    41     public ItemList<ProtocolState> States {
     40    private IList<ProtocolState> states;
     41    public IList<ProtocolState> States {
    4242      get { return states; }
    4343      set {
    44         states.ItemAdded -= new EventHandler<ItemIndexEventArgs>(States_ItemAdded);
    45         states.ItemRemoved -= new EventHandler<ItemIndexEventArgs>(States_ItemRemoved);
    4644        states = value;
    47         states.ItemAdded += new EventHandler<ItemIndexEventArgs>(States_ItemAdded);
    48         states.ItemRemoved += new EventHandler<ItemIndexEventArgs>(States_ItemRemoved);
    49         // if the newly assigned states don't contain the currently selected initial state
     45        // if the newly assigned states list doesn't contain the currently selected initial state
    5046        if (!states.Contains(initialState))
    5147          if (states.Count > 0)
     
    6561
    6662    public Protocol() {
    67       name = new StringData("Unnamed protocol");
    68       states = new ItemList<ProtocolState>();
    69       states.ItemAdded += new EventHandler<ItemIndexEventArgs>(States_ItemAdded);
    70       states.ItemRemoved += new EventHandler<ItemIndexEventArgs>(States_ItemRemoved);
     63      name = "Unnamed protocol";
     64      states = new List<ProtocolState>();
     65
    7166      ProtocolState firstState = new ProtocolState();
    72       firstState.Name = new StringData("InitialState");
    73       firstState.AcceptingState = new BoolData(true);
    74       firstState.Protocol = this;
     67      firstState.Name = "InitialState";
    7568      states.Add(firstState);
    7669      initialState = firstState;
    77     }
    78 
    79     public void Dispose() {
    80       states.ItemAdded -= new EventHandler<ItemIndexEventArgs>(States_ItemAdded);
    81       states.ItemRemoved -= new EventHandler<ItemIndexEventArgs>(States_ItemRemoved);
    8270    }
    8371
     
    8977    }
    9078
     79    #region clone & persistence
    9180    public override object Clone(IDictionary<Guid, object> clonedObjects) {
    9281      Protocol clone = new Protocol();
    9382      clonedObjects.Add(Guid, clone);
    94       clone.Name = (StringData)Auxiliary.Clone(Name, clonedObjects);
    95       clone.States = (ItemList<ProtocolState>)Auxiliary.Clone(States, clonedObjects);
     83      clone.Name = (string)name.Clone();
     84      clone.States = new List<ProtocolState>(states.Count);
     85      foreach (ProtocolState state in states)
     86        clone.States.Add((ProtocolState)state.Clone(clonedObjects));
    9687      // iterate through the states and select the appropriate state in the clone
    97       for (int i = 0 ; i < states.Count ; i++)
    98         if (states[i].Equals(initialState))
    99           clone.InitialState = clone.States[i];
     88      int index = states.IndexOf(initialState);
     89      if (index >= 0) clone.InitialState = clone.States[index];
    10090      return clone;
    10191    }
    10292
    103     #region States Events
    104     void States_ItemRemoved(object sender, ItemIndexEventArgs e) {
    105       e.Item.Changed -= new EventHandler(State_Changed);
    106       State_Changed(this, new EventArgs());
    107     }
    108 
    109     void States_ItemAdded(object sender, ItemIndexEventArgs e) {
    110       e.Item.Changed += new EventHandler(State_Changed);
    111       ((ProtocolState)e.Item).Protocol = this;
    112       State_Changed(this, new EventArgs());
    113     }
    114     #endregion
    115 
    116     public EventHandler StatesChanged;
    117     void State_Changed(object sender, EventArgs e) {
    118       if (StatesChanged != null) StatesChanged(sender, e);
    119     }
    120 
    121     #region persistence
    12293    public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid,IStorable> persistedObjects) {
    12394      XmlNode node = base.GetXmlNode(name, document, persistedObjects);
    124       XmlNode nameNode = PersistenceManager.Persist("Name", Name, document, persistedObjects);
    125       XmlNode statesNode = PersistenceManager.Persist("States", States, document, persistedObjects);
    126       XmlNode initialStatesNode = PersistenceManager.Persist("InitialState", InitialState, document, persistedObjects);
    127       node.AppendChild(nameNode);
     95     
     96      XmlAttribute nameAttrib = document.CreateAttribute("Name");
     97      nameAttrib.Value = this.name;
     98      node.Attributes.Append(nameAttrib);
     99
     100      XmlNode statesNode = document.CreateNode(XmlNodeType.Element, "States", null);
     101      foreach (ProtocolState state in states) {
     102        XmlNode tmp = state.GetXmlNode("State", document, persistedObjects);
     103        if (state.Equals(initialState)) {
     104          XmlAttribute initialStateAttrib = document.CreateAttribute("InitialState");
     105          initialStateAttrib.Value = "1";
     106          tmp.Attributes.Append(initialStateAttrib);
     107        }
     108        statesNode.AppendChild(tmp);
     109      }
    128110      node.AppendChild(statesNode);
    129       node.AppendChild(initialStatesNode);
     111
    130112      return node;
    131113    }
     
    133115    public override void Populate(XmlNode node, IDictionary<Guid,IStorable> restoredObjects) {
    134116      base.Populate(node, restoredObjects);
    135       name = (StringData)PersistenceManager.Restore(node.SelectSingleNode("Name"), restoredObjects);
    136       states = (ItemList<ProtocolState>)PersistenceManager.Restore(node.SelectSingleNode("States"), restoredObjects);
    137       states.ItemAdded += new EventHandler<ItemIndexEventArgs>(States_ItemAdded);
    138       states.ItemRemoved += new EventHandler<ItemIndexEventArgs>(States_ItemRemoved);
    139       initialState = (ProtocolState)PersistenceManager.Restore(node.SelectSingleNode("InitialState"), restoredObjects);
     117      name = node.Attributes.GetNamedItem("Name").Value;
     118
     119      XmlNode statesNode = node.SelectSingleNode("States");
     120      states = new List<ProtocolState>(statesNode.ChildNodes.Count);
     121      foreach (XmlNode childNode in statesNode.ChildNodes) {
     122        ProtocolState tmp = new ProtocolState();
     123        tmp.Populate(childNode, restoredObjects);
     124        states.Add(tmp);
     125        XmlNode initialStateNode = childNode.Attributes.GetNamedItem("InitialState");
     126        if (initialStateNode != null && initialStateNode.Value.Equals("1")) initialState = tmp;
     127      }
    140128    }
    141     #endregion persistence
     129    #endregion clone & persistence
    142130  }
    143131}
  • trunk/sources/HeuristicLab.Communication.Data/ProtocolEditor.Designer.cs

    r591 r704  
    3636      }
    3737      if (Protocol != null) Protocol.Changed -= new System.EventHandler(Protocol_Changed);
    38       nameViewControl.Dispose();
    39       statesItemListView.Dispose();
    4038      base.Dispose(disposing);
    4139    }
     
    4846    /// </summary>
    4947    private void InitializeComponent() {
    50       HeuristicLab.Data.StringData stringData2 = new HeuristicLab.Data.StringData();
    51       this.nameViewControl = new HeuristicLab.Data.StringDataView();
    5248      this.protocolNameLabel = new System.Windows.Forms.Label();
    53       this.initialStateLabel = new System.Windows.Forms.Label();
    54       this.initialStateComboBox = new System.Windows.Forms.ComboBox();
    5549      this.protocolStatesLabel = new System.Windows.Forms.Label();
    56       this.statesItemListView = new HeuristicLab.Data.ItemListView<ProtocolState>();
    57       this.invertButton = new System.Windows.Forms.Button();
     50      this.statesListBox = new System.Windows.Forms.ListBox();
     51      this.stateChartPictureBox = new System.Windows.Forms.PictureBox();
     52      this.addStateButton = new System.Windows.Forms.Button();
     53      this.removeStateButton = new System.Windows.Forms.Button();
     54      this.nameTextBox = new System.Windows.Forms.TextBox();
     55      this.setAsInitialStateButton = new System.Windows.Forms.Button();
     56      ((System.ComponentModel.ISupportInitialize)(this.stateChartPictureBox)).BeginInit();
    5857      this.SuspendLayout();
    59       //
    60       // nameViewControl
    61       //
    62       this.nameViewControl.Caption = "View (StringData)";
    63       this.nameViewControl.Location = new System.Drawing.Point(89, 3);
    64       this.nameViewControl.Name = "nameViewControl";
    65       this.nameViewControl.Size = new System.Drawing.Size(180, 28);
    66       stringData2.Data = "";
    67       this.nameViewControl.StringData = stringData2;
    68       this.nameViewControl.TabIndex = 1;
    6958      //
    7059      // protocolNameLabel
     
    7766      this.protocolNameLabel.Text = "Protocol Name:";
    7867      //
    79       // initialStateLabel
    80       //
    81       this.initialStateLabel.AutoSize = true;
    82       this.initialStateLabel.Location = new System.Drawing.Point(275, 6);
    83       this.initialStateLabel.Name = "initialStateLabel";
    84       this.initialStateLabel.Size = new System.Drawing.Size(62, 13);
    85       this.initialStateLabel.TabIndex = 5;
    86       this.initialStateLabel.Text = "Initial State:";
    87       //
    88       // initialStateComboBox
    89       //
    90       this.initialStateComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
    91       this.initialStateComboBox.FormattingEnabled = true;
    92       this.initialStateComboBox.Location = new System.Drawing.Point(343, 3);
    93       this.initialStateComboBox.Name = "initialStateComboBox";
    94       this.initialStateComboBox.Size = new System.Drawing.Size(166, 21);
    95       this.initialStateComboBox.TabIndex = 6;
    96       this.initialStateComboBox.SelectedIndexChanged += new System.EventHandler(this.initialStateComboBox_SelectedIndexChanged);
    97       //
    9868      // protocolStatesLabel
    9969      //
     
    10575      this.protocolStatesLabel.Text = "Protocol States:";
    10676      //
    107       // statesItemListView
     77      // statesListBox
    10878      //
    109       this.statesItemListView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     79      this.statesListBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     80                  | System.Windows.Forms.AnchorStyles.Left)));
     81      this.statesListBox.FormattingEnabled = true;
     82      this.statesListBox.Location = new System.Drawing.Point(6, 48);
     83      this.statesListBox.MultiColumn = true;
     84      this.statesListBox.Name = "statesListBox";
     85      this.statesListBox.Size = new System.Drawing.Size(159, 303);
     86      this.statesListBox.TabIndex = 10;
     87      this.statesListBox.SelectedIndexChanged += new System.EventHandler(this.statesListBox_SelectedIndexChanged);
     88      this.statesListBox.DoubleClick += new System.EventHandler(this.statesListBox_DoubleClick);
     89      //
     90      // stateChartPictureBox
     91      //
     92      this.stateChartPictureBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    11093                  | System.Windows.Forms.AnchorStyles.Left)
    11194                  | System.Windows.Forms.AnchorStyles.Right)));
    112       this.statesItemListView.Caption = "View";
    113       this.statesItemListView.ItemList = null;
    114       this.statesItemListView.Location = new System.Drawing.Point(3, 51);
    115       this.statesItemListView.Name = "statesItemListView";
    116       this.statesItemListView.Size = new System.Drawing.Size(613, 308);
    117       this.statesItemListView.TabIndex = 7;
     95      this.stateChartPictureBox.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
     96      this.stateChartPictureBox.Location = new System.Drawing.Point(172, 48);
     97      this.stateChartPictureBox.Name = "stateChartPictureBox";
     98      this.stateChartPictureBox.Size = new System.Drawing.Size(444, 303);
     99      this.stateChartPictureBox.TabIndex = 11;
     100      this.stateChartPictureBox.TabStop = false;
    118101      //
    119       // invertButton
     102      // addStateButton
    120103      //
    121       this.invertButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
    122       this.invertButton.Location = new System.Drawing.Point(3, 363);
    123       this.invertButton.Name = "invertButton";
    124       this.invertButton.Size = new System.Drawing.Size(162, 23);
    125       this.invertButton.TabIndex = 9;
    126       this.invertButton.Text = "Invert Send/Receive";
    127       this.invertButton.UseVisualStyleBackColor = true;
    128       this.invertButton.Click += new System.EventHandler(this.invertButton_Click);
     104      this.addStateButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
     105      this.addStateButton.Location = new System.Drawing.Point(6, 357);
     106      this.addStateButton.Name = "addStateButton";
     107      this.addStateButton.Size = new System.Drawing.Size(77, 23);
     108      this.addStateButton.TabIndex = 12;
     109      this.addStateButton.Text = "Add";
     110      this.addStateButton.UseVisualStyleBackColor = true;
     111      this.addStateButton.Click += new System.EventHandler(this.addStateButton_Click);
     112      //
     113      // removeStateButton
     114      //
     115      this.removeStateButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
     116      this.removeStateButton.Location = new System.Drawing.Point(89, 357);
     117      this.removeStateButton.Name = "removeStateButton";
     118      this.removeStateButton.Size = new System.Drawing.Size(75, 23);
     119      this.removeStateButton.TabIndex = 13;
     120      this.removeStateButton.Text = "Remove";
     121      this.removeStateButton.UseVisualStyleBackColor = true;
     122      this.removeStateButton.Click += new System.EventHandler(this.removeStateButton_Click);
     123      //
     124      // nameTextBox
     125      //
     126      this.nameTextBox.Location = new System.Drawing.Point(89, 3);
     127      this.nameTextBox.Name = "nameTextBox";
     128      this.nameTextBox.Size = new System.Drawing.Size(142, 20);
     129      this.nameTextBox.TabIndex = 14;
     130      //
     131      // setAsInitialStateButton
     132      //
     133      this.setAsInitialStateButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
     134      this.setAsInitialStateButton.Location = new System.Drawing.Point(170, 357);
     135      this.setAsInitialStateButton.Name = "setAsInitialStateButton";
     136      this.setAsInitialStateButton.Size = new System.Drawing.Size(75, 23);
     137      this.setAsInitialStateButton.TabIndex = 15;
     138      this.setAsInitialStateButton.Text = "Set Initital";
     139      this.setAsInitialStateButton.UseVisualStyleBackColor = true;
     140      this.setAsInitialStateButton.Click += new System.EventHandler(this.setAsInitialStateButton_Click);
    129141      //
    130142      // ProtocolEditor
     
    132144      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    133145      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    134       this.Controls.Add(this.invertButton);
     146      this.Controls.Add(this.setAsInitialStateButton);
     147      this.Controls.Add(this.nameTextBox);
     148      this.Controls.Add(this.removeStateButton);
     149      this.Controls.Add(this.addStateButton);
     150      this.Controls.Add(this.stateChartPictureBox);
     151      this.Controls.Add(this.statesListBox);
    135152      this.Controls.Add(this.protocolStatesLabel);
    136       this.Controls.Add(this.statesItemListView);
    137       this.Controls.Add(this.initialStateComboBox);
    138       this.Controls.Add(this.initialStateLabel);
    139153      this.Controls.Add(this.protocolNameLabel);
    140       this.Controls.Add(this.nameViewControl);
    141154      this.Name = "ProtocolEditor";
    142155      this.Size = new System.Drawing.Size(619, 389);
     156      ((System.ComponentModel.ISupportInitialize)(this.stateChartPictureBox)).EndInit();
    143157      this.ResumeLayout(false);
    144158      this.PerformLayout();
     
    148162    #endregion
    149163
    150     private HeuristicLab.Data.StringDataView nameViewControl;
    151164    private System.Windows.Forms.Label protocolNameLabel;
    152     private System.Windows.Forms.Label initialStateLabel;
    153     private System.Windows.Forms.ComboBox initialStateComboBox;
    154165    private System.Windows.Forms.Label protocolStatesLabel;
    155     private HeuristicLab.Data.ItemListView<ProtocolState> statesItemListView;
    156     private System.Windows.Forms.Button invertButton;
     166    private System.Windows.Forms.ListBox statesListBox;
     167    private System.Windows.Forms.PictureBox stateChartPictureBox;
     168    private System.Windows.Forms.Button addStateButton;
     169    private System.Windows.Forms.Button removeStateButton;
     170    private System.Windows.Forms.TextBox nameTextBox;
     171    private System.Windows.Forms.Button setAsInitialStateButton;
    157172  }
    158173}
  • trunk/sources/HeuristicLab.Communication.Data/ProtocolEditor.cs

    r591 r704  
    3939    public ProtocolEditor() {
    4040      InitializeComponent();
     41      statesListBox.DrawMode = DrawMode.OwnerDrawFixed;
     42      statesListBox.DrawItem += new DrawItemEventHandler(statesListBox_DrawItem);
    4143    }
     44
     45    void statesListBox_DrawItem(object sender, DrawItemEventArgs e) {
     46      if (e.Index >= 0) { // during Items.Clear() this method is called with index -1
     47        ListBox lb = (ListBox)sender;
     48        ProtocolState state = (ProtocolState)lb.Items[e.Index];
     49        e.DrawBackground();
     50        e.DrawFocusRectangle();
     51        SolidBrush textColor = new SolidBrush(Color.Black);
     52        if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) textColor.Color = Color.White;
     53        if (Protocol.InitialState.Equals(state))
     54          e.Graphics.DrawString(state.Name, new Font(e.Font.FontFamily, e.Font.Size, FontStyle.Bold), textColor, e.Bounds);
     55        else
     56          e.Graphics.DrawString(state.Name, e.Font, textColor, e.Bounds);
     57      }
     58    }
     59
    4260    public ProtocolEditor(Protocol protocol)
    4361      : this() {
     
    4664
    4765    protected override void RemoveItemEvents() {
     66      nameTextBox.DataBindings.Clear();
    4867      Protocol.Changed -= new EventHandler(Protocol_Changed);
    49       Protocol.StatesChanged -= new EventHandler(States_Changed);
    50       Protocol.Name.Changed -= new EventHandler(ProtocolName_Changed);
    5168      base.RemoveItemEvents();
    5269    }
     
    5471      base.AddItemEvents();
    5572      Protocol.Changed += new EventHandler(Protocol_Changed);
    56       Protocol.StatesChanged += new EventHandler(States_Changed);
    57       Protocol.Name.Changed += new EventHandler(ProtocolName_Changed);
    58     }
    59 
    60     private void BuildInitialStateComboBox() {
    61       // Rebuild the two ComboBoxes depicting the initial and final state
    62       IList<ProtocolState> states = new List<ProtocolState>(Protocol.States.Count);
    63       int initialSelectedIndex = -1;
    64       for (int i = 0 ; i < Protocol.States.Count ; i++) {
    65         states.Add((ProtocolState)Protocol.States[i]);
    66         if (Protocol.States[i].Guid.Equals(Protocol.InitialState.Guid))
    67           initialSelectedIndex = i;
    68       }
    69       initialStateComboBox.SelectedIndexChanged -= new EventHandler(initialStateComboBox_SelectedIndexChanged);
    70       BindingList<ProtocolState> bl = new BindingList<ProtocolState>(states);
    71       initialStateComboBox.DataSource = bl;
    72       initialStateComboBox.DisplayMember = "Name";
    73       initialStateComboBox.ValueMember = "Guid";
    74       initialStateComboBox.SelectedIndex = initialSelectedIndex;
    75       initialStateComboBox.SelectedIndexChanged += new EventHandler(initialStateComboBox_SelectedIndexChanged);
     73      nameTextBox.DataBindings.Add("Text", Protocol, "Name");
    7674    }
    7775
     
    8078      if (Protocol == null) {
    8179        Caption = "Protocol";
    82         nameViewControl.Enabled = false;
    83         nameViewControl.StringData = null;
    84         statesItemListView.Enabled = false;
    85         statesItemListView.ItemList = null;
    86         initialStateComboBox.Enabled = false;
    87         initialStateComboBox.DataSource = null;
    88         initialStateComboBox.Items.Clear();
     80        nameTextBox.Enabled = false;
     81        setAsInitialStateButton.Enabled = false;
     82        addStateButton.Enabled = false;
     83        removeStateButton.Enabled = false;
     84        statesListBox.Enabled = false;
     85
     86        nameTextBox.Text = "";
     87        statesListBox.Items.Clear();
    8988      } else {
    90         Caption = Protocol.Name.Data;
    91         nameViewControl.StringData = Protocol.Name;
    92         nameViewControl.Enabled = true;
    93         statesItemListView.ItemList = Protocol.States;
    94         statesItemListView.Enabled = true;
    95         BuildInitialStateComboBox();
    96         initialStateComboBox.Enabled = true;
     89        Caption = Protocol.Name;
     90
     91        statesListBox.Items.Clear();
     92        foreach (ProtocolState state in Protocol.States)
     93          statesListBox.Items.Add(state);
     94
     95        statesListBox.Enabled = true;
     96        addStateButton.Enabled = true;
     97        removeStateButton.Enabled = true;
     98        setAsInitialStateButton.Enabled = true;
     99        nameTextBox.Enabled = true;
    97100      }
    98101    }
    99102
    100     #region Custom events
    101103    void Protocol_Changed(object sender, EventArgs e) {
    102104      Refresh();
    103105    }
    104106
    105     void States_Changed(object sender, EventArgs e) {
     107    private void addStateButton_Click(object sender, EventArgs e) {
     108      ProtocolState tmp = new ProtocolState();
     109      int index = statesListBox.SelectedIndex;
     110      if (index < 0) {
     111        Protocol.States.Add(tmp);
     112      } else {
     113        Protocol.States.Insert(index, tmp);
     114      }
    106115      Refresh();
     116      statesListBox.SelectedIndex = index;
    107117    }
    108118
    109     void ProtocolName_Changed(object sender, EventArgs e) {
    110       Caption = Protocol.Name.Data;
     119    private void removeStateButton_Click(object sender, EventArgs e) {
     120      if (statesListBox.SelectedIndex >= 0) {
     121        int index = statesListBox.SelectedIndex;
     122        Protocol.States.RemoveAt(statesListBox.SelectedIndex);
     123        Refresh();
     124        if (Protocol.States.Count > 0)
     125          statesListBox.SelectedIndex = ((index < Protocol.States.Count) ? (index) : (Protocol.States.Count - 1));
     126      }
    111127    }
    112     #endregion
    113128
    114     #region ComboBox events
    115     private void initialStateComboBox_SelectedIndexChanged(object sender, EventArgs e) {
    116       if (initialStateComboBox.SelectedIndex >= 0)
    117         Protocol.InitialState = (ProtocolState)initialStateComboBox.SelectedItem;
     129    private void setAsInitialStateButton_Click(object sender, EventArgs e) {
     130      if (statesListBox.SelectedIndex >= 0) {
     131        Protocol.InitialState = (ProtocolState)statesListBox.SelectedItem;
     132        statesListBox.Refresh();
     133      }
    118134    }
    119     #endregion
    120135
    121     private void invertButton_Click(object sender, EventArgs e) {
    122       for (int i = 0 ; i < Protocol.States.Count ; i++) {
    123         ConstrainedItemList tmp = ((ProtocolState)Protocol.States[i]).SendingData;
    124         ((ProtocolState)Protocol.States[i]).SendingData = ((ProtocolState)Protocol.States[i]).ReceivingData;
    125         ((ProtocolState)Protocol.States[i]).ReceivingData = tmp;
     136    private void statesListBox_DoubleClick(object sender, EventArgs e) {
     137      if (lastDeselectedIndex >= 0 || lastSelectedIndex >= 0) {
     138        statesListBox.SelectedIndex = (lastDeselectedIndex >= 0) ? (lastDeselectedIndex) : (lastSelectedIndex);
     139        ProtocolState selected = (ProtocolState)statesListBox.Items[(lastDeselectedIndex >= 0) ? (lastDeselectedIndex) : (lastSelectedIndex)];
     140        bool editingInitial = (Protocol.InitialState == selected);
     141        ProtocolState selectedClone = (ProtocolState)selected.Clone(new Dictionary<Guid, object>());
     142        IView stateView = selectedClone.CreateView();
     143        using (WindowedView display = new WindowedView(stateView as UserControl)) {
     144          display.ShowDialog(this);
     145          if (display.DialogResult == DialogResult.OK) {
     146            Protocol.States[(lastDeselectedIndex >= 0) ? (lastDeselectedIndex) : (lastSelectedIndex)] = selectedClone;
     147            if (editingInitial) Protocol.InitialState = selectedClone;
     148            Refresh();
     149          }
     150        }
    126151      }
    127       Refresh();
     152    }
     153
     154    private int lastSelectedIndex = -1;
     155    private int lastDeselectedIndex = -1;
     156
     157    private void statesListBox_SelectedIndexChanged(object sender, EventArgs e) {
     158      if (statesListBox.SelectedIndex >= 0) {
     159        if (lastSelectedIndex == statesListBox.SelectedIndex) {
     160          lastDeselectedIndex = statesListBox.SelectedIndex;
     161          statesListBox.SelectedIndex = -1;
     162          lastSelectedIndex = -1;
     163        } else {
     164          lastSelectedIndex = statesListBox.SelectedIndex;
     165          lastDeselectedIndex = -1;
     166        }
     167      }
    128168    }
    129169  }
  • trunk/sources/HeuristicLab.Communication.Data/ProtocolState.cs

    r591 r704  
    3030namespace HeuristicLab.Communication.Data {
    3131  public class ProtocolState : ItemBase {
    32     private StringData name;
    33     public StringData Name {
     32    private string name;
     33    public string Name {
    3434      get { return name; }
    3535      set {
    36         name.Changed -= new EventHandler(Name_Changed);
    3736        name = value;
    38         name.Changed += new EventHandler(Name_Changed);
    3937        OnChanged();
    4038      }
    4139    }
    42     private BoolData acceptingState;
    43     public BoolData AcceptingState {
    44       get { return acceptingState; }
     40    private bool giveBatch;
     41    public bool GiveBatch {
     42      get { return giveBatch; }
    4543      set {
    46         acceptingState = value;
     44        giveBatch = value;
    4745        OnChanged();
    4846      }
    4947    }
    50     private ConstrainedItemList sendingData;
    51     public ConstrainedItemList SendingData {
    52       get { return sendingData; }
     48    private ItemList<IVariable> give;
     49    public ItemList<IVariable> Give {
     50      get { return give; }
    5351      set {
    54         sendingData = value;
     52        give = value;
    5553        OnChanged();
    5654      }
    5755    }
    58     private ConstrainedItemList receivingData;
    59     public ConstrainedItemList ReceivingData {
    60       get { return receivingData; }
     56    private bool expectBatch;
     57    public bool ExpectBatch {
     58      get { return expectBatch; }
    6159      set {
    62         receivingData = value;
     60        expectBatch = value;
    6361        OnChanged();
    6462      }
    6563    }
    66     private ItemList<StateTransition> stateTransitions;
    67     public ItemList<StateTransition> StateTransitions {
    68       get { return stateTransitions; }
     64    private ItemList<IVariable> expect;
     65    public ItemList<IVariable> Expect {
     66      get { return expect; }
    6967      set {
    70         stateTransitions = value;
    71         OnChanged();
    72       }
    73     }
    74     private Protocol protocol;
    75     public Protocol Protocol {
    76       get { return protocol; }
    77       set {
    78         protocol = value;
     68        expect = value;
    7969        OnChanged();
    8070      }
     
    8272
    8373    public ProtocolState() {
    84       name = new StringData("Unnamed state");
    85       name.Changed += new EventHandler(Name_Changed);
    86       acceptingState = new BoolData(true);
    87       sendingData = new ConstrainedItemList();
    88       sendingData.AddConstraint(new ItemTypeConstraint(typeof(Variable)));
    89       receivingData = new ConstrainedItemList();
    90       receivingData.AddConstraint(new ItemTypeConstraint(typeof(Variable)));
    91       stateTransitions = null;
    92       protocol = null;
    93     }
    94 
    95     public void Dispose() {
    96       name.Changed -= new EventHandler(Name_Changed);
     74      name = Guid.NewGuid().ToString();
     75      giveBatch = false;
     76      expectBatch = false;
     77      give = new ItemList<IVariable>();
     78      expect = new ItemList<IVariable>();
    9779    }
    9880
     
    10183    }
    10284
     85    #region clone & persistence
    10386    public override object Clone(IDictionary<Guid, object> clonedObjects) {
    10487      ProtocolState clone = new ProtocolState();
    10588      clonedObjects.Add(Guid, clone);
    106       clone.name = (StringData)Auxiliary.Clone(Name, clonedObjects);
    107       clone.acceptingState = (BoolData)Auxiliary.Clone(AcceptingState, clonedObjects);
    108       clone.sendingData = (ConstrainedItemList)Auxiliary.Clone(SendingData, clonedObjects);
    109       clone.receivingData = (ConstrainedItemList)Auxiliary.Clone(ReceivingData, clonedObjects);
    110       if (StateTransitions != null)
    111         clone.stateTransitions = (ItemList<StateTransition>)Auxiliary.Clone(StateTransitions, clonedObjects);
    112       else clone.StateTransitions = null;
    113       clone.protocol = Protocol;
     89
     90      clone.name = (string)name.Clone();
     91      clone.giveBatch = giveBatch;
     92      clone.expectBatch = expectBatch;
     93
     94      clone.give = new ItemList<IVariable>();
     95      for (int i = 0; i < give.Count; i++)
     96        clone.give.Add((IVariable)give[i].Clone());
     97
     98      clone.expect = new ItemList<IVariable>();
     99      for (int i = 0; i < expect.Count; i++)
     100        clone.expect.Add((IVariable)expect[i].Clone());
     101
    114102      return clone;
    115103    }
    116104
    117     #region persistence
     105    // use a simpler serialization for the protocol to make reading it in other programming languages easier
    118106    public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid,IStorable> persistedObjects) {
    119107      XmlNode node = base.GetXmlNode(name, document, persistedObjects);
    120       XmlNode protocolNode = PersistenceManager.Persist("ParentProtocol", Protocol, document, persistedObjects);
    121       node.AppendChild(protocolNode);
    122       XmlNode nameNode = PersistenceManager.Persist("Name", Name, document, persistedObjects);
    123       node.AppendChild(nameNode);
    124       XmlNode acceptingNode = PersistenceManager.Persist("AcceptingState", AcceptingState, document, persistedObjects);
    125       node.AppendChild(acceptingNode);
    126       XmlNode requestNode = PersistenceManager.Persist("Request", SendingData, document, persistedObjects);
    127       node.AppendChild(requestNode);
    128       XmlNode responseNode = PersistenceManager.Persist("Response", ReceivingData, document, persistedObjects);
    129       node.AppendChild(responseNode);
    130       if (StateTransitions != null) {
    131         XmlNode transitionsNode = PersistenceManager.Persist("StateTransitions", StateTransitions, document, persistedObjects);
    132         node.AppendChild(transitionsNode);
     108      XmlAttribute nameAttrib = document.CreateAttribute("Name");
     109      nameAttrib.Value = this.name;
     110      node.Attributes.Append(nameAttrib);
     111      XmlAttribute giveBatchAttrib = document.CreateAttribute("GiveBatch");
     112      giveBatchAttrib.Value = giveBatch.ToString();
     113      node.Attributes.Append(giveBatchAttrib);
     114      XmlAttribute expectBatchAttrib = document.CreateAttribute("ExpectBatch");
     115      expectBatchAttrib.Value = expectBatch.ToString();
     116      node.Attributes.Append(expectBatchAttrib);
     117
     118      XmlNode giveNode = document.CreateNode(XmlNodeType.Element, "Give", null);
     119      foreach (IVariable param in give) {
     120        XmlNode tmp = document.CreateNode(XmlNodeType.Element, "Parameter", null);
     121        XmlAttribute paramNameAttrib = document.CreateAttribute("Name");
     122        paramNameAttrib.Value = param.Name;
     123        tmp.Attributes.Append(paramNameAttrib);
     124        XmlAttribute valueTypeAttrib = document.CreateAttribute("Type");
     125        Type type = param.Value.GetType();
     126        valueTypeAttrib.Value = type.FullName + ", " + type.Assembly.FullName.Substring(0, type.Assembly.FullName.IndexOf(","));
     127        tmp.Attributes.Append(valueTypeAttrib);
     128        giveNode.AppendChild(tmp);
    133129      }
     130      node.AppendChild(giveNode);
     131
     132      XmlNode expectNode = document.CreateNode(XmlNodeType.Element, "Expect", null);
     133      foreach (IVariable param in expect) {
     134        XmlNode tmp = document.CreateNode(XmlNodeType.Element, "Parameter", null);
     135        XmlAttribute paramNameAttrib = document.CreateAttribute("Name");
     136        paramNameAttrib.Value = param.Name;
     137        tmp.Attributes.Append(paramNameAttrib);
     138        XmlAttribute valueTypeAttrib = document.CreateAttribute("Type");
     139        Type type = param.Value.GetType();
     140        valueTypeAttrib.Value = type.FullName + ", " + type.Assembly.FullName.Substring(0, type.Assembly.FullName.IndexOf(","));
     141        tmp.Attributes.Append(valueTypeAttrib);
     142        expectNode.AppendChild(tmp);
     143      }
     144      node.AppendChild(expectNode);
    134145      return node;
    135146    }
    136147
     148    // use a simpler serialization for the protocol to make reading it in other programming languages easier
    137149    public override void Populate(XmlNode node, IDictionary<Guid,IStorable> restoredObjects) {
    138150      base.Populate(node, restoredObjects);
    139       protocol = (Protocol)PersistenceManager.Restore(node.SelectSingleNode("ParentProtocol"), restoredObjects);
    140       name = (StringData)PersistenceManager.Restore(node.SelectSingleNode("Name"), restoredObjects);
    141       acceptingState = (BoolData)PersistenceManager.Restore(node.SelectSingleNode("AcceptingState"), restoredObjects);
    142       sendingData = (ConstrainedItemList)PersistenceManager.Restore(node.SelectSingleNode("Request"), restoredObjects);
    143       receivingData = (ConstrainedItemList)PersistenceManager.Restore(node.SelectSingleNode("Response"), restoredObjects);
    144       XmlNode transitions = node.SelectSingleNode("StateTransitions");
    145       if (transitions != null)
    146         stateTransitions = (ItemList<StateTransition>)PersistenceManager.Restore(transitions, restoredObjects);
    147       else
    148         stateTransitions = null;
     151      name = node.Attributes.GetNamedItem("Name").Value;
     152      bool.TryParse(node.Attributes.GetNamedItem("GiveBatch").Value, out giveBatch);
     153      bool.TryParse(node.Attributes.GetNamedItem("ExpectBatch").Value, out expectBatch);
     154
     155      give = new ItemList<IVariable>();
     156      XmlNodeList giveParams = node.SelectSingleNode("Give").SelectNodes("Parameter");
     157      foreach (XmlNode param in giveParams) {
     158        IItem tmp = (IItem)Activator.CreateInstance(System.Type.GetType(param.Attributes.GetNamedItem("Type").Value));
     159        IVariable var = new Variable(param.Attributes.GetNamedItem("Name").Value, tmp);
     160        give.Add(var);
     161      }
     162
     163      expect = new ItemList<IVariable>();
     164      XmlNodeList expectParams = node.SelectSingleNode("Expect").SelectNodes("Parameter");
     165      foreach (XmlNode param in expectParams) {
     166        IItem tmp = (IItem)Activator.CreateInstance(System.Type.GetType(param.Attributes.GetNamedItem("Type").Value));
     167        IVariable var = new Variable(param.Attributes.GetNamedItem("Name").Value, tmp);
     168        expect.Add(var);
     169      }
    149170    }
    150     #endregion persistence
    151 
    152     private void Name_Changed(object sender, EventArgs e) {
    153       OnChanged();
    154     }
     171    #endregion clone & persistence
    155172
    156173    public override string ToString() {
    157       return Name.ToString();
     174      return name.ToString();
    158175    }
    159176  }
  • trunk/sources/HeuristicLab.Communication.Data/ProtocolStateView.Designer.cs

    r591 r704  
    4545    /// </summary>
    4646    private void InitializeComponent() {
    47       HeuristicLab.Data.StringData stringData1 = new HeuristicLab.Data.StringData();
    48       HeuristicLab.Data.BoolData boolData1 = new HeuristicLab.Data.BoolData();
    49       this.nameStringDataView = new HeuristicLab.Data.StringDataView();
    5047      this.nameLabel = new System.Windows.Forms.Label();
    5148      this.communicationDataTabControl = new System.Windows.Forms.TabControl();
    52       this.sendTabPage = new System.Windows.Forms.TabPage();
    53       this.outboundCommunicationDataView = new HeuristicLab.Data.ConstrainedItemListView();
    54       this.receiveTabPage = new System.Windows.Forms.TabPage();
    55       this.inboundCommunicationDataView = new HeuristicLab.Data.ConstrainedItemListView();
    56       this.transitionTabPage = new System.Windows.Forms.TabPage();
    57       this.removeTransitionButton = new System.Windows.Forms.Button();
    58       this.addTransitionButton = new System.Windows.Forms.Button();
    59       this.stateTransitionTabControl = new System.Windows.Forms.TabControl();
    60       this.acceptingStateLabel = new System.Windows.Forms.Label();
    61       this.acceptingStateBoolDataView = new HeuristicLab.Data.BoolDataView();
     49      this.giveTabPage = new System.Windows.Forms.TabPage();
     50      this.giveBatchCheckBox = new System.Windows.Forms.CheckBox();
     51      this.giveVariablesLabel = new System.Windows.Forms.Label();
     52      this.giveBatchLabel = new System.Windows.Forms.Label();
     53      this.expectTabPage = new System.Windows.Forms.TabPage();
     54      this.expectVariablesLabel = new System.Windows.Forms.Label();
     55      this.expectBatchCheckBox = new System.Windows.Forms.CheckBox();
     56      this.expectBatchLabel = new System.Windows.Forms.Label();
     57      this.nameTextBox = new System.Windows.Forms.TextBox();
     58      this.giveItemListView = new HeuristicLab.Data.ItemListView<HeuristicLab.Core.IVariable>();
     59      this.expectItemListView = new HeuristicLab.Data.ItemListView<HeuristicLab.Core.IVariable>();
    6260      this.communicationDataTabControl.SuspendLayout();
    63       this.sendTabPage.SuspendLayout();
    64       this.receiveTabPage.SuspendLayout();
    65       this.transitionTabPage.SuspendLayout();
     61      this.giveTabPage.SuspendLayout();
     62      this.expectTabPage.SuspendLayout();
    6663      this.SuspendLayout();
    67       //
    68       // nameStringDataView
    69       //
    70       this.nameStringDataView.Caption = "View (StringData)";
    71       this.nameStringDataView.Location = new System.Drawing.Point(48, 14);
    72       this.nameStringDataView.Name = "nameStringDataView";
    73       this.nameStringDataView.Size = new System.Drawing.Size(178, 26);
    74       stringData1.Data = "";
    75       this.nameStringDataView.StringData = stringData1;
    76       this.nameStringDataView.TabIndex = 1;
    7764      //
    7865      // nameLabel
     
    9077                  | System.Windows.Forms.AnchorStyles.Left)
    9178                  | System.Windows.Forms.AnchorStyles.Right)));
    92       this.communicationDataTabControl.Controls.Add(this.sendTabPage);
    93       this.communicationDataTabControl.Controls.Add(this.receiveTabPage);
    94       this.communicationDataTabControl.Controls.Add(this.transitionTabPage);
     79      this.communicationDataTabControl.Controls.Add(this.giveTabPage);
     80      this.communicationDataTabControl.Controls.Add(this.expectTabPage);
    9581      this.communicationDataTabControl.Location = new System.Drawing.Point(3, 46);
    9682      this.communicationDataTabControl.Name = "communicationDataTabControl";
    9783      this.communicationDataTabControl.SelectedIndex = 0;
    98       this.communicationDataTabControl.Size = new System.Drawing.Size(483, 381);
     84      this.communicationDataTabControl.Size = new System.Drawing.Size(404, 324);
    9985      this.communicationDataTabControl.TabIndex = 5;
    10086      //
    101       // sendTabPage
    102       //
    103       this.sendTabPage.Controls.Add(this.outboundCommunicationDataView);
    104       this.sendTabPage.Location = new System.Drawing.Point(4, 22);
    105       this.sendTabPage.Name = "sendTabPage";
    106       this.sendTabPage.Padding = new System.Windows.Forms.Padding(3);
    107       this.sendTabPage.Size = new System.Drawing.Size(475, 355);
    108       this.sendTabPage.TabIndex = 0;
    109       this.sendTabPage.Text = "Send";
    110       this.sendTabPage.UseVisualStyleBackColor = true;
    111       //
    112       // outboundCommunicationDataView
    113       //
    114       this.outboundCommunicationDataView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     87      // giveTabPage
     88      //
     89      this.giveTabPage.Controls.Add(this.giveItemListView);
     90      this.giveTabPage.Controls.Add(this.giveBatchCheckBox);
     91      this.giveTabPage.Controls.Add(this.giveVariablesLabel);
     92      this.giveTabPage.Controls.Add(this.giveBatchLabel);
     93      this.giveTabPage.Location = new System.Drawing.Point(4, 22);
     94      this.giveTabPage.Name = "giveTabPage";
     95      this.giveTabPage.Padding = new System.Windows.Forms.Padding(3);
     96      this.giveTabPage.Size = new System.Drawing.Size(396, 298);
     97      this.giveTabPage.TabIndex = 0;
     98      this.giveTabPage.Text = "Give";
     99      this.giveTabPage.UseVisualStyleBackColor = true;
     100      //
     101      // giveBatchCheckBox
     102      //
     103      this.giveBatchCheckBox.AutoSize = true;
     104      this.giveBatchCheckBox.Location = new System.Drawing.Point(58, 20);
     105      this.giveBatchCheckBox.Name = "giveBatchCheckBox";
     106      this.giveBatchCheckBox.Size = new System.Drawing.Size(15, 14);
     107      this.giveBatchCheckBox.TabIndex = 9;
     108      this.giveBatchCheckBox.UseVisualStyleBackColor = true;
     109      //
     110      // giveVariablesLabel
     111      //
     112      this.giveVariablesLabel.AutoSize = true;
     113      this.giveVariablesLabel.Location = new System.Drawing.Point(13, 48);
     114      this.giveVariablesLabel.Name = "giveVariablesLabel";
     115      this.giveVariablesLabel.Size = new System.Drawing.Size(53, 13);
     116      this.giveVariablesLabel.TabIndex = 8;
     117      this.giveVariablesLabel.Text = "Variables:";
     118      //
     119      // giveBatchLabel
     120      //
     121      this.giveBatchLabel.AutoSize = true;
     122      this.giveBatchLabel.Location = new System.Drawing.Point(13, 20);
     123      this.giveBatchLabel.Name = "giveBatchLabel";
     124      this.giveBatchLabel.Size = new System.Drawing.Size(38, 13);
     125      this.giveBatchLabel.TabIndex = 6;
     126      this.giveBatchLabel.Text = "Batch:";
     127      //
     128      // expectTabPage
     129      //
     130      this.expectTabPage.Controls.Add(this.expectItemListView);
     131      this.expectTabPage.Controls.Add(this.expectVariablesLabel);
     132      this.expectTabPage.Controls.Add(this.expectBatchCheckBox);
     133      this.expectTabPage.Controls.Add(this.expectBatchLabel);
     134      this.expectTabPage.Location = new System.Drawing.Point(4, 22);
     135      this.expectTabPage.Name = "expectTabPage";
     136      this.expectTabPage.Padding = new System.Windows.Forms.Padding(3);
     137      this.expectTabPage.Size = new System.Drawing.Size(396, 298);
     138      this.expectTabPage.TabIndex = 1;
     139      this.expectTabPage.Text = "Expect";
     140      this.expectTabPage.UseVisualStyleBackColor = true;
     141      //
     142      // expectVariablesLabel
     143      //
     144      this.expectVariablesLabel.AutoSize = true;
     145      this.expectVariablesLabel.Location = new System.Drawing.Point(13, 48);
     146      this.expectVariablesLabel.Name = "expectVariablesLabel";
     147      this.expectVariablesLabel.Size = new System.Drawing.Size(53, 13);
     148      this.expectVariablesLabel.TabIndex = 12;
     149      this.expectVariablesLabel.Text = "Variables:";
     150      //
     151      // expectBatchCheckBox
     152      //
     153      this.expectBatchCheckBox.AutoSize = true;
     154      this.expectBatchCheckBox.Location = new System.Drawing.Point(58, 20);
     155      this.expectBatchCheckBox.Name = "expectBatchCheckBox";
     156      this.expectBatchCheckBox.Size = new System.Drawing.Size(15, 14);
     157      this.expectBatchCheckBox.TabIndex = 10;
     158      this.expectBatchCheckBox.UseVisualStyleBackColor = true;
     159      //
     160      // expectBatchLabel
     161      //
     162      this.expectBatchLabel.AutoSize = true;
     163      this.expectBatchLabel.Location = new System.Drawing.Point(13, 20);
     164      this.expectBatchLabel.Name = "expectBatchLabel";
     165      this.expectBatchLabel.Size = new System.Drawing.Size(38, 13);
     166      this.expectBatchLabel.TabIndex = 6;
     167      this.expectBatchLabel.Text = "Batch:";
     168      //
     169      // nameTextBox
     170      //
     171      this.nameTextBox.Location = new System.Drawing.Point(48, 14);
     172      this.nameTextBox.Name = "nameTextBox";
     173      this.nameTextBox.Size = new System.Drawing.Size(137, 20);
     174      this.nameTextBox.TabIndex = 6;
     175      //
     176      // giveItemListView
     177      //
     178      this.giveItemListView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    115179                  | System.Windows.Forms.AnchorStyles.Left)
    116180                  | System.Windows.Forms.AnchorStyles.Right)));
    117       this.outboundCommunicationDataView.Caption = "View";
    118       this.outboundCommunicationDataView.ConstrainedItemList = null;
    119       this.outboundCommunicationDataView.Location = new System.Drawing.Point(6, 6);
    120       this.outboundCommunicationDataView.Name = "outboundCommunicationDataView";
    121       this.outboundCommunicationDataView.Size = new System.Drawing.Size(463, 343);
    122       this.outboundCommunicationDataView.TabIndex = 0;
    123       //
    124       // receiveTabPage
    125       //
    126       this.receiveTabPage.Controls.Add(this.inboundCommunicationDataView);
    127       this.receiveTabPage.Location = new System.Drawing.Point(4, 22);
    128       this.receiveTabPage.Name = "receiveTabPage";
    129       this.receiveTabPage.Padding = new System.Windows.Forms.Padding(3);
    130       this.receiveTabPage.Size = new System.Drawing.Size(475, 355);
    131       this.receiveTabPage.TabIndex = 1;
    132       this.receiveTabPage.Text = "Receive";
    133       this.receiveTabPage.UseVisualStyleBackColor = true;
    134       //
    135       // inboundCommunicationDataView
    136       //
    137       this.inboundCommunicationDataView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     181      this.giveItemListView.Caption = "View";
     182      this.giveItemListView.ItemList = null;
     183      this.giveItemListView.Location = new System.Drawing.Point(16, 64);
     184      this.giveItemListView.Name = "giveItemListView";
     185      this.giveItemListView.Size = new System.Drawing.Size(377, 231);
     186      this.giveItemListView.TabIndex = 10;
     187      //
     188      // expectItemListView
     189      //
     190      this.expectItemListView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    138191                  | System.Windows.Forms.AnchorStyles.Left)
    139192                  | System.Windows.Forms.AnchorStyles.Right)));
    140       this.inboundCommunicationDataView.Caption = "View";
    141       this.inboundCommunicationDataView.ConstrainedItemList = null;
    142       this.inboundCommunicationDataView.Location = new System.Drawing.Point(6, 6);
    143       this.inboundCommunicationDataView.Name = "inboundCommunicationDataView";
    144       this.inboundCommunicationDataView.Size = new System.Drawing.Size(463, 343);
    145       this.inboundCommunicationDataView.TabIndex = 0;
    146       //
    147       // transitionTabPage
    148       //
    149       this.transitionTabPage.Controls.Add(this.removeTransitionButton);
    150       this.transitionTabPage.Controls.Add(this.addTransitionButton);
    151       this.transitionTabPage.Controls.Add(this.stateTransitionTabControl);
    152       this.transitionTabPage.Location = new System.Drawing.Point(4, 22);
    153       this.transitionTabPage.Name = "transitionTabPage";
    154       this.transitionTabPage.Padding = new System.Windows.Forms.Padding(3);
    155       this.transitionTabPage.Size = new System.Drawing.Size(475, 355);
    156       this.transitionTabPage.TabIndex = 2;
    157       this.transitionTabPage.Text = "State Transition";
    158       this.transitionTabPage.UseVisualStyleBackColor = true;
    159       //
    160       // removeTransitionButton
    161       //
    162       this.removeTransitionButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
    163       this.removeTransitionButton.Enabled = false;
    164       this.removeTransitionButton.Location = new System.Drawing.Point(365, 326);
    165       this.removeTransitionButton.Name = "removeTransitionButton";
    166       this.removeTransitionButton.Size = new System.Drawing.Size(104, 23);
    167       this.removeTransitionButton.TabIndex = 2;
    168       this.removeTransitionButton.Text = "Remove Transition";
    169       this.removeTransitionButton.UseVisualStyleBackColor = true;
    170       this.removeTransitionButton.Click += new System.EventHandler(this.removeTransitionButton_Click);
    171       //
    172       // addTransitionButton
    173       //
    174       this.addTransitionButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
    175       this.addTransitionButton.Location = new System.Drawing.Point(6, 326);
    176       this.addTransitionButton.Name = "addTransitionButton";
    177       this.addTransitionButton.Size = new System.Drawing.Size(104, 23);
    178       this.addTransitionButton.TabIndex = 1;
    179       this.addTransitionButton.Text = "Add Transition";
    180       this.addTransitionButton.UseVisualStyleBackColor = true;
    181       this.addTransitionButton.Click += new System.EventHandler(this.addTransitionButton_Click);
    182       //
    183       // stateTransitionTabControl
    184       //
    185       this.stateTransitionTabControl.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    186                   | System.Windows.Forms.AnchorStyles.Left)
    187                   | System.Windows.Forms.AnchorStyles.Right)));
    188       this.stateTransitionTabControl.Location = new System.Drawing.Point(0, 0);
    189       this.stateTransitionTabControl.Name = "stateTransitionTabControl";
    190       this.stateTransitionTabControl.SelectedIndex = 0;
    191       this.stateTransitionTabControl.Size = new System.Drawing.Size(475, 320);
    192       this.stateTransitionTabControl.TabIndex = 0;
    193       //
    194       // acceptingStateLabel
    195       //
    196       this.acceptingStateLabel.AutoSize = true;
    197       this.acceptingStateLabel.Location = new System.Drawing.Point(232, 17);
    198       this.acceptingStateLabel.Name = "acceptingStateLabel";
    199       this.acceptingStateLabel.Size = new System.Drawing.Size(86, 13);
    200       this.acceptingStateLabel.TabIndex = 6;
    201       this.acceptingStateLabel.Text = "Accepting State:";
    202       //
    203       // acceptingStateBoolDataView
    204       //
    205       boolData1.Data = true;
    206       this.acceptingStateBoolDataView.BoolData = boolData1;
    207       this.acceptingStateBoolDataView.Caption = "View";
    208       this.acceptingStateBoolDataView.Enabled = false;
    209       this.acceptingStateBoolDataView.Location = new System.Drawing.Point(324, 17);
    210       this.acceptingStateBoolDataView.Name = "acceptingStateBoolDataView";
    211       this.acceptingStateBoolDataView.Size = new System.Drawing.Size(15, 23);
    212       this.acceptingStateBoolDataView.TabIndex = 7;
     193      this.expectItemListView.Caption = "View";
     194      this.expectItemListView.ItemList = null;
     195      this.expectItemListView.Location = new System.Drawing.Point(16, 64);
     196      this.expectItemListView.Name = "expectItemListView";
     197      this.expectItemListView.Size = new System.Drawing.Size(377, 231);
     198      this.expectItemListView.TabIndex = 13;
    213199      //
    214200      // ProtocolStateView
     
    216202      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    217203      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    218       this.Controls.Add(this.acceptingStateBoolDataView);
    219       this.Controls.Add(this.acceptingStateLabel);
     204      this.Controls.Add(this.nameTextBox);
    220205      this.Controls.Add(this.communicationDataTabControl);
    221206      this.Controls.Add(this.nameLabel);
    222       this.Controls.Add(this.nameStringDataView);
    223207      this.Name = "ProtocolStateView";
    224       this.Size = new System.Drawing.Size(489, 430);
     208      this.Size = new System.Drawing.Size(410, 373);
    225209      this.communicationDataTabControl.ResumeLayout(false);
    226       this.sendTabPage.ResumeLayout(false);
    227       this.receiveTabPage.ResumeLayout(false);
    228       this.transitionTabPage.ResumeLayout(false);
     210      this.giveTabPage.ResumeLayout(false);
     211      this.giveTabPage.PerformLayout();
     212      this.expectTabPage.ResumeLayout(false);
     213      this.expectTabPage.PerformLayout();
    229214      this.ResumeLayout(false);
    230215      this.PerformLayout();
     
    234219    #endregion
    235220
    236     private HeuristicLab.Data.StringDataView nameStringDataView;
    237221    private System.Windows.Forms.Label nameLabel;
    238222    private System.Windows.Forms.TabControl communicationDataTabControl;
    239     private System.Windows.Forms.TabPage sendTabPage;
    240     private System.Windows.Forms.TabPage receiveTabPage;
    241     private HeuristicLab.Data.ConstrainedItemListView outboundCommunicationDataView;
    242     private HeuristicLab.Data.ConstrainedItemListView inboundCommunicationDataView;
    243     private System.Windows.Forms.Label acceptingStateLabel;
    244     private HeuristicLab.Data.BoolDataView acceptingStateBoolDataView;
    245     private System.Windows.Forms.TabPage transitionTabPage;
    246     private System.Windows.Forms.TabControl stateTransitionTabControl;
    247     private System.Windows.Forms.Button addTransitionButton;
    248     private System.Windows.Forms.Button removeTransitionButton;
     223    private System.Windows.Forms.TabPage giveTabPage;
     224    private System.Windows.Forms.TabPage expectTabPage;
     225    private System.Windows.Forms.Label giveBatchLabel;
     226    private System.Windows.Forms.Label expectBatchLabel;
     227    private System.Windows.Forms.CheckBox giveBatchCheckBox;
     228    private System.Windows.Forms.Label giveVariablesLabel;
     229    private System.Windows.Forms.Label expectVariablesLabel;
     230    private System.Windows.Forms.CheckBox expectBatchCheckBox;
     231    private System.Windows.Forms.TextBox nameTextBox;
     232    private HeuristicLab.Data.ItemListView<HeuristicLab.Core.IVariable> giveItemListView;
     233    private HeuristicLab.Data.ItemListView<HeuristicLab.Core.IVariable> expectItemListView;
    249234
    250235  }
  • trunk/sources/HeuristicLab.Communication.Data/ProtocolStateView.cs

    r591 r704  
    4646
    4747    protected override void RemoveItemEvents() {
     48      nameTextBox.DataBindings.Clear();
     49      giveBatchCheckBox.DataBindings.Clear();
     50      expectBatchCheckBox.DataBindings.Clear();
    4851      ProtocolState.Changed -= new EventHandler(ProtocolState_Changed);
    49       ProtocolState.Protocol.StatesChanged -= new EventHandler(States_Changed);
    50       if (ProtocolState.StateTransitions != null) {
    51         for (int i = 0 ; i < ProtocolState.StateTransitions.Count ; i++) {
    52           ProtocolState.StateTransitions[i].Changed -= new EventHandler(StateTransitions_Changed);
    53         }
    54       }
    5552      base.RemoveItemEvents();
    5653    }
     
    5855      base.AddItemEvents();
    5956      ProtocolState.Changed += new EventHandler(ProtocolState_Changed);
    60       ProtocolState.Protocol.StatesChanged += new EventHandler(States_Changed);
    61       if (ProtocolState.StateTransitions != null) {
    62         for (int i = 0 ; i < ProtocolState.StateTransitions.Count ; i++) {
    63           ProtocolState.StateTransitions[i].Changed += new EventHandler(StateTransitions_Changed);
    64         }
    65       }
     57      expectBatchCheckBox.DataBindings.Add("Checked", ProtocolState, "ExpectBatch");
     58      giveBatchCheckBox.DataBindings.Add("Checked", ProtocolState, "GiveBatch");
     59      nameTextBox.DataBindings.Add("Text", ProtocolState, "Name");
    6660    }
    6761
     
    6963      base.UpdateControls();
    7064      if (ProtocolState == null) {
    71         nameStringDataView.Enabled = false;
    72         nameStringDataView.StringData = null;
    73         acceptingStateBoolDataView.Enabled = false;
    74         acceptingStateBoolDataView.BoolData = null;
    75         outboundCommunicationDataView.Enabled = false;
    76         outboundCommunicationDataView.ConstrainedItemList = null;
    77         inboundCommunicationDataView.Enabled = false;
    78         inboundCommunicationDataView.ConstrainedItemList = null;
    79         stateTransitionTabControl.Controls.Clear();
     65        nameTextBox.Enabled = false;
     66        communicationDataTabControl.Enabled = false;
     67        giveItemListView.ItemList = null;
     68        expectItemListView.ItemList = null;
    8069      } else {
    81         nameStringDataView.StringData = ProtocolState.Name;
    82         nameStringDataView.Enabled = true;
    83         acceptingStateBoolDataView.Enabled = true;
    84         acceptingStateBoolDataView.BoolData = ProtocolState.AcceptingState;
    85         outboundCommunicationDataView.ConstrainedItemList = ProtocolState.SendingData;
    86         outboundCommunicationDataView.Enabled = true;
    87         inboundCommunicationDataView.ConstrainedItemList = ProtocolState.ReceivingData;
    88         inboundCommunicationDataView.Enabled = true;
     70        nameTextBox.Text = ProtocolState.Name;
     71        giveBatchCheckBox.Checked = ProtocolState.GiveBatch;
     72        expectBatchCheckBox.Checked = ProtocolState.ExpectBatch;
    8973
    90         addTransitionButton.Enabled = (ProtocolState.Protocol.States.Count > 1);
    91         removeTransitionButton.Enabled = (ProtocolState.StateTransitions != null && ProtocolState.StateTransitions.Count > 0);
     74        giveItemListView.ItemList = ProtocolState.Give;
     75        expectItemListView.ItemList = ProtocolState.Expect;
    9276
    93         stateTransitionTabControl.Controls.Clear();
    94         ItemList<StateTransition> stateTransitions = ProtocolState.StateTransitions;
    95         if (stateTransitions != null) {
    96           for (int i = 0 ; i < stateTransitions.Count ; i++) {
    97             StateTransition stateTransition = (StateTransition)stateTransitions[i];
    98             TabPage newTransitionTabPage = new TabPage((stateTransition.TargetState == null) ? ("no target") : (stateTransition.TargetState.Name.ToString()));
    99             Control stateTransitionView = (Control)stateTransition.CreateView();
    100             stateTransitionTabControl.Controls.Add(newTransitionTabPage);
    101 
    102             newTransitionTabPage.Controls.Add(stateTransitionView);
    103             newTransitionTabPage.Location = new Point(4, 22);
    104             newTransitionTabPage.Padding = new Padding(3);
    105             newTransitionTabPage.Size = stateTransitionTabControl.ClientSize;
    106             newTransitionTabPage.UseVisualStyleBackColor = true;
    107 
    108             stateTransitionView.Location = new Point(0, 0);
    109             stateTransitionView.Size = newTransitionTabPage.ClientSize;
    110             stateTransitionView.Dock = DockStyle.Fill;
    111             stateTransitionView.Anchor = (AnchorStyles)(AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right);
    112           }
    113         }
     77        communicationDataTabControl.Enabled = true;
     78        nameTextBox.Enabled = true;
    11479      }
    11580    }
     
    12186    #endregion
    12287
    123     #region Protocol.States change handling (parent object)
    124     void States_Changed(object sender, EventArgs e) {
    125       for (int i = 0 ; i < stateTransitionTabControl.TabCount ; i++)
    126         stateTransitionTabControl.TabPages[i].Controls[0].Refresh();
    127       addTransitionButton.Enabled = (ProtocolState.Protocol.States.Count > 1);
    128     }
    129     #endregion
    130 
    131     #region StateTransitions change handling (child object)
    132     void StateTransitions_Changed(object sender, EventArgs e) {
    133       for (int i = 0 ; i < stateTransitionTabControl.TabCount ; i++) {
    134         if (((StateTransition)ProtocolState.StateTransitions[i]).TargetState != null)
    135           stateTransitionTabControl.TabPages[i].Text = ((StateTransition)ProtocolState.StateTransitions[i]).TargetState.Name.ToString();
    136       }
    137     }
    138     #endregion
    139 
    140     #region Button events
    141     private void addTransitionButton_Click(object sender, EventArgs e) {
    142       //ProtocolState.AcceptingState = new BoolData(false);
    143       StateTransition stateTransition = new StateTransition();
    144       stateTransition.Changed += new EventHandler(StateTransitions_Changed);
    145       stateTransition.SourceState = ProtocolState;
    146 
    147       if (ProtocolState.StateTransitions == null) {
    148         ItemList<StateTransition> temp = new ItemList<StateTransition>();
    149         temp.Add(stateTransition);
    150         ProtocolState.StateTransitions = temp;
    151       } else {
    152         ProtocolState.StateTransitions.Add(stateTransition);
    153         Refresh();
    154       }
    155       removeTransitionButton.Enabled = true;
    156     }
    157 
    158     private void removeTransitionButton_Click(object sender, EventArgs e) {
    159       if (stateTransitionTabControl.TabCount > 0) {
    160         int selIdx = stateTransitionTabControl.SelectedIndex;
    161         ProtocolState.StateTransitions[selIdx].Changed -= new EventHandler(StateTransitions_Changed);
    162         stateTransitionTabControl.Controls.RemoveAt(selIdx);
    163         ProtocolState.StateTransitions.RemoveAt(selIdx);
    164         if (ProtocolState.StateTransitions.Count == 0) {
    165           //ProtocolState.AcceptingState = new BoolData(true);
    166           ProtocolState.StateTransitions = null;
    167           removeTransitionButton.Enabled = false;
    168         }
    169       }
    170     }
    171     #endregion
    17288  }
    17389}
  • trunk/sources/HeuristicLab.Communication.Data/SocketData.cs

    r591 r704  
    112112
    113113    public void Close() {
     114      tcpOut.Client.Close();
     115      tcpOut.Close();
     116      tcpOut = null;
     117      while (tcpIn.Connected) ;
     118      tcpIn.Client.Close();
     119      tcpIn.Close();
     120      tcpIn = null;
    114121      tcpListener.Stop();
    115       if ((tcpOut != null && tcpOut.Connected) && (tcpIn != null && tcpIn.Connected)) {
    116         Write("CLOSING");
    117         if (Read() != null)
    118           throw new InvalidOperationException("ERROR in SocketData: Out of sync during Close()");
    119       }
    120       if (tcpIn != null) {
    121         tcpIn.Close();
    122         tcpIn = null;
    123       }
    124       if (tcpOut != null) {
    125         tcpOut.Close();
    126         tcpOut = null;
    127       }
    128122      buffer = "";
    129123    }
  • trunk/sources/HeuristicLab.Communication.Data/StateTransitionView.cs

    r591 r704  
    4949    protected override void RemoveItemEvents() {
    5050      StateTransition.Changed -= new EventHandler(StateTransition_Changed);
    51       ConstrainedItemList request = StateTransition.SourceState.SendingData;
    52       ConstrainedItemList response = StateTransition.SourceState.ReceivingData;
    53 
    54       request.Changed -= new EventHandler(VariablesList_Changed);
    55       request.ItemAdded -= new EventHandler<ItemIndexEventArgs>(Parameter_Added);
    56       request.ItemRemoved -= new EventHandler<ItemIndexEventArgs>(Parameter_Removed);
    57       for (int i = 0 ; i < request.Count ; i++)
    58         request[i].Changed -= new EventHandler(Parameter_Changed);
    59       response.Changed -= new EventHandler(VariablesList_Changed);
    60       response.ItemAdded -= new EventHandler<ItemIndexEventArgs>(Parameter_Added);
    61       response.ItemRemoved -= new EventHandler<ItemIndexEventArgs>(Parameter_Removed);
    62       for (int i = 0 ; i < response.Count ; i++)
    63         response[i].Changed -= new EventHandler(Parameter_Changed);
    6451      base.RemoveItemEvents();
    6552    }
     
    6754      base.AddItemEvents();
    6855      StateTransition.Changed += new EventHandler(StateTransition_Changed);
    69       ConstrainedItemList request = StateTransition.SourceState.SendingData;
    70       ConstrainedItemList response = StateTransition.SourceState.ReceivingData;
    71 
    72       request.Changed += new EventHandler(VariablesList_Changed);
    73       request.ItemAdded += new EventHandler<ItemIndexEventArgs>(Parameter_Added);
    74       request.ItemRemoved += new EventHandler<ItemIndexEventArgs>(Parameter_Removed);
    75       for (int i = 0 ; i < request.Count ; i++)
    76         request[i].Changed += new EventHandler(Parameter_Changed);
    77       response.Changed += new EventHandler(VariablesList_Changed);
    78       response.ItemAdded += new EventHandler<ItemIndexEventArgs>(Parameter_Added);
    79       response.ItemRemoved += new EventHandler<ItemIndexEventArgs>(Parameter_Removed);
    80       for (int i = 0 ; i < response.Count ; i++) {
    81         response[i].Changed += new EventHandler(Parameter_Changed);
    82       }
    8356    }
    8457
     
    12194    private void BuildTargetStateComboBox() {
    12295      ComboBox comboBox = targetStateComboBox;
    123       ItemList<ProtocolState> states;
    124       if (StateTransition.SourceState == null || StateTransition.SourceState.Protocol == null)
     96      ItemList<ProtocolState> states = null;
     97      /*if (StateTransition.SourceState == null || StateTransition.SourceState.Protocol == null)
    12598        states = null;
    12699      else
    127         states = StateTransition.SourceState.Protocol.States;
     100        states = StateTransition.SourceState.Protocol.States;*/
    128101      ProtocolState selected = StateTransition.TargetState;
    129102      ProtocolState forbidden = StateTransition.SourceState;
     
    152125    private void BuildVariablesListBox() {
    153126      ListBox variables = variablesListBox;
    154       ConstrainedItemList request = StateTransition.SourceState.SendingData;
    155       ConstrainedItemList response = StateTransition.SourceState.ReceivingData;
     127      /*ConstrainedItemList request = StateTransition.SourceState.SendingData;
     128      ConstrainedItemList response = StateTransition.SourceState.ReceivingData;*/
    156129      variables.Items.Clear();
    157130      variables.Items.Add("==Sending==");
    158       for (int i = 0 ; i < request.Count ; i++) {
     131      /*for (int i = 0 ; i < request.Count ; i++) {
    159132        variables.Items.Add(request[i]);
    160       }
     133      }*/
    161134      variables.Items.Add("==Receiving==");
    162       for (int i = 0 ; i < response.Count ; i++) {
     135      /*for (int i = 0 ; i < response.Count ; i++) {
    163136        variables.Items.Add(response[i]);
    164       }
     137      }*/
    165138    }
    166139
  • trunk/sources/HeuristicLab.Communication.Operators/DataStreamCommunicator.cs

    r591 r704  
    2222using System;
    2323using System.Collections.Generic;
     24using System.IO;
    2425using System.Text;
     26using System.Xml;
    2527using HeuristicLab.Core;
    2628using HeuristicLab.Data;
     
    2830
    2931namespace HeuristicLab.Communication.Operators {
    30   public class DataStreamCommunicator : OperatorBase {
     32  public class DataStreamCommunicator : CommunicatorBase {
    3133    public override string Description {
    3234      get {
    33         return @"TODO";
     35        return @"Sends a message if present and otherwise listens for incoming messages";
    3436      }
    3537    }
    3638
    3739    public DataStreamCommunicator() {
    38       AddVariableInfo(new VariableInfo("CurrentState", "", typeof(ProtocolState), VariableKind.In));
    3940      AddVariableInfo(new VariableInfo("DataStream", "", typeof(IDataStream), VariableKind.In));
    40       AddVariableInfo(new VariableInfo("Message", "", typeof(StringData), VariableKind.New | VariableKind.Deleted));
    4141    }
    4242
    43     public override IOperation Apply(IScope scope) {
    44       ProtocolState currentState = GetVariableValue<ProtocolState>("CurrentState", scope, true);
    45       IDataStream connection = GetVariableValue<IDataStream>("DataStream", scope, true);
    46       IVariableInfo info = GetVariableInfo("Message");
    47       string actualName = "";
    48       if (!info.Local)
    49         actualName = scope.TranslateName(info.FormalName);
     43    private string Encode(Message message) {
     44      XmlDocument document = new XmlDocument();
     45      return message.GetXmlNode("Message", document, new Dictionary<Guid, IStorable>()).ToString();
     46    }
    5047
    51       if (currentState.SendingData.Count > 0) {
    52         string toSend = GetVariableValue<StringData>(info.FormalName, scope, false).Data;
    53         connection.Write(toSend);
    54         if (info.Local) RemoveVariable(info.ActualName);
    55         else scope.RemoveVariable(actualName);
     48    private Message Decode(string m) {
     49      XmlDocument document = new XmlDocument();
     50      document.LoadXml(m);
     51      Message message = new Message();
     52      message.Populate(document.SelectSingleNode("Message"), new Dictionary<Guid, IStorable>());
     53      return message;
     54    }
     55
     56    protected override void Send(IScope scope, Protocol protocol, ProtocolState currentState, Message message) {
     57      IDataStream connection = scope.GetVariableValue<IDataStream>("DataStream", true);
     58      connection.Write("PROTOCOL_ID " + protocol.Name);
     59      if (connection.Read().Equals("ACK")) {
     60        connection.Write("STATE_ID " + currentState.Name);
     61        if (connection.Read().Equals("ACK")) {
     62          connection.Write(Encode(message));
     63        }
    5664      }
     65    }
    5766
    58       if (currentState.ReceivingData.Count > 0) {
    59         string received = connection.Read();
    60         if (info.Local) AddVariable(new Variable(info.ActualName, new StringData(received)));
    61         else scope.AddVariable(new Variable(actualName, new StringData(received)));
     67    protected override Message Receive(IScope scope, Protocol protocol, ProtocolState currentState) {
     68      IDataStream connection = scope.GetVariableValue<IDataStream>("DataStream", true);
     69      Message message = new Message();
     70      string rcvd = connection.Read();
     71      if (rcvd.StartsWith("PROTOCOL_ID ")) {
     72        if (rcvd.Substring(12).Equals(protocol.Name)) {
     73          connection.Write("ACK");
     74          rcvd = connection.Read();
     75          if (rcvd.StartsWith("STATE_ID ")) {
     76            if (rcvd.Substring(9).Equals(currentState.Name)) {
     77              connection.Write("ACK");
     78              message = Decode(connection.Read());
     79              return message;
     80            } else {
     81              connection.Write("SYNCERROR STATE_ID");
     82              return null;
     83            }
     84          } else {
     85            connection.Write("ERROR");
     86            return null;
     87          }
     88        } else {
     89          connection.Write("SYNCERROR PROTOCOL_ID");
     90          return null;
     91        }
     92      } else {
     93        connection.Write("ERROR");
     94        return null;
    6295      }
    63       return null;
    6496    }
    6597  }
  • trunk/sources/HeuristicLab.Communication.Operators/DataStreamFinisher.cs

    r591 r704  
    4242      IDataStream datastream = GetVariableValue<IDataStream>("DataStream", scope, true);
    4343
     44      datastream.Write("REQUEST_CLOSE");
     45      string response = datastream.Read();
     46      if (!response.Equals("REQUEST_CLOSE")) throw new InvalidOperationException("ERROR in DataStreamFinisher: Closing connection was denied");
     47      datastream.Write("ACK");
     48      response = datastream.Read();
     49      if (!response.Equals("ACK")) throw new InvalidOperationException("ERROR in DataStreamFinisher: Closing connection was denied");
    4450      datastream.Close();
    4551
  • trunk/sources/HeuristicLab.Communication.Operators/HeuristicLab.Communication.Operators.csproj

    r584 r704  
    4444  -->
    4545  <ItemGroup>
    46     <Compile Include="CurrentStateConstraintChecker.cs" />
    47     <Compile Include="CurrentStateInitializer.cs" />
    48     <Compile Include="CurrentStateVariableInjector.cs" />
     46    <Compile Include="CommunicatorBase.cs" />
     47    <Compile Include="CurrentStateInitializer.cs">
     48      <SubType>Code</SubType>
     49    </Compile>
    4950    <Compile Include="DataStreamCommunicator.cs" />
    5051    <Compile Include="DataStreamFinisher.cs" />
    5152    <Compile Include="HeuristicLabCommunicationOperatorsPlugin.cs" />
    5253    <Compile Include="LocalProcessInitiator.cs" />
     54    <Compile Include="MessageInjector.cs" />
     55    <Compile Include="MessageProcessor.cs" />
    5356    <Compile Include="Properties\AssemblyInfo.cs" />
    5457    <Compile Include="ProtocolInjector.cs" />
     
    5962      <DependentUpon>ProtocolInjectorView.cs</DependentUpon>
    6063    </Compile>
    61     <Compile Include="SimpleReceiveItemDeserializer.cs" />
    62     <Compile Include="SimpleSendItemSerializer.cs" />
    6364    <Compile Include="StateTransistor.cs" />
    64     <Compile Include="SubscopeCurrentStateLooseDataCollector.cs" />
    65     <Compile Include="SubscopeCurrentStateLooseDataDistributor.cs" />
     65    <Compile Include="SubScopeMessageComposer.cs" />
     66    <Compile Include="SubScopeMessageDecomposer.cs" />
    6667    <Compile Include="TcpNetworkInitiator.cs" />
    67     <Compile Include="XMLConstrainedItemListDeserializer.cs" />
    68     <Compile Include="XMLConstrainedItemListSerializer.cs" />
    6968  </ItemGroup>
    7069  <ItemGroup>
  • trunk/sources/HeuristicLab.Communication.Operators/StateTransistor.cs

    r591 r704  
    4444
    4545    public override IOperation Apply(IScope scope) {
    46       ProtocolState currentState = GetVariableValue<ProtocolState>("CurrentState", scope, true);
     46      /*ProtocolState currentState = GetVariableValue<ProtocolState>("CurrentState", scope, true);
    4747      // Terminate as soon as an accepting state is reached
    4848      if (currentState.AcceptingState.Data) return null;
     
    111111
    112112      sp.AddSubOperator(nextTransistor);
    113       return new AtomicOperation(sp, scope);
     113      return new AtomicOperation(sp, scope);*/
     114      return null;
    114115    }
    115116  }
Note: See TracChangeset for help on using the changeset viewer.