示例#1
0
        public void Console_DesignTime(string sampleName, string framework)
        {
            var logger = _loggerFactory.CreateLogger(GetType(), "run", sampleName, nameof(Console_DesignTime), framework);

            using (logger.BeginScope("Root"))
            {
                var samplePath = PathHelper.GetTestAppFolder(sampleName);

                logger.LogInformation("Probe application under " + samplePath);
                Assert.NotNull(samplePath);

                var restoreResult = DnuHelper.RestorePackage(samplePath, framework, quiet: true);
                Assert.True(restoreResult, "Failed to restore packages");

                var prepare = EnvironmentHelper.Prepare();
                Assert.True(prepare, "Failed to prepare the environment");

                var options = new StartupRunnerOptions
                {
                    ProcessStartInfo = DnxHelper.BuildStartInfo(samplePath, framework: framework),
                    Logger           = logger,
                    IterationCount   = _iterationCount
                };
                var runner = new ConsoleAppStartup(options);

                var errors = new List <string>();
                var result = runner.Run();

                Assert.True(result, "Fail:\t" + string.Join("\n\t", errors));
            }
        }
        static async Task MainAsync()
        {
            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();

            try
            {
                ConsoleAppStartup.ConfigureApp();

                var blobstorageProcessor = ConsoleAppStartup.ServiceProvider.GetRequiredService <IBlobStorageDownloadProcessor>();

                await blobstorageProcessor.DownloadPublicFile(fileUrl : new Uri(ConsoleAppStartup.FileImporterSettings.BlobStorageFileUrl),
                                                              localPath : ConsoleAppStartup.FileImporterSettings.DestinationPath,
                                                              localFile : ConsoleAppStartup.FileImporterSettings.SourceFile);

                var csvProcessor = ConsoleAppStartup.ServiceProvider.GetRequiredService <ICsvProcessor>();

                var csvOptions = new CsvCutOptions
                {
                    SourceFile      = Path.Combine(ConsoleAppStartup.FileImporterSettings.DestinationPath, ConsoleAppStartup.FileImporterSettings.SourceFile),
                    DestinationPath = ConsoleAppStartup.FileImporterSettings.DestinationPath,
                    FilePattern     = "csvSplit-",
                    Separator       = ConsoleAppStartup.FileImporterSettings.Separator,
                    ChunkParts      = ConsoleAppStartup.BlobStorageSettings.ChunkBlockSize,
                    HasHeader       = true
                };

                var csvFiles = csvProcessor.CutCsvInFiles(csvOptions);

                var databaseMigrationDataProcessor = ConsoleAppStartup.ServiceProvider.GetRequiredService <IDatabaseMigrationDataProcessor>();

                var databaseMigrationResult = databaseMigrationDataProcessor.MigrateCsvFilesToDatabaseTable(csvFiles, ConsoleAppStartup.FileImporterSettings.Separator);

                if (databaseMigrationResult.HasErrors)
                {
                    Console.WriteLine("We are found errors migrating data to Database");

                    foreach (var message in databaseMigrationResult.ErrorMessages)
                    {
                        Console.WriteLine(message);
                    }
                }
            }
            catch (AggregateException agregateException)
            {
                foreach (var ex in agregateException.Flatten().InnerExceptions)
                {
                    Console.WriteLine(ex.Message);
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine("App has exceptions: " + exception.ToString());
            }



            stopWatch.Stop();

            TimeSpan ts = stopWatch.Elapsed;

            Console.WriteLine(ts);

            Console.ReadLine();
        }