示例#1
0
        public static bool EnumerableCompare <T>(IEnumerable <T> a, IEnumerable <T> b) where T : class
        {
            bool equals;
            var  x = 0;

            if (CompareExtensions.CheckNullEquality(a, b, out equals))
            {
                return(equals);
            }

            if (a.Count() != b.Count())
            {
                return(false);
            }

            foreach (var itemA in a)
            {
                var itemB = b.ElementAt(x);

                if (!itemA.Equals(itemB))
                {
                    return(false);
                }

                x++;
            }

            return(true);
        }
示例#2
0
        public static LoggerConfiguration Relay(this LoggerSinkConfiguration sinkConfiguration, ILoggerRelay loggerRelay, IConfigurationSection serilogConfig, CancellationToken cancellationToken)
        {
            LoggerRelayEventSink eventSink;
            var comparer          = new ObjectHashCodeComparer <IConfiguration>();
            var configurationTree = new ObjectTree <IConfiguration>(comparer);
            IConfigurationSection           relayConfigurationSection;
            ObjectTreeItem <IConfiguration> treeItem;
            LinkedListNode <ObjectTreeItem <IConfiguration> > sibling;
            LoggerRelayEventSinkConfigArgs logRelayEventSinkConfigArgs = null;

            configurationTree.AddChild(serilogConfig);

            serilogConfig.GetDescendantsWithParent(s => s.GetChildren(), (parent, child) =>
            {
                var parentItem = configurationTree.FindTreeItem(parent);

                parentItem.AddChild(child);
            });

            relayConfigurationSection = configurationTree.GetDescendants().Select(d => d.InternalObject).OfType <IConfigurationSection>().SingleOrDefault(s => s.Path.RegexIsMatch(@"Serilog:WriteTo:(\d+:)?Name") && s.Value == "Relay");

            if (relayConfigurationSection == null)
            {
                throw new ConfigurationException("Logger relay requires a configuration section with a RootPath member");
            }
            else
            {
                treeItem = configurationTree.FindTreeItem(relayConfigurationSection);
                sibling  = CompareExtensions.GetNonNull(treeItem.LinkedListNode.Next, treeItem.LinkedListNode.Previous);

                if (sibling != null && ((IConfigurationSection)sibling.Value.InternalObject).Key == "Args")
                {
                    logRelayEventSinkConfigArgs = sibling.Value.InternalObject.Get <LoggerRelayEventSinkConfigArgs>();
                }
                else
                {
                    throw new ConfigurationException("Logger relay requires a configuration section with a RootPath member");
                }

                loggerRelay.Initialize(logRelayEventSinkConfigArgs);
            }

            using (lockObject.Lock())
            {
                if (eventSinks.Any(s => s.Domain == loggerRelay.Domain))
                {
                    eventSink = eventSinks.Single(s => s.Domain == loggerRelay.Domain);
                }
                else
                {
                    eventSink = new LoggerRelayEventSink(loggerRelay, cancellationToken, logRelayEventSinkConfigArgs);

                    eventSinks.Add(eventSink);
                }
            }

            return(sinkConfiguration.Sink(eventSink));
        }
示例#3
0
        public int CompareTo(HSLColor other)
        {
            bool equals;

            if (CompareExtensions.CheckNullEquality(this, other, out equals))
            {
                return(equals ? 0 : 1);
            }
            else
            {
                var compare = CompareExtensions.AllAreTrue(
                    this.Hue == other.Hue,
                    this.Saturation == other.Saturation,
                    this.Luminosity == other.Luminosity);

                return(compare ? 0 : 1);
            }
        }
示例#4
0
        public static LoggerConfiguration Trace(this LoggerSinkConfiguration sinkConfiguration, string ipAddress, int port, IConfigurationSection serilogConfig, CancellationToken cancellationToken)
        {
            TraceLogEventSink eventSink;
            var comparer          = new ObjectHashCodeComparer <IConfiguration>();
            var configurationTree = new ObjectTree <IConfiguration>(comparer);
            IConfigurationSection           traceConfigurationSection;
            ObjectTreeItem <IConfiguration> treeItem;
            LinkedListNode <ObjectTreeItem <IConfiguration> > sibling;
            TraceLogEventSinkConfigArgs traceLogEventSinkConfigArgs = null;

            configurationTree.AddChild(serilogConfig);

            serilogConfig.GetDescendantsWithParent(s => s.GetChildren(), (parent, child) =>
            {
                var parentItem = configurationTree.FindTreeItem(parent);

                parentItem.AddChild(child);
            });

            traceConfigurationSection = configurationTree.GetDescendants().Select(d => d.InternalObject).OfType <IConfigurationSection>().SingleOrDefault(s => s.Path.RegexIsMatch(@"Serilog:WriteTo:(\d+:)?Name") && s.Value == "Trace");
            treeItem = configurationTree.FindTreeItem(traceConfigurationSection);
            sibling  = CompareExtensions.GetNonNull(treeItem.LinkedListNode.Next, treeItem.LinkedListNode.Previous);

            if (sibling != null && ((IConfigurationSection)sibling.Value.InternalObject).Key == "Args")
            {
                traceLogEventSinkConfigArgs = sibling.Value.InternalObject.Get <TraceLogEventSinkConfigArgs>();
            }

            using (lockObject.Lock())
            {
                if (eventSinks.Any(s => s.Address == ipAddress && s.Port == port))
                {
                    eventSink = eventSinks.Single(s => s.Address == ipAddress && s.Port == port);
                }
                else
                {
                    eventSink = new TraceLogEventSink(ipAddress, port, cancellationToken, traceLogEventSinkConfigArgs);

                    eventSinks.Add(eventSink);
                }
            }

            return(sinkConfiguration.Sink(eventSink));
        }
示例#5
0
        public static bool ReflectCompare <T>(T a, T b, Func <string, T, T, bool> propertyCompare)
        {
            bool equals;

            if (CompareExtensions.CheckNullEquality(a, b, out equals))
            {
                return(equals);
            }

            foreach (var property in typeof(T).GetProperties(System.Reflection.BindingFlags.FlattenHierarchy | System.Reflection.BindingFlags.GetProperty | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public))
            {
                if (!propertyCompare(property.Name, a, b))
                {
                    return(false);
                }
            }

            return(true);
        }
示例#6
0
        // kn - best approach to equality comparisons

        private static bool Equals(StatusEntry a, StatusEntry b)
        {
            bool equals;

            if (CompareExtensions.CheckNullEquality(a, b, out equals))
            {
                return(equals);
            }
            else
            {
                if (a.StatusText != b.StatusText || a.ForeColor != b.ForeColor || a.BackColor != b.BackColor)
                {
                    return(false);
                }
                else
                {
                    return(true);
                }
            }
        }