Пример #1
0
        public void SessionChange(int sessionId, SessionChangeReason evnt, SessionProperties properties)
        {
            if (evnt == SessionChangeReason.SessionLogon)
            {
                string username = ApiUtils.GetUserFromSession(sessionId).GetUsername();
                sessionTracker.UserLoggedOn(username, sessionId);
            }
            else if (evnt == SessionChangeReason.SessionLogoff)
            {
                SessionTracker.Information information = sessionTracker.GetInformation(sessionId);
                if (information == null)
                {
                    return;
                }

                try
                {
                    sessionTracker.StartedProfileUploading(information.Username);
                    using (var synchronizer = new SftpSynchronizer(information.Username, information.Password, information.Sid))
                    {
                        synchronizer.UploadProfile();
                    }
                }
                catch (Exception e)
                {
                    Log.Error(e.Message);
                    Log.Error(e.StackTrace);
                }
                finally
                {
                    sessionTracker.UserLoggedOff(information.Username, sessionId);
                }
            }
        }
Пример #2
0
        public BooleanResult AuthenticatedUserGateway(SessionProperties properties)
        {
            var userInformation = properties.GetTrackedSingle <UserInformation>();

            try
            {
                if (!sessionTracker.IsUploadingProfile(userInformation.Username))
                {
                    using (var synchronizer = new SftpSynchronizer(userInformation.Username, userInformation.Password, userInformation.SID))
                    {
                        synchronizer.DownloadProfile();
                    }
                }

                sessionTracker.UserGatewayPassed(userInformation.Username, userInformation.SID, userInformation.Password);
                return(new BooleanResult {
                    Success = true
                });
            }
            catch (Exception e)
            {
                Log.Error(e.Message);
                Log.Error(e.StackTrace);
                return(new BooleanResult {
                    Success = false, Message = e.Message
                });
            }
        }