Free cookie consent management tool by TermsFeed Policy Generator

source: branches/RefactorPluginInfrastructure-2522/HeuristicLab.Clients.Access.Views/3.3/ClientViews/ClientRegistrationDialog.cs @ 13338

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

#2522:

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