Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/25/18 15:05:56 (6 years ago)
Author:
jzenisek
Message:

#2839 fixed lightweightUserInformationView

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/HeuristicLab.Clients.Access.Views/3.3/UserViews/RefreshableLightweightUserInformationView.cs

    r15583 r16186  
    2222using System;
    2323using System.Windows.Forms;
     24using HeuristicLab.MainForm;
     25using HeuristicLab.MainForm.WindowsForms;
    2426
    2527namespace HeuristicLab.Clients.Access.Views {
    26   public partial class RefreshableLightweightUserInformationView : RefreshableView {
     28  [View("RefreshableLightweightUserInformation View")]
     29  [Content(typeof(LightweightUser), false)]
     30  public partial class RefreshableLightweightUserInformationView : AsynchronousContentView {
     31    public new LightweightUser Content {
     32      get { return (LightweightUser)base.Content; }
     33      set { base.Content = value; }
     34    }
     35
    2736    public RefreshableLightweightUserInformationView() {
    2837      InitializeComponent();
     38    }
     39
     40    protected override void OnContentChanged() {
     41      base.OnContentChanged();
     42      lightweightUserInformationView.Content = Content;
     43    }
     44
     45    protected override void SetEnabledStateOfControls() {
     46      base.SetEnabledStateOfControls();
     47      refreshButton.Enabled = Content != null;
     48    }
     49
     50    protected override void DeregisterContentEvents() {
     51      Refreshing -= new EventHandler(Content_Refreshing);
     52      Refreshed -= new EventHandler(Content_Refreshed);
     53      base.DeregisterContentEvents();
     54    }
     55
     56    protected override void RegisterContentEvents() {
     57      base.RegisterContentEvents();
     58      Refreshing += new EventHandler(Content_Refreshing);
     59      Refreshed += new EventHandler(Content_Refreshed);
     60    }
     61
     62    protected void Content_Refreshing(object sender, EventArgs e) {
     63      if (InvokeRequired) {
     64        Invoke(new EventHandler(Content_Refreshing), sender, e);
     65      } else {
     66        Cursor = Cursors.AppStarting;
     67        refreshButton.Enabled = false;
     68
     69        lightweightUserInformationView.Enabled = false;
     70      }
     71    }
     72
     73    protected void Content_Refreshed(object sender, EventArgs e) {
     74      if (InvokeRequired) {
     75        Invoke(new EventHandler(Content_Refreshed), sender, e);
     76      } else {
     77        Cursor = Cursors.Default;
     78        refreshButton.Enabled = true;
     79
     80        lightweightUserInformationView.Enabled = true;
     81        if (!UserInformation.Instance.UserExists) {
     82          MessageBox.Show("Couldn't fetch user information from the server." + Environment.NewLine +
     83            "Please verify that you have an existing user and that your user name and password is correct. ", "HeuristicLab Access Service", MessageBoxButtons.OK, MessageBoxIcon.Error);
     84          lightweightUserInformationView.Content = null;
     85        } else {
     86          lightweightUserInformationView.Content = Content;
     87        }
     88      }
     89    }
     90
     91    void lightweightUserInformationView_Changed(object sender, EventArgs e) {
     92      // nothing to do
    2993    }
    3094
     
    3498    }
    3599
    36     void lightweightUserInformationView_Changed(object sender, EventArgs e) {
    37       if (!storeButton.Enabled) storeButton.Enabled = true;
     100    private void RefreshData() {
     101      ExecuteActionAsync(RefreshUserData, PluginInfrastructure.ErrorHandling.ShowErrorDialog);
    38102    }
    39103
    40     protected override void RefreshData() {
    41       Content.ExecuteActionAsync(RefreshUserData, PluginInfrastructure.ErrorHandling.ShowErrorDialog);
     104    public void ManualRefresh() {
     105      RefreshData();
    42106    }
    43107
    44     protected override void Content_Refreshing(object sender, EventArgs e) {
    45       if (InvokeRequired) {
    46         Invoke(new EventHandler(Content_Refreshing), sender, e);
    47       } else {
    48         base.Content_Refreshing(sender, e);
    49         lightweightUserInformationView.Enabled = false;
    50         storeButton.Enabled = false;
    51       }
     108    protected void refreshButton_Click(object sender, System.EventArgs e) {
     109      RefreshData();
    52110    }
    53111
    54     protected override void Content_Refreshed(object sender, EventArgs e) {
    55       if (InvokeRequired) {
    56         Invoke(new EventHandler(Content_Refreshed), sender, e);
    57       } else {
    58         base.Content_Refreshed(sender, e);
    59         lightweightUserInformationView.Enabled = true;
    60         if (!UserInformation.Instance.UserExists) {
    61           MessageBox.Show("Couldn't fetch user information from the server." + Environment.NewLine +
    62             "Please verify that you have an existing user and that your user name and password is correct. ", "HeuristicLab Access Service", MessageBoxButtons.OK, MessageBoxIcon.Error);
    63           lightweightUserInformationView.Content = null;
    64         } else {
    65           lightweightUserInformationView.Content = UserInformation.Instance.User;
     112    public void ExecuteActionAsync(Action action, Action<Exception> exceptionCallback) {
     113      var call = new Func<Exception>(delegate () {
     114        try {
     115          OnRefreshing();
     116          action();
     117        } catch (Exception ex) {
     118          return ex;
     119        } finally {
     120          OnRefreshed();
    66121        }
    67       }
     122        return null;
     123      });
     124      call.BeginInvoke(delegate (IAsyncResult result) {
     125        Exception ex = call.EndInvoke(result);
     126        if (ex != null) exceptionCallback(ex);
     127      }, null);
    68128    }
    69129
    70     private void storeButton_Click(object sender, EventArgs e) {
    71       AccessClient.Instance.ExecuteActionAsync(new Action(delegate {
    72         AccessClient.CallAccessService(x => x.UpdateLightweightUser(UserInformation.Instance.User));
    73       }), HeuristicLab.PluginInfrastructure.ErrorHandling.ShowErrorDialog);
     130    #region Events
     131    public event EventHandler Refreshing;
     132    private void OnRefreshing() {
     133      EventHandler handler = Refreshing;
     134      if (handler != null) handler(this, EventArgs.Empty);
    74135    }
     136    public event EventHandler Refreshed;
     137    private void OnRefreshed() {
     138      EventHandler handler = Refreshed;
     139      if (handler != null) handler(this, EventArgs.Empty);
     140    }
     141    #endregion
    75142  }
    76143}
Note: See TracChangeset for help on using the changeset viewer.