[7534] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2012 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 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.ServiceModel.Security;
|
---|
| 24 |
|
---|
| 25 | namespace HeuristicLab.Clients.Access {
|
---|
| 26 | public sealed class ClientInformation {
|
---|
| 27 | private static ClientInformation instance;
|
---|
| 28 | public static ClientInformation Instance {
|
---|
| 29 | get {
|
---|
| 30 | if (instance == null) instance = new ClientInformation();
|
---|
| 31 | return instance;
|
---|
| 32 | }
|
---|
| 33 | }
|
---|
| 34 |
|
---|
| 35 | private Client clientInfo;
|
---|
| 36 | public Client ClientInfo {
|
---|
| 37 | get { return clientInfo; }
|
---|
| 38 | }
|
---|
| 39 |
|
---|
| 40 | private bool clientExists = false;
|
---|
| 41 | public bool ClientExists {
|
---|
| 42 | get { return clientExists; }
|
---|
| 43 | }
|
---|
| 44 |
|
---|
| 45 | private bool errorOccured = false;
|
---|
| 46 | public bool ErrorOccured {
|
---|
| 47 | get { return errorOccured; }
|
---|
| 48 | }
|
---|
| 49 |
|
---|
| 50 | private Exception occuredException;
|
---|
| 51 | public Exception OccuredException {
|
---|
| 52 | get { return occuredException; }
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | private ClientInformation() {
|
---|
[7553] | 56 | if (ClientInformationUtils.IsClientHeuristicLab()) {
|
---|
| 57 | FetchClientInformationFromServer();
|
---|
| 58 | } else {
|
---|
| 59 | // this means we are executed by an Hive slave, therefore we just get our machine id (e.g. for OKB Algs)
|
---|
| 60 | // because the slave has already done the registration process
|
---|
| 61 | GenerateLocalClientConfig();
|
---|
| 62 | }
|
---|
[7534] | 63 | }
|
---|
| 64 |
|
---|
[7553] | 65 | private void GenerateLocalClientConfig() {
|
---|
| 66 | clientExists = true;
|
---|
| 67 | errorOccured = false;
|
---|
| 68 | occuredException = null;
|
---|
| 69 | clientInfo = new Client();
|
---|
| 70 | clientInfo.Id = ClientInformationUtils.GetUniqueMachineId();
|
---|
| 71 | }
|
---|
| 72 |
|
---|
[7534] | 73 | private void FetchClientInformationFromServer() {
|
---|
| 74 | Guid clientId = ClientInformationUtils.GetUniqueMachineId();
|
---|
| 75 |
|
---|
| 76 | try {
|
---|
[7536] | 77 | AccessClient.CallAccessService(x => clientInfo = x.GetClient(clientId));
|
---|
[7534] | 78 | if (clientInfo != null)
|
---|
| 79 | clientExists = true;
|
---|
| 80 | errorOccured = false;
|
---|
| 81 | occuredException = null;
|
---|
| 82 | }
|
---|
| 83 | catch (MessageSecurityException e) {
|
---|
| 84 | //wrong username or password
|
---|
| 85 | clientExists = false;
|
---|
| 86 | errorOccured = true;
|
---|
| 87 | occuredException = e;
|
---|
| 88 | }
|
---|
| 89 | catch (Exception e) {
|
---|
| 90 | clientExists = false;
|
---|
| 91 | errorOccured = true;
|
---|
| 92 | occuredException = e;
|
---|
| 93 | }
|
---|
| 94 | }
|
---|
| 95 |
|
---|
| 96 | public void Refresh() {
|
---|
| 97 | FetchClientInformationFromServer();
|
---|
| 98 | }
|
---|
| 99 | }
|
---|
| 100 | }
|
---|