Ejemplo n.º 1
0
        private void CheckLogs(object sender, DoWorkEventArgs e)
        {
            ChannelFactory <IServiceCommunicator> channelFactory = null;

            try
            {
                NetTcpBinding ServiceBinding = new NetTcpBinding();
                ServiceBinding.Security.Mode          = SecurityMode.None;
                ServiceBinding.MaxBufferSize          = 2147483647;
                ServiceBinding.MaxReceivedMessageSize = 2147483647;
                channelFactory = new ChannelFactory <IServiceCommunicator>(ServiceBinding, new EndpointAddress(ServicePath));

                IServiceCommunicator Service =
                    channelFactory.CreateChannel();

                DateTime LatestDate;
                if (ServiceLogs.Count == 0)
                {
                    LatestDate = DateTime.MinValue;
                }
                else
                {
                    LatestDate = ServiceLogs.Max(p => p.Occurred);
                }

                e.Result = Service.GetLatestLogs(LatestDate);
                channelFactory.Close();
            }
            catch (Exception ex)
            {
                if (channelFactory != null)
                {
                    channelFactory.Abort();
                }
            }
        }
Ejemplo n.º 2
0
        private void CheckLogs_Tick(object sender, EventArgs e)
        {
            DateTime LatestDate = DateTime.MinValue;

            if (ServiceLogs.Count > 0)
            {
                LatestDate = ServiceLogs.Max(p => p.Occurred);
            }

            foreach (WcfEvent Event in eventLog.Where(p => p.Occurred > LatestDate))
            {
                ServiceLogs.Insert(0, Event);
            }
            while (ServiceLogs.Count > MaxRowsInLog)
            {
                try
                {
                    ServiceLogs.RemoveAt(MaxRowsInLog - 1);
                }
                catch (ArgumentOutOfRangeException ex) //sometimes threadsafe invoke messes up and throws exception. Ignore this one type of exception
                {
                }
            }
        }