public Operation <string> EnqueueOperation <Service>(IUserContext principal, Expression <Action <Service> > opInvocation, TimeSpan?delay = default(TimeSpan?)) => Operation.Try(() =>
        {
            //Cache all necessary contextual data
            var json = JsonConvert.SerializeObject(new SerializableUserContext
            {
                _currentUserRoles = principal.CurrentUserRoles().ToList(),
                _currentUserLogon = principal.CurrentUserLogon(),
                _currentUser      = principal.CurrentUser()
            });

            string jid = null;
            if (delay == null)
            {
                jid = BackgroundJob.Enqueue(opInvocation);
            }
            else
            {
                jid = BackgroundJob.Schedule(opInvocation, delay.Value);
            }

            //persist the user context
            _connection.SetJobParameter(jid, CustomJobProperty_UserContext, json);

            return(jid);
        });
        public Operation RepeatOperation <Service>(string uniqueOpId, IUserContext principal, Expression <Action <Service> > opInvocation, ScheduleInterval interval) => Operation.Try(() =>
        {
            //Cache all necessary contextual data
            var json = JsonConvert.SerializeObject(new SerializableUserContext
            {
                _currentUserRoles = principal.CurrentUserRoles().ToList(),
                _currentUserLogon = principal.CurrentUserLogon(),
                _currentUser      = principal.CurrentUser()
            });

            //persist the user context
            _connection.SetRangeInHash($"{RecurrentJobKeyPrefix}::{uniqueOpId}", Enumerate(CustomJobProperty_UserContext.ValuePair(json)));

            switch (interval)
            {
            case ScheduleInterval.Daily: RecurringJob.AddOrUpdate(uniqueOpId, opInvocation, Cron.Daily()); break;

            case ScheduleInterval.Hourly: RecurringJob.AddOrUpdate(uniqueOpId, opInvocation, Cron.Hourly()); break;

            case ScheduleInterval.Minutely: RecurringJob.AddOrUpdate(uniqueOpId, opInvocation, Cron.Minutely()); break;

            case ScheduleInterval.Monthly: RecurringJob.AddOrUpdate(uniqueOpId, opInvocation, Cron.Monthly()); break;

            case ScheduleInterval.Weekly: RecurringJob.AddOrUpdate(uniqueOpId, opInvocation, Cron.Weekly()); break;

            case ScheduleInterval.Yearly: RecurringJob.AddOrUpdate(uniqueOpId, opInvocation, Cron.Yearly()); break;

            default: throw new Exception("unknown interval");
            }
        });
Esempio n. 3
0
        public static PermissionProfile CurrentPPP(this IUserContext context)
        {
            var frame     = new StackFrame(1);
            var resources = CachedDescriptors.GetOrAdd(frame.GetMethod().As <MethodInfo>(),
                                                       mi => mi.GetResourceAttribute().SelectMany(ratt => ratt.Resources).ToList());

            return(new PermissionProfile
            {
                Principal = context.CurrentUser(),
                ResourcePaths = resources
            });
        }