Exemple #1
0
        /// <summary>
        /// Groups data from table 'A0Protocol' as a tree structure
        /// </summary>
        /// <param name="topNodeEnum"> type of top node </param>
        /// <param name="year"> year to filter records </param>
        /// <returns> structured data from 'A0Protocol' table as a tree </returns>
        public static ObservableCollection <Node> Group(TopNodeEnum topNodeEnum = TopNodeEnum.Login, int?year = null)
        {
            switch (topNodeEnum)
            {
            case TopNodeEnum.Login:
                return(GroupByLogin(year));

            case TopNodeEnum.SmObjectType:
                return(GroupBySmObjectType(year));

            default:
                return(GroupByLogin(year));
            }
        }
Exemple #2
0
        /// <summary>
        /// Builds an inner part of the tree for A0Protocol structure: 'Operation'-'Date_Progect_ObjectId_LogText'
        /// </summary>
        /// <param name="protocol"> data to be structured </param>
        /// <param name="login"> name of (grand)parent node 'Login' </param>
        /// <param name="smObjectType"> name of (grand)parent node 'SmObjectType' </param>
        /// <param name="topNodeEnum"> type of top node </param>
        /// <returns> structured data as an inner part of a tree </returns>
        private static ObservableCollection <Node> GroupByOperation(List <A0Protocol> protocol, string login, string smObjectType, TopNodeEnum topNodeEnum)
        {
            // Get all possible operation's types for current login and current smObjectType
            var operationTypes = protocol.GroupBy(g => g.Oper)
                                 .Select(u => new { Type = u.Key, Name = Convertor.GetInstance().GetOperationName(u.Key - 1) })
                                 .OrderBy(s => s.Name);

            var operationNodes = new ObservableCollection <Node>();

            foreach (var operationType in operationTypes)
            {
                // Records refered to current login, current smObjectType and current operationType
                var operationRecords = protocol.Where(o => o.Oper == operationType.Type);

                // Get all descriptions for current login, current smObjectType and current operationType
                var descriptionItems = operationRecords.Select(o => new { o.EvDate, ProjID = o.ProjId, SmObjID = o.SmObjId, o.LogText })
                                       .OrderBy(p => p.EvDate);

                var descriptionNodes = new ObservableCollection <Node>();

                foreach (var descriptionItem in descriptionItems)
                {
                    var descriptionNode = new DescriptionNode(descriptionItem.EvDate, descriptionItem.ProjID,
                                                              descriptionItem.SmObjID, descriptionItem.LogText);

                    // Create path according which node is the first
                    switch (topNodeEnum)
                    {
                    case TopNodeEnum.Login:
                        descriptionNode.NodePath = $"{login}/{smObjectType}/{operationType.Name}";
                        break;

                    case TopNodeEnum.SmObjectType:
                        descriptionNode.NodePath = $"{smObjectType}/{login}/{operationType.Name}";
                        break;

                    default:
                        descriptionNode.NodePath = $"{login}/{smObjectType}/{operationType.Name}";
                        break;
                    }

                    descriptionNode.NodeStyle = StyleGetter.Get(3);

                    descriptionNodes.Add(descriptionNode);
                }

                var operationNode = new Node
                {
                    Name      = operationType.Name,
                    Nodes     = descriptionNodes,
                    NodeStyle = StyleGetter.Get(2)
                };

                // Create path according which node is the first
                switch (topNodeEnum)
                {
                case TopNodeEnum.Login:
                    operationNode.NodePath = $"{login}/{smObjectType}";
                    break;

                case TopNodeEnum.SmObjectType:
                    operationNode.NodePath = $"{smObjectType}/{login}";
                    break;

                default:
                    operationNode.NodePath = $"{login}/{smObjectType}";
                    break;
                }

                operationNodes.Add(operationNode);
            }

            return(operationNodes);
        }