Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/02/11 04:28:19 (14 years ago)
Author:
swagner
Message:

Worked on OKB (#1174)

Location:
branches/OKB (trunk integration)
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • branches/OKB (trunk integration)/HeuristicLab.Clients.OKB/3.3/Administration/Views/AlgorithmView.Designer.cs

    r5550 r5587  
    3434    /// </summary>
    3535    private void InitializeComponent() {
    36       System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(AlgorithmView));
    3736      this.platformLabel = new System.Windows.Forms.Label();
    3837      this.platformComboBox = new System.Windows.Forms.ComboBox();
     
    4544      this.refreshUsersButton = new System.Windows.Forms.Button();
    4645      this.dataTabPage = new System.Windows.Forms.TabPage();
     46      this.noViewAvailableLabel = new System.Windows.Forms.Label();
     47      this.dataViewHost = new HeuristicLab.MainForm.WindowsForms.ViewHost();
     48      this.saveFileButton = new System.Windows.Forms.Button();
     49      this.openFileButton = new System.Windows.Forms.Button();
     50      this.newDataButton = new System.Windows.Forms.Button();
     51      this.storeDataButton = new System.Windows.Forms.Button();
     52      this.refreshDataButton = new System.Windows.Forms.Button();
    4753      this.dataTypeNameLabel = new System.Windows.Forms.Label();
    4854      this.dataTypeGroupBox = new System.Windows.Forms.GroupBox();
    4955      this.dataTypeTypeNameTextBox = new System.Windows.Forms.TextBox();
    50       this.setDataTypeButton = new System.Windows.Forms.Button();
    5156      this.dataTypeNameTextBox = new System.Windows.Forms.TextBox();
    5257      this.dataTypeTypeNameLabel = new System.Windows.Forms.Label();
     58      this.openFileDialog = new System.Windows.Forms.OpenFileDialog();
     59      this.saveFileDialog = new System.Windows.Forms.SaveFileDialog();
    5360      this.tabControl.SuspendLayout();
    5461      this.usersTabPage.SuspendLayout();
     62      this.dataTabPage.SuspendLayout();
    5563      this.dataTypeGroupBox.SuspendLayout();
    5664      this.SuspendLayout();
     
    153161      // storeUsersButton
    154162      //
    155       this.storeUsersButton.Image = ((System.Drawing.Image)(resources.GetObject("storeUsersButton.Image")));
     163      this.storeUsersButton.Image = HeuristicLab.Common.Resources.VSImageLibrary.PublishToWeb;
    156164      this.storeUsersButton.Location = new System.Drawing.Point(36, 6);
    157165      this.storeUsersButton.Name = "storeUsersButton";
     
    164172      // refreshUsersButton
    165173      //
    166       this.refreshUsersButton.Image = ((System.Drawing.Image)(resources.GetObject("refreshUsersButton.Image")));
     174      this.refreshUsersButton.Image = HeuristicLab.Common.Resources.VSImageLibrary.Refresh;
    167175      this.refreshUsersButton.Location = new System.Drawing.Point(6, 6);
    168176      this.refreshUsersButton.Name = "refreshUsersButton";
     
    175183      // dataTabPage
    176184      //
     185      this.dataTabPage.Controls.Add(this.noViewAvailableLabel);
     186      this.dataTabPage.Controls.Add(this.dataViewHost);
     187      this.dataTabPage.Controls.Add(this.saveFileButton);
     188      this.dataTabPage.Controls.Add(this.openFileButton);
     189      this.dataTabPage.Controls.Add(this.newDataButton);
     190      this.dataTabPage.Controls.Add(this.storeDataButton);
     191      this.dataTabPage.Controls.Add(this.refreshDataButton);
    177192      this.dataTabPage.Location = new System.Drawing.Point(4, 22);
    178193      this.dataTabPage.Name = "dataTabPage";
     
    183198      this.dataTabPage.UseVisualStyleBackColor = true;
    184199      //
     200      // noViewAvailableLabel
     201      //
     202      this.noViewAvailableLabel.Anchor = System.Windows.Forms.AnchorStyles.None;
     203      this.noViewAvailableLabel.AutoSize = true;
     204      this.noViewAvailableLabel.Location = new System.Drawing.Point(265, 84);
     205      this.noViewAvailableLabel.Name = "noViewAvailableLabel";
     206      this.noViewAvailableLabel.Size = new System.Drawing.Size(94, 13);
     207      this.noViewAvailableLabel.TabIndex = 6;
     208      this.noViewAvailableLabel.Text = "No view available.";
     209      //
     210      // dataViewHost
     211      //
     212      this.dataViewHost.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     213                  | System.Windows.Forms.AnchorStyles.Left)
     214                  | System.Windows.Forms.AnchorStyles.Right)));
     215      this.dataViewHost.Caption = "View";
     216      this.dataViewHost.Content = null;
     217      this.dataViewHost.Enabled = false;
     218      this.dataViewHost.Location = new System.Drawing.Point(6, 36);
     219      this.dataViewHost.Name = "dataViewHost";
     220      this.dataViewHost.ReadOnly = false;
     221      this.dataViewHost.Size = new System.Drawing.Size(613, 138);
     222      this.dataViewHost.TabIndex = 5;
     223      this.dataViewHost.ViewsLabelVisible = true;
     224      this.dataViewHost.ViewType = null;
     225      //
     226      // saveFileButton
     227      //
     228      this.saveFileButton.Image = HeuristicLab.Common.Resources.VSImageLibrary.Save;
     229      this.saveFileButton.Location = new System.Drawing.Point(126, 6);
     230      this.saveFileButton.Name = "saveFileButton";
     231      this.saveFileButton.Size = new System.Drawing.Size(24, 24);
     232      this.saveFileButton.TabIndex = 4;
     233      this.toolTip.SetToolTip(this.saveFileButton, "Save Algorithm Data into File");
     234      this.saveFileButton.UseVisualStyleBackColor = true;
     235      this.saveFileButton.Click += new System.EventHandler(this.saveFileButton_Click);
     236      //
     237      // openFileButton
     238      //
     239      this.openFileButton.Image = HeuristicLab.Common.Resources.VSImageLibrary.Open;
     240      this.openFileButton.Location = new System.Drawing.Point(96, 6);
     241      this.openFileButton.Name = "openFileButton";
     242      this.openFileButton.Size = new System.Drawing.Size(24, 24);
     243      this.openFileButton.TabIndex = 3;
     244      this.toolTip.SetToolTip(this.openFileButton, "Load Algorithm Data from File");
     245      this.openFileButton.UseVisualStyleBackColor = true;
     246      this.openFileButton.Click += new System.EventHandler(this.openFileButton_Click);
     247      //
     248      // newDataButton
     249      //
     250      this.newDataButton.Image = HeuristicLab.Common.Resources.VSImageLibrary.NewDocument;
     251      this.newDataButton.Location = new System.Drawing.Point(66, 6);
     252      this.newDataButton.Name = "newDataButton";
     253      this.newDataButton.Size = new System.Drawing.Size(24, 24);
     254      this.newDataButton.TabIndex = 2;
     255      this.toolTip.SetToolTip(this.newDataButton, "Create New Algorithm Data");
     256      this.newDataButton.UseVisualStyleBackColor = true;
     257      this.newDataButton.Click += new System.EventHandler(this.newDataButton_Click);
     258      //
     259      // storeDataButton
     260      //
     261      this.storeDataButton.Image = HeuristicLab.Common.Resources.VSImageLibrary.PublishToWeb;
     262      this.storeDataButton.Location = new System.Drawing.Point(36, 6);
     263      this.storeDataButton.Name = "storeDataButton";
     264      this.storeDataButton.Size = new System.Drawing.Size(24, 24);
     265      this.storeDataButton.TabIndex = 1;
     266      this.toolTip.SetToolTip(this.storeDataButton, "Store Algorithm Data");
     267      this.storeDataButton.UseVisualStyleBackColor = true;
     268      this.storeDataButton.Click += new System.EventHandler(this.storeDataButton_Click);
     269      //
     270      // refreshDataButton
     271      //
     272      this.refreshDataButton.Image = HeuristicLab.Common.Resources.VSImageLibrary.Refresh;
     273      this.refreshDataButton.Location = new System.Drawing.Point(6, 6);
     274      this.refreshDataButton.Name = "refreshDataButton";
     275      this.refreshDataButton.Size = new System.Drawing.Size(24, 24);
     276      this.refreshDataButton.TabIndex = 0;
     277      this.toolTip.SetToolTip(this.refreshDataButton, "Refresh Algorithm Data");
     278      this.refreshDataButton.UseVisualStyleBackColor = true;
     279      this.refreshDataButton.Click += new System.EventHandler(this.refreshDataButton_Click);
     280      //
    185281      // dataTypeNameLabel
    186282      //
     
    197293                  | System.Windows.Forms.AnchorStyles.Right)));
    198294      this.dataTypeGroupBox.Controls.Add(this.dataTypeTypeNameTextBox);
    199       this.dataTypeGroupBox.Controls.Add(this.setDataTypeButton);
    200295      this.dataTypeGroupBox.Controls.Add(this.dataTypeNameTextBox);
    201296      this.dataTypeGroupBox.Controls.Add(this.dataTypeTypeNameLabel);
     
    214309      this.dataTypeTypeNameTextBox.Location = new System.Drawing.Point(90, 45);
    215310      this.dataTypeTypeNameTextBox.Name = "dataTypeTypeNameTextBox";
    216       this.dataTypeTypeNameTextBox.Size = new System.Drawing.Size(507, 20);
     311      this.dataTypeTypeNameTextBox.Size = new System.Drawing.Size(537, 20);
    217312      this.dataTypeTypeNameTextBox.TabIndex = 3;
    218313      this.toolTip.SetToolTip(this.dataTypeTypeNameTextBox, "Machine Readable Data Type Name (e.g. Assembly Qualified Name)");
    219314      this.dataTypeTypeNameTextBox.TextChanged += new System.EventHandler(this.dataTypeTypeNameTextBox_TextChanged);
    220315      //
    221       // setDataTypeButton
    222       //
    223       this.setDataTypeButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
    224       this.setDataTypeButton.Image = ((System.Drawing.Image)(resources.GetObject("setDataTypeButton.Image")));
    225       this.setDataTypeButton.Location = new System.Drawing.Point(603, 29);
    226       this.setDataTypeButton.Name = "setDataTypeButton";
    227       this.setDataTypeButton.Size = new System.Drawing.Size(24, 24);
    228       this.setDataTypeButton.TabIndex = 4;
    229       this.toolTip.SetToolTip(this.setDataTypeButton, "Set Data Type");
    230       this.setDataTypeButton.UseVisualStyleBackColor = true;
    231       this.setDataTypeButton.Click += new System.EventHandler(this.setDataTypeButton_Click);
    232       //
    233316      // dataTypeNameTextBox
    234317      //
     
    237320      this.dataTypeNameTextBox.Location = new System.Drawing.Point(90, 19);
    238321      this.dataTypeNameTextBox.Name = "dataTypeNameTextBox";
    239       this.dataTypeNameTextBox.Size = new System.Drawing.Size(507, 20);
     322      this.dataTypeNameTextBox.Size = new System.Drawing.Size(537, 20);
    240323      this.dataTypeNameTextBox.TabIndex = 1;
    241324      this.toolTip.SetToolTip(this.dataTypeNameTextBox, "Human Readable Data Type Name");
     
    250333      this.dataTypeTypeNameLabel.TabIndex = 2;
    251334      this.dataTypeTypeNameLabel.Text = "&Type Name:";
     335      //
     336      // openFileDialog
     337      //
     338      this.openFileDialog.FileName = "data";
     339      this.openFileDialog.Filter = "All Files (*.*)|*.*";
     340      this.openFileDialog.Title = "Load Algorithm Data";
     341      //
     342      // saveFileDialog
     343      //
     344      this.saveFileDialog.FileName = "data";
     345      this.saveFileDialog.Filter = "All Files (*.*)|*.*";
     346      this.saveFileDialog.Title = "Save Algorithm Data";
    252347      //
    253348      // AlgorithmView
     
    275370      this.tabControl.ResumeLayout(false);
    276371      this.usersTabPage.ResumeLayout(false);
     372      this.dataTabPage.ResumeLayout(false);
     373      this.dataTabPage.PerformLayout();
    277374      this.dataTypeGroupBox.ResumeLayout(false);
    278375      this.dataTypeGroupBox.PerformLayout();
     
    299396    private System.Windows.Forms.TextBox dataTypeNameTextBox;
    300397    private System.Windows.Forms.Label dataTypeTypeNameLabel;
    301     private System.Windows.Forms.Button setDataTypeButton;
     398    private System.Windows.Forms.Button storeDataButton;
     399    private System.Windows.Forms.Button refreshDataButton;
     400    private System.Windows.Forms.Button openFileButton;
     401    private System.Windows.Forms.Button newDataButton;
     402    private System.Windows.Forms.Button saveFileButton;
     403    private System.Windows.Forms.OpenFileDialog openFileDialog;
     404    private System.Windows.Forms.SaveFileDialog saveFileDialog;
     405    private MainForm.WindowsForms.ViewHost dataViewHost;
     406    private System.Windows.Forms.Label noViewAvailableLabel;
    302407
    303408  }
  • branches/OKB (trunk integration)/HeuristicLab.Clients.OKB/3.3/Administration/Views/AlgorithmView.cs

    r5550 r5587  
    2222using System;
    2323using System.Collections.Generic;
     24using System.IO;
    2425using System.Linq;
    2526using System.Windows.Forms;
    2627using HeuristicLab.Clients.OKB.Authentication;
     28using HeuristicLab.Common;
    2729using HeuristicLab.Core.Views;
    2830using HeuristicLab.MainForm;
    2931using HeuristicLab.MainForm.WindowsForms;
    3032using HeuristicLab.Optimization;
     33using HeuristicLab.Persistence.Default.Xml;
     34using HeuristicLab.PluginInfrastructure;
    3135
    3236namespace HeuristicLab.Clients.OKB.Administration {
     
    3741    private List<AlgorithmClass> algorithmClassComboBoxValues;
    3842    private TypeSelectorDialog typeSelectorDialog;
     43    private byte[] data;
    3944
    4045    public new Algorithm Content {
     
    5863      base.OnContentChanged();
    5964
     65      platformComboBox.SelectedValueChanged -= new EventHandler(platformComboBox_SelectedValueChanged);
    6066      platformComboBoxValues = AdministrationClient.Instance.Platforms.ToList();
    6167      platformComboBox.DataSource = platformComboBoxValues;
     68      platformComboBox.SelectedValueChanged += new EventHandler(platformComboBox_SelectedValueChanged);
     69
     70      algorithmClassComboBox.SelectedValueChanged -= new EventHandler(algorithmClassComboBox_SelectedValueChanged);
    6271      algorithmClassComboBoxValues = AdministrationClient.Instance.AlgorithmClasses.ToList();
    6372      algorithmClassComboBox.DataSource = algorithmClassComboBoxValues;
    64 
     73      algorithmClassComboBox.SelectedValueChanged += new EventHandler(algorithmClassComboBox_SelectedValueChanged);
     74
     75      usersListBox.DataSource = null;
     76      data = null;
     77      dataViewHost.Content = null;
    6578      if (Content == null) {
    6679        platformComboBox.SelectedIndex = -1;
     
    7487        dataTypeTypeNameTextBox.Text = Content.DataTypeTypeName;
    7588      }
    76       usersListBox.DataSource = null;
    7789    }
    7890
     
    8597      storeUsersButton.Enabled = (usersListBox.DataSource != null) && !ReadOnly;
    8698      usersListBox.Enabled = (usersListBox.DataSource != null) && !ReadOnly;
     99      refreshDataButton.Enabled = (Content != null) && (Content.Id != 0);
     100      storeDataButton.Enabled = ((data != null) || (dataViewHost.Content != null)) && !ReadOnly;
     101      openFileButton.Enabled = (Content != null) && (Content.Id != 0);
     102      saveFileButton.Enabled = (data != null) || (dataViewHost.Content != null);
     103      noViewAvailableLabel.Visible = dataViewHost.Content == null;
    87104
    88105      bool isHL33Platform = platformComboBox.Text == "HeuristicLab 3.3";
    89       setDataTypeButton.Enabled = isHL33Platform && !ReadOnly;
    90106      dataTypeNameTextBox.ReadOnly = isHL33Platform;
    91107      dataTypeTypeNameTextBox.ReadOnly = isHL33Platform;
    92     }
    93 
     108      newDataButton.Enabled = isHL33Platform && (Content.Id != 0) && !ReadOnly;
     109    }
     110
     111    #region Content Events
    94112    protected override void OnContentPropertyChanged(string propertyName) {
    95113      switch (propertyName) {
     
    112130      }
    113131    }
    114 
     132    #endregion
     133
     134    #region Control Events
    115135    private void platformComboBox_SelectedValueChanged(object sender, System.EventArgs e) {
    116136      if (Content != null) {
     
    126146    }
    127147
    128     private void setDataTypeButton_Click(object sender, EventArgs e) {
     148    private void dataTypeNameTextBox_TextChanged(object sender, EventArgs e) {
     149      if (dataTypeNameTextBox.Text != Content.DataTypeName)
     150        Content.DataTypeName = dataTypeNameTextBox.Text;
     151    }
     152    private void dataTypeTypeNameTextBox_TextChanged(object sender, EventArgs e) {
     153      if (dataTypeTypeNameTextBox.Text != Content.DataTypeTypeName)
     154        Content.DataTypeTypeName = dataTypeTypeNameTextBox.Text;
     155    }
     156
     157    private void refreshUsersButton_Click(object sender, System.EventArgs e) {
     158      try {
     159        List<Guid> ids = AdministrationClient.GetAlgorithmUsers(Content.Id);
     160        if (ids != null) {
     161          if (AuthenticationClient.Instance.Users == null) AuthenticationClient.Instance.Refresh();
     162          List<User> users = AuthenticationClient.Instance.Users.ToList();
     163          usersListBox.DataSource = users;
     164          usersListBox.DisplayMember = "Name";
     165          for (int i = 0; i < users.Count; i++)
     166            usersListBox.SetItemChecked(i, ids.Contains(users[i].Id));
     167          usersListBox.Enabled = !ReadOnly;
     168          storeUsersButton.Enabled = false;
     169        }
     170      }
     171      catch (Exception ex) {
     172        ErrorHandling.ShowErrorDialog(this, "Refresh authorized users and groups failed.", ex);
     173      }
     174    }
     175    private void storeUsersButton_Click(object sender, System.EventArgs e) {
     176      try {
     177        AdministrationClient.UpdateAlgorithmUsers(Content.Id, usersListBox.SelectedItems.Cast<User>().Select(u => u.Id).ToList());
     178        storeUsersButton.Enabled = false;
     179      }
     180      catch (Exception ex) {
     181        ErrorHandling.ShowErrorDialog(this, "Store authorized users and groups failed.", ex);
     182      }
     183    }
     184    private void usersListBox_ItemCheck(object sender, ItemCheckEventArgs e) {
     185      storeUsersButton.Enabled = !ReadOnly;
     186    }
     187
     188    private void refreshDataButton_Click(object sender, EventArgs e) {
     189      CallAsync(
     190        () => {
     191          data = null;
     192          dataViewHost.Content = null;
     193          data = AdministrationClient.GetAlgorithmData(Content.Id);
     194          if (data != null) {
     195            using (MemoryStream stream = new MemoryStream(data)) {
     196              try {
     197                dataViewHost.Content = XmlParser.Deserialize<IContent>(stream);
     198              }
     199              catch (Exception) { }
     200              stream.Close();
     201            }
     202          }
     203        },
     204        "Refresh algorithm data failed.",
     205        () => SetEnabledStateOfControls()
     206      );
     207    }
     208    private void storeDataButton_Click(object sender, EventArgs e) {
     209      CallAsync(
     210        () => {
     211          if (dataViewHost.Content != null) {
     212            using (MemoryStream stream = new MemoryStream()) {
     213              IAlgorithm algorithm = dataViewHost.Content as IAlgorithm;
     214              algorithm.Prepare(true);
     215              XmlGenerator.Serialize(algorithm, stream);
     216              stream.Close();
     217              data = stream.ToArray();
     218            }
     219          }
     220          AdministrationClient.UpdateAlgorithmData(Content.Id, data);
     221        },
     222        "Store algorithm data failed.",
     223        null
     224      );
     225    }
     226    private void newDataButton_Click(object sender, EventArgs e) {
    129227      if (typeSelectorDialog == null) {
    130228        typeSelectorDialog = new TypeSelectorDialog();
     
    134232      }
    135233      if (typeSelectorDialog.ShowDialog(this) == DialogResult.OK) {
    136         Content.DataTypeName = typeSelectorDialog.TypeSelector.SelectedType.Name;
    137         Content.DataTypeTypeName = typeSelectorDialog.TypeSelector.SelectedType.AssemblyQualifiedName;
    138       }
    139     }
    140     private void dataTypeNameTextBox_TextChanged(object sender, EventArgs e) {
    141       if (dataTypeNameTextBox.Text != Content.DataTypeName)
    142         Content.DataTypeName = dataTypeNameTextBox.Text;
    143     }
    144     private void dataTypeTypeNameTextBox_TextChanged(object sender, EventArgs e) {
    145       if (dataTypeTypeNameTextBox.Text != Content.DataTypeTypeName)
    146         Content.DataTypeTypeName = dataTypeTypeNameTextBox.Text;
    147     }
    148 
    149     private void refreshUsersButton_Click(object sender, System.EventArgs e) {
    150       List<Guid> ids = AdministrationClient.GetAlgorithmUsers(Content.Id);
    151       if (ids != null) {
    152         if (AuthenticationClient.Instance.Users == null) AuthenticationClient.Instance.Refresh();
    153         List<User> users = AuthenticationClient.Instance.Users.ToList();
    154         usersListBox.DataSource = users;
    155         usersListBox.DisplayMember = "Name";
    156         for (int i = 0; i < users.Count; i++)
    157           usersListBox.SetItemChecked(i, ids.Contains(users[i].Id));
    158         usersListBox.Enabled = !ReadOnly;
    159         storeUsersButton.Enabled = false;
    160       }
    161     }
    162     private void storeUsersButton_Click(object sender, System.EventArgs e) {
    163       AdministrationClient.UpdateAlgorithmUsers(Content.Id, usersListBox.SelectedItems.Cast<User>().Select(u => u.Id).ToList());
    164       storeUsersButton.Enabled = false;
    165     }
    166     private void usersListBox_ItemCheck(object sender, ItemCheckEventArgs e) {
    167       storeUsersButton.Enabled = !ReadOnly;
    168     }
     234        try {
     235          Content.DataTypeName = typeSelectorDialog.TypeSelector.SelectedType.Name;
     236          Content.DataTypeTypeName = typeSelectorDialog.TypeSelector.SelectedType.AssemblyQualifiedName;
     237          data = null;
     238          dataViewHost.Content = (IContent)typeSelectorDialog.TypeSelector.CreateInstanceOfSelectedType();
     239        }
     240        catch (Exception ex) {
     241          ErrorHandling.ShowErrorDialog(this, "Create new algorithm data failed.", ex);
     242        }
     243        SetEnabledStateOfControls();
     244      }
     245    }
     246    private void openFileButton_Click(object sender, EventArgs e) {
     247      if (openFileDialog.ShowDialog(this) == DialogResult.OK) {
     248        CallAsync(
     249          () => {
     250            IContent algorithm = null;
     251            try {
     252              algorithm = XmlParser.Deserialize<IContent>(openFileDialog.FileName);
     253            }
     254            catch (Exception) { }
     255
     256            if (algorithm != null) {
     257              Content.DataTypeName = algorithm.GetType().Name;
     258              Content.DataTypeTypeName = algorithm.GetType().AssemblyQualifiedName;
     259              data = null;
     260            } else {
     261              using (FileStream stream = new FileStream(openFileDialog.FileName, FileMode.Open, FileAccess.Read)) {
     262                data = new byte[stream.Length];
     263                stream.Read(data, 0, data.Length);
     264                stream.Close();
     265              }
     266            }
     267            dataViewHost.Content = algorithm;
     268          },
     269          "Save algorithm data into file failed.",
     270          () => SetEnabledStateOfControls()
     271        );
     272      }
     273    }
     274    private void saveFileButton_Click(object sender, EventArgs e) {
     275      if (saveFileDialog.ShowDialog(this) == DialogResult.OK) {
     276        CallAsync(
     277          () => {
     278            if (dataViewHost.Content != null) {
     279              XmlGenerator.Serialize(dataViewHost.Content, saveFileDialog.FileName);
     280            } else {
     281              using (FileStream stream = new FileStream(saveFileDialog.FileName, FileMode.Create, FileAccess.Write)) {
     282                stream.Write(data, 0, data.Length);
     283                stream.Close();
     284              }
     285            }
     286          },
     287          "Save algorithm data into file failed.",
     288          null
     289        );
     290      }
     291    }
     292    #endregion
     293
     294    #region Helpers
     295    private void CallAsync(Action call, string errorMessage, Action continueWith) {
     296      BeginAsyncCall();
     297      call.BeginInvoke(delegate(IAsyncResult result) {
     298        Exception exception = null;
     299        try {
     300          call.EndInvoke(result);
     301        }
     302        catch (Exception ex) {
     303          exception = ex;
     304        }
     305        EndAsyncCall(errorMessage, exception, continueWith);
     306      }, null);
     307    }
     308    private void BeginAsyncCall() {
     309      if (InvokeRequired)
     310        Invoke(new Action(BeginAsyncCall));
     311      else {
     312        Cursor = Cursors.AppStarting;
     313        Enabled = false;
     314      }
     315    }
     316    private void EndAsyncCall(string errorMessage, Exception exception, Action continueWith) {
     317      if (InvokeRequired)
     318        Invoke(new Action<string, Exception, Action>(EndAsyncCall), errorMessage, exception, continueWith);
     319      else {
     320        Cursor = Cursors.Default;
     321        Enabled = true;
     322        if (exception != null) ErrorHandling.ShowErrorDialog(this, errorMessage, exception);
     323        if (continueWith != null) continueWith();
     324      }
     325    }
     326    #endregion
    169327  }
    170328}
  • branches/OKB (trunk integration)/HeuristicLab.Clients.OKB/3.3/Administration/Views/ProblemView.Designer.cs

    r5534 r5587  
    2727    private System.ComponentModel.IContainer components = null;
    2828
    29     /// <summary>
    30     /// Clean up any resources being used.
    31     /// </summary>
    32     /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
    33     protected override void Dispose(bool disposing) {
    34       if (disposing) {
    35         if (components != null) components.Dispose();
    36       }
    37       base.Dispose(disposing);
    38     }
    39 
    4029    #region Component Designer generated code
    4130
     
    5140      this.tabControl = new System.Windows.Forms.TabControl();
    5241      this.usersTabPage = new System.Windows.Forms.TabPage();
     42      this.usersListBox = new System.Windows.Forms.CheckedListBox();
    5343      this.storeUsersButton = new System.Windows.Forms.Button();
    5444      this.refreshUsersButton = new System.Windows.Forms.Button();
    5545      this.dataTabPage = new System.Windows.Forms.TabPage();
    56       this.usersListBox = new System.Windows.Forms.CheckedListBox();
     46      this.noViewAvailableLabel = new System.Windows.Forms.Label();
     47      this.dataViewHost = new HeuristicLab.MainForm.WindowsForms.ViewHost();
     48      this.saveFileButton = new System.Windows.Forms.Button();
     49      this.openFileButton = new System.Windows.Forms.Button();
     50      this.newDataButton = new System.Windows.Forms.Button();
     51      this.storeDataButton = new System.Windows.Forms.Button();
     52      this.refreshDataButton = new System.Windows.Forms.Button();
     53      this.dataTypeNameLabel = new System.Windows.Forms.Label();
     54      this.dataTypeGroupBox = new System.Windows.Forms.GroupBox();
     55      this.dataTypeTypeNameTextBox = new System.Windows.Forms.TextBox();
     56      this.dataTypeNameTextBox = new System.Windows.Forms.TextBox();
     57      this.dataTypeTypeNameLabel = new System.Windows.Forms.Label();
     58      this.openFileDialog = new System.Windows.Forms.OpenFileDialog();
     59      this.saveFileDialog = new System.Windows.Forms.SaveFileDialog();
    5760      this.tabControl.SuspendLayout();
    5861      this.usersTabPage.SuspendLayout();
     62      this.dataTabPage.SuspendLayout();
     63      this.dataTypeGroupBox.SuspendLayout();
    5964      this.SuspendLayout();
    6065      //
     
    99104      this.problemClassLabel.Location = new System.Drawing.Point(3, 111);
    100105      this.problemClassLabel.Name = "problemClassLabel";
    101       this.problemClassLabel.Size = new System.Drawing.Size(76, 13);
     106      this.problemClassLabel.Size = new System.Drawing.Size(81, 13);
    102107      this.problemClassLabel.TabIndex = 7;
    103108      this.problemClassLabel.Text = "&Problem Class:";
     
    122127      this.tabControl.Controls.Add(this.usersTabPage);
    123128      this.tabControl.Controls.Add(this.dataTabPage);
    124       this.tabControl.Location = new System.Drawing.Point(0, 162);
     129      this.tabControl.Location = new System.Drawing.Point(0, 239);
    125130      this.tabControl.Name = "tabControl";
    126131      this.tabControl.SelectedIndex = 0;
    127       this.tabControl.Size = new System.Drawing.Size(633, 283);
    128       this.tabControl.TabIndex = 9;
     132      this.tabControl.Size = new System.Drawing.Size(633, 206);
     133      this.tabControl.TabIndex = 10;
    129134      //
    130135      // usersTabPage
     
    136141      this.usersTabPage.Name = "usersTabPage";
    137142      this.usersTabPage.Padding = new System.Windows.Forms.Padding(3);
    138       this.usersTabPage.Size = new System.Drawing.Size(625, 257);
     143      this.usersTabPage.Size = new System.Drawing.Size(625, 180);
    139144      this.usersTabPage.TabIndex = 0;
    140       this.usersTabPage.Text = "Authorized Users";
     145      this.usersTabPage.Text = "Authorized Users and Groups";
    141146      this.usersTabPage.UseVisualStyleBackColor = true;
     147      //
     148      // usersListBox
     149      //
     150      this.usersListBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     151                  | System.Windows.Forms.AnchorStyles.Left)
     152                  | System.Windows.Forms.AnchorStyles.Right)));
     153      this.usersListBox.CheckOnClick = true;
     154      this.usersListBox.FormattingEnabled = true;
     155      this.usersListBox.Location = new System.Drawing.Point(6, 35);
     156      this.usersListBox.Name = "usersListBox";
     157      this.usersListBox.Size = new System.Drawing.Size(613, 139);
     158      this.usersListBox.TabIndex = 2;
     159      this.usersListBox.ItemCheck += new System.Windows.Forms.ItemCheckEventHandler(this.usersListBox_ItemCheck);
    142160      //
    143161      // storeUsersButton
     
    165183      // dataTabPage
    166184      //
     185      this.dataTabPage.Controls.Add(this.noViewAvailableLabel);
     186      this.dataTabPage.Controls.Add(this.dataViewHost);
     187      this.dataTabPage.Controls.Add(this.saveFileButton);
     188      this.dataTabPage.Controls.Add(this.openFileButton);
     189      this.dataTabPage.Controls.Add(this.newDataButton);
     190      this.dataTabPage.Controls.Add(this.storeDataButton);
     191      this.dataTabPage.Controls.Add(this.refreshDataButton);
    167192      this.dataTabPage.Location = new System.Drawing.Point(4, 22);
    168193      this.dataTabPage.Name = "dataTabPage";
    169194      this.dataTabPage.Padding = new System.Windows.Forms.Padding(3);
    170       this.dataTabPage.Size = new System.Drawing.Size(625, 266);
     195      this.dataTabPage.Size = new System.Drawing.Size(625, 180);
    171196      this.dataTabPage.TabIndex = 1;
    172197      this.dataTabPage.Text = "Platform-Specific Problem Data";
    173198      this.dataTabPage.UseVisualStyleBackColor = true;
    174199      //
    175       // usersListBox
    176       //
    177       this.usersListBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     200      // noViewAvailableLabel
     201      //
     202      this.noViewAvailableLabel.Anchor = System.Windows.Forms.AnchorStyles.None;
     203      this.noViewAvailableLabel.AutoSize = true;
     204      this.noViewAvailableLabel.Location = new System.Drawing.Point(265, 84);
     205      this.noViewAvailableLabel.Name = "noViewAvailableLabel";
     206      this.noViewAvailableLabel.Size = new System.Drawing.Size(94, 13);
     207      this.noViewAvailableLabel.TabIndex = 6;
     208      this.noViewAvailableLabel.Text = "No view available.";
     209      //
     210      // dataViewHost
     211      //
     212      this.dataViewHost.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    178213                  | System.Windows.Forms.AnchorStyles.Left)
    179214                  | System.Windows.Forms.AnchorStyles.Right)));
    180       this.usersListBox.FormattingEnabled = true;
    181       this.usersListBox.Location = new System.Drawing.Point(6, 36);
    182       this.usersListBox.Name = "usersListBox";
    183       this.usersListBox.Size = new System.Drawing.Size(613, 214);
    184       this.usersListBox.TabIndex = 3;
     215      this.dataViewHost.Caption = "View";
     216      this.dataViewHost.Content = null;
     217      this.dataViewHost.Enabled = false;
     218      this.dataViewHost.Location = new System.Drawing.Point(6, 36);
     219      this.dataViewHost.Name = "dataViewHost";
     220      this.dataViewHost.ReadOnly = false;
     221      this.dataViewHost.Size = new System.Drawing.Size(613, 138);
     222      this.dataViewHost.TabIndex = 5;
     223      this.dataViewHost.ViewsLabelVisible = true;
     224      this.dataViewHost.ViewType = null;
     225      //
     226      // saveFileButton
     227      //
     228      this.saveFileButton.Image = HeuristicLab.Common.Resources.VSImageLibrary.Save;
     229      this.saveFileButton.Location = new System.Drawing.Point(126, 6);
     230      this.saveFileButton.Name = "saveFileButton";
     231      this.saveFileButton.Size = new System.Drawing.Size(24, 24);
     232      this.saveFileButton.TabIndex = 4;
     233      this.toolTip.SetToolTip(this.saveFileButton, "Save Problem Data into File");
     234      this.saveFileButton.UseVisualStyleBackColor = true;
     235      this.saveFileButton.Click += new System.EventHandler(this.saveFileButton_Click);
     236      //
     237      // openFileButton
     238      //
     239      this.openFileButton.Image = HeuristicLab.Common.Resources.VSImageLibrary.Open;
     240      this.openFileButton.Location = new System.Drawing.Point(96, 6);
     241      this.openFileButton.Name = "openFileButton";
     242      this.openFileButton.Size = new System.Drawing.Size(24, 24);
     243      this.openFileButton.TabIndex = 3;
     244      this.toolTip.SetToolTip(this.openFileButton, "Load Problem Data from File");
     245      this.openFileButton.UseVisualStyleBackColor = true;
     246      this.openFileButton.Click += new System.EventHandler(this.openFileButton_Click);
     247      //
     248      // newDataButton
     249      //
     250      this.newDataButton.Image = HeuristicLab.Common.Resources.VSImageLibrary.NewDocument;
     251      this.newDataButton.Location = new System.Drawing.Point(66, 6);
     252      this.newDataButton.Name = "newDataButton";
     253      this.newDataButton.Size = new System.Drawing.Size(24, 24);
     254      this.newDataButton.TabIndex = 2;
     255      this.toolTip.SetToolTip(this.newDataButton, "Create New Problem Data");
     256      this.newDataButton.UseVisualStyleBackColor = true;
     257      this.newDataButton.Click += new System.EventHandler(this.newDataButton_Click);
     258      //
     259      // storeDataButton
     260      //
     261      this.storeDataButton.Image = HeuristicLab.Common.Resources.VSImageLibrary.PublishToWeb;
     262      this.storeDataButton.Location = new System.Drawing.Point(36, 6);
     263      this.storeDataButton.Name = "storeDataButton";
     264      this.storeDataButton.Size = new System.Drawing.Size(24, 24);
     265      this.storeDataButton.TabIndex = 1;
     266      this.toolTip.SetToolTip(this.storeDataButton, "Store Problem Data");
     267      this.storeDataButton.UseVisualStyleBackColor = true;
     268      this.storeDataButton.Click += new System.EventHandler(this.storeDataButton_Click);
     269      //
     270      // refreshDataButton
     271      //
     272      this.refreshDataButton.Image = HeuristicLab.Common.Resources.VSImageLibrary.Refresh;
     273      this.refreshDataButton.Location = new System.Drawing.Point(6, 6);
     274      this.refreshDataButton.Name = "refreshDataButton";
     275      this.refreshDataButton.Size = new System.Drawing.Size(24, 24);
     276      this.refreshDataButton.TabIndex = 0;
     277      this.toolTip.SetToolTip(this.refreshDataButton, "Refresh Problem Data");
     278      this.refreshDataButton.UseVisualStyleBackColor = true;
     279      this.refreshDataButton.Click += new System.EventHandler(this.refreshDataButton_Click);
     280      //
     281      // dataTypeNameLabel
     282      //
     283      this.dataTypeNameLabel.AutoSize = true;
     284      this.dataTypeNameLabel.Location = new System.Drawing.Point(6, 22);
     285      this.dataTypeNameLabel.Name = "dataTypeNameLabel";
     286      this.dataTypeNameLabel.Size = new System.Drawing.Size(38, 13);
     287      this.dataTypeNameLabel.TabIndex = 0;
     288      this.dataTypeNameLabel.Text = "&Name:";
     289      //
     290      // dataTypeGroupBox
     291      //
     292      this.dataTypeGroupBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
     293                  | System.Windows.Forms.AnchorStyles.Right)));
     294      this.dataTypeGroupBox.Controls.Add(this.dataTypeTypeNameTextBox);
     295      this.dataTypeGroupBox.Controls.Add(this.dataTypeNameTextBox);
     296      this.dataTypeGroupBox.Controls.Add(this.dataTypeTypeNameLabel);
     297      this.dataTypeGroupBox.Controls.Add(this.dataTypeNameLabel);
     298      this.dataTypeGroupBox.Location = new System.Drawing.Point(0, 146);
     299      this.dataTypeGroupBox.Name = "dataTypeGroupBox";
     300      this.dataTypeGroupBox.Size = new System.Drawing.Size(633, 77);
     301      this.dataTypeGroupBox.TabIndex = 9;
     302      this.dataTypeGroupBox.TabStop = false;
     303      this.dataTypeGroupBox.Text = "Data Type";
     304      //
     305      // dataTypeTypeNameTextBox
     306      //
     307      this.dataTypeTypeNameTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
     308                  | System.Windows.Forms.AnchorStyles.Right)));
     309      this.dataTypeTypeNameTextBox.Location = new System.Drawing.Point(90, 45);
     310      this.dataTypeTypeNameTextBox.Name = "dataTypeTypeNameTextBox";
     311      this.dataTypeTypeNameTextBox.Size = new System.Drawing.Size(537, 20);
     312      this.dataTypeTypeNameTextBox.TabIndex = 3;
     313      this.toolTip.SetToolTip(this.dataTypeTypeNameTextBox, "Machine Readable Data Type Name (e.g. Assembly Qualified Name)");
     314      this.dataTypeTypeNameTextBox.TextChanged += new System.EventHandler(this.dataTypeTypeNameTextBox_TextChanged);
     315      //
     316      // dataTypeNameTextBox
     317      //
     318      this.dataTypeNameTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
     319                  | System.Windows.Forms.AnchorStyles.Right)));
     320      this.dataTypeNameTextBox.Location = new System.Drawing.Point(90, 19);
     321      this.dataTypeNameTextBox.Name = "dataTypeNameTextBox";
     322      this.dataTypeNameTextBox.Size = new System.Drawing.Size(537, 20);
     323      this.dataTypeNameTextBox.TabIndex = 1;
     324      this.toolTip.SetToolTip(this.dataTypeNameTextBox, "Human Readable Data Type Name");
     325      this.dataTypeNameTextBox.TextChanged += new System.EventHandler(this.dataTypeNameTextBox_TextChanged);
     326      //
     327      // dataTypeTypeNameLabel
     328      //
     329      this.dataTypeTypeNameLabel.AutoSize = true;
     330      this.dataTypeTypeNameLabel.Location = new System.Drawing.Point(6, 48);
     331      this.dataTypeTypeNameLabel.Name = "dataTypeTypeNameLabel";
     332      this.dataTypeTypeNameLabel.Size = new System.Drawing.Size(65, 13);
     333      this.dataTypeTypeNameLabel.TabIndex = 2;
     334      this.dataTypeTypeNameLabel.Text = "&Type Name:";
     335      //
     336      // openFileDialog
     337      //
     338      this.openFileDialog.FileName = "data";
     339      this.openFileDialog.Filter = "All Files (*.*)|*.*";
     340      this.openFileDialog.Title = "Load Problem Data";
     341      //
     342      // saveFileDialog
     343      //
     344      this.saveFileDialog.FileName = "data";
     345      this.saveFileDialog.Filter = "All Files (*.*)|*.*";
     346      this.saveFileDialog.Title = "Save Problem Data";
    185347      //
    186348      // ProblemView
    187349      //
    188350      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
     351      this.Controls.Add(this.dataTypeGroupBox);
    189352      this.Controls.Add(this.tabControl);
    190353      this.Controls.Add(this.platformComboBox);
     
    199362      this.Controls.SetChildIndex(this.platformComboBox, 0);
    200363      this.Controls.SetChildIndex(this.tabControl, 0);
     364      this.Controls.SetChildIndex(this.dataTypeGroupBox, 0);
    201365      this.Controls.SetChildIndex(this.storeButton, 0);
    202366      this.Controls.SetChildIndex(this.nameTextBox, 0);
     
    206370      this.tabControl.ResumeLayout(false);
    207371      this.usersTabPage.ResumeLayout(false);
     372      this.dataTabPage.ResumeLayout(false);
     373      this.dataTabPage.PerformLayout();
     374      this.dataTypeGroupBox.ResumeLayout(false);
     375      this.dataTypeGroupBox.PerformLayout();
    208376      this.ResumeLayout(false);
    209377      this.PerformLayout();
     
    223391    private System.Windows.Forms.TabPage dataTabPage;
    224392    private System.Windows.Forms.CheckedListBox usersListBox;
     393    private System.Windows.Forms.Label dataTypeNameLabel;
     394    private System.Windows.Forms.GroupBox dataTypeGroupBox;
     395    private System.Windows.Forms.TextBox dataTypeTypeNameTextBox;
     396    private System.Windows.Forms.TextBox dataTypeNameTextBox;
     397    private System.Windows.Forms.Label dataTypeTypeNameLabel;
     398    private System.Windows.Forms.Button storeDataButton;
     399    private System.Windows.Forms.Button refreshDataButton;
     400    private System.Windows.Forms.Button openFileButton;
     401    private System.Windows.Forms.Button newDataButton;
     402    private System.Windows.Forms.Button saveFileButton;
     403    private System.Windows.Forms.OpenFileDialog openFileDialog;
     404    private System.Windows.Forms.SaveFileDialog saveFileDialog;
     405    private MainForm.WindowsForms.ViewHost dataViewHost;
     406    private System.Windows.Forms.Label noViewAvailableLabel;
    225407
    226408  }
  • branches/OKB (trunk integration)/HeuristicLab.Clients.OKB/3.3/Administration/Views/ProblemView.cs

    r5550 r5587  
    2222using System;
    2323using System.Collections.Generic;
     24using System.IO;
    2425using System.Linq;
    2526using System.Windows.Forms;
    2627using HeuristicLab.Clients.OKB.Authentication;
     28using HeuristicLab.Common;
     29using HeuristicLab.Core.Views;
    2730using HeuristicLab.MainForm;
    2831using HeuristicLab.MainForm.WindowsForms;
     32using HeuristicLab.Optimization;
     33using HeuristicLab.Persistence.Default.Xml;
     34using HeuristicLab.PluginInfrastructure;
    2935
    3036namespace HeuristicLab.Clients.OKB.Administration {
     
    3440    private List<Platform> platformComboBoxValues;
    3541    private List<ProblemClass> problemClassComboBoxValues;
     42    private TypeSelectorDialog typeSelectorDialog;
     43    private byte[] data;
    3644
    3745    public new Problem Content {
     
    4452    }
    4553
    46     protected override void OnInitialized(System.EventArgs e) {
    47       base.OnInitialized(e);
     54    protected override void Dispose(bool disposing) {
     55      if (disposing) {
     56        if (components != null) components.Dispose();
     57        if (typeSelectorDialog != null) typeSelectorDialog.Dispose();
     58      }
     59      base.Dispose(disposing);
     60    }
     61
     62    protected override void OnContentChanged() {
     63      base.OnContentChanged();
     64
     65      platformComboBox.SelectedValueChanged -= new EventHandler(platformComboBox_SelectedValueChanged);
    4866      platformComboBoxValues = AdministrationClient.Instance.Platforms.ToList();
    4967      platformComboBox.DataSource = platformComboBoxValues;
     68      platformComboBox.SelectedValueChanged += new EventHandler(platformComboBox_SelectedValueChanged);
     69
     70      problemClassComboBox.SelectedValueChanged -= new EventHandler(problemClassComboBox_SelectedValueChanged);
    5071      problemClassComboBoxValues = AdministrationClient.Instance.ProblemClasses.ToList();
    5172      problemClassComboBox.DataSource = problemClassComboBoxValues;
    52     }
    53 
    54     protected override void OnContentChanged() {
    55       base.OnContentChanged();
     73      problemClassComboBox.SelectedValueChanged += new EventHandler(problemClassComboBox_SelectedValueChanged);
     74
     75      usersListBox.DataSource = null;
     76      data = null;
     77      dataViewHost.Content = null;
    5678      if (Content == null) {
    5779        platformComboBox.SelectedIndex = -1;
    5880        problemClassComboBox.SelectedIndex = -1;
     81        dataTypeNameTextBox.Text = string.Empty;
     82        dataTypeTypeNameTextBox.Text = string.Empty;
    5983      } else {
    6084        platformComboBox.SelectedItem = platformComboBoxValues.FirstOrDefault(p => p.Id == Content.PlatformId);
    6185        problemClassComboBox.SelectedItem = problemClassComboBoxValues.FirstOrDefault(a => a.Id == Content.ProblemClassId);
    62       }
    63       usersListBox.DataSource = null;
     86        dataTypeNameTextBox.Text = Content.DataTypeName;
     87        dataTypeTypeNameTextBox.Text = Content.DataTypeTypeName;
     88      }
    6489    }
    6590
     
    6893      platformComboBox.Enabled = (Content != null) && !ReadOnly;
    6994      problemClassComboBox.Enabled = (Content != null) && !ReadOnly;
    70       refreshUsersButton.Enabled = Content != null;
     95      dataTypeGroupBox.Enabled = (Content != null) && !ReadOnly;
     96      refreshUsersButton.Enabled = (Content != null) && (Content.Id != 0);
    7197      storeUsersButton.Enabled = (usersListBox.DataSource != null) && !ReadOnly;
    7298      usersListBox.Enabled = (usersListBox.DataSource != null) && !ReadOnly;
    73     }
    74 
     99      refreshDataButton.Enabled = (Content != null) && (Content.Id != 0);
     100      storeDataButton.Enabled = ((data != null) || (dataViewHost.Content != null)) && !ReadOnly;
     101      openFileButton.Enabled = (Content != null) && (Content.Id != 0);
     102      saveFileButton.Enabled = (data != null) || (dataViewHost.Content != null);
     103      noViewAvailableLabel.Visible = dataViewHost.Content == null;
     104
     105      bool isHL33Platform = platformComboBox.Text == "HeuristicLab 3.3";
     106      dataTypeNameTextBox.ReadOnly = isHL33Platform;
     107      dataTypeTypeNameTextBox.ReadOnly = isHL33Platform;
     108      newDataButton.Enabled = isHL33Platform && (Content.Id != 0) && !ReadOnly;
     109    }
     110
     111    #region Content Events
    75112    protected override void OnContentPropertyChanged(string propertyName) {
    76113      switch (propertyName) {
     114        case "Id":
     115          SetEnabledStateOfControls();
     116          break;
    77117        case "PlatformId":
    78118          platformComboBox.SelectedItem = platformComboBoxValues.FirstOrDefault(p => p.Id == Content.PlatformId);
     119          SetEnabledStateOfControls();
    79120          break;
    80121        case "ProblemClassId":
    81122          problemClassComboBox.SelectedItem = problemClassComboBoxValues.FirstOrDefault(a => a.Id == Content.ProblemClassId);
    82123          break;
    83       }
    84     }
    85 
     124        case "DataTypeName":
     125          dataTypeNameTextBox.Text = Content.DataTypeName;
     126          break;
     127        case "DataTypeTypeName":
     128          dataTypeTypeNameTextBox.Text = Content.DataTypeTypeName;
     129          break;
     130      }
     131    }
     132    #endregion
     133
     134    #region Control Events
    86135    private void platformComboBox_SelectedValueChanged(object sender, System.EventArgs e) {
    87136      if (Content != null) {
     
    97146    }
    98147
     148    private void dataTypeNameTextBox_TextChanged(object sender, EventArgs e) {
     149      if (dataTypeNameTextBox.Text != Content.DataTypeName)
     150        Content.DataTypeName = dataTypeNameTextBox.Text;
     151    }
     152    private void dataTypeTypeNameTextBox_TextChanged(object sender, EventArgs e) {
     153      if (dataTypeTypeNameTextBox.Text != Content.DataTypeTypeName)
     154        Content.DataTypeTypeName = dataTypeTypeNameTextBox.Text;
     155    }
     156
    99157    private void refreshUsersButton_Click(object sender, System.EventArgs e) {
    100       List<Guid> ids = AdministrationClient.GetProblemUsers(Content.Id);
    101       if (ids != null) {
    102         List<User> users = AuthenticationClient.Instance.Users.ToList();
    103         usersListBox.DataSource = users;
    104         usersListBox.DisplayMember = "Name";
    105         usersListBox.SelectedItems.Clear();
    106         foreach (Guid id in ids)
    107           usersListBox.SelectedItems.Add(users.First(u => u.Id == id));
    108         usersListBox.Enabled = !ReadOnly;
     158      try {
     159        List<Guid> ids = AdministrationClient.GetProblemUsers(Content.Id);
     160        if (ids != null) {
     161          if (AuthenticationClient.Instance.Users == null) AuthenticationClient.Instance.Refresh();
     162          List<User> users = AuthenticationClient.Instance.Users.ToList();
     163          usersListBox.DataSource = users;
     164          usersListBox.DisplayMember = "Name";
     165          for (int i = 0; i < users.Count; i++)
     166            usersListBox.SetItemChecked(i, ids.Contains(users[i].Id));
     167          usersListBox.Enabled = !ReadOnly;
     168          storeUsersButton.Enabled = false;
     169        }
     170      }
     171      catch (Exception ex) {
     172        ErrorHandling.ShowErrorDialog(this, "Refresh authorized users and groups failed.", ex);
     173      }
     174    }
     175    private void storeUsersButton_Click(object sender, System.EventArgs e) {
     176      try {
     177        AdministrationClient.UpdateProblemUsers(Content.Id, usersListBox.SelectedItems.Cast<User>().Select(u => u.Id).ToList());
    109178        storeUsersButton.Enabled = false;
    110179      }
    111     }
    112     private void storeUsersButton_Click(object sender, System.EventArgs e) {
    113       AdministrationClient.UpdateProblemUsers(Content.Id, usersListBox.SelectedItems.Cast<User>().Select(u => u.Id).ToList());
    114       storeUsersButton.Enabled = false;
    115     }
    116     private void usersListBox_SelectedIndexChanged(object sender, EventArgs e) {
     180      catch (Exception ex) {
     181        ErrorHandling.ShowErrorDialog(this, "Store authorized users and groups failed.", ex);
     182      }
     183    }
     184    private void usersListBox_ItemCheck(object sender, ItemCheckEventArgs e) {
    117185      storeUsersButton.Enabled = !ReadOnly;
    118186    }
     187
     188    private void refreshDataButton_Click(object sender, EventArgs e) {
     189      CallAsync(
     190        () => {
     191          data = null;
     192          dataViewHost.Content = null;
     193          data = AdministrationClient.GetProblemData(Content.Id);
     194          if (data != null) {
     195            using (MemoryStream stream = new MemoryStream(data)) {
     196              try {
     197                dataViewHost.Content = XmlParser.Deserialize<IContent>(stream);
     198              }
     199              catch (Exception) { }
     200              stream.Close();
     201            }
     202          }
     203        },
     204        "Refresh problem data failed.",
     205        () => SetEnabledStateOfControls()
     206      );
     207    }
     208    private void storeDataButton_Click(object sender, EventArgs e) {
     209      CallAsync(
     210        () => {
     211          if (dataViewHost.Content != null) {
     212            using (MemoryStream stream = new MemoryStream()) {
     213              XmlGenerator.Serialize(dataViewHost.Content, stream);
     214              stream.Close();
     215              data = stream.ToArray();
     216            }
     217          }
     218          AdministrationClient.UpdateProblemData(Content.Id, data);
     219        },
     220        "Store problem data failed.",
     221        null
     222      );
     223    }
     224    private void newDataButton_Click(object sender, EventArgs e) {
     225      if (typeSelectorDialog == null) {
     226        typeSelectorDialog = new TypeSelectorDialog();
     227        typeSelectorDialog.Caption = "Select Problem";
     228        typeSelectorDialog.TypeSelector.Caption = "Available Problems";
     229        typeSelectorDialog.TypeSelector.Configure(typeof(IProblem), false, true);
     230      }
     231      if (typeSelectorDialog.ShowDialog(this) == DialogResult.OK) {
     232        try {
     233          Content.DataTypeName = typeSelectorDialog.TypeSelector.SelectedType.Name;
     234          Content.DataTypeTypeName = typeSelectorDialog.TypeSelector.SelectedType.AssemblyQualifiedName;
     235          data = null;
     236          dataViewHost.Content = (IContent)typeSelectorDialog.TypeSelector.CreateInstanceOfSelectedType();
     237        }
     238        catch (Exception ex) {
     239          ErrorHandling.ShowErrorDialog(this, "Create new problem data failed.", ex);
     240        }
     241        SetEnabledStateOfControls();
     242      }
     243    }
     244    private void openFileButton_Click(object sender, EventArgs e) {
     245      if (openFileDialog.ShowDialog(this) == DialogResult.OK) {
     246        CallAsync(
     247          () => {
     248            IContent problem = null;
     249            try {
     250              problem = XmlParser.Deserialize<IContent>(openFileDialog.FileName);
     251            }
     252            catch (Exception) { }
     253
     254            if (problem != null) {
     255              Content.DataTypeName = problem.GetType().Name;
     256              Content.DataTypeTypeName = problem.GetType().AssemblyQualifiedName;
     257              data = null;
     258            } else {
     259              using (FileStream stream = new FileStream(openFileDialog.FileName, FileMode.Open, FileAccess.Read)) {
     260                data = new byte[stream.Length];
     261                stream.Read(data, 0, data.Length);
     262                stream.Close();
     263              }
     264            }
     265            dataViewHost.Content = problem;
     266          },
     267          "Save problem data into file failed.",
     268          () => SetEnabledStateOfControls()
     269        );
     270      }
     271    }
     272    private void saveFileButton_Click(object sender, EventArgs e) {
     273      if (saveFileDialog.ShowDialog(this) == DialogResult.OK) {
     274        CallAsync(
     275          () => {
     276            if (dataViewHost.Content != null) {
     277              XmlGenerator.Serialize(dataViewHost.Content, saveFileDialog.FileName);
     278            } else {
     279              using (FileStream stream = new FileStream(saveFileDialog.FileName, FileMode.Create, FileAccess.Write)) {
     280                stream.Write(data, 0, data.Length);
     281                stream.Close();
     282              }
     283            }
     284          },
     285          "Save problem data into file failed.",
     286          null
     287        );
     288      }
     289    }
     290    #endregion
     291
     292    #region Helpers
     293    private void CallAsync(Action call, string errorMessage, Action continueWith) {
     294      BeginAsyncCall();
     295      call.BeginInvoke(delegate(IAsyncResult result) {
     296        Exception exception = null;
     297        try {
     298          call.EndInvoke(result);
     299        }
     300        catch (Exception ex) {
     301          exception = ex;
     302        }
     303        EndAsyncCall(errorMessage, exception, continueWith);
     304      }, null);
     305    }
     306    private void BeginAsyncCall() {
     307      if (InvokeRequired)
     308        Invoke(new Action(BeginAsyncCall));
     309      else {
     310        Cursor = Cursors.AppStarting;
     311        Enabled = false;
     312      }
     313    }
     314    private void EndAsyncCall(string errorMessage, Exception exception, Action continueWith) {
     315      if (InvokeRequired)
     316        Invoke(new Action<string, Exception, Action>(EndAsyncCall), errorMessage, exception, continueWith);
     317      else {
     318        Cursor = Cursors.Default;
     319        Enabled = true;
     320        if (exception != null) ErrorHandling.ShowErrorDialog(this, errorMessage, exception);
     321        if (continueWith != null) continueWith();
     322      }
     323    }
     324    #endregion
    119325  }
    120326}
  • branches/OKB (trunk integration)/HeuristicLab.Clients.OKB/3.3/HeuristicLab.Clients.OKB-3.3.csproj

    r5550 r5587  
    196196    <None Include="HeuristicLabClientsOKBPlugin.cs.frame" />
    197197  </ItemGroup>
    198   <ItemGroup>
    199     <EmbeddedResource Include="Administration\Views\AlgorithmView.resx">
    200       <DependentUpon>AlgorithmView.cs</DependentUpon>
    201     </EmbeddedResource>
    202   </ItemGroup>
    203198  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
    204199  <PropertyGroup>
  • branches/OKB (trunk integration)/HeuristicLab.Services.OKB.DataAccess/3.3/OKB.dbml

    r5534 r5587  
    9999      <Column Name="Id" Type="System.Int64" DbType="BigInt NOT NULL IDENTITY" IsPrimaryKey="true" IsDbGenerated="true" CanBeNull="false" />
    100100      <Column Name="Data" Type="System.Data.Linq.Binary" DbType="VarBinary(MAX) NOT NULL" CanBeNull="false" UpdateCheck="Never" />
    101       <Column Name="Hash" Type="System.Data.Linq.Binary" DbType="VarBinary(20)" IsDbGenerated="true" CanBeNull="true" UpdateCheck="Never" />
     101      <Column Name="Hash" Type="System.Byte[]" DbType="VarBinary(20) NOT NULL" CanBeNull="false" UpdateCheck="Never" />
    102102      <Association Name="BinaryData_Algorithm" Member="Algorithms" ThisKey="Id" OtherKey="BinaryDataId" Type="Algorithm" />
    103103      <Association Name="BinaryData_Problem" Member="Problems" ThisKey="Id" OtherKey="BinaryDataId" Type="Problem" />
  • branches/OKB (trunk integration)/HeuristicLab.Services.OKB.DataAccess/3.3/OKB.designer.cs

    r5534 r5587  
    21882188    private System.Data.Linq.Binary _Data;
    21892189   
    2190     private System.Data.Linq.Binary _Hash;
     2190    private byte[] _Hash;
    21912191   
    21922192    private EntitySet<Algorithm> _Algorithms;
     
    22042204    partial void OnDataChanging(System.Data.Linq.Binary value);
    22052205    partial void OnDataChanged();
    2206     partial void OnHashChanging(System.Data.Linq.Binary value);
     2206    partial void OnHashChanging(byte[] value);
    22072207    partial void OnHashChanged();
    22082208    #endregion
     
    22562256    }
    22572257   
    2258     [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_Hash", AutoSync=AutoSync.Always, DbType="VarBinary(20)", IsDbGenerated=true, UpdateCheck=UpdateCheck.Never)]
    2259     public System.Data.Linq.Binary Hash
     2258    [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_Hash", DbType="VarBinary(20) NOT NULL", CanBeNull=false, UpdateCheck=UpdateCheck.Never)]
     2259    public byte[] Hash
    22602260    {
    22612261      get
  • branches/OKB (trunk integration)/HeuristicLab.Services.OKB/3.3/Administration/Convert.cs

    r5534 r5587  
    126126      var entity = okb.BinaryDatas.Where(x => x.Hash.Equals(hash)).FirstOrDefault();
    127127      if (entity == null)
    128         entity = new DA.BinaryData() { Id = 0, Data = data };
     128        entity = new DA.BinaryData() { Id = 0, Data = data, Hash = hash };
    129129      return entity;
    130130    }
  • branches/OKB (trunk integration)/HeuristicLab.Services.OKB/3.3/RunCreation/Convert.cs

    r5478 r5587  
    122122      var entity = okb.BinaryDatas.Where(x => x.Hash.Equals(hash)).FirstOrDefault();
    123123      if (entity == null)
    124         entity = new DA.BinaryData() { Id = 0, Data = data };
     124        entity = new DA.BinaryData() { Id = 0, Data = data, Hash = hash };
    125125      return entity;
    126126    }
Note: See TracChangeset for help on using the changeset viewer.