internal static ResultLoggerConfig GetResultLogger(IEnumerable <ResultLoggerConfig> configs, string name) { ResultLoggerConfig logger = configs.SingleOrDefault(x => x.Name.Equals(name)); if (logger == null) { throw new Exception($"ResultLogger with name {name} not found"); } return(logger); }
public async Task ExecuteAsync(Job job) { _job = job ?? throw new ArgumentNullException(nameof(job)); Stopwatch jobStopwatch = Stopwatch.StartNew(); Logger.LogInfo($"Executing job {job.Name}"); foreach (SyncTask task in job.Tasks) { Stopwatch taskStopwatch = Stopwatch.StartNew(); Logger.LogInfo($"Executing task {task.Name}"); string output = String.Empty; // configure logger if (!string.IsNullOrWhiteSpace(task.ResultLogger)) { ResultLoggerConfig rsConfig = Helper.GetResultLogger(job.ResultLoggers, task.ResultLogger); _resultLogger.Connections = job.Connections; _resultLogger.SetConfig(rsConfig.Config); _sqlAdapter.ResultLogger = _resultLogger; _sfdcAdapter.ResultLogger = _resultLogger; } if (task.Type == SyncType.SqlToSfdc) { var results = await SynchToSfdc(task); if (results != null) { output = JsonConvert.SerializeObject(results); } } else if (task.Type == SyncType.SfdcToSql) { var results = await SynchToSql(task); if (results != null) { output = JsonConvert.SerializeObject(results); } } else if (task.Type == SyncType.SqlCommand) { var results = await SqlCommand(task); output = JsonConvert.SerializeObject(results); } //write ouput log string directoryPath = Path.Combine(Logger.OutputPath, job.Name, task.Name); string filePath = Path.Combine(directoryPath, string.Concat(DateTime.Now.ToString("yyyyMMdd_hhmmss"), ".log")); if (!Directory.Exists(directoryPath)) { Directory.CreateDirectory(directoryPath); } File.WriteAllText(filePath, output); Logger.LogInfo($"Log created at {filePath}"); taskStopwatch.Stop(); Logger.LogInfo($"Task {task.Name} completed at {taskStopwatch.ElapsedMilliseconds / 1000} second"); } jobStopwatch.Stop(); Logger.LogInfo($"All Tasks at job {job.Name} completed at {jobStopwatch.ElapsedMilliseconds / 1000} second"); }