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());
        }
Exemplo n.º 3
0
        //private IEnumerable<T> _parseFile<T>(Metadata<T> metadata, byte[] rawData)
        //{
        //    var parsedData = new List<T>();

        //    //create parser
        //    try
        //    {
        //        using (var stream = new MemoryStream(rawData))
        //        {
        //            XSSFWorkbook hssfwb = new XSSFWorkbook(stream);

        //            for (int i = 0; i < hssfwb.NumberOfSheets; i++)
        //            {
        //                XSSFSheet sheet = (XSSFSheet)hssfwb.GetSheetAt(i);

        //                System.Collections.IEnumerator rows = sheet.GetRowEnumerator();
        //                rows.MoveNext();
        //                XSSFRow row = (XSSFRow)rows.Current;

        //                _headerList = _getHeaderList(row);
        //                _headerLookup = LNGProvider_Parser_HeaderLookup.BuildHeaderLookup(_headerList, metadata);

        //                if (_headerList == null)
        //                    throw new Exception("Unable to find Header row");

        //                while (rows.MoveNext())
        //                {
        //                    row = (XSSFRow)rows.Current;

        //                    ParsedRowList.Add(LNGProvider_Parser_Mapper._buildLNGFileValueDailyTotal(row, _headerLookup, LNGProvider_Parser_Constants.Countries[i]));

        //                }

        //            }

        //        }
        //        parsedData.ParsedData = ParsedRowList.ToArray();
        //        parsedData.RawData = rawData;

        //        return parsedData;
        //    }
        //    catch (Exception ex)
        //    {
        //        parsedData.RawData = rawData;
        //        return parsedData;
        //    }

        //    throw new NotImplementedException();
        //}

        private void _scan()
        {
            try
            {
                using (var stream = new MemoryStream(File.ReadAllBytes("c:\\Users\\Peter Vargovcik\\Documents\\Visual Studio 2015\\Projects\\SmartParser\\SmartParser\\Files\\daily_totals_2012-2014.xlsx")))
                {
                    XSSFWorkbook hssfwb = new XSSFWorkbook(stream);

                    Dictionary <XSSFRow, IEnumerable <XSSFRow> > rowDictionary = new Dictionary <XSSFRow, IEnumerable <XSSFRow> >();
                    string previousHash = "";

                    for (int i = 0; i < hssfwb.NumberOfSheets; i++)
                    {
                        XSSFSheet sheet = (XSSFSheet)hssfwb.GetSheetAt(i);

                        IEnumerator rows = sheet.GetRowEnumerator();

                        int rowNumber = 0;

                        while (rows.MoveNext())
                        {
                            XSSFRow row = (XSSFRow)rows.Current;
                            _linkedList.Add(row);

                            Console.Write("Sheet : {0}, Line {1}, ", sheet.SheetName, rowNumber);

                            // hash of the row types
                            var rowTypeString = String.Join("-", row.Cells.Select(x => x.CellType.ToString()).ToArray());

                            var currentHashRow = HelpersMethods.GetMD5(Encoding.ASCII.GetBytes(rowTypeString));

                            if (_hashNotSame(previousHash, currentHashRow))
                            {
                                rowDictionary.Add(row, new List <XSSFRow>());
                            }
                            else
                            {
                                IEnumerable <XSSFRow> list = rowDictionary.Last().Value;
                                ((List <XSSFRow>)list).Add(row);
                            }


                            //for (int j = 0; j < row.Cells.Count; j++)
                            //{
                            //    Console.Write("[{0} : {1}], ", j, row.Cells[j].CellType.ToString());
                            //}

                            //Console.WriteLine();

                            //var firstCell = row.Cells[0].CellType;
                            //Console.WriteLine(firstCell.ToString());
                            rowNumber++;
                            previousHash = currentHashRow;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }