Example #1
0
        public KeyValuePair <FileHeaderInfo, ValuesDynamicDictionary> ReadSingleFileToFileCache(string filepath)
        {
            FileHeaderInfo fileheaderinfo = new FileHeaderInfo(filepath);            //file meta data

            fileheaderinfo.ColumnsUsed = ReadFirstLineOfColumnsToIntArray(filepath); //what particular columns are in that EQRMS extract

            //2. Read the contents of the file into cache
            //	 a) There are two invariants for the same loop
            //	    i)              The indexer to keep track of where we are in the string[] from reading a line in the file
            //		columnNumber)	The current column we are upto as per the corresponding key(e.g. col #215) for the column's value we are populating
            ValuesDynamicDictionary values = new ValuesDynamicDictionary();

            using (var sr = new StreamReader(filepath))
            {
                for (int i = 0; i < numberOfRowsToSkip; i++)
                {
                    sr.ReadLine();
                }                                                               //skip the first x lines which contain column names and other useless info

                while (!sr.EndOfStream)
                {
                    string[] readLine = sr.ReadLine().Split(columnDelimeter); //get 1 row
                    numberofRowsInTotal++;
                    foreach (var columnsIndexes in fileheaderinfo.ColumnsUsed)
                    {
                        values.Add(columnsIndexes.Value, readLine[columnsIndexes.Key]);
                    }
                }
            }

            KeyValuePair <FileHeaderInfo, ValuesDynamicDictionary> ret = new KeyValuePair <FileHeaderInfo, ValuesDynamicDictionary>(fileheaderinfo, values);

            return(ret);
        }