public static Timetable?SafeImport(this IImport imp, string filename, IReducedPluginInterface pluginInterface, ILog?replaceLog = null) { try { using (var stream = File.Open(filename, FileMode.OpenOrCreate, FileAccess.Read)) return(imp.Import(stream, pluginInterface, replaceLog)); } catch (Exception ex) { var log = replaceLog ?? pluginInterface.Logger; log.Error(imp.GetType().Name + ": " + ex.Message); log.LogException(ex); return(null); } }
private static async Task <bool> RunImport(IImport operation, bool depends = true) { var name = operation.GetType().GetCustomAttributes(typeof(OperationAttribute), true).FirstOrDefault() as OperationAttribute; var start = DateTime.UtcNow; Logger.Info("**************************************************************"); Logger.Info($" Running operation {name.Name}"); Logger.Info("**************************************************************"); if (!await operation.Import().ConfigureAwait(false)) { Logger.Info("ERROR - Failed to seed entities!"); return(false); } Logger.Info("**************************************************************"); Logger.Info($" Finished operation {name.Name} in {DateTime.UtcNow - start}"); Logger.Info("**************************************************************"); return(true); }