public static void Main(string[] args) { //сохранение счетов\актов производится внутри транзации что бы она гарантировано //закончилась и акты стали доступны нужно немного подождать Thread.Sleep(1000); XmlConfigurator.Configure(); var logger = LogManager.GetLogger(typeof(Program)); try { var printer = args[1]; var name = args[0]; var ids = args[2].Split(',').Select <string, uint>(id => { uint result = 0; if (UInt32.TryParse(id.Trim(), out result)) { return(result); } return(0); }).ToArray(); #if DEBUG DocumentsForTest = ids; return; #endif var brail = StandaloneInitializer.Init(); IEnumerable documents = null; using (new SessionScope(FlushAction.Never)) { if (name == "invoice") { documents = Invoice.Queryable.Where(a => ids.Contains(a.Id)) .ToList() .OrderBy(a => ids.IndexOf(a.Id)) .ToArray(); } else if (name == "act") { documents = Act.Queryable.Where(a => ids.Contains(a.Id)) .ToList() .OrderBy(a => ids.IndexOf(a.Id)) .ToArray(); } Print(brail, printer, name, documents); } } catch (Exception e) { logger.Error("Ошибка при печати", e); } }
public static int Main(string[] args) { try { var help = false; string task = null; var options = new OptionSet { { "help", x => help = x != null }, { "task=", "Выполнить указанную задачу и выйти", x => task = x }, }; try { options.Parse(args); } catch (Exception e) { Console.WriteLine(e.Message); options.WriteOptionDescriptions(Console.Out); } if (help) { options.WriteOptionDescriptions(Console.Out); return(0); } XmlConfigurator.Configure(); var assembly = typeof(Program).Assembly; StandaloneInitializer.Init(assembly); var jobs = new List <ActiveRecordJob>(); using (new SessionScope()) { var job = new ActiveRecordJob(new SendPaymentNotification()); jobs.Add(job); } var mailer = new MonorailMailer { SiteRoot = ConfigurationManager.AppSettings["SiteRoot"] }; var tasks = new List <Task> { new SendInvoiceTask(mailer) }; tasks = tasks.Concat(assembly.GetTypes().Except(tasks.Select(x => x.GetType()).ToArray()) .Where(t => t.IsClass && !t.IsAbstract && !t.IsInterface && typeof(Task).IsAssignableFrom(t)) .Select(t => Activator.CreateInstance(t)) .OfType <Task>()) .ToList(); if (!String.IsNullOrEmpty(task)) { var toRun = tasks.Where(x => x.GetType().Name.Match(task)).ToList(); if (toRun.Count == 0) { Console.WriteLine($"Не удалось найти задачу {task}, доступные задачи {tasks.Implode(x => x.GetType().Name)}"); return(1); } toRun.Each(x => x.Execute()); return(0); } var actions = tasks.Select(x => new Action(x.Execute)) .Concat(jobs.Select(x => { return(new Action(() => { using (new SessionScope()) x.Run(); })); })).ToList(); var runner = new RepeatableCommand(30.Minute(), () => actions.Each(t => { try { t(); } catch (Exception e) { log.Error($"Выполнение задачи {t} завершилось ошибкой", e); } })); tasks.Each(t => t.Cancellation = runner.Cancellation); jobs.Each(x => x.Job.Cacellation = runner.Cancellation); return(CommandService.Start(args, runner)); } catch (Exception e) { log.Error("Ошибка при запуске приложения", e); return(1); } }