Ejemplo n.º 1
0
        private void Tick(object sender, EventArgs e)
        {
            if (!this.IsOpen)
            {
                Main_Timer.Enabled = false;
            }

            while (!Buffer_TX.Empty)
            {
                string text = Buffer_TX.Dequeue;

                OutgoingData?.Invoke(this, EventArgs.Empty);
                Console.WriteLine($"[TX] :{text}#");

                Write(":");

                long now = 0, before = 0;
                foreach (char c in text)
                {
                    do
                    {
                        now = DateTime.Now.Ticks / (TimeSpan.TicksPerMillisecond / 1000);
                    } while (now - before < 15);

                    before = now;
                    Write($"{c}");
                }

                Write("#");
            }
        }
Ejemplo n.º 2
0
        protected override void BeforeSendOutgoing(byte[] data)
        {
            //这里的data已经不是用户数据,已经包含了reliable
            var type = (Utilities.PackType)data[0];

            switch (type)
            {
            case PackType.Udp:
                var sendbuf = new byte[PackSettings.HEADER_LEN + data.Length];
                defpb.Write(sendbuf, data, 0, data.Length);
                OutgoingData.Enqueue(sendbuf);
                break;

            case PackType.Kcp:
                if (this.Context.EncoderData == null)
                {
                    return;
                }

                //交给kcp需要去掉第一个字节,不是直接发
                fixed(byte *b = &data[1])
                {
                    ikcp_send(this.Context.EncoderData, b, data.Length - 1);
                }

                break;

            default:
                throw new UnknownTypeException("unknown packtype");
                break;
            }
        }
Ejemplo n.º 3
0
        private void Save_Click(object sender, RoutedEventArgs e)
        {
            int vistId = 0;

            if (comboBoxVists.SelectedIndex > -1)
            {
                vistId = vistsList[comboBoxVists.SelectedIndex].Id;
            }
            OutgoingData outgoingData = new OutgoingData();

            if (int.TryParse(textBoxPrice.Text, out int price))
            {
                Outgoing outgoing = new Outgoing()
                {
                    OutGoing = price,
                    Details  = textBoxDetails.Text,
                    Date     = pickerStartDate.SelectedDate ?? DateTime.Now,
                    Vist_Id  = vistId,
                    Notes    = textBoxNotes.Text
                };

                outgoingData.AddOutgoing(outgoing);

                MessageBox.Show("تم الحفظ");
            }
            else
            {
                MessageBox.Show("تاكد من قيمة المصروف");
            }
        }
Ejemplo n.º 4
0
        private void ShowOutgoingStream(OutgoingData theData)
        {
            try
            {
                if (this.OutgoingStreamVisable &&
                    this.cbxRemoteIDs.Text == theData.RemoteDeviceID &&
                    this.FilterStream(theData.Stream))
                {
                    // 防止频繁刷新。
                    if (tvMessageSummary.Nodes.Count >= this.MaxSummaryCount &&
                        tvMessageSummary.SelectedNode != null &&
                        tvMessageSummary.SelectedNode.Index == 0)
                    {
                        this.tvMessageSummary.SelectedNode = null;
                    }

                    // 清除过期数据。
                    if (tvMessageSummary.Nodes.Count >= this.MaxSummaryCount)
                    {
                        tvMessageSummary.Nodes.RemoveAt(0);
                    }

                    // 如果没有指定解析器,则使用默认的解析器。
                    var parser = theData.Parser;
                    if (parser == null)
                    {
                        parser = _outputStreamDefaultParser;
                    }

                    // Create a node
                    var node = new TreeNode();
                    node.Tag              = new TreeNodeTag(theData.Frame, theData.Stream, parser);
                    node.Text             = string.Format("{0}, {1}", theData.RemoteDeviceID, theData.CreationTime.ToString("yyyy-MM-dd HH:mm:ss.fff"));
                    node.ImageKey         = "OutputStream";
                    node.SelectedImageKey = "outputStream_Selected";
                    node.ToolTipText      = theData.ToolTipText;

                    if (theData.Result == FrameSentResult.Successful)
                    {
                        node.ForeColor = Color.Green;
                    }
                    else if (theData.Result == FrameSentResult.Failed)
                    {
                        node.ForeColor = Color.Red;
                    }
                    else
                    {
                        node.ForeColor = Color.Blue;
                    }

                    // Add Node
                    tvMessageSummary.Nodes.Add(node);
                }
            }
            catch (Exception ex)
            {
                this.txtDetail.Text = ex.ToString();
            }
        }
Ejemplo n.º 5
0
        protected virtual int udp_output(byte *buf, int len, k.IKCPCB *kcp, void *user)
        {
            byte[] kcppack = new byte[len];
            Marshal.Copy(new IntPtr(buf), kcppack, 0, len);
#if PRINTPACK
            Console.WriteLine($"kcp_output:size{kcppack.Length}:{string.Join(",", kcppack)}");
#endif
            var sendbuf = new byte[PackSettings.HEADER_LEN + kcppack.Length];
            defpb.Write(sendbuf, kcppack, 0, kcppack.Length);
            OutgoingData.Enqueue(sendbuf);
            return(0);
        }
Ejemplo n.º 6
0
        protected override unsafe int udp_output(byte *buf, int len, k.IKCPCB *kcp, void *user)
        {
            //一定是reliable
            byte[] kcppack = new byte[len + 1];
            Marshal.Copy(new IntPtr(buf), kcppack, 1, len);
            kcppack[0] = (byte)PackType.Kcp;
#if PRINTPACK
            Console.WriteLine($"kcp_output:size{kcppack.Length}:{string.Join(",", kcppack)}");
#endif
            var sendbuf = new byte[PackSettings.HEADER_LEN + kcppack.Length];
            defpb.Write(sendbuf, kcppack, 0, kcppack.Length);
            OutgoingData.Enqueue(sendbuf);
            return(0);
        }