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);
     });
 }
示例#2
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();
        }
示例#3
0
 /// <summary>
 /// Remueve todos los items del mapa
 /// </summary>
 private void RemoveAllPins()
 {
     Action = Action.RemoveAllPins;
     ReceiveAction?.Invoke(this, null);
 }
示例#4
0
 public void ZoomForAllPins()
 {
     Action = Action.ZoomForAllPins;
     ReceiveAction?.Invoke(this, null);
 }
示例#5
0
 /// <summary>
 /// Agrega un pin
 /// </summary>
 /// <param name="pin"></param>
 private void AddPin(Pin pin)
 {
     Action = Action.AddPin;
     ReceiveAction?.Invoke(this, pin);
 }
示例#6
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);
 }
示例#7
0
        public void handleaction(string Action)
        {
            bool OKPressed = false;

            switch (Action)
            {
            case "Cancel": NewEntry = true; break;

            case "BackSpace":
                if (!NewEntry)
                {
                    textBoxNumPadDisplay.Text = textBoxNumPadDisplay.Text.Substring(0, textBoxNumPadDisplay.Text.Length - 1);
                    if (textBoxNumPadDisplay.Text == "")
                    {
                        NewEntry = true;
                    }
                }
                break;

            case "Dot":
                if (NewEntry)
                {
                    textBoxNumPadDisplay.Text = "";
                    NewEntry = false;
                }
                if (!textBoxNumPadDisplay.Text.Contains(decimalStr))
                {
                    textBoxNumPadDisplay.AppendText(decimalStr);
                }
                break;

            case "OK":
                if (textBoxNumPadDisplay.Text == decimalStr)
                {
                    ReturnNumber = 0;
                }
                else
                {
                    try
                    {
                        ReturnNumber = Math.Round(Convert.ToDouble(textBoxNumPadDisplay.Text), RoundingPrecision + 2, MidpointRounding.AwayFromZero);
                    }
                    catch { }
                }
                textBoxNumPadDisplay.Text = string.Format("{0:" + AMOUNT_FORMAT + "}", ReturnNumber);
                NewEntry  = true;
                OKPressed = true;
                receiveAction.Invoke();
                break;

            default:
                if (NewEntry)
                {
                    textBoxNumPadDisplay.Text = "";
                }
                textBoxNumPadDisplay.AppendText(Action);
                NewEntry = false;
                break;
            }
            if (OKPressed)
            {
                OKPressed = false;
            }
            else if (NewEntry)
            {
                textBoxNumPadDisplay.Text = 0.ToString(AMOUNT_FORMAT);
            }
        }