Ejemplo n.º 1
0
        protected override bool PreInvoke(ChoMemberInfo memberInfo)
        {
            object oldValue = ChoType.GetMemberValue(this, memberInfo.Info);
            object newValue = memberInfo.Value;

            bool isEqual = IsMemeberValueEqualInternal(memberInfo.Info, oldValue, newValue);

            if (!isEqual)
            {
                if (memberInfo.DirtyOperation)
                {
                    string propertyName = ChoType.GetMemberName(memberInfo.Info);

                    try
                    {
                        bool handled = RaiseBeforeConfigurationObjectMemberLoaded(memberInfo.Name, propertyName, oldValue, ref newValue);
                        memberInfo.Value = newValue;
                        return(!handled);
                    }
                    catch (Exception ex)
                    {
                        if (!RaiseConfigurationObjectMemberLoadError(memberInfo.Name, propertyName, newValue, ex))
                        {
                            throw;
                        }
                    }
                }
                return(true);
            }
            else
            {
                return(!isEqual);
            }
        }
Ejemplo n.º 2
0
        protected override void PostInvoke(ChoMemberInfo memberInfo)
        {
            object newValue = memberInfo.Value;

            if (memberInfo.DirtyOperation)
            {
                string propertyName = ChoType.GetMemberName(memberInfo.Info);

                if (memberInfo.Exception == null)
                {
                    RaiseAfterConfigurationObjectMemberLoaded(memberInfo.Name, propertyName, newValue);
                }
                else
                {
                    if (!RaiseConfigurationObjectMemberLoadError(memberInfo.Name, propertyName, newValue, memberInfo.Exception))
                    {
                        throw new ChoConfigurationObjectPostInvokeException("Error while loading configuration member load operation.", memberInfo.Exception);
                    }
                    else
                    {
                        memberInfo.ReturnMessage = new ReturnMessage(null, memberInfo.MethodCallMsg);
                    }
                }
            }
            if (memberInfo.DirtyOperation && Dirty && !IsReadOnly() && Initialized)
            {
                ChoPropertyInfoAttribute memberInfoAttribute = ChoType.GetMemberAttribute(memberInfo.Info, typeof(ChoPropertyInfoAttribute)) as ChoPropertyInfoAttribute;
                if (memberInfoAttribute == null || memberInfoAttribute.Persistable)
                {
                    Persist();
                }

                SetDirty(false);
            }
        }
Ejemplo n.º 3
0
        /// In the Invoke Method we do our interception work.
        public override IMessage Invoke(IMessage msg)
        {
            IMethodMessage returnMsg = null;

            if (msg is IConstructionCallMessage)
            {
                _realObject = GetInstance(msg as IConstructionCallMessage, ref returnMsg);
                _objType    = ((IConstructionCallMessage)msg).ActivationType;
                //SetStubData(this, _realObject);
            }
            else
            {
                if (!_isInit)
                {
                    DoObjectInitialize(_target);
                    _isInit = true;
                }

                ///the MethodCallMessageWrapper provides read/write access to the method call arguments.
                MethodCallMessageWrapper methodCallMsg = new MethodCallMessageWrapper((IMethodCallMessage)msg);
                ///This is the reflected method base of the called method.
                MethodInfo methodInfo = (MethodInfo)methodCallMsg.MethodBase;

                ///This is the object we are proxying.
                MarshalByRefObject owner = _target;
                //MarshalByRefObject owner = _realObject as MarshalByRefObject;
                ///Some basic initializations for later use
                if (owner != null)
                {
                    ChoMemberInfo memberInfo = new ChoMemberInfo(owner, _objType, methodCallMsg);
                    if (!ChoType.IsValidObjectMember(memberInfo.Info))
                    {
                        //|| ChoType.GetAttribute<ChoPropertyInfoAttribute>(memberInfo.Info, false) == null)
                        return(RemotingServices.ExecuteMessage(owner, methodCallMsg));
                    }

                    return(ExecuteMethod(ref returnMsg, methodCallMsg, owner, memberInfo));

                    //if (methodCallMsg.LogicalCallContext.GetData("CallerId") != null)
                    //    return ExecuteMethod(ref returnMsg, methodCallMsg, owner, memberInfo);
                    //else
                    //{
                    //    methodCallMsg.LogicalCallContext.SetData("CallerId", ChoRandom.NextRandom());
                    //    IChoAsyncResult result = ChoQueuedExecutionService.Global.Enqueue(() =>
                    //        {
                    //            return ExecuteMethod(ref returnMsg, methodCallMsg, owner, memberInfo);
                    //        });

                    //    return (IMessage)result.EndInvoke();
                    //}
                }
                else
                {
                    return(new ReturnMessage(new NullReferenceException("Missing target object."), methodCallMsg));
                }
            }

            return(returnMsg);
        }
Ejemplo n.º 4
0
 protected override void PostInvoke(ChoMemberInfo memberInfo)
 {
     if (memberInfo.Exception != null)
     {
         //if (RaiseCommandLineArgLoadError(memberInfo.Name, memberInfo.Value, memberInfo.Exception))
         //    memberInfo.Exception = null;
     }
 }
Ejemplo n.º 5
0
        protected override bool PreInvoke(ChoMemberInfo memberInfo)
        {
            object oldValue = ChoType.GetMemberValue(this, memberInfo.Info);
            object newValue = memberInfo.Value;

            bool isEqual = IsMemeberValueEqualInternal(memberInfo.Info, oldValue, newValue);

            if (!isEqual)
            {
                if (memberInfo.DirtyOperation)
                {
                    string propertyName = ChoType.GetMemberName(memberInfo.Info);

                    try
                    {
                        bool cancel = RaiseBeforeConfigurationObjectMemberSet(memberInfo.Name, propertyName, oldValue, ref newValue);
                        //if (!cancel)
                        //{
                        //    //memberInfo.Value = newValue;
                        //    ChoType.SetMemberValue(this, memberInfo.Info, newValue);
                        //    this.OnPropertyChanged(memberInfo.Name);
                        //}
                        return(!cancel);
                    }
                    catch (Exception ex)
                    {
                        if (!RaiseConfigurationObjectMemberSetError(memberInfo.Name, propertyName, newValue, ex))
                        {
                            throw new ChoConfigurationObjectPostInvokeException("Error while setting configuration member value.", memberInfo.Exception);
                        }
                    }
                }
                return(true);
            }
            else
            {
                return(!isEqual);
            }
        }
Ejemplo n.º 6
0
        protected override void PostInvoke(ChoMemberInfo memberInfo)
        {
            object newValue = memberInfo.Value;

            if (memberInfo.DirtyOperation)
            {
                string propertyName = ChoType.GetMemberName(memberInfo.Info);

                if (memberInfo.Exception == null)
                {
                    RaiseAfterConfigurationObjectMemberSet(memberInfo.Name, propertyName, newValue);
                    OnPropertyChanged(memberInfo.Name);
                }
                else
                {
                    if (!RaiseConfigurationObjectMemberSetError(memberInfo.Name, propertyName, newValue, memberInfo.Exception))
                    {
                        memberInfo.Exception = new ChoConfigurationObjectPostInvokeException("Error while setting '{0}' configuration member value.".FormatString(memberInfo.Name), memberInfo.Exception);
                    }
                    else
                    {
                        memberInfo.Exception = null;
                    }
                }
            }
            if (memberInfo.DirtyOperation /*&& Dirty */ && !IsReadOnly() && Initialized)
            {
                ChoPropertyInfoAttribute memberInfoAttribute = ChoType.GetMemberAttribute(memberInfo.Info, typeof(ChoPropertyInfoAttribute)) as ChoPropertyInfoAttribute;
                if (memberInfoAttribute == null || memberInfoAttribute.Persistable)
                {
                    Persist();
                }

                SetDirty(false);
            }
        }
Ejemplo n.º 7
0
        private ReturnMessage ExecuteMethod(ref IMethodMessage returnMsg, MethodCallMessageWrapper methodCallMsg, MarshalByRefObject owner, ChoMemberInfo memberInfo)
        {
            try
            {
                PreMethodInvoke(owner, methodCallMsg, memberInfo);

                returnMsg = RemotingServices.ExecuteMessage(owner, methodCallMsg);
                memberInfo.ReturnMessage = returnMsg as ReturnMessage;

                if (memberInfo.Info != null)
                {
                    memberInfo.MethodMsg = returnMsg;
                }

                PostMethodInvoke(owner, methodCallMsg, memberInfo);

                return(memberInfo.ReturnMessage);
            }
            catch (TargetInvocationException ex)
            {
                return(new ReturnMessage(ex.InnerException, methodCallMsg));
            }
            catch (ChoFatalApplicationException)
            {
                throw;
            }
            catch (Exception ex)
            {
                //Trace.TraceError(ex.ToString());
                ChoInterceptableObject interceptableObject = owner as ChoInterceptableObject;
                if (interceptableObject != null && interceptableObject.Initialized)
                {
                    if (interceptableObject.IsConfigObjectSilent)
                    {
                        ChoConfigurationObjectErrorManagerService.SetObjectMemberError(interceptableObject, memberInfo.Name,
                                                                                       String.Format(Resources.ConfigConstructMsg, ChoString.ToString(memberInfo.Value), ex.Message));

                        //PostMethodInvoke(owner, methodCallMsg, memberInfo);

                        //return new ReturnMessage(null, methodCallMsg);
                    }
                }
                string msg = "{0}: {1}".FormatString(memberInfo.Name, String.Format(Resources.ConfigConstructMsg, ChoString.ToString(memberInfo.Value), ex.Message));
                ChoValidationException ex1 = new ChoValidationException(msg);
                if (OnMemberError(owner, memberInfo, ref ex))
                {
                    return(new ReturnMessage(null, null, 0, null, methodCallMsg));
                }
                else
                {
                    return(new ReturnMessage(ex1, methodCallMsg));
                }
            }
        }
 protected virtual void PostInvoke(ChoMemberInfo memberInfo)
 {
 }
 internal void PostInvokeInternal(ChoMemberInfo memberInfo)
 {
     PostInvoke(memberInfo);
 }
 protected virtual bool PreInvoke(ChoMemberInfo memberInfo)
 {
     return(false);
 }
 internal bool PreInvokeInternal(ChoMemberInfo memberInfo)
 {
     return(PreInvoke(memberInfo));
 }
Ejemplo n.º 12
0
        public virtual void PreMethodInvoke(object owner, MethodCallMessageWrapper methodCallMsg, ChoMemberInfo memberInfo)
        {
            MethodInfo methodInfo = (MethodInfo)methodCallMsg.MethodBase;

            ChoInterceptableObject interceptableObject = owner as ChoInterceptableObject;

            if (interceptableObject != null)
            {
                if (memberInfo.DirtyOperation && !interceptableObject.Silent)
                {
                    if (interceptableObject.PreInvokeInternal(memberInfo))
                    {
                        if (interceptableObject.Initialized)
                        {
                            interceptableObject.SetDirty(memberInfo.DirtyOperation);
                        }
                        else
                        {
                            interceptableObject.IsModified = true;
                        }
                    }
                    else
                    {
                        return;
                    }
                }
            }

            if (memberInfo.Info != null)
            {
                if (memberInfo.DirtyOperation)
                {
                    ChoValidation.Validate(memberInfo.Info, memberInfo.Value);
                    if (interceptableObject != null && interceptableObject.Initialized)
                    {
                        ChoConfigurationObjectErrorManagerService.ResetObjectMemberError(interceptableObject, memberInfo.Name);
                    }
                }
            }
        }
Ejemplo n.º 13
0
 protected internal virtual bool OnMemberError(MarshalByRefObject owner, ChoMemberInfo memberInfo, ref Exception ex)
 {
     return(false);
 }
Ejemplo n.º 14
0
        private void DoPostMethodInvoke(MethodCallMessageWrapper methodCallMsg, MarshalByRefObject owner, ChoMemberInfo memberInfo)
        {
            try
            {
                PostMethodInvoke(owner, methodCallMsg, memberInfo);
            }
            catch { }

            if (memberInfo.Exception == null)
            {
                if (memberInfo.ReturnMessage == null)
                {
                    memberInfo.ReturnMessage = new ReturnMessage(null, null, 0, null, methodCallMsg);
                }
            }
            else
            {
                memberInfo.ReturnMessage = new ReturnMessage(memberInfo.Exception, methodCallMsg);
            }
        }
Ejemplo n.º 15
0
        /// In the Invoke Method we do our interception work.
        public override IMessage Invoke(IMessage msg)
        {
            if (msg is IConstructionCallMessage)
            {
                ChoRealProxyInstanceState instance = GetInstance(msg as IConstructionCallMessage);
                if (instance.Exception != null)
                {
                    throw instance.Exception;
                }

                _target = instance.Target;
                return(EnterpriseServicesHelper.CreateConstructionReturnMessage(msg as IConstructionCallMessage, (MarshalByRefObject)this.GetTransparentProxy()));
            }
            else
            {
                IMethodMessage            returnMsg = null;
                ChoRealProxyInstanceState instance  = _instances[_target.GetType()];
                if (!instance.IsInitialized)
                {
                    DoObjectInitialize(_target);
                    instance.IsInitialized = true;
                }

                ///the MethodCallMessageWrapper provides read/write access to the method call arguments.
                MethodCallMessageWrapper methodCallMsg = new MethodCallMessageWrapper((IMethodCallMessage)msg);
                ///This is the reflected method base of the called method.
                MethodInfo methodInfo = (MethodInfo)methodCallMsg.MethodBase;

                ///This is the object we are proxying.
                MarshalByRefObject owner = _target as MarshalByRefObject;
                //MarshalByRefObject owner = _realObject as MarshalByRefObject;
                ///Some basic initializations for later use
                if (owner != null)
                {
                    ChoMemberInfo memberInfo = new ChoMemberInfo(owner, _objType, methodCallMsg);
                    if (!ChoType.IsValidObjectMember(memberInfo.Info))
                    {
                        return(RemotingServices.ExecuteMessage(owner, methodCallMsg));
                    }

                    return(ExecuteMethod(ref returnMsg, methodCallMsg, owner, memberInfo));

                    //if (methodCallMsg.LogicalCallContext.GetData("CallerId") != null)
                    //    return ExecuteMethod(ref returnMsg, methodCallMsg, owner, memberInfo);
                    //else
                    //{
                    //    methodCallMsg.LogicalCallContext.SetData("CallerId", ChoRandom.NextRandom());
                    //    IChoAsyncResult result = ChoQueuedExecutionService.Global.Enqueue(() =>
                    //        {
                    //            return ExecuteMethod(ref returnMsg, methodCallMsg, owner, memberInfo);
                    //        });

                    //    return (IMessage)result.EndInvoke();
                    //}
                }
                else
                {
                    return(new ReturnMessage(new NullReferenceException("Missing target object."), methodCallMsg));
                }
            }
        }
Ejemplo n.º 16
0
        public virtual void PostMethodInvoke(object owner, MethodCallMessageWrapper methodCallMsg, ChoMemberInfo memberInfo)
        {
            MethodInfo methodInfo = (MethodInfo)methodCallMsg.MethodBase;

            ChoInterceptableObject interceptableObject = owner as ChoInterceptableObject;

            //if (memberInfo.Info != null)
            //{
            //    if (memberInfo.DirtyOperation)
            //    {
            //        ChoValidation.Validate(memberInfo.Info, memberInfo.Value);
            //        if (interceptableObject.Initialized)
            //            ChoConfigurationObjectErrorManagerService.ResetObjectMemberError(interceptableObject, memberInfo.Name);
            //    }
            //}

            if (interceptableObject != null)
            {
                interceptableObject.PostInvokeInternal(memberInfo);
            }
        }
Ejemplo n.º 17
0
        /// In the Invoke Method we do our interception work.
        public override IMessage Invoke(IMessage msg)
        {
            ///the MethodCallMessageWrapper provides read/write access to the method call arguments.
            MethodCallMessageWrapper methodCallMsg = new MethodCallMessageWrapper((IMethodCallMessage)msg);
            ///This is the reflected method base of the called method.
            MethodInfo methodInfo = (MethodInfo)methodCallMsg.MethodBase;

            ///This is the object we are proxying.
            MarshalByRefObject owner = GetUnwrappedServer();
            ///Some basic initializations for later use
            IMethodReturnMessage returnMsg = null;

            if (owner != null)
            {
                ChoMemberInfo memberInfo = new ChoMemberInfo(owner, methodCallMsg);
                try
                {
                    lock (this)
                    {
                        if (owner is ChoInterceptableObject && memberInfo.DirtyOperation && !((ChoInterceptableObject)owner).Silent)
                        {
                            ((ChoInterceptableObject)owner).SetDirty(memberInfo.DirtyOperation);
                        }

                        if (owner is ChoInterceptableObject)
                        {
                            ((ChoInterceptableObject)owner).PreInvoke(methodCallMsg, memberInfo);
                        }

                        if (memberInfo.Info != null)
                        {
                            foreach (IChoBeforeMemberCallAttribute beforeMemberCallAttribute in ChoType.GetMemberAttributesByBaseType(memberInfo.Info,
                                                                                                                                      typeof(IChoBeforeMemberCallAttribute)))
                            {
                                beforeMemberCallAttribute.Validate(memberInfo.Value, ((ChoInterceptableObject)owner).Silent);
                            }
                        }

                        //outVal = methodInfo.Invoke(owner, methodCallMsg.Args);
                        returnMsg = RemotingServices.ExecuteMessage(owner, methodCallMsg);

                        if (memberInfo.Info != null)
                        {
                            memberInfo.MethodMsg = returnMsg;
                            foreach (IChoAfterMemberCallAttribute afterMemberCallAttribute in ChoType.GetMemberAttributesByBaseType(memberInfo.Info,
                                                                                                                                    typeof(IChoAfterMemberCallAttribute)))
                            {
                                afterMemberCallAttribute.Validate(memberInfo.Value, ((ChoInterceptableObject)owner).Silent);
                            }
                        }

                        if (owner is ChoInterceptableObject)
                        {
                            ((ChoInterceptableObject)owner).PostInvoke(methodCallMsg, memberInfo);
                        }

                        return(returnMsg); // new ReturnMessage(outVal, methodCallMsg.Args, methodCallMsg.Args.Length, methodCallMsg.LogicalCallContext, methodCallMsg);
                    }
                }
                catch (TargetInvocationException ex)
                {
                    return(new ReturnMessage(ex.InnerException, methodCallMsg));
                }
            }

            throw new NullReferenceException("Missing target object.");
        }