Ejemplo n.º 1
0
        public static void getExampleDTO(out MyDupFinderProjectDTO myDupFinderProjectDTO)
        {
            //project
            myDupFinderProjectDTO = new MyDupFinderProjectDTO();

            //scan
            var myDupFinderScanJobDTO = new MyDupFinderScanJobDTO();

            myDupFinderScanJobDTO.JobName        = "Example scanjob name";
            myDupFinderScanJobDTO.OriginComputer = "E6600";
            myDupFinderScanJobDTO.BasePath       = @"m:\Test";
            myDupFinderScanJobDTO.ScanName       = "Backup of old computer";
            myDupFinderScanJobDTO.DatabaseFile   = @"m:\finddupdb\base.db";
            myDupFinderScanJobDTO.ReportPath     = @"m:\finddupdb\";
            myDupFinderProjectDTO.MyDupFinderScanJobDTOs.Add(myDupFinderScanJobDTO);

            //check
            var myDupFinderCheckJobDTO = new MyDupFinderCheckJobDTO();

            myDupFinderCheckJobDTO.ScanJobDTO         = myDupFinderScanJobDTO;
            myDupFinderCheckJobDTO.ScanJobDTO.JobName = "Example checkjob name";
            myDupFinderCheckJobDTO.IgnoreBasePath     = false;
            myDupFinderCheckJobDTO.SkipHashCheck      = true;
            myDupFinderProjectDTO.MyDupFinderCheckJobDTOs.Add(myDupFinderCheckJobDTO);

            //FindDups
            var myDupFinderFindDupsJobDTO = new MyDupFinderFindDupsJobDTO();

            myDupFinderFindDupsJobDTO.JobName          = "Example FindDupsJob name";
            myDupFinderFindDupsJobDTO.FindDupsMode     = MyDupFinderFindDupsJobDTO.EFindDupsMode.FindOnlyDups;
            myDupFinderFindDupsJobDTO.DatabaseFileBase = @"m:\finddupdb\base.db";
            myDupFinderFindDupsJobDTO.DatabaseFile     = @"m:\finddupdb\newdb.db";
            myDupFinderFindDupsJobDTO.ReportPath       = @"m:\finddupdb\";
            myDupFinderProjectDTO.MyDupFinderFindDupsJobDTOs.Add(myDupFinderFindDupsJobDTO);
        }
Ejemplo n.º 2
0
 public static void WriteConfigurationToFile(MyDupFinderProjectDTO myDupFinderProjectDTO, string pathAndFilename)
 {
     Contract.Requires(myDupFinderProjectDTO != null);
     System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(myDupFinderProjectDTO !.GetType());
     using (FileStream fs = new FileStream(pathAndFilename, FileMode.CreateNew, FileAccess.Write))
     {
         x.Serialize(fs, myDupFinderProjectDTO);
     }
 }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            System.Threading.Thread.CurrentThread.Name = "MainThread";

            // Setup log with DI
            var serviceCollection = new ServiceCollection();

            ConfigureServices(serviceCollection);
            var serviceProvider = serviceCollection.BuildServiceProvider();
            var logger          = serviceProvider.GetService <Microsoft.Extensions.Logging.ILogger <Program> >();
            var assembly        = typeof(Program).Assembly;

            logger.LogInformation($"Application with version {assembly.GetName().Version}  ({ThisAssembly.AssemblyInformationalVersion}) started...");


            //Do stuff
            //Scan commandline
            if (args.Length == 2)
            {
                CultureInfo ci = new CultureInfo("");
                if (args[0].ToLower(ci) == "exampleproject")
                {
                    try
                    {
                        MyDupFinderProjectDTO dto;
                        MyDupFinderProject.getExampleDTO(out dto);
                        MyDupFinderProject.WriteConfigurationToFile(dto, args[1]);
                        logger.LogInformation($"Example project file succesfully written! {args[1]}");
                    }
                    catch (Exception ex)
                    {
                        logger.LogError(ex, $"Example project file could not be written! {args[1]}");
                    }
                }
                else if (args[0].ToLower(ci) == "dryrun")
                {
                    try
                    {
                        MyDupFinderProjectDTO?dto;
                        MyDupFinderProject.ReadConfigurationFromFile(args[1], out dto);
                        logger.LogInformation($"Example project file succesfully read! {args[1]}");
                    }
                    catch (Exception ex)
                    {
                        logger.LogError(ex, $"Example project file could not be read! {args[1]}");
                    }
                }
                else if (args[0].ToLower(ci) == "run")
                {
                    try
                    {
                        MyDupFinderProjectDTO?dto;
                        MyDupFinderProject.ReadConfigurationFromFile(args[1], out dto);
                        if (dto is null)
                        {
                            logger.LogError("Could not read Project file");
                            return;
                        }

                        //Check and fix config
                        MyDupFinderProjectDTO.CheckSanity(dto);
                        MyDupFinderProjectDTO.FixDto(dto);

                        //Scan Jobs
                        foreach (MyDupFinderScanJobDTO scanDto in dto.MyDupFinderScanJobDTOs)
                        {
                            using (var scanService = serviceProvider.GetService <ScanService>())
                            {
                                if (scanService is null)
                                {
                                    logger.LogError("No scanService registered!");
                                    return;
                                }
                                logger.LogInformation("Running Job {JobName}...", scanDto.JobName);
                                ThreadStart ts = delegate { scanService.StartScan(scanDto); };
                                var         t  = new Thread(ts);
                                t.Name = "ScanService";
                                t.Start();
                                //Wait for t or for a key press
                                WaitForThreadOrKeyPress(logger, scanDto.JobName, scanService, t);
                            }
                        }

                        //Find Dups Jobs
                        foreach (MyDupFinderFindDupsJobDTO findDupsDto in dto.MyDupFinderFindDupsJobDTOs)
                        {
                            using (var findDupsService = serviceProvider.GetService <FindDupsService>())
                            {
                                if (findDupsService is null)
                                {
                                    logger.LogError("No scanService registered!");
                                    return;
                                }
                                logger.LogInformation("Running Job {JobName}...", findDupsDto.JobName);
                                ThreadStart ts = delegate { findDupsService.Start(findDupsDto); };
                                var         t  = new Thread(ts);
                                t.Name = "ScanService";
                                t.Start();
                                //Wait for t or for a key press
                                WaitForThreadOrKeyPress(logger, findDupsDto.JobName, findDupsService, t);
                            }
                        }


                        logger.LogInformation("All Jobs finished");
                    }
                    catch (Exception ex)
                    {
                        logger.LogError(ex, $"Exception during run of the job...! {args[1]}");
                    }
                }
                else
                {
                    ShowHelp();
                }
            }
            else
            {
                ShowHelp();
            }

            // Finish log
            logger.LogInformation("Application closing...");

            // Use for Microsoft logger.... for serilog, we do it with AppDomain.CurrentDomain.ProcessExit
            // serviceProvider.Dispose();
        }