Exemplo n.º 1
0
        /// <summary>
        /// Add a new Node to the list.
        /// </summary>
        public void Add(NPOI_Node content)
        {
            size++;
            Node tempCurrent = current;

            var rowTypeString = HelpersMethods.StringArrayToString(content.Cells.Select(x => x.CellType.ToString()).ToArray());

            var rowValueString = HelpersMethods.StringArrayToString(content.Cells.Select(x => HelpersMethods.GetICellStringValue(x)).ToArray());

            var typeHash   = HelpersMethods.GetMD5(Encoding.ASCII.GetBytes(rowTypeString));
            var valuesHash = HelpersMethods.GetMD5(Encoding.ASCII.GetBytes(rowValueString));

            // This is a more verbose implementation to avoid adding nodes to the head of the list
            var node = new Node()
            {
                NodeContent = content,
                TypesHash   = typeHash,
                ValuesHash  = valuesHash
            };

            if (head == null)
            {
                // This is the first node. Make it the head
                head = node;
            }
            else
            {
                // This is not the head. Make it current's next node.
                current.Next  = node;
                node.Previous = tempCurrent;
            }

            // Makes newly added node the current node
            current = node;


            // This implementation is simpler but adds nodes in reverse order. It adds nodes to the head of the list

            //head = new Node()
            //{
            //    Next = head,
            //    NodeContent = content
            //};
        }
Exemplo n.º 2
0
        private void _buildHeadersCombinationFromAttributes()
        {
            PropertyInfo[] props = _model.GetProperties();

            // convert to dictionary
            var headders = props
                           .Where(x => x.GetCustomAttribute <TableHeader>() != null)
                           .Select
                           (
                x => new KeyValuePair <int, KeyValuePair <string, string[]> >
                (
                    x.GetCustomAttribute <TableHeader>().Index,
                    new KeyValuePair <string, string[]>(x.Name, x.GetCustomAttribute <TableHeader>().Headers)
                )
                           )
                           .OrderBy(x => x.Key)
                           .ToList();

            // possible combination count & check

            //var combinationPerProperty = headders
            //    .Select(x => x.Value.Value.Length)
            //    .ToArray<int>();

            //int combinationCount = combinationPerProperty.Aggregate(1, (a, b) => a * b);

            List <string[]> combinations = _getCombinations(headders);

            _headersCombinationsHash = _getCombinations(headders).Select(x =>
            {
                byte[] headder = Encoding.ASCII.GetBytes(HelpersMethods.StringArrayToString(x.ToArray()));
                return(HelpersMethods.GetMD5(headder));
            }).ToArray <string>();


            _headderMap = _getCombinations(headders).ToDictionary(k =>
            {
                return(HelpersMethods.GetMD5(Encoding.ASCII.GetBytes(HelpersMethods.StringArrayToString(k.ToArray()))));
            }
                                                                  , v => v.ToArray());
        }