示例#1
0
 public List()
 {
     Count          = 0;
     Mooc           = new Node(0);
     Head           = null;
     Tail           = null;
     ListEnumerator = new ListEnumerator(Mooc);
 }
示例#2
0
 public void SingleConsTest()
 {
     var symbol = new Symbol("abc");
     var cons = new Cons(symbol, LispNull.Nil);
     var enumerator = new ListEnumerator(cons);
     Assert.IsTrue(enumerator.MoveNext());
     Assert.AreSame(symbol, enumerator.Current);
     Assert.IsFalse(enumerator.MoveNext());
 }
示例#3
0
        private void BtnShowLeftListItems_Click(System.Object sender, System.EventArgs e)
        {
            IEnumerator ListEnumerator;
            String      ListContents = "";

            ListEnumerator = ucoPartnerFindCriteriaSetup.CriteriaFieldsLeft.GetEnumerator();

            while (ListEnumerator.MoveNext())
            {
                ListContents = ListContents + ListEnumerator.Current.ToString() + Environment.NewLine;
            }

            MessageBox.Show(ListContents);
        }
示例#4
0
        public IEnumerator <GeneralTreeNode <NodeValueType> > ReverseBreadthFirstNodeEnumerator()
        {
            IEnumerator <GeneralTreeNode <NodeValueType> > result;

            if (!IsEmpty)
            {
                result = Root.ReverseBreadthFirstNodeEnumerator();
            }
            else
            {
                result = new ListEnumerator <GeneralTreeNode <NodeValueType> >();
            }

            return(result);
        }
示例#5
0
        public IEnumerator <GeneralTreeNode <NodeValueType> > ForwardDepthFirstNodeEnumerator()
        {
            IEnumerator <GeneralTreeNode <NodeValueType> > result;

            if (!IsEmpty)
            {
                result = Root.ForwardDepthFirstNodeEnumerator();
            }
            else
            {
                result = new ListEnumerator <GeneralTreeNode <NodeValueType> >();
            }

            return(result);
        }
示例#6
0
        public IEnumerator <NodeValueType> ForwardBreadthFirstNodeValueEnumerator()
        {
            IEnumerator <NodeValueType> result;

            if (!IsEmpty)
            {
                result = Root.ForwardBreadthFirstNodeValueEnumerator();
            }
            else
            {
                result = new ListEnumerator <NodeValueType>();
            }

            return(result);
        }
示例#7
0
        public IEnumerator <NodeValueType> ReverseDepthFirstNodeValueEnumerator()
        {
            IEnumerator <NodeValueType> result;

            if (!IsEmpty)
            {
                result = Root.ReverseDepthFirstNodeValueEnumerator();
            }
            else
            {
                result = new ListEnumerator <NodeValueType>();
            }

            return(result);
        }
示例#8
0
        public void Test_Empty_List()
        {
            //Given
            var array = new List <int>();

            var arrayEnumerator = new ListEnumerator <int>(array);
            //When
            var enumerator = array.GetEnumerator();

            //Then
            Assert.False(enumerator.MoveNext());

            Exception ex = Assert.Throws <ArgumentException>(() => arrayEnumerator.Current);

            Assert.Equal("List is empty!", ex.Message);

            // ObjectEnumerator.Reset() method can only be used when using an auxiliary class
            // to implement the enumerating attribute.
            // enumerator.Reset();
        }
        internal static ZipkinSpan ToZipkinSpan(this SpanData otelSpan, ZipkinEndpoint defaultLocalEndpoint, bool useShortTraceIds = false)
        {
            var context        = otelSpan.Context;
            var startTimestamp = ToEpochMicroseconds(otelSpan.StartTimestamp);
            var endTimestamp   = ToEpochMicroseconds(otelSpan.EndTimestamp);

            string parentId = null;

            if (otelSpan.ParentSpanId != default)
            {
                parentId = EncodeSpanId(otelSpan.ParentSpanId);
            }

            var attributeEnumerationState = new AttributeEnumerationState
            {
                Tags = PooledList <KeyValuePair <string, string> > .Create(),
            };

            DictionaryEnumerator <string, object, AttributeEnumerationState> .AllocationFreeForEach(otelSpan.Attributes, ref attributeEnumerationState, ProcessAttributesRef);

            DictionaryEnumerator <string, object, AttributeEnumerationState> .AllocationFreeForEach(otelSpan.LibraryResource.Attributes, ref attributeEnumerationState, ProcessLibraryResourcesRef);

            var localEndpoint = defaultLocalEndpoint;

            var serviceName = attributeEnumerationState.ServiceName;

            // override default service name
            if (!string.IsNullOrWhiteSpace(serviceName))
            {
                if (!string.IsNullOrWhiteSpace(attributeEnumerationState.ServiceNamespace))
                {
                    serviceName = attributeEnumerationState.ServiceNamespace + "." + serviceName;
                }

                if (!LocalEndpointCache.TryGetValue(serviceName, out localEndpoint))
                {
                    localEndpoint = defaultLocalEndpoint.Clone(serviceName);
                    LocalEndpointCache.TryAdd(serviceName, localEndpoint);
                }
            }

            ZipkinEndpoint remoteEndpoint = null;

            if ((otelSpan.Kind == SpanKind.Client || otelSpan.Kind == SpanKind.Producer) && attributeEnumerationState.RemoteEndpointServiceName != null)
            {
                remoteEndpoint = RemoteEndpointCache.GetOrAdd(attributeEnumerationState.RemoteEndpointServiceName, ZipkinEndpoint.Create);
            }

            var status = otelSpan.Status;

            if (status.IsValid)
            {
                if (!CanonicalCodeCache.TryGetValue(status.CanonicalCode, out string canonicalCode))
                {
                    canonicalCode = status.CanonicalCode.ToString();
                    CanonicalCodeCache.TryAdd(status.CanonicalCode, canonicalCode);
                }

                PooledList <KeyValuePair <string, string> > .Add(ref attributeEnumerationState.Tags, new KeyValuePair <string, string>(StatusCode, canonicalCode));

                if (status.Description != null)
                {
                    PooledList <KeyValuePair <string, string> > .Add(ref attributeEnumerationState.Tags, new KeyValuePair <string, string>(StatusDescription, status.Description));
                }
            }

            var annotations = PooledList <ZipkinAnnotation> .Create();

            ListEnumerator <Event, PooledList <ZipkinAnnotation> > .AllocationFreeForEach(otelSpan.Events, ref annotations, ProcessEventsRef);

            return(new ZipkinSpan(
                       EncodeTraceId(context.TraceId, useShortTraceIds),
                       parentId,
                       EncodeSpanId(context.SpanId),
                       ToSpanKind(otelSpan),
                       otelSpan.Name,
                       ToEpochMicroseconds(otelSpan.StartTimestamp),
                       duration: endTimestamp - startTimestamp,
                       localEndpoint,
                       remoteEndpoint,
                       annotations,
                       attributeEnumerationState.Tags,
                       null,
                       null));
        }
        internal static ZipkinSpan ToZipkinSpan(this Activity activity, ZipkinEndpoint defaultLocalEndpoint, bool useShortTraceIds = false)
        {
            var context        = activity.Context;
            var startTimestamp = activity.StartTimeUtc.ToEpochMicroseconds();

            string parentId = EncodeSpanId(activity.ParentSpanId);

            if (string.Equals(parentId, InvalidSpanId, StringComparison.Ordinal))
            {
                parentId = null;
            }

            var attributeEnumerationState = new AttributeEnumerationState
            {
                Tags = PooledList <KeyValuePair <string, string> > .Create(),
            };

            DictionaryEnumerator <string, string, AttributeEnumerationState> .AllocationFreeForEach(activity.Tags, ref attributeEnumerationState, ProcessTagsRef);

            var activitySource = activity.Source;

            if (!string.IsNullOrEmpty(activitySource.Name))
            {
                PooledList <KeyValuePair <string, string> > .Add(ref attributeEnumerationState.Tags, new KeyValuePair <string, string>("library.name", activitySource.Name));

                if (!string.IsNullOrEmpty(activitySource.Version))
                {
                    PooledList <KeyValuePair <string, string> > .Add(ref attributeEnumerationState.Tags, new KeyValuePair <string, string>("library.version", activitySource.Version));
                }
            }

            var localEndpoint = defaultLocalEndpoint;

            var serviceName = attributeEnumerationState.ServiceName;

            // override default service name
            if (!string.IsNullOrWhiteSpace(serviceName))
            {
                if (!string.IsNullOrWhiteSpace(attributeEnumerationState.ServiceNamespace))
                {
                    serviceName = attributeEnumerationState.ServiceNamespace + "." + serviceName;
                }

                if (!LocalEndpointCache.TryGetValue(serviceName, out localEndpoint))
                {
                    localEndpoint = defaultLocalEndpoint.Clone(serviceName);
                    LocalEndpointCache.TryAdd(serviceName, localEndpoint);
                }
            }

            ZipkinEndpoint remoteEndpoint = null;

            if ((activity.Kind == ActivityKind.Client || activity.Kind == ActivityKind.Producer) && attributeEnumerationState.RemoteEndpointServiceName != null)
            {
                remoteEndpoint = RemoteEndpointCache.GetOrAdd(attributeEnumerationState.RemoteEndpointServiceName, ZipkinEndpoint.Create);
            }

            var annotations = PooledList <ZipkinAnnotation> .Create();

            ListEnumerator <ActivityEvent, PooledList <ZipkinAnnotation> > .AllocationFreeForEach(activity.Events, ref annotations, ProcessActivityEventsRef);

            return(new ZipkinSpan(
                       EncodeTraceId(context.TraceId, useShortTraceIds),
                       parentId,
                       EncodeSpanId(context.SpanId),
                       ToActivityKind(activity),
                       activity.OperationName,
                       activity.StartTimeUtc.ToEpochMicroseconds(),
                       duration: (long)activity.Duration.ToEpochMicroseconds(),
                       localEndpoint,
                       remoteEndpoint,
                       annotations,
                       attributeEnumerationState.Tags,
                       null,
                       null));
        }
示例#11
0
 public void EmptyListTest()
 {
     var enumerator = new ListEnumerator(LispNull.Nil);
     Assert.IsFalse(enumerator.MoveNext());
 }