private void NewMessagesHandlerSender(object sender, NewChannelMessagesDelegateEventArgs args)
        {
            int i = 0;

            while (i < args.Messages.Count && sinfoResponse == null)
            {
                var m = args.Messages[i];
                GetSessionInfoResponse resp = null;
                if (m.ChannelName == Global.AccountsChannel)
                {
                    switch (m.Type)
                    {
                    case "GetSessionInfoResponse":
                        resp = JsonSerializer.DeserializeFromString(m.Payload, typeof(GetSessionInfoResponse)) as GetSessionInfoResponse;
                        if (resp != null && resp.RequestID == sinfo.RequestID)
                        {
                            Global.MQClient.DeleteMessage(m.Id);
                            sinfoResponse = resp;
                            // this is our message - removing it from queue and raising event to unblock the thread
                            eventRespReceived.Set();
                        }
                        break;
                    }
                }
                ++i;
            }
        }
Ejemplo n.º 2
0
        public void GetSessionInfo_Success(string name)
        {
            RunInitSql(name, "ConnectionStringAccounts");

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

            InitSessionResponse response = Post <InitSession, InitSessionResponse>("InitSession", request);

            string sessionToken = response.SessionToken;

            // 2. 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.IsEmpty(sessionInfo.Errors, "Errors are not empty");
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Gets the is model acceptable for using.
 /// </summary>
 /// <param name="trainSessionInfo">The train session information.</param>
 /// <returns><c>true</c> if model is acceptable and can be used for future prediction.</returns>
 protected virtual bool GetIsModelAcceptable(GetSessionInfoResponse trainSessionInfo)
 {
     if (_modelConfig.MetricThreshold <= 0)
     {
         return(true);
     }
     trainSessionInfo.ModelSummary.CheckArgumentNull("ModelSummary");
     return(trainSessionInfo.ModelSummary.Metric >= _modelConfig.MetricThreshold);
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Gets information about the training session.
        /// </summary>
        /// <param name="trainSessionId">The train session identifier.</param>
        /// <returns>Session state. If session is completed, returns information about the training.</returns>
        public GetSessionInfoResponse GetTrainingSessionInfo(Guid trainSessionId)
        {
            trainSessionId.CheckArgumentEmpty("trainSessionId");
            var request = new GetSessionInfoRequest {
                SessionId = trainSessionId
            };
            GetSessionInfoResponse response =
                Post <GetSessionInfoResponse>(GetSessionInfoMethodName, request, DefaultTimeoutSec);

            return(response);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Updates the model instance.
        /// </summary>
        /// <param name="trainSessionInfo">The train session information.</param>
        /// <param name="trainSessionId">The train session identifier.</param>
        protected virtual void UpdateModelInstance(GetSessionInfoResponse trainSessionInfo, Guid trainSessionId)
        {
            ModelSummary modelSummary = trainSessionInfo.ModelSummary;

            modelSummary.CheckArgumentNull("ModelSummary");
            modelSummary.ModelInstanceUId.CheckArgumentEmpty("MLModelConfig.ModelSummary.ModelInstanceUId");
            Update updateQuery = (Update) new Update(_userConnection, "MLModel")
                                 .Set("ModelInstanceUId", Column.Parameter(modelSummary.ModelInstanceUId))
                                 .Set("InstanceMetric", Column.Parameter(modelSummary.Metric))
                                 .Set("TrainedOn", Column.Parameter(DateTime.UtcNow))
                                 .Where("TrainSessionId").IsEqual(Column.Parameter(trainSessionId));

            updateQuery.Execute();
        }
Ejemplo n.º 6
0
        public void GetSessionInfo_InvalidSession(string name)
        {
            RunInitSql(name, "ConnectionStringAccounts");


            GetSessionInfo getSesionInfo = PrepareRequest <GetSessionInfo>(name);

            getSesionInfo.SessionToken = ConfigurationManager.AppSettings["InvalidSessionToken"];

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

            RunFinalizeSql(name, "ConnectionStringAccounts");

            Assert.AreEqual(sessionInfo.Success, false, "Session with invalid token was unpetedly found");
            Assert.IsNotEmpty(sessionInfo.Errors, "Errors are empty");
            Assert.AreEqual(sessionInfo.Errors[0].Code, EErrorCodes.InvalidSession, "Wrong error code returned");
        }
Ejemplo n.º 7
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");
        }
Ejemplo n.º 8
0
        private EErrorCodes ValidateSession(string sessionToken)
        {
            EErrorCodes result = EErrorCodes.InvalidSession;

            if (sessionToken == ConfigurationManager.AppSettings["ServiceSessionToken"])
            {
                result = EErrorCodes.Success;
            }
            else
            {
                GetSessionInfo sinfo = new GetSessionInfo();
                sinfo.SessionToken = sessionToken;
                sinfo.CheckActive  = true;

                DMFX.Client.Accounts.ServiceClient accnts    = new Client.Accounts.ServiceClient();
                GetSessionInfoResponse             sInfoResp = accnts.PostGetSessionInfo(sinfo);

                result = sInfoResp.Success ? EErrorCodes.Success : sInfoResp.Errors[0].Code;
            }

            return(result);
        }
        public ResponseBase Any(GetSessionInfo request)
        {
            _logger.Log(EErrorType.Info, " ****** Call start: GetSessionInfo");
            GetSessionInfoResponse response = new GetSessionInfoResponse();

            try
            {
                Interfaces.DAL.SessionInfo sinfo = new Interfaces.DAL.SessionInfo();

                sinfo.SessionId = !string.IsNullOrEmpty(request.SessionToken) ? request.SessionToken : string.Empty;

                _logger.Log(EErrorType.Info, string.Format("_dal.GetSessionInfo({0}, {1})", sinfo.SessionId, request.CheckActive));

                sinfo = _dal.GetSessionInfo(sinfo, request.CheckActive);
                if (sinfo != null)
                {
                    response.Payload.SessionStart = sinfo.SessionStart;
                    response.Payload.SessionEnd   = sinfo.SessionEnd;
                    if (!request.CheckActive)
                    {
                        // checking all sessions - just returning the warning that this session was closed
                        if (response.Payload.SessionEnd > DateTime.MinValue)
                        {
                            response.Errors.Add(new Error()
                            {
                                Code = EErrorCodes.SessionClosed, Message = "Session with given token was closed", Type = EErrorType.Warning
                            });
                        }
                        response.Success = true;
                    }
                    else
                    {
                        // checking for active session!
                        // if expiration date >= now - closing the session and returning error; in other case returning true
                        _logger.Log(EErrorType.Info, string.Format("Expires: {0}, Now: {1}", sinfo.SessionExpires, DateTime.UtcNow));
                        if (sinfo.SessionExpires <= DateTime.UtcNow)
                        {
                            _logger.Log(EErrorType.Info, string.Format("Closing session {0}", sinfo.SessionId));
                            sinfo.SessionEnd = DateTime.UtcNow;
                            _dal.CloseSession(sinfo);

                            response.Errors.Add(new Error()
                            {
                                Code = EErrorCodes.SessionClosed, Message = "Session with given token expired and was closed", Type = EErrorType.Error
                            });
                            response.Success = false;
                        }
                        else
                        {
                            response.Success = true;
                        }
                    }
                }
                else
                {
                    response.Errors.Add(new Error()
                    {
                        Code = EErrorCodes.InvalidSession, Message = "Invalid session token", Type = EErrorType.Error
                    });
                }
            }
            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: GetSessionInfo");

            return(response);
        }