[8042] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[15973] | 3 | * Copyright (C) 2002-2018 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.IO;
|
---|
| 24 | using System.Reflection;
|
---|
| 25 | using System.Threading.Tasks;
|
---|
| 26 | using System.Windows.Forms;
|
---|
[13338] | 27 | using HeuristicLab.MainForm;
|
---|
[8042] | 28 |
|
---|
| 29 | namespace 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;
|
---|
[13338] | 106 | MainFormManager.MainForm.ShowError(task.Exception.Message, task.Exception);
|
---|
[8042] | 107 | }
|
---|
| 108 | }
|
---|
| 109 | }
|
---|
| 110 |
|
---|
| 111 | private void richTextBox1_LinkClicked(object sender, LinkClickedEventArgs e) {
|
---|
| 112 | System.Diagnostics.Process.Start(e.LinkText);
|
---|
| 113 | }
|
---|
| 114 | }
|
---|
| 115 | }
|
---|