Example #1
0
        public static async Task <PSALoginResponse> LoginToPSA(Context context, string username, string password, string hubAddress)
        {
            Communication.ActiveHostServer = hubAddress;

            var credentials = new PSAUserCredentials()
            {
                Username = username,
                Password = password
            };

            var request = new PSALoginRequest(credentials);

            DebugLog.LazyWrite(context, "Getting response async...");
            string response = await PSACommunication.GetResponseAsync(hubAddress, PSALoginRequest.DefaultServiceName, request.ToParameterString());

            DebugLog.LazyWrite(context, "Got response async -> " + response);
            var loginResponse = PSALoginResponse.ParseXMLString(response);

            DebugLog.LazyWrite(context, "Parsed response async!");

            if (loginResponse.Status == Com.TTS.Util.GUI.WSStatusTypes.OK)
            {
                Communication.LastSessionRenewal    = DateTime.Now;
                Communication.ActiveSessionUsername = username;
                Communication.ActiveSessionCode     = loginResponse.SessionInfo.SessionCode;
                Communication.UserCoverage          = loginResponse.Coverage;
            }

            return(loginResponse);
        }
Example #2
0
        public static async Task RenewPSASession()
        {
            if (Communication.NeedsToRenewSession(PSACredentials))
            {
                var request = new PSALoginRequest(PSACredentials);

                string response = await PSACommunication.GetResponseAsync(HubAddress, PSALoginRequest.DefaultServiceName, request.ToParameterString());

                var loginResponse = PSALoginResponse.ParseXMLString(response);

                if (loginResponse.Status != Com.TTS.Util.GUI.WSStatusTypes.OK)
                {
                    throw new UnauthorizedAccessException("Failed to reach PSA back-end. Returned message: " + loginResponse.Message + ")");
                }

                Communication.LastSessionRenewal    = DateTime.Now;
                Communication.ActiveSessionUsername = PSACredentials.Username;
                Communication.ActiveSessionCode     = loginResponse.SessionInfo.SessionCode;
                Communication.UserCoverage          = loginResponse.Coverage;
            }
        }