/// <summary>
        ///  invoke presentation in order to add a new packet and refreshed counters
        ///  </summary>
        /// <param name="package"></param>
        /// <param name="amountOfReceivedPackages"></param>
        /// <param name="amountOfUniqueIps"></param>
        public void UpdatePresentation(PresentationPackage package, int amountOfReceivedPackages, int amountOfUniqueIps)
        {
            Dispatcher.BeginInvoke(DispatcherPriority.Background, (SendOrPostCallback)(state =>
            {
                try
                {
                    entries.Insert(0, package);

                    amount.Content = amountOfReceivedPackages;
                    uniqueIP.Content = amountOfUniqueIps;

                    //Delets old entries from List if the amount is > 100
                    if (entries.Count > MaxStoredPackage)
                    {
                        entries.RemoveAt(entries.Count - 1);
                    }
                }
                catch (Exception e)
                {
                    caller.GuiLogMessage(e.Message, NotificationLevel.Error);
                }
            }), null);
        }
示例#2
0
        private void UpdatePresentation(byte[] data, string ipFrom)
        {
            if (data == null || ipFrom == null)
            {
                return;
            }

            receivedPackagesCount++;
            // package recieved. fill local storage
            if (lastPackages.Count > NetworkReceiverPresentation.MaxStoredPackage)
            {
                lastPackages.RemoveAt(lastPackages.Count - 1);
            }
            else
            {
                lastPackages.Add(data);
            }

            uniqueSrcIps.Add(ipFrom);
            ReceivedDataSize += data.Length;

            // create Package
            var length = data.Length % 100;
            var packet = new PresentationPackage
            {
                PackageSize = generateSizeString(data.Length) + "yte", // 42B + "yte"
                IPFrom      = ipFrom,
                Payload     = (settings.ByteAsciiSwitch
                    ? Encoding.ASCII.GetString(data, 0, length)
                    : BitConverter.ToString(data, 0, length))
            };

            // update Presentation
            var clientCount = settings.Protocol == 0 ? uniqueSrcIps.Count : 0;

            presentation.UpdatePresentation(packet, receivedPackagesCount, clientCount);
        }