private IHangfireConsole GetHangfireConsole(HttpContext httpContext, Type jobType, IHangfireStorage storage) { IHangfireConsole console = null; try { //默认每次都是有一个新的实例 var consoleFactory = httpContext.RequestServices.GetService <IStorageFactory>(); console = consoleFactory.CreateHangforeConsole(storage); ConsoleInfo consoleInfo = null; var agentConsole = httpContext.Request.Headers["x-job-agent-console"].ToString(); if (!string.IsNullOrEmpty(agentConsole)) { consoleInfo = agentConsole.ToJson <ConsoleInfo>(); } if (console != null && consoleInfo != null) { var initConsole = console as IHangfireConsoleInit; if (initConsole == null) { console = null; } else { initConsole.Init(consoleInfo); } } else { console = null; } } catch (Exception) { //ignore } if (console == null) { var jobLogger = _loggerFactory.CreateLogger(jobType); console = new LoggerConsole(jobLogger); } return(console); }
/// <summary> /// Returns an <see cref="IEnumerable{T}"/> reporting enumeration progress. /// </summary> /// <typeparam name="T">Item type</typeparam> /// <param name="enumerable">Source enumerable</param> /// <param name="context">Perform context</param> /// <param name="name">Progress bar name</param> /// <param name="color">Progress bar color</param> /// <param name="count">Item count</param> public static IEnumerable <T> WithProgress <T>(this IEnumerable <T> enumerable, IHangfireConsole context, string name, ConsoleFontColor color = null, int count = -1) { return(WithProgress(enumerable, context.WriteProgressBar(name, 0, color), count)); }
/// <summary> /// Returns ab <see cref="IEnumerable"/> reporting enumeration progress. /// </summary> /// <param name="enumerable">Source enumerable</param> /// <param name="context">Perform context</param> /// <param name="color">Progress bar color</param> /// <param name="count">Item count</param> public static IEnumerable WithProgress(this IEnumerable enumerable, IHangfireConsole context, ConsoleFontColor color = null, int count = -1) { return(WithProgress(enumerable, context.WriteProgressBar("ProgressBar", 0, color), count)); }