[8042] | 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 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.ServiceModel.Security;
|
---|
| 24 |
|
---|
| 25 | namespace HeuristicLab.Clients.Access {
|
---|
| 26 | public sealed class UserInformation {
|
---|
[8043] | 27 | public const string AdministratorRoleName = "AccessService Administrator";
|
---|
| 28 |
|
---|
[8042] | 29 | private static UserInformation instance;
|
---|
| 30 | public static UserInformation Instance {
|
---|
| 31 | get {
|
---|
| 32 | if (instance == null) instance = new UserInformation();
|
---|
| 33 | return instance;
|
---|
| 34 | }
|
---|
| 35 | }
|
---|
| 36 |
|
---|
| 37 | private string userName;
|
---|
| 38 | public string UserName {
|
---|
| 39 | get { return userName; }
|
---|
| 40 | }
|
---|
| 41 |
|
---|
| 42 | private bool userExists = false;
|
---|
| 43 | public bool UserExists {
|
---|
| 44 | get { return userExists; }
|
---|
| 45 | }
|
---|
| 46 |
|
---|
| 47 | private LightweightUser user;
|
---|
| 48 | public LightweightUser User {
|
---|
| 49 | get { return user; }
|
---|
| 50 | }
|
---|
| 51 |
|
---|
| 52 | private bool errorOccured;
|
---|
| 53 | public bool ErrorOccured {
|
---|
| 54 | get { return errorOccured; }
|
---|
| 55 | }
|
---|
| 56 |
|
---|
| 57 | private Exception occuredException;
|
---|
| 58 | public Exception OccuredException {
|
---|
| 59 | get { return occuredException; }
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | private UserInformation() {
|
---|
| 63 | //this blocks, so there should be anywhere in the Optimizer startup process
|
---|
| 64 | //a call to FetchUserInformationFromServerAsync which is non-blocking
|
---|
| 65 | FetchUserInformationFromServer();
|
---|
| 66 | }
|
---|
| 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 | }
|
---|
| 94 | }
|
---|
| 95 | }
|
---|