Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Clients.Access/3.3/UserInformation.cs @ 8042

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

#1648 integrated access service client parts into trunk

File size: 2.7 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 UserInformation {
27    private static UserInformation instance;
28    public static UserInformation Instance {
29      get {
30        if (instance == null) instance = new UserInformation();
31        return instance;
32      }
33    }
34
35    private string userName;
36    public string UserName {
37      get { return userName; }
38    }
39
40    private bool userExists = false;
41    public bool UserExists {
42      get { return userExists; }
43    }
44
45    private LightweightUser user;
46    public LightweightUser User {
47      get { return user; }
48    }
49
50    private bool errorOccured;
51    public bool ErrorOccured {
52      get { return errorOccured; }
53    }
54
55    private Exception occuredException;
56    public Exception OccuredException {
57      get { return occuredException; }
58    }
59
60    private UserInformation() {
61      //this blocks, so there should be anywhere in the Optimizer startup process
62      //a call to FetchUserInformationFromServerAsync which is non-blocking
63      FetchUserInformationFromServer();
64    }
65
66
67    private void FetchUserInformationFromServer() {
68      userName = HeuristicLab.Clients.Common.Properties.Settings.Default.UserName;
69
70      try {
71        AccessClient.CallAccessService(x => user = x.Login());
72        errorOccured = false;
73        userExists = true;
74        occuredException = null;
75      }
76      catch (MessageSecurityException e) {
77        //wrong username or password
78        errorOccured = false;
79        userExists = false;
80        occuredException = e;
81      }
82      catch (Exception e) {
83        errorOccured = true;
84        userExists = false;
85        occuredException = e;
86      }
87    }
88
89    public void Refresh() {
90      FetchUserInformationFromServer();
91    }
92  }
93}
Note: See TracBrowser for help on using the repository browser.