[8042] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[16565] | 3 | * Copyright (C) 2002-2019 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[8042] | 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.Windows.Forms;
|
---|
[16186] | 24 | using HeuristicLab.MainForm;
|
---|
| 25 | using HeuristicLab.MainForm.WindowsForms;
|
---|
[8042] | 26 |
|
---|
| 27 | namespace HeuristicLab.Clients.Access.Views {
|
---|
[16186] | 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 |
|
---|
[8042] | 36 | public RefreshableLightweightUserInformationView() {
|
---|
| 37 | InitializeComponent();
|
---|
| 38 | }
|
---|
| 39 |
|
---|
[16186] | 40 | protected override void OnContentChanged() {
|
---|
| 41 | base.OnContentChanged();
|
---|
| 42 | lightweightUserInformationView.Content = Content;
|
---|
[8042] | 43 | }
|
---|
| 44 |
|
---|
[16186] | 45 | protected override void SetEnabledStateOfControls() {
|
---|
| 46 | base.SetEnabledStateOfControls();
|
---|
[16187] | 47 | this.Locked = true;
|
---|
[16186] | 48 | refreshButton.Enabled = Content != null;
|
---|
[8042] | 49 | }
|
---|
| 50 |
|
---|
[16186] | 51 | protected override void DeregisterContentEvents() {
|
---|
| 52 | Refreshing -= new EventHandler(Content_Refreshing);
|
---|
| 53 | Refreshed -= new EventHandler(Content_Refreshed);
|
---|
| 54 | base.DeregisterContentEvents();
|
---|
[8042] | 55 | }
|
---|
| 56 |
|
---|
[16186] | 57 | protected override void RegisterContentEvents() {
|
---|
| 58 | base.RegisterContentEvents();
|
---|
| 59 | Refreshing += new EventHandler(Content_Refreshing);
|
---|
| 60 | Refreshed += new EventHandler(Content_Refreshed);
|
---|
| 61 | }
|
---|
| 62 |
|
---|
| 63 | protected void Content_Refreshing(object sender, EventArgs e) {
|
---|
[8042] | 64 | if (InvokeRequired) {
|
---|
| 65 | Invoke(new EventHandler(Content_Refreshing), sender, e);
|
---|
| 66 | } else {
|
---|
[16186] | 67 | Cursor = Cursors.AppStarting;
|
---|
| 68 | refreshButton.Enabled = false;
|
---|
| 69 |
|
---|
[8042] | 70 | lightweightUserInformationView.Enabled = false;
|
---|
| 71 | }
|
---|
| 72 | }
|
---|
| 73 |
|
---|
[16186] | 74 | protected void Content_Refreshed(object sender, EventArgs e) {
|
---|
[8042] | 75 | if (InvokeRequired) {
|
---|
| 76 | Invoke(new EventHandler(Content_Refreshed), sender, e);
|
---|
| 77 | } else {
|
---|
[16186] | 78 | Cursor = Cursors.Default;
|
---|
| 79 | refreshButton.Enabled = true;
|
---|
| 80 |
|
---|
[8042] | 81 | lightweightUserInformationView.Enabled = true;
|
---|
| 82 | if (!UserInformation.Instance.UserExists) {
|
---|
| 83 | MessageBox.Show("Couldn't fetch user information from the server." + Environment.NewLine +
|
---|
| 84 | "Please verify that you have an existing user and that your user name and password is correct. ", "HeuristicLab Access Service", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
---|
| 85 | lightweightUserInformationView.Content = null;
|
---|
| 86 | } else {
|
---|
[16186] | 87 | lightweightUserInformationView.Content = Content;
|
---|
[8042] | 88 | }
|
---|
| 89 | }
|
---|
| 90 | }
|
---|
| 91 |
|
---|
[16186] | 92 | void lightweightUserInformationView_Changed(object sender, EventArgs e) {
|
---|
| 93 | // nothing to do
|
---|
[8042] | 94 | }
|
---|
[16186] | 95 |
|
---|
| 96 | private void RefreshUserData() {
|
---|
| 97 | UserInformation.Instance.Refresh();
|
---|
| 98 | lightweightUserInformationView.UserInformationChanged += new EventHandler(lightweightUserInformationView_Changed);
|
---|
| 99 | }
|
---|
| 100 |
|
---|
| 101 | private void RefreshData() {
|
---|
| 102 | ExecuteActionAsync(RefreshUserData, PluginInfrastructure.ErrorHandling.ShowErrorDialog);
|
---|
| 103 | }
|
---|
| 104 |
|
---|
| 105 | public void ManualRefresh() {
|
---|
| 106 | RefreshData();
|
---|
| 107 | }
|
---|
| 108 |
|
---|
| 109 | protected void refreshButton_Click(object sender, System.EventArgs e) {
|
---|
| 110 | RefreshData();
|
---|
| 111 | }
|
---|
| 112 |
|
---|
| 113 | public void ExecuteActionAsync(Action action, Action<Exception> exceptionCallback) {
|
---|
| 114 | var call = new Func<Exception>(delegate () {
|
---|
| 115 | try {
|
---|
| 116 | OnRefreshing();
|
---|
| 117 | action();
|
---|
| 118 | } catch (Exception ex) {
|
---|
| 119 | return ex;
|
---|
| 120 | } finally {
|
---|
| 121 | OnRefreshed();
|
---|
| 122 | }
|
---|
| 123 | return null;
|
---|
| 124 | });
|
---|
| 125 | call.BeginInvoke(delegate (IAsyncResult result) {
|
---|
| 126 | Exception ex = call.EndInvoke(result);
|
---|
| 127 | if (ex != null) exceptionCallback(ex);
|
---|
| 128 | }, null);
|
---|
| 129 | }
|
---|
| 130 |
|
---|
| 131 | #region Events
|
---|
| 132 | public event EventHandler Refreshing;
|
---|
| 133 | private void OnRefreshing() {
|
---|
| 134 | EventHandler handler = Refreshing;
|
---|
| 135 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
| 136 | }
|
---|
| 137 | public event EventHandler Refreshed;
|
---|
| 138 | private void OnRefreshed() {
|
---|
| 139 | EventHandler handler = Refreshed;
|
---|
| 140 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
| 141 | }
|
---|
| 142 | #endregion
|
---|
[8042] | 143 | }
|
---|
| 144 | }
|
---|