コード例 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SearchCommand" /> class.
        /// </summary>
        /// <param name="maxRunsText">The maximum runs text.</param>
        /// <param name="city">The city.</param>
        /// <param name="state">The state.</param>
        /// <param name="zip">The zip.</param>
        /// <param name="namesFilePath">The names text file path.</param>
        /// <param name="options">The options.</param>
        public SearchCommand(string maxRunsText, string city, string state, string zip, string namesFilePath, CommandLineOptions options)
        {
            int.TryParse(maxRunsText, out int maxRuns);
            _maxRuns          = maxRuns;
            _city             = city;
            _state            = state;
            _zip              = zip;
            _namesFilePath    = namesFilePath;
            _resultOutputPath = Program.SearchResultsDirectory;
            _options          = options;

            this.Repository           = Program.Repository;
            this.Configuration        = Program.Configuration;
            this.FindPersonController = new FindPersonController(this.Configuration);
            this.Import             = new Import();
            this.Export             = new Export();
            this.Mapper             = MapperFactory.Get();
            this.SerializerSettings = JsonSerializerSettingsFactory.Get();


            //Default Value
            this.SearchWaitMs = 60000;
            var waitMs = Configuration.GetValue <string>("SearchSettings:WaitMs");

            int.TryParse(waitMs, out this.SearchWaitMs);


            this.PeopleSearch = new PeopleSearch(Repository, FindPersonController, SerializerSettings, Mapper, Export, _resultOutputPath, SearchWaitMs);
        }
コード例 #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ImportExportTests"/> class.
 /// </summary>
 public ImportExportTests()
 {
     this.MockRepository     = MockRepositoryFactory.Get();
     this.SerializerSettings = JsonSerializerSettingsFactory.Get();
     this.Mapper             = MapperFactory.Get();
     this.MockImport         = MockImportFactory.Get();
     this.MockExport         = MockExportFactory.Get();
     this.ImportExport       = new ImportExport(MockRepository.Object, this.SerializerSettings, Mapper, MockImport.Object, MockExport.Object);
 }
コード例 #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PeopleSearchHelper_ShouldCreatePersonSearchResult"/> class.
        /// </summary>
        public PersonSearchResultHelperTests()
        {
            MockRepository = MockRepositoryFactory.Get();

            var serializerSettings = JsonSerializerSettingsFactory.Get();
            var mapper             = MapperFactory.Get();

            this.PersonSearchResultHelper = new PersonSearchResultHelper(MockRepository.Object, serializerSettings, mapper);
        }
コード例 #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PeopleSearchTests"/> class.
        /// </summary>
        public PeopleSearchTests()
        {
            this.MockRepository           = MockRepositoryFactory.Get();
            this.MockFindPersonController = MockFindPersonControllerFactory.Get();
            this.SerializerSettings       = JsonSerializerSettingsFactory.Get();
            this.Mapper     = MapperFactory.Get();
            this.MockExport = MockExportFactory.Get();
            var resultOutputPath = "";
            var searchWaitMs     = 60000;

            this.PeopleSearch = new PeopleSearch(MockRepository.Object, MockFindPersonController.Object, SerializerSettings, Mapper, MockExport.Object, resultOutputPath, searchWaitMs);
        }
コード例 #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PeopleSearchHelper_ShouldCreatePersonSearchResult"/> class.
        /// </summary>
        public PersonSearchRequestHelperTests()
        {
            MockRepository           = MockRepositoryFactory.Get();
            MockFindPersonController = MockFindPersonControllerFactory.Get();
            MockExport = MockExportFactory.Get();

            var serializerSettings = JsonSerializerSettingsFactory.Get();
            var mapper             = MapperFactory.Get();
            var resultOutputPath   = "";

            this.PersonSearchRequestHelper = new PersonSearchRequestHelper(MockRepository.Object, MockFindPersonController.Object, serializerSettings, mapper, MockExport.Object, resultOutputPath);
        }
コード例 #6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ImportSearchesCommand" /> class.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <param name="options">The options.</param>
        public ImportSearchesCommand(string path, CommandLineOptions options)
        {
            _path    = path;
            _options = options;

            this.Repository         = Program.Repository;
            this.Import             = new Import();
            this.Export             = new Export();
            this.Mapper             = MapperFactory.Get();
            this.SerializerSettings = JsonSerializerSettingsFactory.Get();

            this.ImportExport = new ImportExport(Repository, SerializerSettings, Mapper, Import, Export);
        }
コード例 #7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ExportPeopleCommand" /> class.
        /// </summary>
        /// <param name="options">The options.</param>
        public ExportPeopleCommand(CommandLineOptions options)
        {
            _options = options;

            this.Repository         = Program.Repository;
            this.Import             = new Import();
            this.Export             = new Export();
            this.Mapper             = MapperFactory.Get();
            this.SerializerSettings = JsonSerializerSettingsFactory.Get();

            _fullPath = Path.Combine(Program.ExportDirectory, $"PeopleExport-{DateTime.Now}.csv");

            this.ImportExport = new ImportExport(Repository, SerializerSettings, Mapper, Import, Export);
        }
コード例 #8
0
ファイル: Program.cs プロジェクト: duncansultan/NameSearch
        /// <summary>
        /// Main application entry point.
        /// </summary>
        /// <param name="args">The arguments.</param>
        /// <returns></returns>
        public static int Main(string[] args)
        {
            #region Test args for debugging

            //args = new string[2] { "exportpeople" };
            //args = new string[2] { "importsearches", @"C:\Users\dunca\Desktop\RaleighSwahiliNamesSearch\export.csv" };
            //args = new string[7] { "search", "", "NC", "", @"C:\Users\dunca\Desktop\RaleighSwahiliNamesSearch\SwahiliNames.A.csv", "100" };

            #endregion

            #region Configure Logging

            var logsFolder = Path.Combine(Environment.CurrentDirectory, "logs");
            Directory.CreateDirectory(logsFolder);

            Log.Logger = new LoggerConfiguration()
                         .MinimumLevel.Debug()
                         .MinimumLevel.Override("Microsoft", LogEventLevel.Information)
                         .Enrich.FromLogContext()
                         .WriteTo.RollingFile("logs/namesearch-{Date}.log")
                         .WriteTo.Console()
                         .CreateLogger();

            #endregion Configure Logging

            var log = Log.Logger;

            try
            {
                var builder = new ConfigurationBuilder()
                              .SetBasePath(Directory.GetCurrentDirectory())
                              .AddJsonFile("appsettings.json");

                Configuration = builder.Build();

                #region Create Directories

                ExportDirectory = Path.Combine(Environment.CurrentDirectory, "Exports");
                Directory.CreateDirectory(ExportDirectory);

                SearchResultsDirectory = Path.Combine(Environment.CurrentDirectory, "SearchResults");
                Directory.CreateDirectory(SearchResultsDirectory);

                #endregion

                #region Dependency Injection Container

                // use Dependency injection in console app https://andrewlock.net/using-dependency-injection-in-a-net-core-console-application/
                // add the framework services
                var services = new ServiceCollection()
                               .AddLogging(loggingBuilder => loggingBuilder.AddSerilog(dispose: true))
                               .AddDbContext <ApplicationDbContext>(optionsBuilder => optionsBuilder.UseSqlite("Data Source=blog.db"))
                               .AddTransient <IMapper, IMapper>((ctx) =>
                {
                    return(MapperFactory.Get());
                })
                               .AddTransient <JsonSerializerSettings, JsonSerializerSettings>((ctx) =>
                {
                    return(JsonSerializerSettingsFactory.Get());
                })
                               .AddScoped <IEntityFrameworkRepository, EntityFrameworkRepository>();

                services.AddMvc();

                // add StructureMap
                var container = new Container();
                container.Configure(config =>
                {
                    // Register stuff in container, using the StructureMap APIs...
                    config.Scan(_ =>
                    {
                        _.AssemblyContainingType(typeof(Program));
                        _.WithDefaultConventions();
                    });
                    // Populate the container using the service collection
                    config.Populate(services);
                });

                //Set static instances
                Repository         = container.GetInstance <IEntityFrameworkRepository>();
                Mapper             = container.GetInstance <IMapper>();
                SerializerSettings = container.GetInstance <JsonSerializerSettings>();

                #endregion Dependency Injection Container

                var options = CommandLineOptions.Parse(args);

                log.InformationEvent("Main", "Run command {command} with arguments {args}", options?.Command, args);

                if (options?.Command == null)
                {
                    // RootCommand will have printed help
                    return(1);
                }

                var result = options.Command.Run();

                return(result);
            }
            catch (Exception ex)
            {
                log.FatalEvent(ex, "Main", "Fatal Application Failure with message {message}", ex.Message);
                throw;
            }
            finally
            {
                log.InformationEvent("Main", "Application Ending");
                Log.CloseAndFlush();

                // Allow users to see output.  Prevent console closing on its own
                Console.ReadLine();
            }
        }