Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
10/18/18 14:07:32 (6 years ago)
Author:
ddorfmei
Message:

#2931: Merged [16168-16232/trunk] into branch

Location:
branches/2931_OR-Tools_LP_MIP
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • branches/2931_OR-Tools_LP_MIP

  • branches/2931_OR-Tools_LP_MIP/HeuristicLab.Clients.Hive.Administrator

  • branches/2931_OR-Tools_LP_MIP/HeuristicLab.Clients.Hive.Administrator/3.3/Views/HiveAdministratorView.Designer.cs

    r16139 r16235  
    2929      this.components = new System.ComponentModel.Container();
    3030      this.tabAdmin = new System.Windows.Forms.TabControl();
    31       this.tabSlaves = new System.Windows.Forms.TabPage();
     31      this.tabResources = new System.Windows.Forms.TabPage();
    3232      this.resourcesView = new HeuristicLab.Clients.Hive.Administrator.Views.ResourcesView();
    33       this.tabPage1 = new System.Windows.Forms.TabPage();
     33      this.tabProjects = new System.Windows.Forms.TabPage();
    3434      this.imageListUsers = new System.Windows.Forms.ImageList(this.components);
    3535      this.projectsView = new HeuristicLab.Clients.Hive.Administrator.Views.ProjectsView();
    3636      this.tabAdmin.SuspendLayout();
    37       this.tabSlaves.SuspendLayout();
    38       this.tabPage1.SuspendLayout();
     37      this.tabResources.SuspendLayout();
     38      this.tabProjects.SuspendLayout();
    3939      this.SuspendLayout();
    4040      //
     
    4444            | System.Windows.Forms.AnchorStyles.Left)
    4545            | System.Windows.Forms.AnchorStyles.Right)));
    46       this.tabAdmin.Controls.Add(this.tabSlaves);
    47       this.tabAdmin.Controls.Add(this.tabPage1);
     46      this.tabAdmin.Controls.Add(this.tabResources);
     47      this.tabAdmin.Controls.Add(this.tabProjects);
    4848      this.tabAdmin.Location = new System.Drawing.Point(3, 0);
    4949      this.tabAdmin.Name = "tabAdmin";
     
    5252      this.tabAdmin.TabIndex = 0;
    5353      //
    54       // tabSlaves
     54      // tabResources
    5555      //
    56       this.tabSlaves.Controls.Add(this.resourcesView);
    57       this.tabSlaves.Location = new System.Drawing.Point(4, 22);
    58       this.tabSlaves.Name = "tabSlaves";
    59       this.tabSlaves.Padding = new System.Windows.Forms.Padding(3);
    60       this.tabSlaves.Size = new System.Drawing.Size(734, 520);
    61       this.tabSlaves.TabIndex = 3;
    62       this.tabSlaves.Text = "Slaves";
    63       this.tabSlaves.UseVisualStyleBackColor = true;
     56      this.tabResources.Controls.Add(this.resourcesView);
     57      this.tabResources.Location = new System.Drawing.Point(4, 22);
     58      this.tabResources.Name = "tabResources";
     59      this.tabResources.Padding = new System.Windows.Forms.Padding(3);
     60      this.tabResources.Size = new System.Drawing.Size(734, 520);
     61      this.tabResources.TabIndex = 3;
     62      this.tabResources.Text = "Resources";
     63      this.tabResources.UseVisualStyleBackColor = true;
    6464      //
    6565      // resourcesView
     
    7676      this.resourcesView.TabIndex = 0;
    7777      //
    78       // tabPage1
     78      // tabProjects
    7979      //
    80       this.tabPage1.Controls.Add(this.projectsView);
    81       this.tabPage1.Location = new System.Drawing.Point(4, 22);
    82       this.tabPage1.Name = "tabPage1";
    83       this.tabPage1.Size = new System.Drawing.Size(734, 520);
    84       this.tabPage1.TabIndex = 4;
    85       this.tabPage1.Text = "Projects";
    86       this.tabPage1.UseVisualStyleBackColor = true;
     80      this.tabProjects.Controls.Add(this.projectsView);
     81      this.tabProjects.Location = new System.Drawing.Point(4, 22);
     82      this.tabProjects.Name = "tabProjects";
     83      this.tabProjects.Size = new System.Drawing.Size(734, 520);
     84      this.tabProjects.TabIndex = 4;
     85      this.tabProjects.Text = "Projects";
     86      this.tabProjects.UseVisualStyleBackColor = true;
    8787      //
    8888      // imageListUsers
     
    112112      this.Size = new System.Drawing.Size(745, 546);
    113113      this.tabAdmin.ResumeLayout(false);
    114       this.tabSlaves.ResumeLayout(false);
    115       this.tabPage1.ResumeLayout(false);
     114      this.tabResources.ResumeLayout(false);
     115      this.tabProjects.ResumeLayout(false);
    116116      this.ResumeLayout(false);
    117117
     
    122122    private System.ComponentModel.IContainer components;
    123123    private System.Windows.Forms.ImageList imageListUsers;
    124     private System.Windows.Forms.TabPage tabSlaves;
    125     private System.Windows.Forms.TabPage tabPage1;
     124    private System.Windows.Forms.TabPage tabResources;
     125    private System.Windows.Forms.TabPage tabProjects;
    126126    private ProjectsView projectsView;
    127127  }
  • branches/2931_OR-Tools_LP_MIP/HeuristicLab.Clients.Hive.Administrator/3.3/Views/ProjectJobsView.Designer.cs

    r16139 r16235  
    2020#endregion
    2121
     22using System.Windows.Forms;
    2223using HeuristicLab.Data.Views;
    2324
     
    5051      this.refreshButton = new System.Windows.Forms.Button();
    5152      this.removeButton = new System.Windows.Forms.Button();
     53      this.startButton = new System.Windows.Forms.Button();
     54      this.stopButton = new System.Windows.Forms.Button();
     55      this.pauseButton = new System.Windows.Forms.Button();
    5256      this.matrixView = new HeuristicLab.Data.Views.StringConvertibleMatrixView();
    5357      this.toolTip = new System.Windows.Forms.ToolTip(this.components);
     
    7276      this.removeButton.Size = new System.Drawing.Size(24, 24);
    7377      this.removeButton.TabIndex = 2;
    74       this.toolTip.SetToolTip(this.removeButton, "Delete job(s)");
     78      this.toolTip.SetToolTip(this.removeButton, "Remove job(s)");
    7579      this.removeButton.UseVisualStyleBackColor = true;
    7680      this.removeButton.Click += new System.EventHandler(this.removeButton_Click);
     81      //
     82      // startButton
     83      //
     84      this.startButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)));
     85      this.startButton.Image = HeuristicLab.Common.Resources.VSImageLibrary.Play;
     86      this.startButton.Location = new System.Drawing.Point(63, 3);
     87      this.startButton.Name = "startButton";
     88      this.startButton.Size = new System.Drawing.Size(24, 24);
     89      this.startButton.TabIndex = 4;
     90      this.toolTip.SetToolTip(this.startButton, "Resume job(s)");
     91      this.startButton.UseVisualStyleBackColor = true;
     92      this.startButton.Click += new System.EventHandler(this.startButton_Click);
     93      //
     94      // pauseButton
     95      //
     96      this.pauseButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)));
     97      this.pauseButton.Enabled = false;
     98      this.pauseButton.Image = HeuristicLab.Common.Resources.VSImageLibrary.Pause;
     99      this.pauseButton.Location = new System.Drawing.Point(93, 3);
     100      this.pauseButton.Name = "pauseButton";
     101      this.pauseButton.Size = new System.Drawing.Size(24, 24);
     102      this.pauseButton.TabIndex = 5;
     103      this.toolTip.SetToolTip(this.pauseButton, "Pause job(s)");
     104      this.pauseButton.UseVisualStyleBackColor = true;
     105      this.pauseButton.Click += new System.EventHandler(this.pauseButton_Click);
     106      //
     107      // stopButton
     108      //
     109      this.stopButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)));
     110      this.stopButton.Image = HeuristicLab.Common.Resources.VSImageLibrary.Stop;
     111      this.stopButton.Location = new System.Drawing.Point(123, 3);
     112      this.stopButton.Name = "stopButton";
     113      this.stopButton.Size = new System.Drawing.Size(24, 24);
     114      this.stopButton.TabIndex = 6;
     115      this.toolTip.SetToolTip(this.stopButton, "Stop job(s)");
     116      this.stopButton.UseVisualStyleBackColor = true;
     117      this.stopButton.Click += new System.EventHandler(this.stopButton_Click);
    77118      //
    78119      // matrixView
     
    98139      this.Controls.Add(this.refreshButton);
    99140      this.Controls.Add(this.removeButton);
     141      this.Controls.Add(this.startButton);
     142      this.Controls.Add(this.pauseButton);
     143      this.Controls.Add(this.stopButton);
    100144      this.Name = "ProjectJobsView";
    101145      this.Size = new System.Drawing.Size(510, 385);
     
    110154    private System.Windows.Forms.Button refreshButton;
    111155    private System.Windows.Forms.Button removeButton;
     156    private System.Windows.Forms.Button startButton;
     157    private System.Windows.Forms.Button stopButton;
     158    private System.Windows.Forms.Button pauseButton;
    112159    private StringConvertibleMatrixView matrixView;
    113160  }
  • branches/2931_OR-Tools_LP_MIP/HeuristicLab.Clients.Hive.Administrator/3.3/Views/ProjectJobsView.cs

    r16139 r16235  
    2424using System.Drawing;
    2525using System.Linq;
     26using System.Threading.Tasks;
    2627using System.Windows.Forms;
    2728using HeuristicLab.MainForm;
     
    3031using HeuristicLab.Data;
    3132using HeuristicLab.Clients.Hive.Views;
     33using HeuristicLab.Core;
    3234
    3335namespace HeuristicLab.Clients.Hive.Administrator.Views {
     
    4143    private const string JOB_DATECREATED = "Date Created";
    4244    private const string JOB_STATE = "State";
     45    private const string JOB_EXECUTIONSTATE = "Execution State";
     46    private const string JOB_EXECUTIONTIME = "Execution Time";
    4347    private const string JOB_DESCRIPTION = "Description";
    4448    private const string JOB_TASKCOUNT = "Tasks";
     49    private const string JOB_WAITINGTASKCOUNT = "Waiting";
    4550    private const string JOB_CALCULATINGTASKCOUNT = "Calculating";
    4651    private const string JOB_FINISHEDTASKCOUNT = "Finished";
    47 
    4852
    4953    private readonly Color onlineStatusColor = Color.FromArgb(255, 189, 249, 143); // #bdf98f
     
    5357    private readonly Color deletionPendingStatusColor2 = Color.FromArgb(255, 249, 149, 143); // #f9958f
    5458
     59    private IProgress progress;
     60    public IProgress Progress {
     61      get { return progress; }
     62      set {
     63        this.progress = value;
     64        OnIsProgressingChanged();
     65      }
     66    }
     67
    5568    public new Project Content {
    5669      get { return (Project)base.Content; }
     
    6073    public ProjectJobsView() {
    6174      InitializeComponent();
    62 
    63       removeButton.Enabled = false;
     75      progress = new Progress();
     76
     77      removeButton.Enabled = false;     
     78    }
     79
     80    protected override void RegisterContentEvents() {
     81      base.RegisterContentEvents();
    6482      matrixView.DataGridView.SelectionChanged += DataGridView_SelectionChanged;
     83      MainFormManager.GetMainForm<HeuristicLab.MainForm.WindowsForms.MainForm>().AddOperationProgressToView(this, progress);
     84    }
     85
     86    protected override void DeregisterContentEvents() {
     87      matrixView.DataGridView.SelectionChanged -= DataGridView_SelectionChanged;
     88      MainFormManager.GetMainForm<HeuristicLab.MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(this, false);
     89      base.DeregisterContentEvents();
    6590    }
    6691
    6792    private void DataGridView_SelectionChanged(object sender, EventArgs e) {
    68       if (matrixView.DataGridView.SelectedRows == null || matrixView.DataGridView.SelectedRows.Count == 0) return;
    69 
    70       bool anyDeletable = false;
    71       foreach (DataGridViewRow r in matrixView.DataGridView.SelectedRows) {
    72         if (((string)r.Cells[0].Value) == JobState.Online.ToString()) anyDeletable = true;
    73       }
    74 
    75       removeButton.Enabled = anyDeletable;
     93      SetEnabledStateOfControls();
    7694    }
    7795
     
    8199      removeButton.Enabled = false;
    82100      UpdateJobs();
    83     }
     101      SetEnabledStateOfControls();
     102    }
     103
    84104    protected override void SetEnabledStateOfControls() {
    85105      base.SetEnabledStateOfControls();
    86106      bool enabled = Content != null && !Locked && !ReadOnly;
    87107
    88       refreshButton.Enabled = enabled;
    89       removeButton.Enabled = false;
    90108      matrixView.Enabled = enabled;
    91     }
     109
     110      // Buttons (start/resume, pause, stop, remove)
     111      refreshButton.Enabled = startButton.Enabled = pauseButton.Enabled = stopButton.Enabled = removeButton.Enabled = false;
     112
     113      if (enabled && progress.ProgressState != ProgressState.Started) {
     114        var jobs = GetSelectedJobs().ToList();
     115        if (jobs.Any()) {
     116                   
     117          startButton.Enabled = jobs.All(x =>
     118            !x.IsProgressing && HiveAdminClient.Instance.Tasks.ContainsKey(x.Id) && HiveAdminClient.Instance.Tasks[x.Id].Count > 0
     119            && x.Job.ProjectId != Guid.Empty //&& x.Job.ResourceIds != null && x.Job.ResourceIds.Any()
     120            && (x.ExecutionState == ExecutionState.Prepared || x.ExecutionState == ExecutionState.Paused));
     121          pauseButton.Enabled = jobs.All(x => !x.IsProgressing && x.ExecutionState == ExecutionState.Started);
     122          stopButton.Enabled = jobs.All(x => !x.IsProgressing && (x.ExecutionState == ExecutionState.Started || x.ExecutionState == ExecutionState.Paused));
     123          removeButton.Enabled = jobs.All(x => !x.IsProgressing && x.Job.State == JobState.Online);
     124        }
     125      }
     126
     127      // refresh Button
     128      if (Content != null && !Locked && progress.ProgressState != ProgressState.Started) {
     129        refreshButton.Enabled = true;
     130      }
     131    }
     132
    92133    #endregion Overrides
    93134
     
    98139
    99140    private void refreshButton_Click(object sender, EventArgs e) {
    100       RefreshJobs();
    101     }
    102 
    103     private async void removeButton_Click(object sender, EventArgs e) {
    104       if (matrixView.DataGridView.SelectedRows == null || matrixView.DataGridView.SelectedRows.Count == 0) return;
    105 
    106       var jobNamesToDelete = new List<string>();
    107       var jobIdsToDelete = new List<Guid>();
    108       foreach (DataGridViewRow r in matrixView.DataGridView.SelectedRows) {
    109         if(((string)r.Cells[0].Value) == JobState.Online.ToString()) {
    110           jobNamesToDelete.Add(" - " + ((string)r.Cells[3].Value));
    111           jobIdsToDelete.Add(Guid.Parse((string)r.Cells[8].Value));
    112         }
    113       }
    114 
    115       if(jobIdsToDelete.Any()) {
     141      progress.Start("Refreshing jobs...");
     142      SetEnabledStateOfControls();
     143      var task = System.Threading.Tasks.Task.Factory.StartNew(RefreshJobsAsync);
     144
     145      task.ContinueWith((t) => {
     146        progress.Finish();       
     147        SetEnabledStateOfControls();
     148      });
     149    }
     150
     151    private void removeButton_Click(object sender, EventArgs e) {
     152      var jobs = GetSelectedJobs();
     153
     154      if (jobs.Any()) {
    116155        var result = MessageBox.Show("Do you really want to remove following job(s):\n\n"
    117           + String.Join("\n", jobNamesToDelete),
     156                                     + String.Join("\n", jobs.Select(x => x.Job.Name)),
    118157          "HeuristicLab Hive Administrator",
    119158          MessageBoxButtons.YesNo,
     
    121160
    122161        if (result == DialogResult.Yes) {
    123           await SecurityExceptionUtil.TryAsyncAndReportSecurityExceptions(
    124             action: () => {
    125               DeleteJobs(jobIdsToDelete);
    126             },
    127             finallyCallback: () => {
    128               matrixView.DataGridView.ClearSelection();
    129               removeButton.Enabled = false;
    130               RefreshJobs();
    131             });
    132         }
    133       }
    134     }
    135 
     162          progress.Start("Removing job(s)...");
     163          SetEnabledStateOfControls();
     164          var task = System.Threading.Tasks.Task.Factory.StartNew(RemoveJobsAsync, jobs);
     165
     166          task.ContinueWith((t) => {
     167            RefreshJobs();
     168            progress.Finish();
     169            SetEnabledStateOfControls();
     170          }, TaskContinuationOptions.NotOnFaulted);
     171
     172          task.ContinueWith((t) => {
     173            RefreshJobs();
     174            progress.Finish();
     175            SetEnabledStateOfControls();
     176            MessageBox.Show("An error occured removing the job(s).", "HeuristicLab Hive Administrator", MessageBoxButtons.OK, MessageBoxIcon.Error);
     177          }, TaskContinuationOptions.OnlyOnFaulted);
     178        }
     179      }
     180    }
     181
     182    private void startButton_Click(object sender, EventArgs e) {
     183      var jobs = GetSelectedJobs();
     184
     185      if (jobs.Any()) {
     186        var result = MessageBox.Show("Do you really want to resume following job(s):\n\n"
     187                                     + String.Join("\n", jobs.Select(x => x.Job.Name)),
     188          "HeuristicLab Hive Administrator",
     189          MessageBoxButtons.YesNo,
     190          MessageBoxIcon.Question);
     191
     192        if (result == DialogResult.Yes) {
     193          progress.Start("Resuming job(s)...");
     194          SetEnabledStateOfControls();
     195          var task = System.Threading.Tasks.Task.Factory.StartNew(ResumeJobsAsync, jobs);
     196
     197          task.ContinueWith((t) => {
     198            RefreshJobs();           
     199            progress.Finish();
     200            SetEnabledStateOfControls();
     201          }, TaskContinuationOptions.NotOnFaulted);
     202
     203          task.ContinueWith((t) => {
     204            RefreshJobs();
     205            progress.Finish();
     206            SetEnabledStateOfControls();
     207            MessageBox.Show("An error occured resuming the job(s).", "HeuristicLab Hive Administrator", MessageBoxButtons.OK, MessageBoxIcon.Error);
     208          }, TaskContinuationOptions.OnlyOnFaulted);
     209        }
     210      }
     211    }
     212
     213    private void pauseButton_Click(object sender, EventArgs e) {
     214      var jobs = GetSelectedJobs();
     215
     216      if (jobs.Any()) {
     217        var result = MessageBox.Show("Do you really want to pause following job(s):\n\n"
     218                                     + String.Join("\n", jobs.Select(x => x.Job.Name)),
     219          "HeuristicLab Hive Administrator",
     220          MessageBoxButtons.YesNo,
     221          MessageBoxIcon.Question);
     222
     223        if (result == DialogResult.Yes) {
     224          progress.Start("Pausing job(s)...");
     225          SetEnabledStateOfControls();
     226          var task = System.Threading.Tasks.Task.Factory.StartNew(PauseJobsAsync, jobs);
     227
     228          task.ContinueWith((t) => {
     229            RefreshJobs();           
     230            progress.Finish();
     231            SetEnabledStateOfControls();
     232          }, TaskContinuationOptions.NotOnFaulted);
     233
     234          task.ContinueWith((t) => {
     235            RefreshJobs();
     236            progress.Finish();
     237            SetEnabledStateOfControls();
     238            MessageBox.Show("An error occured pausing the job(s).", "HeuristicLab Hive Administrator", MessageBoxButtons.OK, MessageBoxIcon.Error);
     239          }, TaskContinuationOptions.OnlyOnFaulted);
     240        }
     241      }
     242    }
     243
     244    private void stopButton_Click(object sender, EventArgs e) {
     245      var jobs = GetSelectedJobs();
     246
     247      if (jobs.Any()) {
     248        var result = MessageBox.Show("Do you really want to stop following job(s):\n\n"
     249                                     + String.Join("\n", jobs.Select(x => x.Job.Name)),
     250          "HeuristicLab Hive Administrator",
     251          MessageBoxButtons.YesNo,
     252          MessageBoxIcon.Question);
     253
     254        if (result == DialogResult.Yes) {
     255          progress.Start("Stopping job(s)...");
     256          SetEnabledStateOfControls();
     257          var task = System.Threading.Tasks.Task.Factory.StartNew(StopJobsAsync, jobs);
     258
     259          task.ContinueWith((t) => {
     260            RefreshJobs();
     261            progress.Finish();
     262            SetEnabledStateOfControls();
     263          }, TaskContinuationOptions.NotOnFaulted);
     264
     265          task.ContinueWith((t) => {
     266            RefreshJobs();
     267            progress.Finish();
     268            SetEnabledStateOfControls();
     269            MessageBox.Show("An error occured stopping the job(s).", "HeuristicLab Hive Administrator", MessageBoxButtons.OK, MessageBoxIcon.Error);           
     270          }, TaskContinuationOptions.OnlyOnFaulted);
     271        }
     272      }
     273    }
     274
     275    public event EventHandler IsProgressingChanged;
     276    private void OnIsProgressingChanged() {
     277      var handler = IsProgressingChanged;
     278      if (handler != null) handler(this, EventArgs.Empty);
     279    }
    136280    #endregion Event Handlers
    137281
    138282    #region Helpers
     283
     284    private IEnumerable<RefreshableJob> GetSelectedJobs() {
     285      if (Content == null || matrixView.DataGridView.SelectedRows == null || matrixView.DataGridView.SelectedRows.Count == 0)
     286        return Enumerable.Empty<RefreshableJob>() ;
     287
     288      var jobs = new List<RefreshableJob>();
     289      foreach (DataGridViewRow r in matrixView.DataGridView.SelectedRows) {
     290        if (((string)r.Cells[0].Value) == JobState.Online.ToString()) {
     291          jobs.Add(HiveAdminClient.Instance.Jobs[Content.Id].FirstOrDefault(x => x.Id == Guid.Parse((string) r.Cells[11].Value)));
     292        }
     293      }
     294
     295      return jobs;
     296    }
     297
    139298    private void RefreshJobs() {
    140299      HiveAdminClient.Instance.RefreshJobs();
    141300      UpdateJobs();
     301      SetEnabledStateOfControls();
    142302    }
    143303
     
    148308      var jobs = HiveAdminClient.Instance.Jobs[Content.Id];
    149309      var resources = HiveAdminClient.Instance.Resources;
    150       string[,] values = new string[jobs.Count, 10];
     310      string[,] values = new string[jobs.Count, 13];
    151311
    152312      for(int i = 0; i < jobs.Count; i++) {
    153         var job = jobs.ElementAt(i);
    154        
    155         values[i, 0] = job.State.ToString();
    156         values[i, 1] = job.DateCreated.ToString();
    157         values[i, 2] = job.OwnerUsername;
    158         values[i, 3] = job.Name;
    159         values[i, 4] = job.JobCount.ToString();
    160         values[i, 5] = job.CalculatingCount.ToString();
    161         values[i, 6] = job.FinishedCount.ToString();
    162         values[i, 7] = job.Description;       
    163         values[i, 8] = job.Id.ToString();
    164         values[i, 9] = job.OwnerUserId.ToString();
     313        var job = jobs.ElementAt(i);       
     314        values[i, 0] = job.Job.State.ToString();
     315        values[i, 1] = job.ExecutionState.ToString();
     316        values[i, 2] = job.ExecutionTime.ToString();
     317        values[i, 3] = job.Job.DateCreated.ToString();
     318        values[i, 4] = job.Job.OwnerUsername;
     319        values[i, 5] = job.Job.Name;
     320        values[i, 6] = job.Job.JobCount.ToString();
     321        values[i, 7] = (job.Job.JobCount - job.Job.CalculatingCount - job.Job.FinishedCount).ToString();
     322        values[i, 8] = job.Job.CalculatingCount.ToString();
     323        values[i, 9] = job.Job.FinishedCount.ToString();
     324        values[i, 10] = job.Job.Description;       
     325        values[i, 11] = job.Job.Id.ToString();
     326        values[i, 12] = job.Job.OwnerUserId.ToString();
    165327      }
    166328     
    167329      var matrix = new StringMatrix(values);
    168       matrix.ColumnNames = new string[] { JOB_STATE, JOB_DATECREATED, JOB_OWNER, JOB_NAME, JOB_TASKCOUNT, JOB_CALCULATINGTASKCOUNT, JOB_FINISHEDTASKCOUNT, JOB_DESCRIPTION, JOB_ID, JOB_OWNERID };
     330      matrix.ColumnNames = new string[] { JOB_STATE, JOB_EXECUTIONSTATE, JOB_EXECUTIONTIME, JOB_DATECREATED, JOB_OWNER, JOB_NAME, JOB_TASKCOUNT, JOB_WAITINGTASKCOUNT, JOB_CALCULATINGTASKCOUNT, JOB_FINISHEDTASKCOUNT, JOB_DESCRIPTION, JOB_ID, JOB_OWNERID };
    169331      matrix.SortableView = true;
    170332      return matrix;
     
    193355            matrixView.DataGridView.Columns[1].MinimumWidth = 108;
    194356          }
    195         } else {
    196           refreshButton.Enabled = false;
    197           removeButton.Enabled = false;
    198           matrixView.Content = null;
    199         }
    200       }
    201     }
    202 
    203     private void DeleteJobs(List<Guid> jobIds) {
    204       try {
    205         HiveAdminClient.DeleteJobs(jobIds);
    206       } catch (AnonymousUserException) {
    207         ShowHiveInformationDialog();
    208       }
     357        }
     358      }
     359    }
     360
     361    private void RefreshJobsAsync() {
     362      HiveAdminClient.Instance.RefreshJobs();
     363      UpdateJobs();
     364    }
     365
     366    private void ResumeJobsAsync(object jobs) {
     367      var jobList = (IEnumerable<RefreshableJob>)jobs;
     368      foreach (var job in jobList) {
     369        progress.Status = "Resuming job \"" + job.Job.Name + "\"...";
     370        HiveAdminClient.ResumeJob(job);
     371      }
     372    }
     373
     374    private void PauseJobsAsync(object jobs) {
     375      var jobList = (IEnumerable<RefreshableJob>)jobs;
     376      foreach (var job in jobList) {
     377        progress.Status = "Pausing job \"" + job.Job.Name + "\"...";
     378        HiveAdminClient.PauseJob(job);
     379      }
     380    }
     381
     382    private void StopJobsAsync(object jobs) {
     383      var jobList = (IEnumerable<RefreshableJob>) jobs;
     384      foreach (var job in jobList) {       
     385        progress.Status = "Stopping job \"" + job.Job.Name + "\"...";
     386        HiveAdminClient.StopJob(job);
     387      }
     388    }
     389
     390    private void RemoveJobsAsync(object jobs) {
     391      var jobList = (IEnumerable<RefreshableJob>)jobs;
     392      progress.Start();
     393      foreach (var job in jobList) {
     394        progress.Status = "Removing job \"" + job.Job.Name + "\"...";
     395        HiveAdminClient.RemoveJob(job);
     396      }
     397      progress.Finish();
    209398    }
    210399
  • branches/2931_OR-Tools_LP_MIP/HeuristicLab.Clients.Hive.Administrator/3.3/Views/ProjectPermissionsView.cs

    r16139 r16235  
    7878        detailsViewHost.Content = null;
    7979      } else {
    80         UpdatePermissionList();
    81         detailsViewHost.ActiveView.Locked = true;
    82       }
     80        UpdatePermissionList();       
     81      }
     82      SetEnabledStateOfControls();
    8383    }
    8484
     
    9090      saveButton.Enabled = enabled;
    9191      treeView.Enabled = enabled;
     92
     93      if (detailsViewHost != null) {
     94        detailsViewHost.Locked = true;
     95      }
     96
    9297    }
    9398    #endregion
  • branches/2931_OR-Tools_LP_MIP/HeuristicLab.Clients.Hive.Administrator/3.3/Views/ProjectResourcesView.cs

    r16139 r16235  
    3030using HeuristicLab.MainForm;
    3131using System.Collections;
     32using HeuristicLab.Common;
    3233
    3334namespace HeuristicLab.Clients.Hive.Administrator.Views {
     
    7273      treeView.ImageList.Images.Add(VSImageLibrary.MonitorLarge);
    7374      treeView.ImageList.Images.Add(VSImageLibrary.NetworkCenterLarge);
     75
     76      HiveAdminClient.Instance.Refreshing += HiveAdminClient_Instance_Refreshing;
     77      HiveAdminClient.Instance.Refreshed += HiveAdminClient_Instance_Refreshed;
    7478    }
    7579
    7680    #region Overrides
     81    protected override void OnClosing(FormClosingEventArgs e) {
     82      HiveAdminClient.Instance.Refreshed -= HiveAdminClient_Instance_Refreshed;
     83      HiveAdminClient.Instance.Refreshing -= HiveAdminClient_Instance_Refreshing;
     84      base.OnClosing(e);
     85    }
     86
    7787    protected override void OnContentChanged() {
    7888      base.OnContentChanged();
     
    8696        UpdateAssignedResources();
    8797        UpdateIncludedResources();
    88         var top = BuildResourceTree();
    89         detailsViewHost.Content = top;
    90         detailsViewHost.Locked = true;
    91       }
     98        detailsViewHost.Content = BuildResourceTree();
     99      }
     100      SetEnabledStateOfControls();
    92101    }
    93102
     
    99108      saveButton.Enabled = enabled;
    100109      treeView.Enabled = enabled;
     110
     111      if (detailsViewHost != null) {
     112        detailsViewHost.Locked = true;
     113      }
    101114    }
    102115    #endregion
    103116
    104117    #region Event Handlers
     118    private void HiveAdminClient_Instance_Refreshing(object sender, EventArgs e) {
     119      if (InvokeRequired) Invoke((Action<object, EventArgs>)HiveAdminClient_Instance_Refreshing, sender, e);
     120      else {
     121        SetEnabledStateOfControls();
     122      }
     123    }
     124
     125    private void HiveAdminClient_Instance_Refreshed(object sender, EventArgs e) {
     126      if (InvokeRequired) Invoke((Action<object, EventArgs>)HiveAdminClient_Instance_Refreshed, sender, e);
     127      else {
     128        OnContentChanged();
     129      }
     130    }
     131
    105132    private void ProjectResourcesView_Load(object sender, EventArgs e) {
    106133
     
    382409        }
    383410
    384           if (includedResources.Contains(newResource) && newIncludedResources.Contains(newResource)) {
     411        if (includedResources.Contains(newResource) && newIncludedResources.Contains(newResource)) {
    385412          newNode.Text += INCLUDED_TAG;
    386413        } else if (addedIncludes.Contains(newResource)) {
     
    421448      }
    422449
     450      ExpandResourceNodesOfInterest(treeView.Nodes);
     451
     452      bool expandUngroupedGroupNode = false;
    423453      var ungroupedSlaves = subResources.OfType<Slave>().OrderBy(x => x.Name);
    424454      if(ungroupedSlaves.Any()) {
     
    433463        foreach (var slave in ungroupedSlaves) {
    434464          var slaveNode = new TreeNode(slave.Name) { Tag = slave };
     465          if (newAssignedResources.Contains(slave)) {
     466            slaveNode.Checked = true;
     467            expandUngroupedGroupNode = true;
     468          }
     469
     470          if (!HiveRoles.CheckAdminUserPermissions()) {
     471            slaveNode.ForeColor = SystemColors.GrayText;
     472            slaveNode.Text += IMMUTABLE_TAG;
     473          } else {
     474            if (addedAssignments.Contains(slave)) {
     475              slaveNode.BackColor = addedAssignmentColor;
     476              slaveNode.ForeColor = SystemColors.ControlText;
     477              slaveNode.Text += ADDED_ASSIGNMENT_TAG;
     478            } else if (removedAssignments.Contains(slave)) {
     479              slaveNode.BackColor = removedAssignmentColor;
     480              slaveNode.ForeColor = SystemColors.ControlText;
     481              slaveNode.Text += REMOVED_ASSIGNMENT_TAG;
     482              expandUngroupedGroupNode = true;
     483            }
     484          }
    435485          ungroupedGroupNode.Nodes.Add(slaveNode);
    436486        }
     487
     488        if(expandUngroupedGroupNode) ungroupedGroupNode.Expand();
    437489        treeView.Nodes.Add(ungroupedGroupNode);
    438490      } else if (ungroupedGroupNode != null) {
     
    441493
    442494      treeView.BeforeCheck += treeView_BeforeCheck;
    443       treeView.AfterCheck += treeView_AfterCheck;
    444      
    445       ExpandResourceNodesOfInterest(treeView.Nodes);
     495      treeView.AfterCheck += treeView_AfterCheck;         
    446496
    447497      return top;
  • branches/2931_OR-Tools_LP_MIP/HeuristicLab.Clients.Hive.Administrator/3.3/Views/ProjectView.cs

    r16139 r16235  
    118118        endDateTimePicker.Enabled = !indefiniteCheckBox.Checked;
    119119      }
     120      SetEnabledStateOfControls();
    120121      RegisterControlEvents();
    121122    }
     
    134135
    135136      if (Content != null) {
    136         var parentProject = HiveAdminClient.Instance.GetAvailableProjectAncestors(Content.Id).LastOrDefault();
    137         if (parentProject == null || parentProject.EndDate.HasValue) {
     137        //var parentProject = HiveAdminClient.Instance.GetAvailableProjectAncestors(Content.Id).LastOrDefault();
     138        var parentProject = HiveAdminClient.Instance.Projects.FirstOrDefault(x => x.Id == Content.ParentProjectId);
     139        if ((!IsAdmin() && (parentProject == null || parentProject.EndDate.HasValue))
     140           || (IsAdmin() && parentProject != null && parentProject.EndDate.HasValue)) {
    138141          indefiniteCheckBox.Enabled = false;
    139142        }
    140143
    141         if (!IsAdmin() && !HiveAdminClient.Instance.CheckOwnershipOfParentProject(Content, UserInformation.Instance.User.Id)) {
     144        if (Content.Id != Guid.Empty && !IsAdmin() && !HiveAdminClient.Instance.CheckOwnershipOfParentProject(Content, UserInformation.Instance.User.Id)) {
    142145          ownerComboBox.Enabled = false;
    143146          startDateTimePicker.Enabled = false;
  • branches/2931_OR-Tools_LP_MIP/HeuristicLab.Clients.Hive.Administrator/3.3/Views/ProjectsView.cs

    r16139 r16235  
    4343    private const string NOT_STORED_TAG = "*"; // " [not stored]";
    4444    private const string CHANGES_NOT_STORED_TAG = "*"; // " [changes not stored]";
     45    private const string INACTIVE_TAG = " [inactive]";
    4546
    4647    private readonly Color selectedBackColor = Color.DodgerBlue;
     
    106107        BuildProjectTree(Content);
    107108      }
     109      SetEnabledStateOfControls();
    108110    }
    109111
    110112    protected override void SetEnabledStateOfControls() {
    111       base.SetEnabledStateOfControls();
    112       bool selectedProjectExists = selectedProject != null && selectedProject.Id != Guid.Empty && Content.Contains(selectedProject);
    113       bool projectIsNew = selectedProject != null && selectedProject.Id == Guid.Empty;
    114       bool locked = Content == null || selectedProject == null || Locked || ReadOnly;
    115       bool parentOwner = HiveAdminClient.Instance.CheckOwnershipOfParentProject(selectedProject, UserInformation.Instance.User.Id);
    116       bool saveLocked = locked || (!IsAdmin() && selectedProject.OwnerUserId != UserInformation.Instance.User.Id && !parentOwner);
    117       bool addLocked = saveLocked || projectIsNew || selectedProject.Id == Guid.Empty;
    118       bool deleteLocked = locked || (!IsAdmin() && !parentOwner) || Content.Where(x => x.ParentProjectId == selectedProject.Id).Any();
    119 
    120       var now = DateTime.Now;
    121       if (!addLocked && (now < selectedProject.StartDate || now > selectedProject.EndDate)) addLocked = true;
     113      base.SetEnabledStateOfControls();     
     114
     115      bool locked = Content == null || Locked || ReadOnly;     
     116      bool parentOwner = selectedProject != null && HiveAdminClient.Instance.CheckOwnershipOfParentProject(selectedProject, UserInformation.Instance.User.Id);
     117      bool selectedProjectDisabled = selectedProject == null
     118                                     || selectedProject != null && selectedProject.Id == Guid.Empty;
     119
     120      bool selectedProjectHasJobs =
     121        !selectedProjectDisabled && HiveAdminClient.Instance.Jobs.ContainsKey(selectedProject.Id)
     122                                 && HiveAdminClient.Instance.Jobs[selectedProject.Id] != null
     123                                 && HiveAdminClient.Instance.Jobs[selectedProject.Id].Any();
     124
     125      bool addLocked = locked
     126                       || (selectedProject == null && !IsAdmin())
     127                       || (selectedProject != null && selectedProject.Id == Guid.Empty)
     128                       || (selectedProject != null && !IsAdmin() && !parentOwner && selectedProject.OwnerUserId != UserInformation.Instance.User.Id)
     129                       || (selectedProject != null && (DateTime.Now < selectedProject.StartDate || DateTime.Now > selectedProject.EndDate));
     130
     131      bool deleteLocked = locked
     132                          || !Content.Any()
     133                          || selectedProject == null
     134                          || Content.Any(x => x.ParentProjectId == selectedProject.Id)
     135                          || selectedProjectHasJobs
     136                          || (!IsAdmin() && !parentOwner);
     137
     138      bool saveLocked = locked
     139                        || !Content.Any()
     140                        || selectedProject == null
     141                        || (!IsAdmin() && !parentOwner && selectedProject.OwnerUserId != UserInformation.Instance.User.Id);
     142
    122143
    123144      addButton.Enabled = !addLocked;
    124145      removeButton.Enabled = !deleteLocked;
    125146      saveProjectButton.Enabled = !saveLocked;
     147
    126148      projectView.Enabled = !locked;
    127       projectPermissionsView.Enabled = !locked;
    128       projectResourcesView.Enabled = !locked;
    129       projectJobsView.Enabled = !locked;
     149      projectPermissionsView.Enabled = !locked && !selectedProjectDisabled;
     150      projectResourcesView.Enabled = !locked && !selectedProjectDisabled;
     151      projectJobsView.Enabled = !locked && !selectedProjectDisabled;
    130152
    131153      projectView.Locked = locked;
    132       projectPermissionsView.Locked = locked;
    133       projectResourcesView.Locked = locked;
    134       projectJobsView.Locked = locked;
     154      projectPermissionsView.Locked = locked || selectedProjectDisabled;
     155      projectResourcesView.Locked = locked || selectedProjectDisabled;
     156      projectJobsView.Locked = locked || selectedProjectDisabled;
    135157    }
    136158    #endregion
     
    254276      }
    255277
    256       // double check of ChangeSelectedProject(..):
    257       // if the user is no admin nor owner of a parent project
    258       if (!IsAdmin() && !HiveAdminClient.Instance.CheckOwnershipOfParentProject(selectedProject, UserInformation.Instance.User.Id)) {
    259         MessageBox.Show(
    260           "Only admins and owners of parent projects are allowed to delete this project.",
    261           "HeuristicLab Hive Administrator",
    262           MessageBoxButtons.OK,
    263           MessageBoxIcon.Error);
    264         return;
    265       }           
    266 
    267 
    268       if (Content.Any(x => x.ParentProjectId == selectedProject.Id)
    269           || HiveAdminClient.Instance.ProjectDescendants[selectedProject.Id].Any()) {
    270         MessageBox.Show(
    271           "Only empty projects can be deleted.",
    272           "HeuristicLab Hive Administrator",
    273           MessageBoxButtons.OK,
    274           MessageBoxIcon.Error);
    275         return;
    276       }
    277 
    278       if (HiveAdminClient.Instance.Jobs.ContainsKey(selectedProject.Id)
    279         && HiveAdminClient.Instance.Jobs[selectedProject.Id] != null
    280         && HiveAdminClient.Instance.Jobs[selectedProject.Id].Any()) {
    281         MessageBox.Show(
    282           "There are " + HiveAdminClient.Instance.Jobs[selectedProject.Id].Count + " job(s) using this project and/or child-projects. It is necessary to delete them before the project.",
    283           "HeuristicLab Hive Administrator",
    284           MessageBoxButtons.OK,
    285           MessageBoxIcon.Error);
    286         return;
    287       }
    288 
    289278      var result = MessageBox.Show(
    290279        "Do you really want to delete " + selectedProject.Name + "?",
     
    297286          action: () => {
    298287            RemoveProject(selectedProject); 
    299           },
    300           finallyCallback: () => {
    301             removeButton.Enabled = true;
    302288          });
    303       } else {
    304         removeButton.Enabled = true;
    305       }
     289      }
     290      SetEnabledStateOfControls();
    306291    }
    307292
     
    492477      if (HiveAdminClient.Instance.DisabledParentProjects.Select(x => x.Id).Contains(p.Id)) {
    493478        n.ForeColor = grayTextColor;
    494       } else if (p.Id == Guid.Empty) {
    495         n.Text += NOT_STORED_TAG;
    496       } else if (p.Modified) {
    497         n.Text += CHANGES_NOT_STORED_TAG;
     479      } else {
     480        if (p.Id == Guid.Empty) {
     481          n.Text += NOT_STORED_TAG;
     482        } else if (p.Modified) {
     483          n.Text += CHANGES_NOT_STORED_TAG;
     484        }
     485
     486        if (!IsActive(p)) {
     487          n.ForeColor = grayTextColor;
     488          n.Text += INACTIVE_TAG;
     489        }
    498490      }
    499491    }
     
    540532      try {
    541533        if (project.Id != Guid.Empty) {
    542           var projectsToSave = Content.Where(x => x.Id == Guid.Empty || x.Modified);
    543           foreach (var p in projectsToSave)
    544             p.Store();
    545 
    546534          SelectedProject = HiveAdminClient.Instance.GetAvailableProjectAncestors(project.Id).LastOrDefault();
    547535          HiveAdminClient.Delete(project);         
    548536          UpdateProjects();
    549         } else {
     537        } else {         
     538          SelectedProject = Content.FirstOrDefault(x => x.Id == project.ParentProjectId);
    550539          Content.Remove(project);
    551540        }
     
    553542        ShowHiveInformationDialog();
    554543      }
     544    }
     545
     546    private bool IsActive(Project project) {
     547      return DateTime.Now >= project.StartDate
     548             && (project.EndDate == null
     549                 || DateTime.Now < project.EndDate.Value);
    555550    }
    556551
  • branches/2931_OR-Tools_LP_MIP/HeuristicLab.Clients.Hive.Administrator/3.3/Views/ResourcesView.Designer.cs

    r16139 r16235  
    164164      this.treeView.DragOver += new System.Windows.Forms.DragEventHandler(this.treeSlaveGroup_DragEnterOver);
    165165      this.treeView.BeforeCheck += new System.Windows.Forms.TreeViewCancelEventHandler(this.treeSlaveGroup_BeforeCheck);
     166      this.treeView.AfterCheck += new System.Windows.Forms.TreeViewEventHandler(this.treeSlaveGroup_AfterCheck);
    166167      //
    167168      // tabSlaveGroup
  • branches/2931_OR-Tools_LP_MIP/HeuristicLab.Clients.Hive.Administrator/3.3/Views/ResourcesView.cs

    r16139 r16235  
    125125
    126126      HashSet<Guid> descendantResources = null;
     127      bool selectedRDeleteLocked = selectedResource == null
     128                              || (selectedResource.Id != Guid.Empty && (!HiveAdminClient.Instance.ResourceDescendants.TryGetValue(selectedResource.Id, out descendantResources) || descendantResources.Any()));
     129
     130      var nodes = GetCheckedNodes(treeView.Nodes).ToList();
     131      var checkedResources = nodes.Select(x => x.Tag).OfType<Resource>().ToList();
     132      bool checkedRDeleteLocked = false;
     133      for (int i = 0; !checkedRDeleteLocked && i < checkedResources.Count; i++) {
     134        if (checkedResources[i].Id != Guid.Empty &&
     135            (!HiveAdminClient.Instance.ResourceDescendants.TryGetValue(checkedResources[i].Id, out descendantResources) ||
     136             descendantResources.Any()))
     137          checkedRDeleteLocked = true;
     138      }
    127139
    128140      bool deleteLocked = locked
    129                        || !IsAdmin()
    130                        || !Content.Any()
    131                        || selectedResource == null
    132                        || (selectedResource.Id != Guid.Empty && (!HiveAdminClient.Instance.ResourceDescendants.TryGetValue(selectedResource.Id, out descendantResources) || descendantResources.Any()));
     141                          || !IsAdmin()
     142                          || !Content.Any()
     143                          || checkedResources.Any() && checkedRDeleteLocked
     144                          || !checkedResources.Any() && selectedRDeleteLocked;
    133145
    134146      bool saveLocked = locked
     
    235247    }
    236248
    237     private async void btnRemoveGroup_Click(object sender, EventArgs e) {
    238       if (selectedResource == null) return;
     249    private async void btnRemoveGroup_Click(object sender, EventArgs e) {     
     250      var nodes = GetCheckedNodes(treeView.Nodes).ToList();
     251      var checkedResources = nodes.Select(x => x.Tag).OfType<Resource>().ToList();
     252      if (selectedResource == null && !checkedResources.Any()) return;
    239253
    240254      lock (locker) {
     
    243257      }
    244258
    245       var result = MessageBox.Show(
    246         "Do you really want to delete " + selectedResource.Name + "?",
    247         "HeuristicLab Hive Administrator",
    248         MessageBoxButtons.YesNo,
    249         MessageBoxIcon.Question);
    250       if (result == DialogResult.Yes) {
    251         await SecurityExceptionUtil.TryAsyncAndReportSecurityExceptions(
    252           action: () => {
    253             RemoveResource(selectedResource);
    254           });
    255 
    256         OnContentChanged();
    257         SetEnabledStateOfControls();
    258       }
     259      if (checkedResources.Count > 0) {
     260        var result = MessageBox.Show(
     261          "Do you really want to delete all " + checkedResources.Count + " checked resources?",
     262          "HeuristicLab Hive Administrator",
     263          MessageBoxButtons.YesNo,
     264          MessageBoxIcon.Question);
     265        if (result == DialogResult.Yes) {
     266          await SecurityExceptionUtil.TryAsyncAndReportSecurityExceptions(
     267            action: () => {
     268              RemoveResource(checkedResources);
     269            });
     270        }
     271      } else {
     272        var res = checkedResources.Any() ? checkedResources.First() : selectedResource;
     273        var result = MessageBox.Show(
     274          "Do you really want to delete the selected resource " + res.Name + "?",
     275          "HeuristicLab Hive Administrator",
     276          MessageBoxButtons.YesNo,
     277          MessageBoxIcon.Question);
     278        if (result == DialogResult.Yes) {
     279          await SecurityExceptionUtil.TryAsyncAndReportSecurityExceptions(
     280            action: () => {
     281              RemoveResource(res);
     282            });
     283        }
     284      }
     285
     286      OnContentChanged();
     287      SetEnabledStateOfControls();
    259288    }
    260289
     
    289318
    290319    private void treeSlaveGroup_BeforeCheck(object sender, TreeViewCancelEventArgs e) {
    291       if (e.Node == ungroupedGroupNode) {
     320      if (!IsAdmin() || e.Node == ungroupedGroupNode) {
    292321        e.Cancel = true;
    293322      } else {
     
    297326        }
    298327      }
     328    }
     329
     330    private void treeSlaveGroup_AfterCheck(object sender, TreeViewEventArgs e) {
     331      SetEnabledStateOfControls();
    299332    }
    300333
     
    535568        if (resource.Id != Guid.Empty) {
    536569          SelectedResource = HiveAdminClient.Instance.GetAvailableResourceAncestors(resource.Id).LastOrDefault();
    537           HiveAdminClient.Delete(resource);
     570
     571          // deal with all new, but not yet saved resources
     572          var newResources = Content.Where(x => x.ParentResourceId == resource.Id).ToList();
     573          if (newResources.Any(x => x.Id != Guid.Empty)) return;
     574          foreach (var nr in newResources) Content.Remove(nr);
     575
     576          HiveAdminClient.Delete(resource);         
    538577          UpdateResources();
    539578        } else {
    540           SelectedResource = null;
     579          SelectedResource = Content.FirstOrDefault(x => x.Id == resource.ParentResourceId);
    541580          Content.Remove(resource);
    542581        }
     582      } catch (AnonymousUserException) {
     583        ShowHiveInformationDialog();
     584      }
     585    }
     586
     587    private void RemoveResource(IEnumerable<Resource> resources) {
     588      if (resources == null || !resources.Any()) return;
     589
     590      var ids = resources.Select(x => x.Id).ToList();     
     591      try {
     592        bool update = false;
     593        foreach (var r in resources) {         
     594          if (r.Id != Guid.Empty)  {
     595            if(r.Id == SelectedResource.Id)
     596              SelectedResource = HiveAdminClient.Instance.GetAvailableResourceAncestors(r.Id).LastOrDefault();
     597
     598            // deal with all new, but not yet saved resources
     599            var newResources = Content.Where(x => x.ParentResourceId == r.Id).ToList();
     600            if (newResources.Any(x => x.Id != Guid.Empty)) return;
     601            foreach (var nr in newResources) Content.Remove(nr);
     602
     603            HiveAdminClient.Delete(r);
     604            update = true;
     605          } else {
     606            if (r.Id == SelectedResource.Id)
     607              SelectedResource = Content.FirstOrDefault(x => x.Id == r.ParentResourceId);
     608            Content.Remove(r);
     609          }
     610        }
     611        if (update) UpdateResources();
    543612      } catch (AnonymousUserException) {
    544613        ShowHiveInformationDialog();
     
    678747    private Dictionary<Guid, HashSet<Resource>> GetResourceDescendants() {
    679748      var resourceDescendants = new Dictionary<Guid, HashSet<Resource>>();
     749      //var resources = Content.Where(x => x.Id != Guid.Empty).Union(HiveAdminClient.Instance.DisabledParentResources).ToList();     
    680750      var resources = Content.Union(HiveAdminClient.Instance.DisabledParentResources).ToList();
    681751
    682       foreach (var r in resources) resourceDescendants.Add(r.Id, new HashSet<Resource>());
     752      foreach (var r in resources) {
     753        if(!resourceDescendants.ContainsKey(r.Id))
     754          resourceDescendants.Add(r.Id, new HashSet<Resource>());
     755      }
    683756      foreach (var r in resources) {
    684757        var parentResourceId = r.ParentResourceId;
  • branches/2931_OR-Tools_LP_MIP/HeuristicLab.Clients.Hive.Administrator/3.3/Views/ScheduleView.cs

    r16139 r16235  
    227227      base.SetEnabledStateOfControls();
    228228      bool enabled = Content != null && !Locked;
     229      dtpFrom.Enabled = enabled;
     230      dtpTo.Enabled = enabled;
     231      chbade.Enabled = enabled;
    229232      btCreate.Enabled = enabled;
    230       btbDelete.Enabled = enabled;
     233      btbDelete.Enabled = enabled;     
     234      btnRecurrence.Enabled = enabled;
    231235      btnClearCal.Enabled = enabled;
    232       btnRecurrence.Enabled = enabled;
    233236      btnSaveCal.Enabled = enabled;
    234237    }
Note: See TracChangeset for help on using the changeset viewer.