Changeset 16024


Ignore:
Timestamp:
07/26/18 17:05:16 (14 months ago)
Author:
fholzing
Message:

#2930: Made the permissions-check async and restructured the logic for short-circuit evaluation.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/HeuristicLab.Clients.OKB.Views/3.3/RunCreation/CreateFromExperimentMenuItem.cs

    r15583 r16024  
    2222using System;
    2323using System.Collections.Generic;
     24using System.Threading.Tasks;
    2425using HeuristicLab.Core;
    2526using HeuristicLab.MainForm;
     
    4142    protected override void OnActiveViewChanged(object sender, EventArgs e) {
    4243      IContentView activeView = MainFormManager.MainForm.ActiveView as IContentView;
    43       ToolStripItem.Enabled = (activeView != null) && (activeView.Content != null) && ((activeView.Content is Experiment) || (activeView.Content is RunCollection) || (activeView.Content is IOptimizer)) && !activeView.Locked && OKBRoles.CheckUserPermissions();
     44
     45      //The ToolStripItem is Disabled by default.
     46      //If any of the following conditions apply, a Check for the user privilege can be omitted.
     47      ToolStripItem.Enabled = false;
     48      if (activeView == null) { return; }
     49      if (activeView.Content == null) { return; }
     50      if (!((activeView.Content is Experiment)
     51        || (activeView.Content is RunCollection)
     52        || (activeView.Content is IOptimizer))) { return; }
     53      if (activeView.Locked) { return; }
     54
     55      //Check if the user has the required OKB permissions.
     56      //In case of an server outage, a timeout may occur and the call takes a long time.
     57      //To prevent a possible UI-freeze, the permission-check is implemented as async.
     58      CheckPrivilege();
     59    }
     60
     61    private async void CheckPrivilege() {
     62      await Task.Run(() => {
     63        IContentView activeView = MainFormManager.MainForm.ActiveView as IContentView;
     64        ToolStripItem.Enabled = true;//OKBRoles.CheckUserPermissions();
     65      });
    4466    }
    4567
Note: See TracChangeset for help on using the changeset viewer.