Esempio n. 1
0
        internal async Task HandleCloseSessionRequest(CloseSessionParams closeSessionParams, RequestContext <CloseSessionResponse> context)
        {
            Logger.Write(LogLevel.Verbose, "HandleCloseSessionRequest");
            Func <Task <CloseSessionResponse> > closeSession = () =>
            {
                Validate.IsNotNull(nameof(closeSessionParams), closeSessionParams);
                Validate.IsNotNull(nameof(context), context);
                return(Task.Factory.StartNew(() =>
                {
                    string uri = closeSessionParams.SessionId;
                    ObjectExplorerSession session = null;
                    bool success = false;
                    if (!sessionMap.TryGetValue(uri, out session))
                    {
                        Logger.Write(LogLevel.Verbose, $"Cannot close object explorer session. Couldn't find session for uri. {uri} ");
                    }

                    if (session != null)
                    {
                        // refresh the nodes for given node path
                        CloseSession(uri);
                        success = true;
                    }

                    var response = new CloseSessionResponse()
                    {
                        Success = success, SessionId = uri
                    };
                    return response;
                }));
            };

            await HandleRequestAsync(closeSession, context, "HandleCloseSessionRequest");
        }
        public ResponseBase Any(CloseSession request)
        {
            _logger.Log(EErrorType.Info, " ****** Call start: CloseSession");
            CloseSessionResponse response = new CloseSessionResponse();

            try
            {
                _logger.Log(EErrorType.Info, string.Format("Closing Session: {0}", request.SessionToken));
                Interfaces.DAL.SessionInfo sinfo = new Interfaces.DAL.SessionInfo();
                sinfo.SessionEnd = DateTime.UtcNow;
                sinfo.SessionId  = request.SessionToken;

                _dal.CloseSession(sinfo);

                response.Success = true;
            }
            catch (Exception ex)
            {
                _logger.Log(ex);
                response.Success = false;
                response.Errors.Add(new Error()
                {
                    Code = EErrorCodes.GeneralError, Type = EErrorType.Error, Message = string.Format("Unexpected error: {0}", ex.Message)
                });
            }

            _logger.Log(EErrorType.Info, " ****** Call end: CloseSession");

            return(response);
        }
Esempio n. 3
0
        public void CloseSession_Sussess(string name)
        {
            RunInitSql(name, "ConnectionStringAccounts");

            CloseSession request = PrepareRequest <CloseSession>(name);

            CloseSessionResponse response = Post <CloseSession, CloseSessionResponse>("CloseSession", request);

            RunFinalizeSql(name, "ConnectionStringAccounts");

            Assert.AreEqual(response.Success, true, "Session was not closed");
            Assert.IsEmpty(response.Errors, "Errors are not empty");
        }
Esempio n. 4
0
        protected void CloseSession(string url)
        {
            // Initializing session
            using (var accountClient = new JsonServiceClient(url))
            {
                CloseSession reqInit = new CloseSession();
                reqInit.RequestID    = System.Guid.NewGuid().ToString();
                reqInit.SessionToken = SessionToken;

                CloseSessionResponse resClose = accountClient.Post <CloseSessionResponse>("CloseSession", reqInit);

                if (resClose.Success)
                {
                    SessionToken = null;
                }
                else
                {
                    throw new Exception(string.Format("CloseSession call error:{0}", resClose.Errors[0].Code));
                }
            }
        }
Esempio n. 5
0
        public void GetSessionInfo_Closed(string name)
        {
            RunInitSql(name, "ConnectionStringAccounts");

            // 1. initializing the session
            InitSession initReq = new InitSession()
            {
                AccountKey   = ConfigurationManager.AppSettings["AccountKey"],
                RequestID    = "D3770630-9532-457D-8EBB-DBF99F6A23D3",
                SessionToken = null
            };

            InitSessionResponse initResp = Post <InitSession, InitSessionResponse>("InitSession", initReq);

            string sessionToken = initResp.SessionToken;

            // 2. closing session
            CloseSession closeReq = new CloseSession()
            {
                SessionToken = sessionToken
            };

            CloseSessionResponse closeRes = Post <CloseSession, CloseSessionResponse>("CloseSession", closeReq);

            // 3. getting session information
            GetSessionInfo getSesionInfo = PrepareRequest <GetSessionInfo>(name);

            getSesionInfo.SessionToken = sessionToken;

            GetSessionInfoResponse sessionInfo = Post <GetSessionInfo, GetSessionInfoResponse>("GetSessionInfo", getSesionInfo);

            RunFinalizeSql(name, "ConnectionStringAccounts");

            Assert.AreEqual(sessionInfo.Success, true, "Session was not found");
            Assert.AreNotEqual(sessionInfo.Payload.SessionStart, DateTime.MinValue, "SessionStart time was not provided");
            Assert.AreNotEqual(sessionInfo.Payload.SessionEnd, DateTime.MinValue, "SessionEnd time was not provided");
            Assert.IsNotEmpty(sessionInfo.Errors, "Errors are empty");
            Assert.AreEqual(sessionInfo.Errors[0].Type, EErrorType.Warning, "Warning of closed session is expected");
            Assert.AreEqual(sessionInfo.Errors[0].Code, EErrorCodes.SessionClosed, "Invalid code returned");
        }
        public EErrorCodes CloseSession()
        {
            EErrorCodes result = EErrorCodes.GeneralError;

            try
            {
                if (SessionToken != null)
                {
                    CloseSession reqInit = new CloseSession();
                    reqInit.RequestID    = System.Guid.NewGuid().ToString();
                    reqInit.SessionToken = SessionToken;

                    CloseSessionResponse resInit = Post <CloseSession, CloseSessionResponse>("/api/accounts/CloseSession", reqInit);

                    if (resInit.Success)
                    {
                        SessionToken = null;
                        result       = EErrorCodes.Success;
                    }
                    else
                    {
                        result = resInit.Errors[0].Code;
                    }
                }
                else
                {
                    result = EErrorCodes.Success;
                }
            }
            catch (Exception ex)
            {
                _lastError = ex;
                result     = EErrorCodes.GeneralError;
            }

            return(result);
        }
Esempio n. 7
0
        public async Task <CloseSessionResponse> CloseSessionAsync(CloseSessionRequest closeSessionRequest)
        {
            UpdateRequestHeader(closeSessionRequest, true, "CloseSession");
            CloseSessionResponse closeSessionResponse = null;

            try
            {
                if (UseTransportChannel)
                {
                    var serviceResponse = await Task <IServiceResponse> .Factory.FromAsync(TransportChannel.BeginSendRequest, TransportChannel.EndSendRequest, closeSessionRequest, null).ConfigureAwait(false);

                    if (serviceResponse == null)
                    {
                        throw new ServiceResultException(StatusCodes.BadUnknownResponse);
                    }
                    ValidateResponse(serviceResponse.ResponseHeader);
                    closeSessionResponse = (CloseSessionResponse)serviceResponse;
                }
                else
                {
                    var closeSessionResponseMessage = await Task <CloseSessionResponseMessage> .Factory.FromAsync(InnerChannel.BeginCloseSession, InnerChannel.EndCloseSession, new CloseSessionMessage(closeSessionRequest), null).ConfigureAwait(false);

                    if (closeSessionResponseMessage == null || closeSessionResponseMessage.CloseSessionResponse == null)
                    {
                        throw new ServiceResultException(StatusCodes.BadUnknownResponse);
                    }
                    closeSessionResponse = closeSessionResponseMessage.CloseSessionResponse;
                    ValidateResponse(closeSessionResponse.ResponseHeader);
                }
            }
            finally
            {
                RequestCompleted(closeSessionRequest, closeSessionResponse, "CloseSession");
            }
            return(closeSessionResponse);
        }
Esempio n. 8
0
        /// <summary>
        /// Invokes the CloseSession service.
        /// </summary>
        public IServiceResponse CloseSession(IServiceRequest incoming)
        {
            CloseSessionResponse response = null;

            CloseSessionRequest request = (CloseSessionRequest)incoming;


            response = new CloseSessionResponse();

            response.ResponseHeader = ServerInstance.CloseSession(
               request.RequestHeader,
               request.DeleteSubscriptions);


            return response;
        }
Esempio n. 9
0
        /// <summary>
        /// Invokes the CloseSession service.
        /// </summary>
        public IServiceResponse CloseSession(IServiceRequest incoming)
        {
            CloseSessionResponse response = null;

            try
            {
                // OnRequestReceived(incoming);

                CloseSessionRequest request = (CloseSessionRequest)incoming;


                response = new CloseSessionResponse();

                response.ResponseHeader = ServerInstance.CloseSession(
                   request.RequestHeader,
                   request.DeleteSubscriptions);

            }
            finally
            {
                // OnResponseSent(response);
            }

            return response;
        }
Esempio n. 10
0
        /// <summary>
        /// Initializes the message with a service fault.
        /// </summary>
        public CloseSessionResponseMessage(ServiceFault ServiceFault)
        {
            this.CloseSessionResponse = new CloseSessionResponse();

            if (ServiceFault != null)
            {
                this.CloseSessionResponse.ResponseHeader = ServiceFault.ResponseHeader;
            }
        }
Esempio n. 11
0
 /// <summary>
 /// Initializes the message with the body.
 /// </summary>
 public CloseSessionResponseMessage(CloseSessionResponse CloseSessionResponse)
 {
     this.CloseSessionResponse = CloseSessionResponse;
 }
Esempio n. 12
0
        /// <summary cref="IServiceMessage.CreateResponse" />
        public object CreateResponse(IServiceResponse response)
        {
            CloseSessionResponse body = response as CloseSessionResponse;

            if (body == null)
            {
                body = new CloseSessionResponse();
                body.ResponseHeader = ((ServiceFault)response).ResponseHeader;
            }

            return new CloseSessionResponseMessage(body);
        }