Free cookie consent management tool by TermsFeed Policy Generator

source: branches/ClientUserManagement/HeuristicLab.Clients.Access/3.3/ClientInformation.cs @ 7982

Last change on this file since 7982 was 7982, checked in by ascheibe, 12 years ago

#1648

  • always update the client information
  • allow a normal user to change the FullName and E-Mail
File size: 3.2 KB
Line 
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
22using System;
23using System.ServiceModel.Security;
24
25namespace 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() {
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      }
63    }
64
65    private void GenerateLocalClientConfig() {
66      clientExists = true;
67      errorOccured = false;
68      occuredException = null;
69      clientInfo = new Client();
70      clientInfo.Id = ClientInformationUtils.GetUniqueMachineId();
71    }
72
73    private void FetchClientInformationFromServer() {
74      Guid clientId = ClientInformationUtils.GetUniqueMachineId();
75
76      try {
77        AccessClient.CallAccessService(x => clientInfo = x.GetClient(clientId));
78        if (clientInfo != null) {
79          clientExists = true;
80          clientInfo.HeuristicLabVersion = ClientInformationUtils.GetHLVersion();
81          AccessClient.CallAccessService(x => x.UpdateClient(clientInfo));
82        }
83        errorOccured = false;
84        occuredException = null;
85      }
86      catch (MessageSecurityException e) {
87        //wrong username or password
88        clientExists = false;
89        errorOccured = true;
90        occuredException = e;
91      }
92      catch (Exception e) {
93        clientExists = false;
94        errorOccured = true;
95        occuredException = e;
96      }
97    }
98
99    public void Refresh() {
100      FetchClientInformationFromServer();
101    }
102  }
103}
Note: See TracBrowser for help on using the repository browser.