Esempio n. 1
0
        /// <summary>
        /// 登录必调用 方法  用于存userlist
        /// </summary>
        public void sendloginmsg(Model model)
        {
            //调用所有客户端的sendMessage方法
            //Clients.All.sendMessage(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), message);
            var obj = ConnectionIds.FirstOrDefault(a => chkemployeeid(a.Key, model.companyID, model.employeeid));

            if (!string.IsNullOrEmpty(obj.Key))
            {
                //存在连接发送一个断开方法
                ClientList.Client(obj.Value).sendfocusoffline();
            }
            //检查登录信息(需传参数)
            checklogininfo(model.source + "@" + model.companyID + "@" + model.employeeid);

            //修改数据库当前用户登录状态TODO:

            Dictionary <string, string> resultlist = ConnectionIds.Where(a => chkcompanyID(a.Key, model.companyID)).ToDictionary(b => b.Key, c => c.Value);

            if (resultlist.Count > 0)
            {
                foreach (var item in resultlist)
                {
                    ClientList.Client(item.Value).customerloginstatemessage(new { employeeid = model.employeeid, isonline = true });
                }
            }
        }
Esempio n. 2
0
        public TradingAgent(string connId, double initialAmount, IHubCallerConnectionContext <IStockTickerHubClient> caller)
        {
            var initialState = new State
            {
                Cash       = initialAmount,
                Portfolio  = new Dictionary <string, TradingDetails>(),
                BuyOrders  = new Dictionary <string, List <TradingDetails> >(),
                SellOrders = new Dictionary <string, List <TradingDetails> >()
            };

            agent = Agent.Start <State, Trading>(initialState,
                                                 (state, message) =>
            {
                if (message is Trading.Kill)
                {
                    throw new NotImplementedException("Kill messages should not be send to Dataflow based Agents");
                }
                else if (message is Trading.Error msgError)
                {
                    throw msgError.Item;
                }
                else if (message is Trading.Buy msgBuy)
                {
                    var items = HelperFunctions.setOrder(state.BuyOrders, msgBuy.symbol, msgBuy.Item2);
                    var order = HelperFunctions.createOrder(msgBuy.symbol, msgBuy.Item2, TradingType.Buy);
                    caller.Client(connId).UpdateOrderBuy(order);
                    state.BuyOrders = items;
                }
                else if (message is Trading.Sell msgSell)
                {
                    var items = HelperFunctions.setOrder(state.SellOrders, msgSell.symbol, msgSell.Item2);
                    var order = HelperFunctions.createOrder(msgSell.symbol, msgSell.Item2, TradingType.Sell);
                    caller.Client(connId).UpdateOrderSell(order);
                    state.SellOrders = items;
                }
                else if (message is Trading.UpdateStock msgStock)
                {
                    caller.Client(connId).UpdateStockPrice(msgStock.Item);

                    var x            = HelperFunctions.updatePortfolio(state.Cash, msgStock.Item, state.Portfolio, state.SellOrders, TradingType.Sell);
                    state.Cash       = x.Item1;
                    state.Portfolio  = x.Item2;
                    state.SellOrders = x.Item3;

                    var y           = HelperFunctions.updatePortfolio(state.Cash, msgStock.Item, state.Portfolio, state.BuyOrders, TradingType.Buy);
                    state.Cash      = y.Item1;
                    state.Portfolio = y.Item2;
                    state.BuyOrders = y.Item3;

                    var asset = HelperFunctions.getUpdatedAsset(state.Portfolio, state.SellOrders, state.BuyOrders, state.Cash);
                    caller.Client(connId).UpdateAsset(asset);
                }
                return(state);
            });
        }
Esempio n. 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="stopCalled"></param>
        /// <returns></returns>
        public override Task OnDisconnected(bool stopCalled)
        {
            ClientList    = Clients;
            ServerContext = Context;
            if (ConnectionIds.Count > 0)
            {
                KeyValuePair <string, string> tmpconnect = ConnectionIds.FirstOrDefault(a => a.Value == Context.ConnectionId);
                if (tmpconnect.Key != null)
                {
                    int    employeeid = Convert.ToInt32(tmpconnect.Key.Split('@').Last());
                    string companyID  = tmpconnect.Key.Split('@').First();

                    //离线调用数据库更新用户登录状态TODO:
                    //

                    ConnectionIds.Remove(tmpconnect.Key);//删除连接 list 中 当前退出的客户端


                    Dictionary <string, string> resultlist = ConnectionIds.Where(a => chkcompanyID(a.Key, companyID)).ToDictionary(b => b.Key, c => c.Value);
                    if (resultlist.Count > 0)
                    {
                        foreach (var item in resultlist)
                        {
                            ClientList.Client(item.Value).customerloginstatemessage(new { companyID = companyID, employeeid = employeeid, isonline = false });
                        }
                    }
                }
            }
            return(base.OnDisconnected(true));
        }
Esempio n. 4
0
        public async Task OnConnect_QueriesUserProjectAndBuildConfigs_AndSendMappedInfoToClient_AndTriggersRefreshForThisClient()
        {
            string username     = _fixture.Create <string>();
            string connectionId = _fixture.Create <string>();

            A.CallTo(() => _principal.Identity.Name).Returns(username);
            A.CallTo(() => _context.ConnectionId).Returns(connectionId);
            A.CallTo(() => _context.User).Returns(_principal);

            List <Project> projects = _fixture.CreateMany <Project>().ToList();

            A.CallTo(() => _infoQuery.GetUserProjectsAndBuildConfigs(username))
            .Returns(projects);

            A.CallTo(() => _fakeClients.Client(connectionId)).Returns(_fakeClient);

            CiDashboardHub hub = new CiDashboardHub(_connectionsManager, _commandProcessor, _infoQuery, _refreshInfo)
            {
                Context = _context
            };

            hub.Clients = _fakeClients;
            await hub.OnConnected();

            A.CallTo(() => _infoQuery.GetUserProjectsAndBuildConfigs(username))
            .MustHaveHappened();

            List <string> buildCiIds = projects
                                       .SelectMany(
                p => p.Builds
                .Where(b => !string.IsNullOrEmpty(b.CiExternalId))
                .ToList())
                                       .Select(b => b.CiExternalId)
                                       .ToList();

            A.CallTo(() => _connectionsManager.AddBuildConfigs(connectionId,
                                                               A <IEnumerable <BuildConfig> > .That.Matches(l => !l.Select(b => b.CiExternalId).Except(buildCiIds).Any())))
            .MustHaveHappened();

            A.CallTo(() => _refreshInfo.SendRefreshBuildResults(connectionId))
            .MustHaveHappened();

            A.CallTo(() => _fakeClient
                     .SendProjectsAndBuildConfigs(projects))
            .MustHaveHappened();
        }
Esempio n. 5
0
        public void MsgProcess(ClientMsgPackEntity value, IHubCallerConnectionContext <dynamic> clients = null, string connectionId = "")
        {
            Task <bool> ts = new Task <bool>((arg) =>
            {
                bool ret = ConvertUtil.ConvertObjectToBool(arg, false);
                try
                {
                    if (value != null)
                    {
                        NewPushMsgPack newMsgPack = JsonUtil <NewPushMsgPack> .Deserialize(value.mp_cotent.ToString());
                        if (newMsgPack != null)
                        {
                            List <string> connIds = RedisHelper.Hash_Get <List <string> >(Constant.RedisClusterConn, Constant.ClientConnKey, newMsgPack.uid);
                            if (connIds != null && connIds.Any())
                            {
                                if (clients != null)
                                {
                                    clients.Clients(connIds).Push(newMsgPack.resdata);
                                    ret = true;
                                }
                            }
                        }
                    }
                }
                catch { }
                return(ret);
            }, false);

            ts.Start();
            ts.ContinueWith(t =>
            {
                clients.Client(connectionId).Push(ts.Result ? "推送消息到客户端成功!" : "推送消息到客户端失败!");
            });

            clients.Client(connectionId).Push("服务端接受到消息!");
        }
 public dynamic Client(string connectionId)
 {
     return(_clients.Client(connectionId));
 }