コード例 #1
0
 private void InterceptGetter(IInvocation invocation, CodeFirstLazyInitialiser codeFirstLazyInitialiser)
 {
     if (!codeFirstLazyInitialiser.IsDone)
     {
         CodeFirstModelContext.ReinstateContext(invocation.InvocationTarget);
         codeFirstLazyInitialiser.Execute();
         CodeFirstModelContext.ResetContext();
     }
 }
コード例 #2
0
        private CodeFirstModelContext Clone()
        {
            var result = new CodeFirstModelContext();

            result.ContentType        = ContentType;
            result.CurrentTab         = CurrentTab;
            result.CurrentProperty    = CurrentProperty;
            result.CurrentComposition = CurrentComposition;
            result.ParentContext      = ParentContext;
            return(result);
        }
コード例 #3
0
        internal static CodeFirstModelContext GetCompositionParentContext(ContentTypeCompositionRegistration registration)
        {
            var newContext = new CodeFirstModelContext()
            {
                ContentType        = _currentFrame.ContentType, //should never be null - compositions only exist on documents, which would have a context
                CurrentComposition = registration
            };

            //TODO needed?
            _currentFrame = newContext;
            return(newContext);
        }
コード例 #4
0
 private static CodeFirstModelContext RegisterFrozenContext(object key, CodeFirstModelContext context)
 {
     if (ContextContainer.Current == null || ContextContainer.Current.Dictionary == null || context == null)
     {
         return(null);
     }
     if (!ContextContainer.Current.Dictionary.ContainsKey(key))
     {
         ContextContainer.Current.Dictionary.Add(key, context);
     }
     _currentFrame = context;
     return(ContextContainer.Current.Dictionary[key]);
 }
コード例 #5
0
        internal static void ReinstateContext(object key)
        {
            if (ContextContainer.Current == null || ContextContainer.Current.Dictionary == null)
            {
                return;
            }
            var target = GetContext(key);

            if (_currentFrame != null)
            {
                _stack.Push(_currentFrame);
            }
            _currentFrame = target;
        }
コード例 #6
0
        internal static void ResetContext()
        {
            if (ContextContainer.Current == null || ContextContainer.Current.Dictionary == null)
            {
                return;
            }

            if (_stack.Count > 0)
            {
                _currentFrame = _stack.Pop();
            }
            else
            {
                _currentFrame = null;
            }
        }
コード例 #7
0
 internal static void MoveNextContext(object instance, CodeFirstRegistration registration, CodeFirstModelContext parentContext = null)
 {
     if (ContextContainer.Current == null || ContextContainer.Current.Dictionary == null)
     {
         return;
     }
     else if (!ContextContainer.Current.Dictionary.ContainsKey(instance))
     {
         if (registration is ContentTypeRegistration)
         {
             var newContext = new CodeFirstModelContext()
             {
                 ContentType   = (registration as ContentTypeRegistration),
                 ParentContext = parentContext == null ? parentContext : _currentFrame
             };
             if (_currentFrame != null)
             {
                 _stack.Push(_currentFrame);
             }
             _currentFrame = newContext;
             ContextContainer.Current.Dictionary.Add(instance, _currentFrame);
         }
         else if (registration is TabRegistration)
         {
             var newContext = _currentFrame.Clone();
             newContext.CurrentTab = registration as TabRegistration;
             _currentFrame         = newContext;
             ContextContainer.Current.Dictionary.Add(instance, _currentFrame);
         }
         else if (registration is PropertyRegistration)
         {
             var newContext = _currentFrame.Clone();
             newContext.CurrentProperty = registration as PropertyRegistration;
             _currentFrame = newContext;
             ContextContainer.Current.Dictionary.Add(instance, _currentFrame);
         }
         else
         {
             throw new InvalidOperationException("Unknown context registration type");
         }
     }
 }
コード例 #8
0
 internal static object CreateContextualInstance(Type type, CodeFirstRegistration registration, out Dictionary <PropertyInfo, CodeFirstLazyInitialiser> dict, CodeFirstModelContext parentContext = null, bool useProxy = true)
 {
     if (CodeFirstManager.Current.Features.UseLazyLoadingProxies && useProxy)
     {
         dict = new Dictionary <PropertyInfo, CodeFirstLazyInitialiser>();
         var proxy = _generator.CreateClassProxy(type, _opts, new CodeFirstProxyInterceptor(dict));
         MoveNextContext(proxy, registration, parentContext);
         return(proxy);
     }
     else
     {
         dict = null;
         var instance = Activator.CreateInstance(type);
         MoveNextContext(instance, registration, parentContext);
         return(instance);
     }
 }