Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 10166 was 9456, checked in by swagner, 12 years ago

Updated copyright year and added some missing license headers (#1889)

File size: 2.9 KB
RevLine 
[8042]1#region License Information
2/* HeuristicLab
[9456]3 * Copyright (C) 2002-2013 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
22using System;
23using System.ServiceModel.Security;
[8076]24using System.Threading.Tasks;
[8042]25
26namespace HeuristicLab.Clients.Access {
27  public sealed class UserInformation {
[8043]28    public const string AdministratorRoleName = "AccessService Administrator";
29
[8042]30    private static UserInformation instance;
31    public static UserInformation Instance {
32      get {
[8076]33        InitializeUserInformation();
[8042]34        return instance;
35      }
36    }
37
38    private string userName;
39    public string UserName {
40      get { return userName; }
41    }
42
43    private bool userExists = false;
44    public bool UserExists {
45      get { return userExists; }
46    }
47
48    private LightweightUser user;
49    public LightweightUser User {
50      get { return user; }
51    }
52
53    private bool errorOccured;
54    public bool ErrorOccured {
55      get { return errorOccured; }
56    }
57
58    private Exception occuredException;
59    public Exception OccuredException {
60      get { return occuredException; }
61    }
62
63    private UserInformation() {
[8076]64      if (instance == null) {
65        FetchUserInformationFromServer();
66      }
[8042]67    }
68
69    private void FetchUserInformationFromServer() {
70      userName = HeuristicLab.Clients.Common.Properties.Settings.Default.UserName;
71
72      try {
73        AccessClient.CallAccessService(x => user = x.Login());
74        errorOccured = false;
75        userExists = true;
76        occuredException = null;
77      }
78      catch (MessageSecurityException e) {
79        //wrong username or password
80        errorOccured = false;
81        userExists = false;
82        occuredException = e;
83      }
84      catch (Exception e) {
85        errorOccured = true;
86        userExists = false;
87        occuredException = e;
88      }
89    }
90
91    public void Refresh() {
92      FetchUserInformationFromServer();
93    }
[8076]94
95    private static void InitializeUserInformation() {
96      if (instance == null) instance = new UserInformation();
97    }
98
99    public static void InitializeAsync() {
100      Task.Factory.StartNew(InitializeUserInformation);
101    }
[8042]102  }
103}
Note: See TracBrowser for help on using the repository browser.