Ejemplo n.º 1
0
        /// <summary>
        /// Compares two trees and verifies if the scope nodes are equal
        /// </summary>
        /// <param name="root1"></param>
        /// <param name="root2"></param>
        /// <returns></returns>
        private static bool AreScopesEqual(ScopeNodeDto root1, ScopeNodeDto root2)
        {
            if (root1 == null && root2 == null)
            {
                return true;
            }

            if (root1 == null || root2 == null)
            {
                return false;
            }

            if (!string.Equals(root1.State?.ToString(), root2.State?.ToString(), StringComparison.OrdinalIgnoreCase)
                || root1.Children.Count != root2.Children.Count)
            {
                return false;
            }

            bool isChildScopeEqual = true;
            for (int i = 0; i < root1.Children.Count; i++)
            {
                isChildScopeEqual = AreScopesEqual(root1.Children[i], root2.Children[i]);

                if (!isChildScopeEqual)
                {
                    break;
                }
            }

            return isChildScopeEqual;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Traverses the scope node sub-tree and collects the list scopes
        /// </summary>
        /// <param name="root"></param>
        /// <param name="scopes"></param>
        private static void TraverseScopeTree(ScopeNodeDto root, List<string> scopes)
        {
            if (root == null)
            {
                return;
            }

            scopes.Add(root.State?.ToString());

            foreach (var childScope in root.Children)
            {
                TraverseScopeTree(childScope, scopes);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Compares two trees and verifies if the scope nodes are equal
        /// </summary>
        /// <param name="expected"></param>
        /// <param name="actual"></param>
        /// <returns></returns>
        public static bool ScopesEqual(ScopeNodeDto expected, ScopeNodeDto actual)
        {
            // To enable diagnosis, here a flat-list(pe-order traversal based) of 
            // these trees is provided.
            if (!AreScopesEqual(expected, actual))
            {
                var expectedScopes = new List<string>();
                var actualScopes = new List<string>();

                TraverseScopeTree(expected, expectedScopes);
                TraverseScopeTree(actual, actualScopes);

                throw new EqualException(expected: string.Join(", ", expectedScopes),
                                        actual: string.Join(", ", actualScopes));
            }

            return true;
        }
        private IEnumerable<ActivityContextDto> GetLogDetails(ElmStore elmStore)
        {
            var activities = new List<ActivityContextDto>();
            foreach (var activity in elmStore.GetActivities().Reverse())
            {
                var rootScopeNodeDto = new ScopeNodeDto();
                CopyScopeNodeTree(activity.Root, rootScopeNodeDto);

                activities.Add(new ActivityContextDto()
                {
                    RequestInfo = GetRequestInfoDto(activity.HttpInfo),
                    Id = activity.Id,
                    RepresentsScope = activity.RepresentsScope,
                    Root = rootScopeNodeDto
                });
            }

            return activities;
        }
Ejemplo n.º 5
0
        private IEnumerable <ActivityContextDto> GetLogDetails(ElmStore elmStore)
        {
            var activities = new List <ActivityContextDto>();

            foreach (var activity in elmStore.GetActivities().Reverse())
            {
                var rootScopeNodeDto = new ScopeNodeDto();
                CopyScopeNodeTree(activity.Root, rootScopeNodeDto);

                activities.Add(new ActivityContextDto()
                {
                    RequestInfo     = GetRequestInfoDto(activity.HttpInfo),
                    Id              = activity.Id,
                    RepresentsScope = activity.RepresentsScope,
                    Root            = rootScopeNodeDto
                });
            }

            return(activities);
        }
Ejemplo n.º 6
0
        private void CopyScopeNodeTree(ScopeNode root, ScopeNodeDto rootDto)
        {
            rootDto.LoggerName = root.Name;
            rootDto.State      = root.State?.ToString();
            rootDto.StateType  = root.State?.GetType();

            foreach (var logInfo in root.Messages)
            {
                rootDto.Messages.Add(GetLogInfoDto(logInfo));
            }

            foreach (var scopeNode in root.Children)
            {
                ScopeNodeDto childDto = new ScopeNodeDto();

                CopyScopeNodeTree(scopeNode, childDto);

                rootDto.Children.Add(childDto);
            }
        }
        private void CopyScopeNodeTree(ScopeNode root, ScopeNodeDto rootDto)
        {
            rootDto.LoggerName = root.Name;
            rootDto.State = root.State;
            rootDto.StateType = root.State?.GetType();

            foreach (var logInfo in root.Messages)
            {
                rootDto.Messages.Add(GetLogInfoDto(logInfo));
            }

            foreach (var scopeNode in root.Children)
            {
                ScopeNodeDto childDto = new ScopeNodeDto();

                CopyScopeNodeTree(scopeNode, childDto);

                rootDto.Children.Add(childDto);
            }
        }