Ejemplo n.º 1
0
        public Dictionary <string, string> DiffB(DataChunk b, DataChunk a, DictCompareOnKeyOnly keyOnly, Options options)
        {                //Here comes the magic simple Except and Intersect and force it back to Dictionary.
            var setDiffSw = Stopwatch.StartNew();
            var diffB     = b.LineDictionary.Except(a.LineDictionary, keyOnly).ToDictionary(ld => ld.Key, ld => ld.Value);

            if (options.Verbose)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("File {0} ({4}) has {1} keys. {2} of them do not exist in file {3} ({5})", Path.GetFileName(b.DataPath), b.LineDictionary.Count(), diffB.Count(), Path.GetFileName(a.DataPath), b.Name, a.Name);
                Console.WriteLine("Time after creating set operator {0} ms", setDiffSw.ElapsedMilliseconds);
            }
            setDiffSw.Stop();
            return(diffB);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Takes two parameters file A and File B. Set A is contained in B also.
        /// A is file n and B is file n+1
        /// </summary>
        /// <param name="args">-a fileA -b fileB -v optional verbose</param>
        public static void Main(string[] args)
        {
            var options = new Options();

            if (Parser.Default.ParseArguments(args, options))
            {
                var programStopwatch = Stopwatch.StartNew();
                var chunkList        = new List <DataChunk>
                {
                    new DataChunk(dataPath: options.FileA, name: "A", option: options),
                    new DataChunk(dataPath: options.FileB, name: "B", option: options)
                };
                //Multithread the reading of files and making dictionary of all lines in file
                Parallel.ForEach(chunkList, dl => dl.GetDataContent(new FileLineReader(dl.DataPath)));
                //Give the sets nicer names
                var a = chunkList.First(f => f.Name == "A");
                var b = chunkList.First(f => f.Name == "B");
                //We need Compare to use set logic on keys only not Key and Value which is the default - odd that is the default and we have to override it.
                var keyOnly = new DictCompareOnKeyOnly();
                var setOp   = new SetOperator();
                //Here we save the output as text files and do magic in the DiffDB function
                var outPutList = new List <OutputObj>
                {
                    new OutputObj(name: "DiffB", dict: setOp.DiffB(b, a, keyOnly, options), opt: options),
                };
                //Multithread the output of files
                Parallel.ForEach(outPutList, oL => oL.Output());
                programStopwatch.Stop();
                if (options.Verbose)
                {
                    Console.ForegroundColor = ConsoleColor.White;
                    Console.WriteLine("Done ! hit any key to exit program. ExecutionTime was {0} ms",
                                      programStopwatch.Elapsed.Milliseconds);
                    Console.ReadLine();
                }
            }
        }