Free cookie consent management tool by TermsFeed Policy Generator

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

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

#1648 worked on user and client information singletons

File size: 2.5 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      FetchClientInformationFromServer();
57    }
58
59    private void FetchClientInformationFromServer() {
60      Guid clientId = ClientInformationUtils.GetUniqueMachineId();
61
62      try {
63        AccessClient.CallRunCreationService(x => clientInfo = x.GetClient(clientId));
64        if (clientInfo != null)
65          clientExists = true;
66        errorOccured = false;
67        occuredException = null;
68      }
69      catch (MessageSecurityException e) {
70        //wrong username or password
71        clientExists = false;
72        errorOccured = true;
73        occuredException = e;
74      }
75      catch (Exception e) {
76        clientExists = false;
77        errorOccured = true;
78        occuredException = e;
79      }
80    }
81
82    public void Refresh() {
83      FetchClientInformationFromServer();
84    }
85  }
86}
Note: See TracBrowser for help on using the repository browser.