public static string ConvertDatToCSV(string file)
 {
     try
     {
         var dat     = new DatContainer(file);
         var csvData = dat.GetCsvFormat();
         if (csvData == null)
         {
             throw new Exception("ConvertDatToCSV Error,is DatDefinitions.xml exist?");
         }
         return(csvData);
     }
     catch (Exception e)
     {
         throw;
     }
 }
示例#2
0
 public string GetCSV()
 {
     return(_dat.GetCsvFormat());
 }
示例#3
0
        /// <summary>
        /// Creates for each given .dat files it's .csv analogue
        /// </summary>
        /// <param name="files"></param>
        private void ConvertFiles(List <string> files)
        {
            if (files == null)
            {
                return;
            }
            ButtonSelectFolderEnnabled = false;
            ButtonSelectFilesEnabled   = false;
            var taskAction = new Action(() =>
            {
                foreach (var file in files)
                {
                    try
                    {
                        var dat     = new DatContainer(file);
                        var csvData = dat.GetCsvFormat();
                        var csvName = file + ".csv";
                        File.WriteAllText(csvName, csvData);
                        OutputLine(String.Format("Success: {0}", file));

                        // stats
                        var fileName = Path.GetFileName(file);
                        if (dat.RecordInfo.Fields.Count > 0)
                        {
                            _lengths[fileName] = dat.Records.Count;
                        }
                        else
                        {
                            _counts[fileName] = dat.Count;
                        }
                    }
                    catch (Exception e)
                    {
                        OutputLine(String.Format("Error: {0}\n\t{1}", file, e.Message));
                    }
                }
                OutputLine("\nFinished.");
            });
            var taskFinished = new Action <Task>(t =>
            {
                ButtonSelectFolderEnnabled = true;
                ButtonSelectFilesEnabled   = true;

                var tmp100   = new Dictionary <string, string>();
                var tmp1000  = new Dictionary <string, string>();
                var tmp10000 = new Dictionary <string, string>();
                foreach (var kv in _lengths)
                {
                    if (kv.Value < 100)
                    {
                        tmp100[kv.Key] = String.Format("{0}\t{1,-7}\t{2}", 0, kv.Value, kv.Key);
                    }
                    else if (kv.Value < 1000)
                    {
                        tmp1000[kv.Key] = String.Format("{0}\t{1,-7}\t{2}", 0, kv.Value, kv.Key);
                    }
                    else
                    {
                        tmp10000[kv.Key] = String.Format("{0}\t{1,-7}\t{2}", 0, kv.Value, kv.Key);
                    }
                }

                // 1000+ records
                var sortedFiles = tmp10000.Keys.ToList();
                sortedFiles.Sort();
                foreach (var s in sortedFiles)
                {
                    OutputLine(tmp10000[s]);
                }
                OutputLine("");

                // 100+ records
                sortedFiles = tmp1000.Keys.ToList();
                sortedFiles.Sort();
                foreach (var s in sortedFiles)
                {
                    OutputLine(tmp1000[s]);
                }
                OutputLine("");

                // <100 records
                sortedFiles = tmp100.Keys.ToList();
                sortedFiles.Sort();
                foreach (var s in sortedFiles)
                {
                    OutputLine(tmp100[s]);
                }
                OutputLine("");

                // no recors
                sortedFiles = _counts.Keys.ToList();
                sortedFiles.Sort();
                foreach (var s in sortedFiles)
                {
                    OutputLine(String.Format("{0}\t{1,-7}\t{2}", _counts[s], 0, s));
                }
            }
                                                 );

            var task = new Task(taskAction);

            task.ContinueWith(taskFinished);
            task.Start();
        }