Beispiel #1
0
 /// <summary>
 /// Extended method that saves the value part of a string string dictionary as rows in a textfile
 /// </summary>
 /// <param name="dict">this dictionary</param>
 /// <param name="filePath">The path to where the files should be stored eg: c:\temp</param>
 public static void SaveValuesAsFile(this Dictionary <string, string> dict, string filePath, Options opt)
 {
     using (StreamWriter writer = new StreamWriter(filePath))
         foreach (var item in dict)
         {
             writer.WriteLine("{0}",
                              opt.FieldCompression ? StringCompressor.DecompressString(item.Value) : item.Value);
         }
 }
Beispiel #2
0
        public void GetDataContent(ILineReader dr)
        {
            int i = 0; //rowcounter to see where error occured

            try
            {
                var fileStopwatch = Stopwatch.StartNew();
                #region Verbose output

                if (Option.Verbose)
                {
                    Console.ForegroundColor = ConsoleColor.DarkRed;
                    Console.WriteLine("Start reading {0}", DataPath);
                }

                #endregion
                using (dr)
                {
                    string line;
                    var    rowKey  = new StringBuilder();
                    var    colKeys = Option.Keycolumns;
                    var    sepChar = Option.Fieldseparator;

                    while ((line = dr.ReadLine()) != null)
                    {
                        i += 1;

                        //Fields 4,6,7 makes the row unique according to rumours. Not that fieldArr is nollbased so it is: 3,5,6
                        BuildRowKey(ref rowKey, line, sepChar, colKeys);
                        if (Option.FieldCompression)
                        {
                            line = StringCompressor.CompressString(line);
                        }
                        LineDictionary.Add(rowKey.ToString(), line);
                        rowKey.Clear();
                    }
                }
                fileStopwatch.Stop();
                #region Verbose output

                if (Option.Verbose)
                {
                    Console.ForegroundColor = ConsoleColor.DarkGreen;
                    Console.WriteLine("Done Reading {0} called file {3}. It took {1} ms and contained {2} rows", DataPath, fileStopwatch.Elapsed.Milliseconds, LineDictionary.Count, Name);
                    Console.ForegroundColor = ConsoleColor.DarkRed;
                }

                #endregion
            }
            #region Catch if error

            catch (Exception e)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("The file {0} could not be transformed to Dictionary structure error in line {1}:",
                                  DataPath, i);
                Console.WriteLine(e.Message);
                Console.ForegroundColor = ConsoleColor.White;
            }

            #endregion
        }