示例#1
0
        public override bool Equals(object obj)
        {
            if (obj == null || !(obj is TerminalInfo))
            {
                return(false);
            }

            TerminalInfo other = (TerminalInfo)obj;

            if (!string.Equals(this.id, other.id))
            {
                return(false);
            }

            return(true);
        }
        private void ReceiveUdpMessage(IAsyncResult result)
        {
            UdpClient client = (UdpClient)result.AsyncState;

            if (client == null)
            {
                return;
            }

            try
            {
                var    remoteIPEndPoint = new IPEndPoint(IPAddress.Any, 0);
                Byte[] buffer           = client.EndReceive(result, ref remoteIPEndPoint);
                if (buffer != null)
                {
                    LoggingData loggingData = (LoggingData)formatter.Deserialize(new MemoryStream(buffer));
                    try
                    {
                        if (this.MessageReceived != null)
                        {
                            TerminalInfo terminalInfo;
                            string       key = remoteIPEndPoint.ToString();
                            if (!this.terminalInfos.TryGetValue(key, out terminalInfo))
                            {
                                terminalInfo = new TerminalInfo(loggingData.UserName, remoteIPEndPoint.Address.ToString(), remoteIPEndPoint.Port);
                                this.terminalInfos.Add(key, terminalInfo);
                            }

                            this.MessageReceived(terminalInfo, loggingData);
                        }
                    }
                    catch (Exception)
                    {
                    }
                }
            }
            catch (ObjectDisposedException)
            {
                return;
            }
            catch (Exception e)
            {
                UnityEngine.Debug.LogError(e);
            }

            client.BeginReceive(ReceiveUdpMessage, result.AsyncState);
        }
示例#3
0
        void AddLoggingData(TerminalInfo terminalInfo, LoggingData loggingData)
        {
            lock (_lock)
            {
                LoggingContainer container = null;
                int index = this.terminalInfos.IndexOf(terminalInfo);
                if (index < 0)
                {
                    this.terminalInfos.Add(terminalInfo);
                    container = new LoggingContainer(terminalInfo, this.maxCapacity);
                    this.containers.Add(container);
                    if (this.currentIndex < 0 || this.currentIndex >= this.terminalInfos.Count)
                    {
                        this.currentIndex = 0;
                    }
                }
                else
                {
                    container = this.containers[index];
                }

                container.Add(loggingData);
            }
        }
示例#4
0
 public LoggingContainer(TerminalInfo terminalInfo, int capacity)
 {
     this.terminalInfo = terminalInfo;
     this.capacity     = capacity;
 }
示例#5
0
 private void OnMesageReceived(TerminalInfo terminalInfo, LoggingData loggingData)
 {
     this.AddLoggingData(terminalInfo, loggingData);
 }