Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PersistenceReintegration/HeuristicLab.Clients.Access.Views/3.3/ClientViews/ClientRegistrationDialog.cs @ 15866

Last change on this file since 15866 was 14927, checked in by gkronber, 8 years ago

#2520: changed all usages of StorableClass to use StorableType with an auto-generated GUID (did not add StorableType to other type definitions yet)

File size: 4.1 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2016 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      } catch (Exception) { }
37    }
38
39    private void btnCollectInformation_Click(object sender, EventArgs e) {
40      progressBar.Visible = true;
41      progressBar.Style = ProgressBarStyle.Marquee;
42      btnCollectInformation.Enabled = false;
43      btnRegisterClient.Enabled = false;
44
45      Task<Client> task = Task.Factory.StartNew<Client>(ClientInformationUtils.CollectClientInformation);
46      task.ContinueWith(c => DisplayContent(c.Result));
47    }
48
49    private void DisplayContent(Client client) {
50      if (!this.Disposing) {
51        if (this.InvokeRequired) {
52          Invoke(new Action<Client>(DisplayContent), client);
53        } else {
54          clientView.Content = client;
55          progressBar.Visible = false;
56          btnCollectInformation.Enabled = true;
57          btnRegisterClient.Enabled = true;
58        }
59      }
60    }
61
62    private void AddClient() {
63      AccessClient.CallAccessService(x => x.AddClient(clientView.Content));
64    }
65
66    private void RefreshClientInformation(Task task) {
67      ClientInformation.Instance.Refresh();
68    }
69
70    private void btnRegisterClient_Click(object sender, EventArgs e) {
71      progressBar.Visible = true;
72      btnRegisterClient.Enabled = false;
73      btnCollectInformation.Enabled = false;
74      btnCancel.Enabled = false;
75
76      Task task = Task.Factory.StartNew(AddClient);
77      task.ContinueWith(RefreshClientInformation, TaskContinuationOptions.NotOnFaulted);
78      task.ContinueWith(FinishRegistration, TaskContinuationOptions.NotOnFaulted);
79      task.ContinueWith(HandleRegistrationError, TaskContinuationOptions.OnlyOnFaulted);
80    }
81
82    private void FinishRegistration(Task task) {
83      if (!this.Disposing) {
84        if (this.InvokeRequired) {
85          Invoke(new Action<Task>(FinishRegistration), task);
86        } else {
87          progressBar.Visible = false;
88          btnCollectInformation.Enabled = true;
89          btnCancel.Enabled = true;
90          MessageBox.Show("Your HeuristicLab client has been registered successfully.", "HeuristicLab Registration", MessageBoxButtons.OK, MessageBoxIcon.Information);
91        }
92      }
93    }
94
95    private void HandleRegistrationError(Task task) {
96      if (!this.Disposing) {
97        if (this.InvokeRequired) {
98          Invoke(new Action<Task>(HandleRegistrationError), task);
99        } else {
100          progressBar.Visible = false;
101          btnRegisterClient.Enabled = true;
102          btnCollectInformation.Enabled = true;
103          btnCancel.Enabled = true;
104          PluginInfrastructure.ErrorHandling.ShowErrorDialog(task.Exception);
105        }
106      }
107    }
108
109    private void richTextBox1_LinkClicked(object sender, LinkClickedEventArgs e) {
110      System.Diagnostics.Process.Start(e.LinkText);
111    }
112  }
113}
Note: See TracBrowser for help on using the repository browser.