Free cookie consent management tool by TermsFeed Policy Generator

source: branches/ClientUserManagement/HeuristicLab.Clients.Access/3.3/UserInformation.cs @ 7555

Last change on this file since 7555 was 7553, checked in by ascheibe, 13 years ago

#1648 adapted client management for use with Hive

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