Exemple #1
0
        public async Task RunAsync()
        {
            Log.Info($"Running Migration Tool ..... ");
            foreach (var file in _filesLister.GetSqlFilesWithContents())
            {
                var entry = new ReportEntry
                {
                    File         = file.FullPath,
                    StartRunTime = DateTime.Now,
                    Status       = "Success"
                };
                try
                {
                    //check if file has been modified before executing it.
                    if (!_scriptCacheStrategy.HasScriptChanged(file))
                    {
                        entry.Status = "Skipped";
                        continue;
                    }
                    await ExecuteAsync(file);

                    // maintain history if executed successfully.
                    _scriptCacheStrategy.CacheScript(file);
                }
                catch (Exception ex)
                {
                    entry.Exception       = ex.Message;
                    entry.ReportEntryType = ReportEntryType.Error;
                    entry.Status          = "Fail";
                }
                finally
                {
                    entry.EndRunTime = DateTime.Now;
                    ExecutionReport.AddEntry(entry);
                }
            }
            try
            {
                Log.Info("Writing reports.....");
                var createLogViewerWork = CreateLogViewerFileAsync();
                await ExecutionReport.WriteReportAsync(ReportFileName);

                await createLogViewerWork;
                Log.Info("Finished running migration tool.");
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }