예제 #1
0
        public static void Start()
        {
            if (Navigator.Manager.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                Navigator.RegisterArea(typeof(IsolationClient));

                WidgetsHelper.GetWidget += ctx => ctx.Entity is Entity && MixinDeclarations.IsDeclared(ctx.Entity.GetType(), typeof(IsolationMixin)) ?
                                           IsolationWidgetHelper.CreateWidget(ctx) : null;

                Navigator.AddSetting(new EntitySettings <IsolationEntity> {
                    PartialViewName = _ => ViewPrefix.FormatWith("Isolation")
                });

                Constructor.ClientManager.GlobalPreConstructors += ctx =>
                                                                   (!MixinDeclarations.IsDeclared(ctx.Type, typeof(IsolationMixin)) || IsolationEntity.Current != null) ? null :
                                                                   Module["getIsolation"](ClientConstructorManager.ExtraJsonParams, ctx.Prefix,
                                                                                          IsolationMessage.SelectAnIsolation.NiceToString(),
                                                                                          GetIsolationChooserOptions(ctx.Type));

                //Unnecessary with the filter
                Constructor.Manager.PreConstructors += ctx =>
                                                       !MixinDeclarations.IsDeclared(ctx.Type, typeof(IsolationMixin)) ? null :
                                                       IsolationEntity.Override(GetIsolation(ctx.Controller.ControllerContext));

                MapClient.GetColorProviders += GetMapColors;
            }
        }
예제 #2
0
        public static IDisposable IsolationFromOperationContext()
        {
            MessageHeaders headers = OperationContext.Current.IncomingMessageHeaders;

            int val = headers.FindHeader("CurrentIsolation", "http://www.signumsoftware.com/Isolation");

            if (val == -1)
            {
                return(null);
            }

            return(IsolationEntity.Override(Lite.Parse <IsolationEntity>(headers.GetHeader <string>(val))));
        }
예제 #3
0
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            var iso = IsolationClient.GetIsolation(filterContext.Controller.ControllerContext);

            ViewDataDictionary viewData = filterContext.Controller.ViewData;

            IDisposable isolation = IsolationEntity.Override(iso);

            if (isolation != null)
            {
                viewData.Add(Key, isolation);
            }
        }
예제 #4
0
        public static IEnumerable <EmailMessageEntity> CreateEmailMessage(this IEmailModel emailModel)
        {
            if (emailModel.UntypedEntity == null)
            {
                throw new InvalidOperationException("Entity property not set on EmailModel");
            }

            using (IsolationEntity.Override((emailModel.UntypedEntity as Entity)?.TryIsolation()))
            {
                var emailModelEntity = ToEmailModelEntity(emailModel.GetType());
                var template         = GetDefaultTemplate(emailModelEntity, emailModel.UntypedEntity as Entity);

                return(EmailTemplateLogic.CreateEmailMessage(template.ToLite(), model: emailModel));
            }
        }
예제 #5
0
        public static IEnumerable <EmailMessageEntity> CreateEmailMessage(this ISystemEmail systemEmail)
        {
            if (systemEmail.UntypedEntity == null)
            {
                throw new InvalidOperationException("Entity property not set on SystemEmail");
            }

            using (IsolationEntity.Override((systemEmail.UntypedEntity as Entity)?.TryIsolation()))
            {
                var systemEmailEntity = ToSystemEmailEntity(systemEmail.GetType());
                var template          = GetDefaultTemplate(systemEmailEntity, systemEmail.UntypedEntity as Entity);

                return(EmailTemplateLogic.CreateEmailMessage(template.ToLite(), systemEmail: systemEmail));
            }
        }
예제 #6
0
        public static SMSMessageEntity CreateSMSMessage(this ISMSModel smsModel, CultureInfo?forceCultureInfo = null)
        {
            if (smsModel.UntypedEntity == null)
            {
                throw new InvalidOperationException("Entity property not set on SMSModel");
            }

            using (IsolationEntity.Override((smsModel.UntypedEntity as Entity)?.TryIsolation()))
            {
                var smsModelEntity = ToSMSModelEntity(smsModel.GetType());
                var template       = GetDefaultTemplate(smsModelEntity);

                return(SMSLogic.CreateSMSMessage(template.ToLite(), smsModel.UntypedEntity, smsModel, forceCultureInfo));
            }
        }
예제 #7
0
        static IDisposable Constructor_PreConstructors(ConstructorContext ctx)
        {
            if (MixinDeclarations.IsDeclared(ctx.Type, typeof(IsolationMixin)))
            {
                Lite <IsolationEntity> isolation = GetIsolation(ctx, IsValid.TryGetC(ctx.Type));

                if (isolation == null)
                {
                    ctx.CancelConstruction = true;
                    return(null);
                }
                ctx.Args.Add(isolation);

                return(IsolationEntity.Override(isolation));
            }

            return(null);
        }
예제 #8
0
        public override void OnResultExecuting(ResultExecutingContext filterContext)
        {
            ViewDataDictionary viewData = filterContext.Controller.ViewData;

            IDisposable isolation = (IDisposable)viewData[Key];

            if (isolation == null && filterContext.Result is ViewResult)
            {
                var model = ((ViewResult)filterContext.Result).Model;

                Entity entity = (model as TypeContext)?.Let(tc => tc.UntypedValue as Entity) ?? model as Entity;

                if (entity != null)
                {
                    viewData[Key] = IsolationEntity.Override(entity.TryIsolation());
                }
            }
        }
예제 #9
0
        public override IDisposable?GetResource(ResourceExecutingContext context)
        {
            var user = UserEntity.Current;

            if (user == null)
            {
                return(null);
            }

            var isolation = user.TryMixin <IsolationMixin>()?.Isolation;

            if (isolation == null)
            {
                var isolationKey = context.HttpContext.Request.Headers["SF_Isolation"].FirstOrDefault();
                if (isolationKey != null)
                {
                    isolation = Lite.Parse <IsolationEntity>(isolationKey);
                }
            }

            return(IsolationEntity.Override(isolation));
        }
예제 #10
0
 static IDisposable OperationLogic_SurroundOperation(IOperation operation, OperationLogEntity log, Entity entity, object[] args)
 {
     return(IsolationEntity.Override(entity?.TryIsolation() ?? args.TryGetArgC <Lite <IsolationEntity> >()));
 }
예제 #11
0
 static IDisposable SchedulerLogic_ApplySession(ITaskEntity task, ScheduledTaskEntity scheduled, IUserEntity user)
 {
     return(IsolationEntity.Override(scheduled?.TryIsolation() ?? task?.TryIsolation() ?? user?.TryIsolation()));
 }
예제 #12
0
 static IDisposable ProcessLogic_ApplySession(ProcessEntity process)
 {
     return(IsolationEntity.Override(process.Data.TryIsolation()));
 }
예제 #13
0
        public static ScheduledTaskLogEntity ExecuteSync(ITaskEntity task, ScheduledTaskEntity?scheduledTask, IUserEntity?user)
        {
            IUserEntity entityIUser = (user ?? (IUserEntity?)scheduledTask?.User.RetrieveAndRemember()) !;

            var isolation = entityIUser.TryIsolation();

            if (isolation == null)
            {
                var ientity = task as IEntity;
                isolation = ientity?.TryIsolation();
            }

            using (IsolationEntity.Override(isolation))
            {
                ScheduledTaskLogEntity stl = new ScheduledTaskLogEntity
                {
                    Task            = task,
                    ScheduledTask   = scheduledTask,
                    StartTime       = TimeZoneManager.Now,
                    MachineName     = Environment.MachineName,
                    ApplicationName = Schema.Current.ApplicationName,
                    User            = entityIUser.ToLite(),
                };

                using (AuthLogic.Disable())
                {
                    using (Transaction tr = Transaction.ForceNew())
                    {
                        stl.Save();

                        tr.Commit();
                    }
                }

                try
                {
                    var ctx = new ScheduledTaskContext(stl);
                    RunningTasks.TryAdd(stl, ctx);

                    using (UserHolder.UserSession(entityIUser))
                    {
                        using (Transaction tr = Transaction.ForceNew())
                        {
                            stl.ProductEntity = ExecuteTask.Invoke(task, ctx);

                            using (AuthLogic.Disable())
                            {
                                stl.EndTime = TimeZoneManager.Now;
                                stl.Remarks = ctx.StringBuilder.ToString();
                                stl.Save();
                            }

                            tr.Commit();
                        }
                    }
                }
                catch (Exception ex)
                {
                    using (AuthLogic.Disable())
                    {
                        if (Transaction.InTestTransaction)
                        {
                            throw;
                        }

                        var exLog = ex.LogException().ToLite();

                        using (Transaction tr = Transaction.ForceNew())
                        {
                            stl.Exception = exLog;
                            stl.EndTime   = TimeZoneManager.Now;
                            stl.Save();

                            tr.Commit();
                        }
                    }
                    throw;
                }
                finally
                {
                    RunningTasks.TryRemove(stl, out var ctx);
                    OnFinally?.Invoke(stl);
                }

                return(stl);
            }
        }