Пример #1
0
        static async Task ProcessEvent(CancellationToken token, DbEvent evt, Boolean isAdminMode)
        {
            IServiceLocator loc       = new ServiceLocator();
            var             host      = loc.GetService <IApplicationHost>();
            var             dbContext = loc.GetService <IDbContext>();

            host.SetAdmin(isAdminMode);
            host.StartApplication(isAdminMode);
            var ctrl = new BaseController(loc);

            if (token.IsCancellationRequested)
            {
                return;
            }
            try
            {
                await ProcessEvent(evt, ctrl);
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null)
                {
                    ex = ex.InnerException;
                }
                var evtError = new DbEventError()
                {
                    Id = evt.Id, ErrorMessage = ex.Message
                };
                dbContext.Execute <DbEventError>(evt.Source, "a2sys.[DbEvent.Error]", evtError);
            }
        }
Пример #2
0
        static async Task ProcessEvent(DbEvent evt, BaseController ctrl)
        {
            // json, data, from evt
            var eo = new ExpandoObject();

            eo.Set("baseUrl", $"/_simple{evt.Path}");
            eo.Set("cmd", evt.Command);
            eo.Set("Id", evt.ItemId);
            var json = JsonConvert.SerializeObject(eo, JsonHelpers.StandardSerializerSettings);
            await ctrl.Data("invoke",
                            prms => {
                prms.Set("UserId", 0 /*system*/);
                prms.Set("Id", evt.ItemId);
            },
                            json,
                            null
                            );

            var evtBase = new DbEventBase()
            {
                Id = evt.Id
            };

            ctrl.DbContext.Execute <DbEventBase>(evt.Source, "a2sys.[DbEvent.Complete]", evtBase);
        }