Beispiel #1
0
        public void SetTransactionGuid(Guid value)
        {
            IContextChild contextChild = this.target as IContextChild;

            if (contextChild != null)
            {
                IContext ctx = ((IContextChild)this.target).Context;
                if (ctx != null)
                {
                    if (!ctx.IsDisposed)
                    {
                        if (ctx.WriteConsistency.Equals(ConsistencyMode.Pessimistic))
                        {
                            if (Guid.Empty.Equals(value))
                            {
                                throw new WriteConsistencyException(
                                          string.Format("A write consistency exception has occurred. The object of type {0} and with identity {1} was loaded or created outside of a transaction. This is not permitted in a context using Pessimistic WriteConsistency.",
                                                        target.GetType(),
                                                        ctx.ObjectManager.GetObjectIdentity(target)),
                                          target);
                            }
                        }
                        if (ctx.ReadConsistency.Equals(ConsistencyMode.Pessimistic))
                        {
                            if (Guid.Empty.Equals(value))
                            {
                                throw new ReadConsistencyException(
                                          string.Format("A read consistency exception has occurred. The object of type {0} and with identity {1} was loaded or created outside of a transaction. This is not permitted in a context using Pessimistic ReadConsistency.",
                                                        target.GetType(),
                                                        ctx.ObjectManager.GetObjectIdentity(target)),
                                          target);
                            }

                            if (hasTransactionGuid)
                            {
                                if (!(transactionGuid.Equals(value)))
                                {
                                    throw new ReadConsistencyException(
                                              string.Format("A read consistency exception has occurred. The object of type {0} and with identity {1} has already been loaded or created inside a transactions with Guid {2} and was now loaded again under another transaction with Guid {3}. This is not permitted in a context using Pessimistic ReadConsistency.",
                                                            target.GetType(),
                                                            ctx.ObjectManager.GetObjectIdentity(target),
                                                            transactionGuid,
                                                            value),
                                              transactionGuid,
                                              value,
                                              target);
                                }
                            }
                        }
                    }
                }
            }
            this.transactionGuid = value;
            hasTransactionGuid   = true;
        }
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public SerializedProxy GetSerializedProxy()
        {
            SerializedProxy proxy = new SerializedProxy();

            VizType vizType = new VizType();

            vizType.Name     = target.GetType().Name;
            vizType.FullName = target.GetType().FullName;

            Type tmp = target.GetType();

            while (typeof(IAopProxy).IsAssignableFrom(tmp))
            {
                tmp = tmp.BaseType;
            }

            vizType.BaseName = tmp.Name;

            IList mixins = (IList)MethodCache.mixinsLookup[target.GetType()];

            foreach (Type mixinType in mixins)
            {
                VizMixin vizMixin = new VizMixin();
                vizMixin.TypeName     = mixinType.Name;
                vizMixin.FullTypeName = mixinType.FullName;
                vizType.Mixins.Add(vizMixin);
            }
            IList aspects = (IList)MethodCache.aspectsLookup[target.GetType()];

            foreach (IAspect aspect in aspects)
            {
                IGenericAspect tmpAspect;
                if (aspect is IGenericAspect)
                {
                    tmpAspect = (IGenericAspect)aspect;
                }
                else
                {
                    tmpAspect = TypedToGenericConverter.Convert((ITypedAspect)aspect);
                }


                VizAspect vizAspect = new VizAspect();
                vizAspect.Name = tmpAspect.Name;
            }
            IList methods = (IList)MethodCache.methodsLookup[target.GetType()];

            foreach (string methodId in methods)
            {
                MethodBase methodBase = (MethodBase)MethodCache.methodLookup[methodId];
                if (methodBase is ConstructorInfo)
                {
                    ConstructorInfo constructor    = (ConstructorInfo)methodBase;
                    VizConstructor  vizConstructor = new VizConstructor();
                    vizConstructor.Name = constructor.Name;


                    ParameterInfo[] paramInfos = constructor.GetParameters();
                    SerializeParameters(vizConstructor, paramInfos);

                    IList interceptors = (IList)MethodCache.methodInterceptorsLookup[methodId];
                    SerializeInterceptors(vizConstructor, interceptors);
                    vizConstructor.OwnerType = vizType;
                    vizType.Methods.Add(vizConstructor);
                }
                else if (methodBase is MethodInfo)
                {
                    MethodInfo method    = (MethodInfo)methodBase;
                    VizMethod  vizMethod = new VizMethod();
                    vizMethod.Name       = method.Name;
                    vizMethod.ReturnType = method.ReturnType.Name;


                    ParameterInfo[] paramInfos = method.GetParameters();
                    SerializeParameters(vizMethod, paramInfos);

                    IList interceptors = (IList)MethodCache.methodInterceptorsLookup[methodId];
                    SerializeInterceptors(vizMethod, interceptors);
                    vizMethod.OwnerType = vizType;
                    vizType.Methods.Add(vizMethod);
                }
            }


            proxy.ProxyType = vizType;
            return(proxy);
        }
        public void CheckPartiallyLoadedList(string propertyName, ITransaction transaction)
        {
            IList partialList = GetPartiallyLoadedList(propertyName, transaction);
            int   count       = GetCount(propertyName, transaction);

            if (count == partialList.Count)
            {
                IContext       context = ((IInterceptable)this.target).GetInterceptor().Context;
                IObjectManager om      = context.ObjectManager;

                IInterceptableList iList = om.GetPropertyValue(target, propertyName) as IInterceptableList;
                if (iList == null)
                {
                    throw new NPersistException(string.Format("Object of type {0} and identity {1} does not have an interceptable list injected in property {2}", target.GetType(), om.GetObjectIdentity(target), propertyName));
                }

                bool stackMute = iList.MuteNotify;
                iList.MuteNotify = true;

                if (iList.Count < 1)
                {
                    IList orgList = new ArrayList();
                    foreach (object refObj in partialList)
                    {
                        iList.Add(refObj);
                        orgList.Add(refObj);
                    }
                    iList.MuteNotify = stackMute;
                    om.SetPropertyValue(target, propertyName, iList);
                    om.SetOriginalPropertyValue(target, propertyName, orgList);
                    om.SetNullValueStatus(target, propertyName, false);
                    om.SetUpdatedStatus(target, propertyName, false);

                    context.InverseManager.NotifyPropertyGet(target, propertyName);
                }
                else
                {
                    iList.MuteNotify = stackMute;
                }
            }
        }