Пример #1
0
        public void Compare([ArgRequired] CompareArguments arg)
        {
            logger.Info("File1 \"{0}\".", arg.FilePath);
            logger.Info("File2 \"{0}\".", arg.FilePath2);

            if (!File.Exists(arg.FilePath))
            {
                logger.Error("File1 \"{0}\" does not exist or is inaccessible", arg.FilePath);
                Environment.Exit(-1);
            }

            if (!File.Exists(arg.FilePath2))
            {
                logger.Error("File2 \"{0}\" does not exist or is inaccessible", arg.FilePath2);
                Environment.Exit(-1);
            }

            logger.Info("Loading file 1");
            List <CSVAccountValue> file1List = File.ReadAllLines(arg.FilePath)
                                               .Skip(1)
                                               .Select(v => CSVAccountValue.FromCsv(v))
                                               .ToList();

            logger.Info("Loading file 2");
            List <CSVAccountValue> file2List = File.ReadAllLines(arg.FilePath2)
                                               .Skip(1)
                                               .Select(v => CSVAccountValue.FromCsv(v))
                                               .ToList();

            logger.Info("Convert file 1 to dictionary");
            Dictionary <string, string> file1Dictionary = new Dictionary <string, string>();

            foreach (var row in file1List)
            {
                file1Dictionary.Add(row.account_name, row.total_eos);
            }

            logger.Info("Convert file 2 to dictionary");
            Dictionary <string, string> file2Dictionary = new Dictionary <string, string>();

            foreach (var row in file2List)
            {
                file2Dictionary.Add(row.account_name, row.total_eos);
            }

            //We're assuming all the keys match and only the values differ
            foreach (var file1account in file1Dictionary.Keys)
            {
                if (file1Dictionary[file1account] != file2Dictionary[file1account])
                {
                    logger.Warn("DIFF: {0}\t{1}\t{2}", file1account, file1Dictionary[file1account], file2Dictionary[file1account]);
                }
            }

            /*
             * var diffDictionary = file2Dictionary.Where(entry => file1Dictionary[entry.Key] != entry.Value)
             *   .ToDictionary(entry => entry.Key, entry => entry.Value);
             */
        }
Пример #2
0
        public static CSVAccountValue FromCsv(string csvLine)
        {
            string[]        values    = csvLine.Split(',');
            CSVAccountValue csvValues = new CSVAccountValue();

            csvValues.creation_time = values[0];
            csvValues.account_name  = values[1];
            csvValues.total_eos     = values[2];
            return(csvValues);
        }