示例#1
0
 /// <summary>
 /// 创建一个工作任务单元 并指定读取流和写入流的实现
 /// </summary>
 /// <param name="channel"></param>
 /// <param name="receiveFunc">自定义从缓冲区读取数据的方法</param>
 /// <param name="sendFunc">自定义写入缓冲区数据的方法</param>
 public Task(BaseChannel channel, ReceiveAction receiveFunc, SendAction sendFunc)
 {
     _Chan         = channel;
     receiveAction = receiveFunc;
     sendAction    = sendFunc;
     cglock.DoWork();
 }
 public TPLMessageQueue(Action <Byte[]> receiveAction, CancellationToken?cancellationToken) : base(receiveAction, cancellationToken)
 {
     Messages = new ActionBlock <Byte[]>((message) => {
         // ToDO: Wrap in try catch and/or  Polly
         ReceiveAction.Invoke(message);
     });
 }
示例#3
0
        public void Datahandle(byte[] bytes)
        {
            BaseNetObject bno = NetBaseTool.BytesToObject(bytes) as BaseNetObject;

            if (bno is SystemNetObject)
            {
                SystemNetObject systemNetObject = bno as SystemNetObject;
                if (systemNetObject.GetType() == typeof(Msg))
                {
                    Console.WriteLine(systemNetObject);
                }
                else if (systemNetObject.GetType() == typeof(GetMyUserData))
                {
                    MyUserData = (systemNetObject as GetMyUserData).userData;
                }
                else if (systemNetObject.GetType() == typeof(CreateRoomS2C))
                {
                    transmit = (systemNetObject as CreateRoomS2C).PlayerId;
                    wait.Set();
                }
                else if (systemNetObject.GetType() == typeof(JoinRoomS2C))
                {
                    transmit = (systemNetObject as JoinRoomS2C);
                    wait.Set();
                }
                else if (systemNetObject.GetType() == typeof(GetRoomListS2C))
                {
                    transmit = (systemNetObject as GetRoomListS2C).rooms;
                    wait.Set();
                }
                else if (systemNetObject.GetType() == typeof(PlayerJoinS2C))
                {
                    PlayerJoin?.Invoke((systemNetObject as PlayerJoinS2C).playerId);
                }
                else if (systemNetObject.GetType() == typeof(PlayerLeaveS2C))
                {
                    PlayerLeave?.Invoke((systemNetObject as PlayerLeaveS2C).playerId);
                }
                else if (systemNetObject.GetType() == typeof(GameStart))
                {
                    StartAction?.Invoke();
                }
            }
            else
            {
                GameNetObject gno = bno as GameNetObject;
                if (gno == null)
                {
                    throw new ArgumentException(bno.GetType() + " Can't Used");
                }
                ReceiveAction?.Invoke(gno);
            }
            //防止死锁
            // wait.Set();
        }
示例#4
0
        /// <summary>
        ///     Handler send, receive and events in frame for client
        /// </summary>

        #region HandleSendReceiveAndEventsInFrame

        protected void HandleSendReceiveAndEventsInFrame()
        {
            while (ReceiveAction.Any())
            {
                ReceiveAction.Dequeue()(true);
            }

            while (EventsQueue.Any())
            {
                EventsQueue.Dequeue()();
            }
        }
示例#5
0
        /// <summary>
        /// 创建一个工作任务单元
        /// </summary>
        /// <param name="channel"></param>
        public Task(BaseChannel channel)
        {
            _Chan         = channel;
            receiveAction = (x, y) => {
                return(y.Read(64));
            };
            sendAction = (x, y) => {
                return(y.Write(x.GetTX()));
            };

            cglock.DoWork();
        }
示例#6
0
 /// <summary>
 /// Remueve todos los items del mapa
 /// </summary>
 private void RemoveAllPins()
 {
     Action = Action.RemoveAllPins;
     ReceiveAction?.Invoke(this, null);
 }
示例#7
0
 public void ZoomForAllPins()
 {
     Action = Action.ZoomForAllPins;
     ReceiveAction?.Invoke(this, null);
 }
示例#8
0
 /// <summary>
 /// Agrega un pin
 /// </summary>
 /// <param name="pin"></param>
 private void AddPin(Pin pin)
 {
     Action = Action.AddPin;
     ReceiveAction?.Invoke(this, pin);
 }
示例#9
0
 /// <summary>
 /// Permite asignar el centro del mapa
 /// </summary>
 /// <param name="center"></param>
 public void SetCenter(Center center)
 {
     Action = Action.SetCenter;
     ReceiveAction?.Invoke(this, center);
 }