public static void Start(SchemaBuilder sb) { if (sb.NotDefined(MethodInfo.GetCurrentMethod())) { sb.Include <OrderEntity>() .WithQuery(() => o => new { Entity = o, o.Id, o.State, o.Customer, o.Employee, o.OrderDate, o.RequiredDate, o.ShipAddress, o.ShipVia, }); QueryLogic.Queries.Register(OrderQuery.OrderLines, () => from o in Database.Query <OrderEntity>() from od in o.Details select new { Entity = o, o.Id, od.Product, od.Quantity, od.UnitPrice, od.Discount, od.SubTotalPrice, }); OrderGraph.Register(); ProcessLogic.Register(OrderProcess.CancelOrders, new CancelOrderAlgorithm()); SimpleTaskLogic.Register(OrderTask.CancelOldOrdersWithProcess, ctx => { var package = new PackageEntity().CreateLines(Database.Query <OrderEntity>().Where(a => a.OrderDate < DateTime.Now.AddDays(-7) && a.State != OrderState.Canceled)); var process = ProcessLogic.Create(OrderProcess.CancelOrders, package); process.Execute(ProcessOperation.Execute); return(process.ToLite()); }); SimpleTaskLogic.Register(OrderTask.CancelOldOrders, ctx => { Database.Query <OrderEntity>() .Where(a => a.OrderDate < DateTime.Now.AddDays(-7)) .UnsafeUpdate() .Set(o => o.CancelationDate, o => DateTime.Now) .Set(o => o.State, o => OrderState.Canceled) .Execute(); return(null); });//CancelOldOrdersProcess } }
public static void Start(SchemaBuilder sb, FileTypeSymbol?testFileType = null) { if (sb.NotDefined(MethodInfo.GetCurrentMethod())) { TestFileType = testFileType; sb.Include <PrintLineEntity>() .WithQuery(() => p => new { Entity = p, p.CreationDate, p.File, p.State, p.Package, p.PrintedOn, p.Referred, }); sb.Include <PrintPackageEntity>() .WithQuery(() => e => new { Entity = e, e.Id, e.Name }); ProcessLogic.AssertStarted(sb); ProcessLogic.Register(PrintPackageProcess.PrintPackage, new PrintPackageAlgorithm()); PermissionAuthLogic.RegisterPermissions(PrintPermission.ViewPrintPanel); PrintLineGraph.Register(); SimpleTaskLogic.Register(PrintTask.RemoveOldFiles, (ScheduledTaskContext ctx) => { var lines = Database.Query <PrintLineEntity>().Where(a => a.State == PrintLineState.Printed).Where(b => b.CreationDate <= DateTime.Now.AddMinutes(-DeleteFilesAfter)); foreach (var line in lines) { try { using (Transaction tr = new Transaction()) { line.File.DeleteFileOnCommit(); line.State = PrintLineState.PrintedAndDeleted; using (OperationLogic.AllowSave <PackageLineEntity>()) line.Save(); tr.Commit(); } } catch (Exception e) { e.LogException(); } } return(null); }); } }
public static void Start(SchemaBuilder sb) { if (sb.NotDefined(MethodInfo.GetCurrentMethod())) { sb.Include <SMSSendPackageEntity>(); sb.Include <SMSUpdatePackageEntity>(); SMSLogic.AssertStarted(sb); ProcessLogic.AssertStarted(sb); ProcessLogic.Register(SMSMessageProcess.Send, new SMSMessageSendProcessAlgortihm()); ProcessLogic.Register(SMSMessageProcess.UpdateStatus, new SMSMessageUpdateStatusProcessAlgorithm()); SimpleTaskLogic.Register(SMSMessageTask.UpdateSMSStatus, ctx => UpdateAllSentSMS()?.ToLite()); new Graph <ProcessEntity> .ConstructFromMany <SMSMessageEntity>(SMSMessageOperation.CreateUpdateStatusPackage) { Construct = (messages, _) => UpdateMessages(messages.RetrieveFromListOfLite()) } .Register(); QueryLogic.Queries.Register(typeof(SMSSendPackageEntity), () => from e in Database.Query <SMSSendPackageEntity>() let p = e.LastProcess() select new { Entity = e, e.Id, e.Name, NumLines = e.SMSMessages().Count(), LastProcess = p, NumErrors = e.SMSMessages().Count(s => s.Exception(p) != null), }); QueryLogic.Queries.Register(typeof(SMSUpdatePackageEntity), () => from e in Database.Query <SMSUpdatePackageEntity>() let p = e.LastProcess() select new { Entity = e, e.Id, e.Name, NumLines = e.SMSMessages().Count(), LastProcess = p, NumErrors = e.SMSMessages().Count(s => s.Exception(p) != null), }); } }
public static void Start(SchemaBuilder sb, DynamicQueryManager dqm, Func <Pop3ConfigurationEntity, IPop3Client> getPop3Client) { if (sb.NotDefined(MethodInfo.GetCurrentMethod())) { GetPop3Client = getPop3Client; MixinDeclarations.AssertDeclared(typeof(EmailMessageEntity), typeof(EmailReceptionMixin)); sb.Include <Pop3ConfigurationEntity>() .WithSave(Pop3ConfigurationOperation.Save) .WithQuery(dqm, () => s => new { Entity = s, s.Id, s.Host, s.Port, s.Username, s.EnableSSL }); sb.Include <Pop3ReceptionEntity>(); sb.Include <Pop3ReceptionExceptionEntity>(); sb.Include <EmailMessageEntity>() .WithQuery(dqm, () => e => new { Entity = e, e.Id, e.From, e.Subject, e.Template, e.State, e.Sent, SentDate = (DateTime?)e.Mixin <EmailReceptionMixin>().ReceptionInfo.SentDate, e.Package, e.Exception, }); dqm.RegisterQuery(typeof(Pop3ReceptionEntity), () => DynamicQueryCore.Auto( from s in Database.Query <Pop3ReceptionEntity>() select new { Entity = s, s.Id, s.Pop3Configuration, s.StartDate, s.EndDate, s.NewEmails, EmailMessages = s.EmailMessages().Count(), Exceptions = s.Exceptions().Count(), s.Exception, }) .ColumnDisplayName(a => a.EmailMessages, () => typeof(EmailMessageEntity).NicePluralName()) .ColumnDisplayName(a => a.Exceptions, () => typeof(ExceptionEntity).NicePluralName())); dqm.RegisterExpression((Pop3ConfigurationEntity c) => c.Receptions(), () => typeof(Pop3ReceptionEntity).NicePluralName()); dqm.RegisterExpression((Pop3ReceptionEntity r) => r.EmailMessages(), () => typeof(EmailMessageEntity).NicePluralName()); dqm.RegisterExpression((Pop3ReceptionEntity r) => r.Exceptions(), () => typeof(ExceptionEntity).NicePluralName()); dqm.RegisterExpression((ExceptionEntity r) => r.Pop3Reception(), () => typeof(Pop3ReceptionEntity).NiceName()); new Graph <Pop3ReceptionEntity> .ConstructFrom <Pop3ConfigurationEntity>(Pop3ConfigurationOperation.ReceiveEmails) { AllowsNew = true, Lite = false, Construct = (e, _) => { using (Transaction tr = Transaction.None()) { var result = e.ReceiveEmails(); return(tr.Commit(result)); } } } .Register(); SchedulerLogic.ExecuteTask.Register((Pop3ConfigurationEntity smtp, ScheduledTaskContext ctx) => smtp.ReceiveEmails().ToLite()); SimpleTaskLogic.Register(Pop3ConfigurationAction.ReceiveAllActivePop3Configurations, (ScheduledTaskContext ctx) => { if (!EmailLogic.Configuration.ReciveEmails) { throw new InvalidOperationException("EmailLogic.Configuration.ReciveEmails is set to false"); } foreach (var item in Database.Query <Pop3ConfigurationEntity>().Where(a => a.Active).ToList()) { item.ReceiveEmails(); } return(null); }); } }