public WebFormPurchaseDataAdapter(EntityReference target, string targetPrimaryKeyLogicalName, EntityReference webForm, IEnumerable <Entity> webFormMetadata, SessionHistory webFormSession, IDataAdapterDependencies dependencies)
            : base(dependencies)
        {
            if (target == null)
            {
                throw new ArgumentNullException("target");
            }
            if (targetPrimaryKeyLogicalName == null)
            {
                throw new ArgumentNullException("targetPrimaryKeyLogicalName");
            }
            if (webForm == null)
            {
                throw new ArgumentNullException("webForm");
            }
            if (webFormMetadata == null)
            {
                throw new ArgumentNullException("webFormMetadata");
            }

            Target = target;
            TargetPrimaryKeyLogicalName = targetPrimaryKeyLogicalName;
            WebForm         = webForm;
            WebFormMetadata = webFormMetadata.ToArray();
            WebFormSession  = webFormSession;
        }
 public bool DeleteSessionHistory(SessionHistory entity)
 {
     if (entity == null) return false;
     _unitOfWork.SessionHistoryRepository.Delete(entity);
     _unitOfWork.Save();
     return true;
 }
Пример #3
0
 public bool DeleteSessionHistory(SessionHistory entity)
 {
     if (entity == null)
     {
         return(false);
     }
     _unitOfWork.SessionHistoryRepository.Delete(entity);
     _unitOfWork.Save();
     return(true);
 }
Пример #4
0
        /// <summary>
        /// 查找指定会话的GGA信息
        /// </summary>
        /// <param name="session">会话实体</param>
        /// <returns>查找到的GGA信息列表,定位之间倒叙排列</returns>
        public List <GGAHistory> FindGGAHistoriesBySessionHistory(SessionHistory session)
        {
            List <GGAHistory> result = new List <GGAHistory>();

            using (var ctx = new NtripForwardDB())
            {
                result = ctx.GGAHistories.Where <GGAHistory>(g => g.SessionID == session.ID).OrderByDescending(g => g.FixedTime).ToList();
            }
            return(result);
        }
Пример #5
0
        /// <summary>
        /// 添加会话
        /// </summary>
        /// <param name="session">会话信息</param>
        /// <returns>是否添加成功</returns>
        public bool AddSessionHistory(SessionHistory session)
        {
            bool result = false;

            using (var ctx = new NtripForwardDB())
            {
                ctx.SessionHistories.Add(session);
                result = ctx.SaveChanges() == 1;
            }
            return(result);
        }
Пример #6
0
 public async Task ArchiveSessionDetailAsync(SessionHistory session)
 {
     if (session != null)
     {
         if (base.LoadTableSilent(Constants.SessionHistoryTableName))
         {
             session.PartitionKey = session.ProfileID;
             session.RowKey       = session.ClientTimeStamp;
             TableOperation insertSession = TableOperation.Insert(session);
             await base.EntityTable.ExecuteAsync(insertSession);
         }
     }
 }
Пример #7
0
        /// <summary>
        /// 更新会话历史基础信息
        /// </summary>
        /// <param name="session">会话信息</param>
        /// <returns>是否更新成功</returns>
        public bool UpdateSessionHistory(SessionHistory session)
        {
            bool result = false;

            using (var ctx = new NtripForwardDB())
            {
                if (session.ID != null)
                {
                    ctx.SessionHistories.Attach(session);
                    ctx.Entry(session).State = EntityState.Modified;
                    result = ctx.SaveChanges() >= 1;
                }
            }
            return(result);
        }
        //Lấy KeyName cho entity
        public static string GetKeyName(string entityName)
        {
            string keyName = entityName + "Id";

            try
            {
                #region Trường hợp key đặc biệt viết tại đây
                if (entityName == ConfigApprovalTransaction.EntityName())
                {
                    keyName = ConfigApprovalTransaction.ConfigApprovalTransactionFields.ConfigType.ToString();
                }
                if (entityName == MemberInfo.EntityName())
                {
                    keyName = MemberInfo.MemberInfoFields.MemberId.ToString();
                }
                if (entityName == UserInfo.EntityName())
                {
                    keyName = UserInfo.UserInfoFields.UserId.ToString();
                }
                if (entityName == SessionHistory.EntityName())
                {
                    keyName = SessionHistory.SessionHistoryFields.SessionId.ToString();
                }
                if (entityName == AccountTransaction.EntityName())
                {
                    keyName = AccountTransaction.AccountTransactionFields.TransactionId.ToString();
                }
                if (entityName == AccountTransactionView.EntityName())
                {
                    keyName = AccountTransactionView.AccountTransactionViewFields.TransactionViewId.ToString();
                }
                if (entityName == ChangedPasswordHist.EntityName())
                {
                    keyName = ChangedPasswordHist.ChangedPasswordHistFields.Id.ToString();
                }
                if (entityName == MemberTradingLimit.EntityName())
                {
                    keyName = MemberTradingLimit.MemberTradingLimitFields.Id.ToString();
                }
                #endregion
            }
            catch (Exception ex)
            {
                LogTo.Error(ex.ToString());
            }
            return(keyName);
        }
        /// <summary>
        /// SessionHistory,转换基础信息到SessionHistoryEntity
        /// </summary>
        /// <param name="session">DAL层会话</param>
        /// <returns>WebApi层会话实体</returns>
        public static SessionHistoryEntity ToSessionHistoryEntity(this SessionHistory session)
        {
            SessionHistoryEntity sessionHistoryEntity = new SessionHistoryEntity
            {
                ID              = session.ID,
                AccountName     = session.AccountName,
                AccountType     = session.AccountType,
                AccountSYSName  = session.AccountSYSName,
                MountPoint      = session.MountPoint,
                Client          = session.Client,
                ClientAddress   = session.ClientAddress,
                ConnectionStart = session.ConnectionStart,
                ConnectionEnd   = session.ConnectionEnd,
                GGACount        = (int)session.GGACount,
                FixedCount      = (int)session.FixedCount,
                ErrorInfo       = session.ErrorInfo
            };

            return(sessionHistoryEntity);
        }
Пример #10
0
        protected override async void HandleLocationChanged(object sender, LocationChangedEventArgs e)
        {
            base.HandleLocationChanged(sender, e);

            var shortLocationUrl    = e.Location.Replace(NavigationManager.BaseUri, "/");
            var localSessionHistory = await ProtectedBrowserStore.GetAsync <SessionHistory>(StaticLiterals.SessionHistoryKey).ConfigureAwait(false);

            if (localSessionHistory == null)
            {
                localSessionHistory = new SessionHistory();
            }

            if (localSessionHistory.PeekHistory().Equals(shortLocationUrl) == false)
            {
                localSessionHistory.PushHistory(shortLocationUrl.Equals($"/{StaticLiterals.LoginPage}") ? "/" : shortLocationUrl);
                await ProtectedBrowserStore.SetAsync(StaticLiterals.SessionHistoryKey, localSessionHistory).ConfigureAwait(false);

                HasLocationChanged = true;
            }
        }
Пример #11
0
        /// <summary>
        /// 转换WebApi会话实体为dal层会话基础信息
        /// </summary>
        /// <returns>dal层会话</returns>
        public SessionHistory ToSessionHistory()
        {
            SessionHistory sessionHistory = new SessionHistory()
            {
                ID              = ID,
                AccountName     = AccountName,
                AccountType     = AccountType,
                AccountSYSName  = AccountSYSName,
                MountPoint      = MountPoint,
                Client          = Client,
                ClientAddress   = ClientAddress,
                ConnectionStart = ConnectionStart,
                ConnectionEnd   = ConnectionEnd,
                GGACount        = GGACount,
                FixedCount      = FixedCount,
                ErrorInfo       = ErrorInfo
            };

            return(sessionHistory);
        }
        public static List <SessionHistory> Select400SessionHistory(long itemCount)
        {
            //SELECT * FROM (SELECT * FROM SessionHistory  ORDER BY SessionId DESC ) WHERE ROWNUM <= 400;
            var entityQry = new EntityQuery
            {
                EntityName  = SessionHistory.EntityName(),
                QueryAction = EntityGet.GetCustomValues,
            };

            entityQry.ItemsCount = itemCount;
            entityQry.ItemsSort  = SessionHistory.SessionHistoryFields.SessionId.ToString();
            entityQry.SortType   = "DESC";
            entityQry            = GetEntityQuery(entityQry);
            var sessionHistories = new List <SessionHistory>();

            if (entityQry.ReturnValue != null)
            {
                sessionHistories = entityQry.ReturnValue.Select(baseEntity =>
                                                                baseEntity.GetEntity() as SessionHistory).ToList();
            }
            return(sessionHistories);
        }
        public void UT_When_HandleOpenGame_Then_Success()
        {
            var session1 = this.sessions.First(s => s.Name == this.session1Name);
            var session1Player1Name = session1.Player1Name;
            var session1Player2Name = session1.Player2Name;
            var player1SessionHistory = new SessionHistory<TestMoveObject, TestResponseObject>(this.session1Name, session1Player1Name);
            var player2SessionHistory = new SessionHistory<TestMoveObject, TestResponseObject>(this.session1Name, session1Player2Name);

            this.sessionServiceMock
                .Setup(s => s.GetByName(It.Is<string>(x => x == this.session1Name)))
                .Returns(session1)
                .Verifiable();
            this.sessionHistoryServiceMock
                .Setup(s => s.GetBySessionPlayer(It.Is<string>(x => x == this.session1Name), It.Is<string>(x => x == session1Player1Name)))
                .Returns(player1SessionHistory)
                .Verifiable();
            this.sessionHistoryServiceMock
                .Setup(s => s.GetBySessionPlayer(It.Is<string>(x => x == this.session1Name), It.Is<string>(x => x == session1Player2Name)))
                .Returns(player2SessionHistory)
                .Verifiable();

            var openGameClientMessage = new OpenGameClientMessage
            {
                SessionName = this.session1Name,
                UserName = this.requestPlayer
            };
            var clientContract = new ClientContract
            {
                Type = GamifyClientMessageType.OpenGame,
                Sender = this.requestPlayer,
                SerializedClientMessage = this.serializer.Serialize(openGameClientMessage)
            };

            var gameSelectionPluginComponent = this.GetGameSelectionPluginComponent();
            var canHandle = gameSelectionPluginComponent.CanHandleClientMessage(clientContract);

            gameSelectionPluginComponent.HandleClientMessage(clientContract);

            this.sessionServiceMock.VerifyAll();
            this.sessionHistoryServiceMock.VerifyAll();
            this.notificationServiceMock.Verify(s => s.Send(It.Is<int>(t => t == GamifyServerMessageType.GameInformationReceived),
                It.Is<object>(o => ((GameInformationReceivedServerMessage)o).SessionName == this.session1Name),
                It.Is<string>(x => x == this.requestPlayer)));

            Assert.IsTrue(canHandle);
        }
Пример #14
0
        private void acceptCallback(IAsyncResult ar)
        {
            TcpListener   lstn   = (TcpListener)ar.AsyncState;
            TcpClient     client = lstn.EndAcceptTcpClient(ar);
            NetworkStream stream = client.GetStream();

            Task.Run(() =>
            {
                TcpClient qianxunClient = new TcpClient();
                qianxunClient.Connect(IPAddress.Parse(qianxunIP), ROMOTE_PORT);
                //中继缓存数据
                string bufferMsg = "";
                //主机地址
                string host = client.Client.RemoteEndPoint.ToString();
                //拨号的账户
                ACCOUNT account = new ACCOUNT();
                //使用的千寻账户
                ACCOUNTSYS accountSYS = new ACCOUNTSYS();
                //会话状态,并初始化
                SessionHistory session = new SessionHistory();
                session.ID             = Guid.NewGuid();
                session.GGACount       = 0;
                session.FixedCount     = 0;
                //GGA记录频率
                int GGARecordRate = settings.GGARecordRate;
                //GGA初始计数
                int GGACounter = 1;

                //是否继续维持连接
                bool isLoop = true;

                //设置定时器,作为gga发送的中继
                System.Timers.Timer timerRepeat = new System.Timers.Timer();
                timerRepeat.Interval            = settings.GGARepeatRate;
                timerRepeat.AutoReset           = true;
                timerRepeat.Elapsed            += delegate
                {
                    if (MsgHelper.CheckRequestType(bufferMsg) == 3)
                    {
                        byte[] sendMsg = Connect(qianxunClient, bufferMsg);
                        //将千寻返回数据转发给客户端
                        stream.Write(sendMsg, 0, sendMsg.Length);
                    }
                };
                timerRepeat.Start();

                //设置定时器,如果长时间不发送数据,则关掉tcp连接
                System.Timers.Timer timerTimeout = new System.Timers.Timer();
                timerTimeout.Interval            = settings.Timeout;
                timerTimeout.AutoReset           = false;
                timerTimeout.Elapsed            += delegate
                {
                    //记录session
                    session.ConnectionEnd = DateTime.Now;
                    if (session.AccountType != null)
                    {
                        sessionDAL.UpdateSessionHistory(session);
                    }
                    //更新在线状态
                    if (session.AccountType == "Normal")
                    {
                        account.Account_IsOnline       = false;
                        accountSYS.AccountSYS_IsOnline = false;
                        accountDAL.UpdateAccount(account);
                        accountSYSDAL.UpdateAccountSYS(accountSYS);
                    }
                    //关闭计时器
                    timerTimeout.Stop();
                    timerRepeat.Stop();
                    //关闭所有连接
                    stream.Close();
                    client.Close();
                    qianxunClient.Close();
                    //跳出循环
                    isLoop = false;
                };
                timerTimeout.Start();

                #region  步读取

                while (isLoop)
                {
                    //解决cpu100%占用问题
                    Thread.Sleep(1);
                    try
                    {
                        if (stream.DataAvailable)
                        {
                            //计时器重置
                            timerTimeout.Stop();
                            timerTimeout.Start();

                            //用来存储网络字节流数据
                            byte[] buffer = new byte[1024];
                            stream.Read(buffer, 0, buffer.Length);
                            string recMsg  = Encoding.UTF8.GetString(buffer);
                            byte[] sendMsg = new byte[1024];

                            switch (MsgHelper.CheckRequestType(recMsg))
                            {
                            //浏览器请求
                            case 1:
                                sendMsg = Connect(qianxunClient, recMsg);
                                break;

                            //手部首次请求
                            case 2:
                                string[] namePassword = MsgHelper.GetAuthorization(recMsg);
                                account = accountDAL.FindAccountByName(namePassword[0]);
                                //第三方账号
                                if (account == null)
                                {
                                    session.AccountType     = "Third";
                                    session.AccountName     = namePassword[0];
                                    session.MountPoint      = MsgHelper.GetMountPoint(recMsg);
                                    session.ConnectionStart = DateTime.Now;
                                    session.Client          = MsgHelper.GetUserAgent(recMsg);
                                    session.ClientAddress   = host;
                                    session.ErrorInfo       = string.Join(":", MsgHelper.GetAuthorization(recMsg));
                                    sessionDAL.AddSessionHistory(session);
                                    recMsg  = recMsg + Environment.NewLine;
                                    sendMsg = Connect(qianxunClient, recMsg);
                                }
                                else
                                {
                                    if (account.Account_Password == namePassword[1])
                                    {
                                        //账户已过期
                                        if (account.Account_Expire < DateTime.Now)
                                        {
                                            session.AccountType     = "Expire";
                                            session.AccountName     = namePassword[0];
                                            session.MountPoint      = MsgHelper.GetMountPoint(recMsg);
                                            session.ConnectionStart = DateTime.Now;
                                            session.Client          = MsgHelper.GetUserAgent(recMsg);
                                            session.ClientAddress   = host;
                                            session.ErrorInfo       = "账户已过期";
                                            sessionDAL.AddSessionHistory(session);
                                            //sendMsg = Connect(qianxunClient, recMsg);
                                        }
                                        else
                                        {
                                            //账户已在线
                                            if ((bool)account.Account_IsOnline)
                                            {
                                                session.AccountType     = "Online";
                                                session.AccountName     = namePassword[0];
                                                session.MountPoint      = MsgHelper.GetMountPoint(recMsg);
                                                session.ConnectionStart = DateTime.Now;
                                                session.Client          = MsgHelper.GetUserAgent(recMsg);
                                                session.ClientAddress   = host;
                                                session.ErrorInfo       = "账户已在线";
                                                sessionDAL.AddSessionHistory(session);
                                                //sendMsg = Connect(qianxunClient, recMsg);
                                            }
                                            else
                                            {
                                                //账户被锁定
                                                if ((bool)account.Account_IsLocked)
                                                {
                                                    session.AccountType     = "Locked";
                                                    session.AccountName     = namePassword[0];
                                                    session.MountPoint      = MsgHelper.GetMountPoint(recMsg);
                                                    session.ConnectionStart = DateTime.Now;
                                                    session.Client          = MsgHelper.GetUserAgent(recMsg);
                                                    session.ClientAddress   = host;
                                                    session.ErrorInfo       = "账户已锁定";
                                                    sessionDAL.AddSessionHistory(session);
                                                    //sendMsg = Connect(qianxunClient, recMsg);
                                                }
                                                else
                                                {
                                                    //账户正常
                                                    session.AccountType = "Normal";
                                                    //更新账户状态
                                                    account.Account_IsOnline  = true;
                                                    account.Account_LastLogin = DateTime.Now;
                                                    accountDAL.UpdateAccount(account);
                                                    //找到可替换的系统账号并更新状态
                                                    accountSYS = accountSYSDAL.FindSuitableAccountSYS();
                                                    accountSYS.AccountSYS_IsOnline  = true;
                                                    accountSYS.AccountSYS_LastLogin = DateTime.Now;
                                                    accountSYS.AccountSYS_Age++;
                                                    accountSYSDAL.UpdateAccountSYS(accountSYS);
                                                    //更新session状态
                                                    session.AccountName     = account.Account_Name;
                                                    session.AccountSYSName  = accountSYS.AccountSYS_Name;
                                                    session.ConnectionStart = DateTime.Now;
                                                    session.Client          = MsgHelper.GetUserAgent(recMsg);
                                                    session.MountPoint      = MsgHelper.GetMountPoint(recMsg);
                                                    session.ClientAddress   = host;
                                                    sessionDAL.AddSessionHistory(session);
                                                    //替换信息
                                                    string replaceMessage = MsgHelper.ReplaceAuthorization(recMsg, accountSYS.AccountSYS_Name, accountSYS.AccountSYS_Password) + Environment.NewLine;
                                                    sendMsg = Connect(qianxunClient, replaceMessage);
                                                }
                                            }
                                        }
                                    }
                                    else
                                    {
                                        //用户名密码错误
                                        session.AccountType              = "PasswordError";
                                        session.AccountName              = namePassword[0];
                                        session.MountPoint               = MsgHelper.GetMountPoint(recMsg);
                                        session.ConnectionStart          = DateTime.Now;
                                        session.Client                   = MsgHelper.GetUserAgent(recMsg);
                                        session.ClientAddress            = host;
                                        session.ErrorInfo                = "用户名密码错误";
                                        account.Account_PasswordOvertime = DateTime.Now;
                                        account.Account_PasswordOvercount++;
                                        sessionDAL.AddSessionHistory(session);
                                        sendMsg = Connect(qianxunClient, recMsg);
                                    }
                                }
                                break;

                            //GGA数据采集
                            case 3:
                                //发送的GGA数据递增
                                session.GGACount++;
                                //是否固定解
                                if (MsgHelper.FixModule(recMsg) == 4)
                                {
                                    session.FixedCount++;
                                }
                                //更新session信息
                                sessionDAL.UpdateSessionHistory(session);
                                //中继缓冲gga信息
                                bufferMsg = recMsg;
                                if (
                                    //是否记录GGA数据
                                    settings.EnableLogGGA
                                    //到达指定评率记录GGA数据
                                    && GGACounter % GGARecordRate == 0
                                    //第三方账户不记录GGA数据
                                    && account != null
                                    )
                                {
                                    GGAHistory gga  = new GGAHistory();
                                    gga.ID          = Guid.NewGuid();
                                    gga.Account     = account.Account_Name;
                                    gga.AccountSYS  = accountSYS.AccountSYS_Name;
                                    gga.AccountType = "Normal";
                                    gga.FixedTime   = DateTime.Now;
                                    gga.Lng         = Convert.ToDecimal(MsgHelper.GetLng(recMsg));
                                    gga.Lat         = Convert.ToDecimal(MsgHelper.GetLat(recMsg));
                                    gga.Status      = MsgHelper.FixModule(recMsg);
                                    gga.GGAInfo     = recMsg;
                                    gga.SessionID   = session.ID;
                                    ggaDAL.AddGGAHistory(gga);
                                }
                                GGACounter++;
                                sendMsg = Connect(qianxunClient, recMsg);
                                break;

                            default:
                                break;
                            }

                            //将千寻返回数据转发给客户端
                            stream.Write(sendMsg, 0, sendMsg.Length);
                        }
                    }
                    catch (Exception e)
                    {
                        //更新在线状态
                        if (session.AccountType == "Normal")
                        {
                            account.Account_IsOnline       = false;
                            accountSYS.AccountSYS_IsOnline = false;
                            accountDAL.UpdateAccount(account);
                            accountSYSDAL.UpdateAccountSYS(accountSYS);
                        }
                        //结束会话
                        session.ConnectionEnd = DateTime.Now;
                        //session.ErrorInfo = e.Message;
                        sessionDAL.UpdateSessionHistory(session);
                        //关闭所有连接
                        stream.Close();
                        client.Close();
                        qianxunClient.Close();
                        timerTimeout.Stop();
                        timerRepeat.Stop();
                        break;
                    }
                }
                #endregion
            });

            lstn.BeginAcceptTcpClient(new AsyncCallback(acceptCallback), lstn);
        }
Пример #15
0
 public bool EditSessionHistory(SessionHistory entity)
 {
     _unitOfWork.SessionHistoryRepository.Edit(entity);
     _unitOfWork.Save();
     return(true);
 }
 public bool EditSessionHistory(SessionHistory entity)
 {
     _unitOfWork.SessionHistoryRepository.Edit(entity);
     _unitOfWork.Save();
     return true;
 }