Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Clients.Access.Views/3.3/ClientViews/ClientRegistrationDialog.cs @ 15962

Last change on this file since 15962 was 15583, checked in by swagner, 7 years ago

#2640: Updated year of copyrights in license headers

File size: 4.1 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
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
22using System;
23using System.IO;
24using System.Reflection;
25using System.Threading.Tasks;
26using System.Windows.Forms;
27
28namespace HeuristicLab.Clients.Access.Views {
29  public partial class ClientRegistrationDialog : Form {
30    public ClientRegistrationDialog() {
31      InitializeComponent();
32
33      try {
34        using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(typeof(ClientRegistrationDialog), "Documents.ClientRegistrationInfo.rtf"))
35          richTextBox1.LoadFile(stream, RichTextBoxStreamType.RichText);
36      }
37      catch (Exception) { }
38    }
39
40    private void btnCollectInformation_Click(object sender, EventArgs e) {
41      progressBar.Visible = true;
42      progressBar.Style = ProgressBarStyle.Marquee;
43      btnCollectInformation.Enabled = false;
44      btnRegisterClient.Enabled = false;
45
46      Task<Client> task = Task.Factory.StartNew<Client>(ClientInformationUtils.CollectClientInformation);
47      task.ContinueWith(c => DisplayContent(c.Result));
48    }
49
50    private void DisplayContent(Client client) {
51      if (!this.Disposing) {
52        if (this.InvokeRequired) {
53          Invoke(new Action<Client>(DisplayContent), client);
54        } else {
55          clientView.Content = client;
56          progressBar.Visible = false;
57          btnCollectInformation.Enabled = true;
58          btnRegisterClient.Enabled = true;
59        }
60      }
61    }
62
63    private void AddClient() {
64      AccessClient.CallAccessService(x => x.AddClient(clientView.Content));
65    }
66
67    private void RefreshClientInformation(Task task) {
68      ClientInformation.Instance.Refresh();
69    }
70
71    private void btnRegisterClient_Click(object sender, EventArgs e) {
72      progressBar.Visible = true;
73      btnRegisterClient.Enabled = false;
74      btnCollectInformation.Enabled = false;
75      btnCancel.Enabled = false;
76
77      Task task = Task.Factory.StartNew(AddClient);
78      task.ContinueWith(RefreshClientInformation, TaskContinuationOptions.NotOnFaulted);
79      task.ContinueWith(FinishRegistration, TaskContinuationOptions.NotOnFaulted);
80      task.ContinueWith(HandleRegistrationError, TaskContinuationOptions.OnlyOnFaulted);
81    }
82
83    private void FinishRegistration(Task task) {
84      if (!this.Disposing) {
85        if (this.InvokeRequired) {
86          Invoke(new Action<Task>(FinishRegistration), task);
87        } else {
88          progressBar.Visible = false;
89          btnCollectInformation.Enabled = true;
90          btnCancel.Enabled = true;
91          MessageBox.Show("Your HeuristicLab client has been registered successfully.", "HeuristicLab Registration", MessageBoxButtons.OK, MessageBoxIcon.Information);
92        }
93      }
94    }
95
96    private void HandleRegistrationError(Task task) {
97      if (!this.Disposing) {
98        if (this.InvokeRequired) {
99          Invoke(new Action<Task>(HandleRegistrationError), task);
100        } else {
101          progressBar.Visible = false;
102          btnRegisterClient.Enabled = true;
103          btnCollectInformation.Enabled = true;
104          btnCancel.Enabled = true;
105          PluginInfrastructure.ErrorHandling.ShowErrorDialog(task.Exception);
106        }
107      }
108    }
109
110    private void richTextBox1_LinkClicked(object sender, LinkClickedEventArgs e) {
111      System.Diagnostics.Process.Start(e.LinkText);
112    }
113  }
114}
Note: See TracBrowser for help on using the repository browser.