public static void RunObjectsDiff(object data)
    {
        if (null == data ||
            !(data is CompareFiles))
        {
            return;
        }

        CompareFiles param = (CompareFiles)data;

        string path1 = param.Path1;
        string path2 = param.Path2;

        if (!File.Exists(path1))
        {
            Debug.LogError(string.Format("Can't find object 1={0}", path1));
            return;
        }

        if (!File.Exists(path2))
        {
            Debug.LogError(string.Format("Can't find object 2={0}", path2));
            return;
        }

        string diffProgram = string.Empty;

        switch (Application.platform)
        {
        case RuntimePlatform.OSXEditor:
            diffProgram = @"/Applications/Xcode.app/Contents/Applications/FileMerge.app/Contents/MacOS/FileMerge";
            break;

        case RuntimePlatform.WindowsEditor:
            diffProgram = @"C:\Program Files (x86)\WinMerge\WinMergeU.exe";
            break;
        }

        if (!File.Exists(diffProgram))
        {
            Debug.LogError(string.Format("Can't find diff program={0}", diffProgram));
            return;
        }

        switch (Application.platform)
        {
        case RuntimePlatform.OSXEditor:
            RunProcess(diffProgram, string.Format("-left \"{0}\" -right \"{1}\"",
                                                  path1,
                                                  path2));
            break;

        case RuntimePlatform.WindowsEditor:
            RunProcess(diffProgram, string.Format("\"{0}\" \"{1}\"",
                                                  path1,
                                                  path2));
            break;
        }
    }
 public void CompareFilesBadConstructor(IDeltaController ic)
 {
     Assert.Throws <ArgumentNullException>(() =>
     {
         CompareFiles cf = new CompareFiles(ic);
     }
                                           );
 }
        public void CompareFilesGoodConstructor()
        {
            Mock <IDeltaController> deltacontrollerDouble = new Mock <IDeltaController>();

            deltaController = deltacontrollerDouble.Object;

            CompareFiles cf = new CompareFiles(deltaController);

            Assert.AreEqual(cf.dc, deltaController);
        }
Example #4
0
 static void Main(string[] args)
 {
     Parser.Default.ParseArguments <Options>(args)
     .WithParsed <Options>(o =>
     {
         var cmp = new CompareFiles(o.Left, o.Right, o.Comparison);
         Console.WriteLine($" Left file \"{Path.GetFileName(o.Left.FilePath)}\" coverage = {AggregateCoverage(o.Left.Modules, o.Comparison)}");
         Console.WriteLine($"Right file \"{Path.GetFileName(o.Right.FilePath)}\" coverage = {AggregateCoverage(o.Right.Modules, o.Comparison)}");
         RenderComparison(cmp, "", o.ShowExclusiveItems);
     });
 }
Example #5
0
        protected override void Initialize()
        {
            base.Initialize();

            Configuration = (ConfigurationPage)GetDialogPage(typeof(ConfigurationPage));

            BreakAllInCurrentDocument.Initialize(0x0001, this);
            LocateInSolutionExplorer.Initialize(0x0002, this);
            LocateInSourceControlExplorer.Initialize(0x0003, this);
            EditSolutionFile.Initialize(0x0004, this);
            EditProjectFile.Initialize(0x0005, this);
            CompareFiles.Initialize(0x0006, this);
        }
        public void CompareFiles(string content, string databaseContent)
        {
            Mock <IDeltaController> deltacontrollerDouble = new Mock <IDeltaController>();

            deltaController = deltacontrollerDouble.Object;

            CompareFiles cf = new CompareFiles(deltaController);

            Delta d = cf.Compare(content, databaseContent, "nekiFajl");

            Assert.AreEqual(d.Content, "nesto\n druga\n");
            Assert.AreEqual(d.LineRange, "1,2,");
        }
        public void CompareFilesBadException(string content, string databaseContent)
        {
            Mock <IDeltaController> deltacontrollerDouble = new Mock <IDeltaController>();

            deltaController = deltacontrollerDouble.Object;

            CompareFiles cf = new CompareFiles(deltaController);

            Assert.Throws <ArgumentException>(() =>
            {
                cf.Compare(content, databaseContent, "bzvId");
            }
                                              );
        }
Example #8
0
        static void Main(string[] args)
        {
            string pathToTempFile = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString() + ".txt";

            ProcessFile.DeleteEmptiesAndNonArs(Config.pathToRptNewNewFile, pathToTempFile);
            var outputFile  = CompareFiles.Compare(pathToTempFile, Config.pathToRptFile);
            var outputFile2 = CompareFiles.Compare(Config.pathToRptFile, pathToTempFile);

            using (StreamReader reader = new StreamReader(outputFile))
            {
                string line;
                while ((line = reader.ReadLine()) != null)
                {
                    Console.WriteLine(line);
                }
            }
            Console.WriteLine("OutpultFile: " + outputFile);
            Console.WriteLine("Tempfile: " + pathToTempFile);
            Console.WriteLine("Outputfile2: " + outputFile2);
            Console.WriteLine("********** END OF OUTPUT **********");

            //SaveAccountToDb.Save(new Account());
            //string line;
            //ProcessFile.DeleteEmptiesAndNonArs(pathToRptFile, pathToTempFile);

            //StreamReader cleanFile = new StreamReader(pathToTempFile);
            //while ((line = cleanFile.ReadLine()) != null)
            //{
            //    if (!char.IsWhiteSpace(line[0]))
            //    {
            //        var accountHeader = new AccountHeader();
            //        accountHeader = ProcessFile.SetAccountHeader(line);
            //    }
            //    else if (!line.Contains("TOTAL"))
            //    {
            //        var accountInfo = new AccountInfo();
            //        if (line.Substring(18, 9).Contains('/'))
            //        {
            //            accountInfo.TranDate = Convert.ToDateTime(line.Substring(18, 9));
            //        }
            //        string tranDescription = string.Empty;
            //        if (!string.IsNullOrWhiteSpace(line.Substring(28, 13)))
            //        {
            //            if (char.IsDigit(line[42]))
            //            {
            //                accountInfo.TranDetail = line.Substring(28, 11);
            //            }
            //            else
            //            {
            //                accountInfo.TranDetail = line.Substring(28, 13);
            //            }
            //        }

            //        var invoice = string.Empty;
            //        if (!line.Substring(39, 10).Contains('T') && !char.IsWhiteSpace(line[44]))
            //        {
            //            accountInfo.InvoiceNumber = line.Substring(39, 10);
            //        }


            //        var referenceNumber = string.Empty;
            //        if (!string.IsNullOrWhiteSpace(line.Substring(49, 13)) && !line.Substring(49, 13).Contains("Customer"))
            //        {
            //            accountInfo.ReferenceNumber = line.Substring(49, 13).TrimStart();
            //        }
            //        var dueDate = string.Empty;
            //        if (!string.IsNullOrWhiteSpace(line.Substring(64, 7)))
            //        {
            //            accountInfo.DueDate = Convert.ToDateTime(line.Substring(63, 8).TrimStart());
            //        }

            //        var inv = new InvoiceBalance();

            //        if (line.Substring(74, line.Length - 74).Any(char.IsDigit))
            //        {
            //            List<string> vs = ParseInvoiceNumber.Parse(line.Substring(74, line.Length - 74));
            //            PropertyInfo[] properties = inv.GetType().GetProperties();

            //            for (int i = 0; i < vs.Count; i++)
            //            {
            //                if (!string.IsNullOrEmpty(vs[i]))
            //                {
            //                    properties[i].SetValue(inv, vs[i].Last() == '-' ? (Convert.ToDecimal(vs[i].Remove(vs[i].Length - 1)) * -1) : Convert.ToDecimal(vs[i]));
            //                }
            //                else
            //                {
            //                    properties[i].SetValue(inv, 0.0m);
            //                }
            //            }

            //        }

            //    }
            //    else
            //    {
            //        Console.WriteLine("Total Customer: ");


            //        var inv = new InvoiceBalance();
            //        if (line.Substring(74, line.Length - 74).Any(char.IsDigit))
            //        {
            //            List<string> vs = ParseInvoiceNumber.Parse(line.Substring(74, line.Length - 74));
            //            PropertyInfo[] properties = inv.GetType().GetProperties();

            //            for (int i = 0; i < vs.Count; i++)
            //            {
            //                if (!string.IsNullOrEmpty(vs[i]))
            //                {
            //                    properties[i].SetValue(inv, vs[i].Last() == '-' ? (Convert.ToDecimal(vs[i].Remove(vs[i].Length - 1)) * -1) : Convert.ToDecimal(vs[i]));
            //                }
            //                else
            //                {
            //                    properties[i].SetValue(inv, 0.0m);
            //                }
            //            }

            //        }

            //    }
            //}
        }
Example #9
0
        static void Main(string[] args)
        {
            int           depth               = 0;
            bool          printProcesTime     = false;
            bool          extendedOutput      = false;
            bool          waitBeforeTerminate = false;
            int           maxThreads          = 0;
            uint          doubleDataFound     = 0;
            List <string> path   = new List <string>();
            List <string> filter = new List <string>();

            if (args.Length < 2)
            {
                printHelp();
                return;
            }

            //handle input arguments
            for (int i = 0; i < args.Length; i++)
            {
                try
                {
                    string argument = args[i];
                    if (argument == "-r")
                    {
                        try
                        {
                            depth = int.Parse(args[i + 1]);
                            if (depth < 0)
                            {
                                Console.WriteLine("Error: folder depth must be > 0");
                            }
                            i++;
                        }
                        catch (Exception e)
                        {
                            depth = -2;     //search in all subdirectories
                        }
                    }
                    else if (argument == "-f")
                    {
                        string[] temp = args[i + 1].Split(';');
                        filter.AddRange(temp);
                        i++;
                    }
                    else if (argument == "-t")
                    {
                        maxThreads = int.Parse(args[i + 1]);
                        if (depth <= 0)
                        {
                            Console.WriteLine("Error: there must be at least 1 Thread");
                        }
                        i++;
                    }
                    else if (argument == "-s")
                    {
                        path.Add(args[i + 1]);
                        i++;
                    }
                    else if (argument == "-h")
                    {
                        printHelp();
                        break;
                    }
                    else if (argument == "-p")
                    {
                        printProcesTime = true;
                    }
                    else if (argument == "-v")
                    {
                        extendedOutput = true;
                    }
                    else if (argument == "-w")
                    {
                        waitBeforeTerminate = true;
                    }
                    else
                    {
                        if (i == (args.Length - 1))
                        {
                            path.Add(argument);
                        }
                        else
                        {
                            Console.WriteLine("wrong argument: " + argument);
                        }
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("Error: in interpreting arguments " + args[i]);
                }
            }

            //if no filter is set add filter to all
            if (filter.Count == 0)
            {
                filter.Add("*");
            }

            Console.WriteLine("Started finding multibe files files...");
            Stopwatch timer = new Stopwatch();

            timer.Start();

            //get all files and their size
            GetFiles getFiles = new GetFiles();
            ConcurrentDictionary <long, string> files = new ConcurrentDictionary <long, string>();

            foreach (string entry in path)
            {
                getFiles.getFilesFromDirectory(entry, depth, filter, files);
            }


            // get all files that have the same size
            ConcurrentDictionary <long, string> doubleFiles = new ConcurrentDictionary <long, string>();

            foreach (KeyValuePair <long, string> entry in files)
            {
                if (entry.Value.Contains(";"))
                {
                    doubleFiles.TryAdd(entry.Key, entry.Value);
                }
            }

            //Compare files with same size
            CompareFiles  compareFiles    = new CompareFiles();
            List <string> realDoubleFiles = new List <string>();

            if (maxThreads == 0)
            {
                Parallel.ForEach(files, (entry) =>
                {
                    compareFiles.compareFileTest(entry.Value, realDoubleFiles);
                });
            }
            else
            {
                Parallel.ForEach(files, new ParallelOptions {
                    MaxDegreeOfParallelism = maxThreads
                },
                                 (entry) =>
                {
                    compareFiles.compareFileTest(entry.Value, realDoubleFiles);
                });
            }

            //print files
            foreach (string pathes in realDoubleFiles)
            {
                Console.WriteLine("Files with the same content:");
                string[] temp = pathes.Split(';');
                foreach (string tempPath in temp)
                {
                    Console.WriteLine("\t" + tempPath);
                }
            }

            timer.Stop();
            if (extendedOutput)
            {
                Console.WriteLine("\nAnzahl gefundener Dateien mit unterschiedlicher Dateigröße: " + files.Count());
                Console.WriteLine("Gefundene Dateien mit gleicher Dateigröße: " + doubleFiles.Count());
                Console.WriteLine("Gefundene Doppelte Dateien: " + realDoubleFiles.Count());
            }
            if (printProcesTime)
            {
                TimeSpan ts          = timer.Elapsed;
                string   elapsedTime = String.Format("{0:00}.{1:000}", ts.TotalSeconds, ts.Milliseconds);
                Console.WriteLine("\nRunTime: " + elapsedTime + " seconds\n");
            }
            if (waitBeforeTerminate)
            {
                Console.Write("Press any key to exit...");
                //Console.ReadLine();
                Console.ReadKey();
            }
        }