Exemple #1
0
        public static void Setup(bool host)
        {
            if (!host)
            {
                type = ConnectionMode.RemoteConnection;
                return;
            }

            try
            {
                ussHost     = new ServiceHost(typeof(UserSessionService));
                privateHost = new ServiceHost(typeof(PrivateUserSessionService));

                Log.Debug("Opening ServiceHost...");
                ussHost.Open();
                privateHost.Open();

                Log.Info("UserSessionService started...");
                type            = ConnectionMode.SelfHosting;
                ussInstance     = new UserSessionService();
                privateInstance = new PrivateUserSessionService();
            }
            catch (AddressAlreadyInUseException)
            {
                Log.Info("Address for UserSessionService is already in use");
                type = ConnectionMode.RemoteConnection;
            }
            catch (Exception ex)
            {
                Log.Error("Failed to start service", ex);
                type = ConnectionMode.Failure;
            }
        }
Exemple #2
0
        private String RequestAccessThroughPrivateUSS(string token, string client, string ip, CancellationTokenSource cancelToken)
        {
            IPrivateUserSessionService channel = null;

            try
            {
                var factory = new ClientFactory <IPrivateUserSessionService>();
                channel = factory.CreateLocalTcpConnection(9751, "MPExtended/UserSessionServicePrivate");

                // request access
                bool   result       = channel.RequestAccess(token, client, ip, Configuration.Authentication.Users.Select(x => x.Username).ToList());
                String selectedUser = null;

                if (result)
                {
                    while (!cancelToken.IsCancellationRequested)
                    {
                        WebAccessRequestResponse response = channel.GetAccessRequestStatus(token);
                        if (response.UserHasResponded)
                        {
                            selectedUser = response.IsAllowed ? response.Username : null;
                            break;
                        }
                        Thread.Sleep(500);
                    }
                }

                if (cancelToken.IsCancellationRequested)
                {
                    channel.CancelAccessRequest(token);
                }

                // close channel
                (channel as ICommunicationObject).Close();
                return(selectedUser);
            }
            catch (Exception ex)
            {
                Log.Error(String.Format("Failed to request access for client {0} at {1} through USS", client, ip), ex);
                return(ERROR);
            }
        }