Inheritance: InternalMessageWrapper, IMethodCallMessage, IMethodMessage, IMessage
		// Messages will be intercepted here and redirected
		// to another object.
		public override IMessage Invoke (IMessage msg)
		{
			try {
				if (msg is IConstructionCallMessage) {
					IActivator remActivator = (IActivator) RemotingServices.Connect (typeof (IActivator), "tcp://localhost:1234/RemoteActivationService.rem");
					IConstructionReturnMessage crm = remActivator.Activate ((IConstructionCallMessage) msg);
					return crm;
				} else {
					methodOverloaded = RemotingServices.IsMethodOverloaded ((IMethodMessage) msg);

					_mthBase = RemotingServices.GetMethodBaseFromMethodMessage ((IMethodMessage) msg);
					MethodCallMessageWrapper mcm = new MethodCallMessageWrapper ((IMethodCallMessage) msg);
					mcm.Uri = RemotingServices.GetObjectUri ((MarshalByRefObject) target);
					MarshalByRefObject objRem = (MarshalByRefObject) Activator.CreateInstance (GetProxiedType ());
					RemotingServices.ExecuteMessage ((MarshalByRefObject) objRem, (IMethodCallMessage) msg);
					IMessage rtnMsg = null;

					try {
						rtnMsg = _sink.SyncProcessMessage (msg);
					} catch (Exception e) {
						Console.WriteLine (e.Message);
					}

					Console.WriteLine ("RR:" + rtnMsg);
					return rtnMsg;
				}
			} catch (Exception ex) {
				Console.WriteLine (ex);
				return null;
			}
		}
示例#2
0
		/// <summary>
		/// This reflective method for invoking methods. Overriden from RealProxy.
		/// Handles the object invocation. This method wrapps an instance call to the service 
		/// requests, sends it to the service and translates the reply of this call to the C# - data type
		/// <see cref="System.Runtime.Remoting.Proxies.RealProxy"/>
		/// </summary>
		/// <param name="msg"></param>
		/// <returns></returns>
		public override IMessage Invoke(IMessage msg)
		{
            // Convert to a MethodCallMessage
            IMethodCallMessage methodMessage = new MethodCallMessageWrapper((IMethodCallMessage)msg);
            MethodInfo methodInfo = this.GetMethodInfoForMethodBase(methodMessage);

            var ps = methodInfo.GetParameters();
            Type[] argumentTypes = new Type[ps.Length];
            for(int i=0;i<ps.Length;i++)
            {
                argumentTypes[i] = ps[i].ParameterType;
            }
            object objReturnValue = null;
            if (methodInfo != null)
            {
                if (methodInfo.Name.Equals("Equals") && argumentTypes != null &&
                    argumentTypes.Length == 1 && argumentTypes[0].IsAssignableFrom((typeof(Object))))
                {
                    Object value = methodMessage.Args[0];
                    if (value == null)
                    {
                        objReturnValue = false;
                    }
                    else
                    {
                        objReturnValue = false;
                    }
                }
                else if(methodInfo.Name.Equals("GetHashCode") && argumentTypes.Length == 0)
                {
                    objReturnValue = msg.GetHashCode();
                }
                else if (methodInfo.Name.Equals("ToString") && argumentTypes.Length == 0)
                {
                    objReturnValue = this.ToString();
                }
                else if (methodInfo.Name.Equals("GetType") && argumentTypes.Length == 0)
                {
                    objReturnValue = this.m_proxyType;
                }
                else
                {
                    objReturnValue = this.m_methodCaller.DoMethodCall(methodMessage.Args, methodInfo);
                }
            }
            else
            {
                if (methodMessage.MethodName.Equals("GetType") && (methodMessage.ArgCount == 0))
                {
                    objReturnValue = this.m_proxyType;
                }
            }
           
            // Create the return message (ReturnMessage)
            return new ReturnMessage(objReturnValue, methodMessage.Args, methodMessage.ArgCount, methodMessage.LogicalCallContext, methodMessage);
		}
 public override IMessage Process(MethodCallMessageWrapper mc)
 {
     if (!mc.InArgs.SequenceEqual(expectedArgs))
     {
         string[] expected = expectedArgs.Select(o => o.ToString()).ToArray();
         string[] actual = mc.InArgs.Select(o => o.ToString()).ToArray();
         string message = String.Format("Expected arguments {0} but found {1}", String.Join(", ", expected), String.Join(", ", actual));
         var exception = new MockException(message);
         return new ExceptionBehaviour(exception).Process(mc);
     }
     return base.Process(mc);
 }
示例#4
0
        public override IMessage Invoke(IMessage msg)
        {
            MethodCallMessageWrapper mc = new MethodCallMessageWrapper((IMethodCallMessage)msg);

            CallBehaviour behaviour = CallBehaviours.FirstOrDefault(i => i.Profile(mc));

            if (behaviour != null)
            {
                return behaviour.Process(mc);
            }

            return CatchAllBehaviour.Process(mc);
        }
        public override IMessage Invoke(IMessage message)
        {
            var methodMessage = new MethodCallMessageWrapper((IMethodCallMessage)message);
            var method = methodMessage.MethodBase;

            object returnValue = null;
            if (method.DeclaringType == typeof(IDynamicProxy))
                returnValue = method.Invoke(this, methodMessage.Args);
            else
                returnValue = invocationHandler(proxyTarget, method, methodMessage.Args);

            return new ReturnMessage(returnValue, methodMessage.Args, methodMessage.ArgCount,
                methodMessage.LogicalCallContext, methodMessage);
        }
        private static void combineMultipleNewParamValuesIntoNewMessage(ArrayList newCallMessages, ref IMethodCallMessage callMessage)
        {
            object[] combinedNewValues = new object[callMessage.Args.Length];

            foreach (IMethodCallMessage newCallMessage in  newCallMessages)
            {
                //notice that we run the rist that the same parameter can be changed twice
                //in two different places and the last change wins
                for (int i = 0; i < newCallMessage.Args.Length; i++)
                {
                    combinedNewValues[i] = newCallMessage.Args[i];
                }
            }
            MethodCallMessageWrapper newCombinedMessageCall = new MethodCallMessageWrapper(callMessage);
            newCombinedMessageCall.Args = combinedNewValues;
            callMessage = newCombinedMessageCall;
        }
示例#7
0
        public override IMessage Process(MethodCallMessageWrapper mc)
        {
            MethodInfo mi = (MethodInfo)mc.MethodBase;

            if (mi.ReturnType == typeof(void))
            {
                return ReturnBehaviour.Void.Process(mc);
            }
            else
            {
                object returnValue = null;
                if (mi.ReturnType.IsValueType)
                {
                    returnValue = Activator.CreateInstance(mi.ReturnType);
                }
                return new ReturnBehaviour(returnValue).Process(mc);
            }
        }
示例#8
0
        /// <summary>
        /// Handles the messages that our proxy receives
        /// </summary>
        public override IMessage Invoke(IMessage msg)
        {
            if (msg is IMethodCallMessage)
            {
                var methodCallMessage = msg as IMethodCallMessage;
                var methodCallMessageWrapper = new MethodCallMessageWrapper(methodCallMessage);

                object returnValue = null;
                MockedMemberInfo methodCallInfo = null;

                // First, try to find the PropertyInfo for this method (because it might be a backing
                // method for a property). If that fails, just use the method from the message.
                object key = GetPropertyInfoFromMethodInfo(methodCallMessageWrapper.MethodBase as MethodInfo);
                if (key == null)
                    key = methodCallMessageWrapper.MethodBase;

                if (MemberCallInfoCollection.TryGetValue(key, out methodCallInfo))
                {
                    // Method call has been arranged. Figure out the desired return value.
                    returnValue = methodCallInfo.ExecuteMockedMember(methodCallMessage.InArgs);
                }
                else
                {
                    // Method call has not been arranged. Add an arrangement for it (for logging purposes)
                    // and return a default value
                    methodCallInfo = new MockedMemberInfo();
                    MemberCallInfoCollection.Add(methodCallMessageWrapper.MethodBase, methodCallInfo);
                    returnValue = CalculateDefaultReturnValue(methodCallMessageWrapper);
                }

                methodCallInfo.LogMethodCall(methodCallMessage.InArgs);

                var returnMessage = new ReturnMessage(returnValue, null, 0, methodCallMessageWrapper.LogicalCallContext, methodCallMessage);
                return returnMessage;
            }

            return null;
        }
        public IMessage SyncProcessMessage(IMessage msg)
        {
            var methodMessage = new MethodCallMessageWrapper((IMethodCallMessage) msg);

            IMethodReturnMessage mrm = null;

            Reporters.ExecuteStep(
                () =>
                {
                    var rtnMsg = NextSink.SyncProcessMessage(msg);
                    mrm = (IMethodReturnMessage)rtnMsg;

                    if (mrm.Exception != null)
                    {
                        throw mrm.Exception;
                    }
                },
                methodMessage.MethodBase,
                methodMessage.Args
                );

            return mrm;
        }
        public override IMessage Invoke(IMessage msg)
        {
            IMethodCallMessage methodMessage = new MethodCallMessageWrapper((IMethodCallMessage)msg);

            var executeType = GetExecuteType(methodMessage);

            if (executeType != ExecuteType.None)
                profiler.ExecuteStart(instance, executeType);

            object returnValue = methodMessage.MethodBase.Invoke(instance, methodMessage.Args);

            if (executeType == ExecuteType.Reader)
                returnValue = new ProfiledDbDataReader((DbDataReader)returnValue, instance.Connection, profiler);

            IMessage returnMessage = new ReturnMessage(returnValue, methodMessage.Args, methodMessage.ArgCount, methodMessage.LogicalCallContext, methodMessage);

            if (executeType == ExecuteType.Reader)
                profiler.ExecuteFinish(instance, executeType, (DbDataReader)returnValue);
            else if (executeType != ExecuteType.None)
                profiler.ExecuteFinish(instance, executeType, null);

            return returnMessage;
        }
        public override IMessage Invoke(IMessage msg)
        {
            MethodCallMessageWrapper mc = new MethodCallMessageWrapper((IMethodCallMessage)msg);
            MarshalByRefObject owner = GetUnwrappedServer();
            MethodInfo mi = (MethodInfo)mc.MethodBase;

            Log.Trace("OS Proxy class invoking method " + mi.Name + " in class " + _originalObject.GetType().FullName);

            object outVal = null;
            bool isGet;

            if (mi.Name == "GetType")
                outVal = _originalObject.GetType();
            else{
                PropertyInfo pi = GetMethodProperty(mi, _originalObject, out isGet);
                if (pi != null)
                {
                    if (pi.GetCustomAttributes(typeof(OperatingSystemOverridablePropertyAttribute), false).Length > 0)
                    {
                        Log.Trace("Detected overridable property of " + pi.Name + " in type " + _originalObject.GetType().ToString());
                        if (_propertyOverrides.ContainsKey(pi.Name))
                        {
                            Log.Trace("Overriding property call " + pi.Name + " for class " + owner.GetType().FullName + " using class " + _propertyOverrides[pi.Name].OverrideClass.FullName);
                            Monitor.Enter(_producedClasses);
                            if (!_producedClasses.ContainsKey(_propertyOverrides[pi.Name].OverrideClass))
                                _producedClasses.Add(_propertyOverrides[pi.Name].OverrideClass,
                                    _propertyOverrides[pi.Name].OverrideClass.GetConstructor(Type.EmptyTypes).Invoke(new object[0]));
                            owner = (MarshalByRefObject)_producedClasses[_propertyOverrides[pi.Name].OverrideClass];
                            Monitor.Exit(_producedClasses);
                            mi = (isGet ? _propertyOverrides[pi.Name].Property.GetGetMethod() : _propertyOverrides[pi.Name].Property.GetSetMethod());
                        }
                    }
                }
                else
                {
                    if (mi.GetCustomAttributes(typeof(OperatingSystemOverridableFunctionAttribute), false).Length > 0)
                    {
                        Log.Trace("Detected overridable method of " + mi.Name + " in type " + _originalObject.GetType().ToString());
                        if (_methodOverrides.ContainsKey(mi.Name))
                        {
                            foreach (sMethodOverride smo in _methodOverrides[mi.Name])
                            {
                                if (smo.IsMatchForMethod(mi))
                                {
                                    Log.Trace("Overriding method call " + mi.Name + " for class " + owner.GetType().FullName + " using class " + smo.OverrideClass.FullName);
                                    Monitor.Enter(_producedClasses);
                                    if (!_producedClasses.ContainsKey(smo.OverrideClass))
                                        _producedClasses.Add(smo.OverrideClass,
                                            smo.OverrideClass.GetConstructor(Type.EmptyTypes).Invoke(new object[0]));
                                    owner = (MarshalByRefObject)_producedClasses[smo.OverrideClass];
                                    Monitor.Exit(_producedClasses);
                                    mi = smo.Method;
                                }
                            }
                        }
                    }
                }
                outVal = mi.Invoke(owner, mc.Args);
            }
            return new ReturnMessage(outVal, mc.Args, mc.Args.Length, mc.LogicalCallContext, mc);
        }
        public override IMessage Invoke(IMessage msg)
        {
            MethodCallMessageWrapper mc = new MethodCallMessageWrapper((IMethodCallMessage)msg);

            MethodInfo mi = (MethodInfo)mc.MethodBase;

            try
            {
                OnBeforeInvoke(mi, _wrapped, mc.Args);
                object outVal = mi.Invoke(_wrapped, mc.Args);
                OnAfterInvoke(mi, _wrapped, mc.Args, ref outVal);
                return new ReturnMessage(outVal, mc.Args, mc.Args.Length, mc.LogicalCallContext, mc);
            }
            catch (TargetInvocationException e)
            {
                return new ReturnMessage(e.InnerException, (IMethodCallMessage)msg);
            }
            catch (Exception e)
            {
                return new ReturnMessage(e, (IMethodCallMessage)msg);
            }
        }
示例#13
0
        /// <summary>
        /// Calculates and returns the default return value for the given message based on its type
        /// </summary>
        private static object CalculateDefaultReturnValue(MethodCallMessageWrapper methodCallMessage)
        {
            Object returnValue = null;
            var methodInfo = methodCallMessage.MethodBase as MethodInfo;
            if (methodInfo != null)
            {
                var returnType = methodInfo.ReturnType;
                if (returnType.IsValueType && returnType != typeof(void))
                    returnValue = Activator.CreateInstance(returnType);
            }

            return returnValue;
        }
        public override IMessage Invoke(IMessage message)
        {
            if (message is IConstructionCallMessage)
            {
                IConstructionReturnMessage myIConstructionReturnMessage =
                   this.InitializeServerObject((IConstructionCallMessage)message);
                ConstructionResponse constructionResponse = new
                   ConstructionResponse(null, (IMethodCallMessage)message);
                return constructionResponse;
            }
            IMethodCallMessage methodMessage = new MethodCallMessageWrapper((IMethodCallMessage)message);

            MethodBase method = methodMessage.MethodBase;

            object returnValue = null;
            if (method.DeclaringType == typeof(IDynamicProxy))
                returnValue = method.Invoke(this, methodMessage.Args);
            else
                returnValue = InvocationHandler(ProxyTargetTyped, method, methodMessage.Args);

            ReturnMessage returnMessage = new ReturnMessage(returnValue, methodMessage.Args, methodMessage.ArgCount, methodMessage.LogicalCallContext, methodMessage);
            return returnMessage;
        }
示例#15
0
 public override IMessage Process(MethodCallMessageWrapper mc)
 {
     return new ReturnMessage(exception, mc);
 }
 /// <summary>
 /// This reflective method for invoking methods. Overriden from RealProxy.
 /// Handles the object invocation. This method wrapps an instance call to the hessian 
 /// requests, sends it to the burlap service and translates the reply of this call to the C# - data type
 /// <see cref="System.Runtime.Remoting.Proxies.RealProxy"/>
 /// </summary>
 /// <param name="msg"></param>
 /// <returns></returns>
 public override IMessage Invoke(IMessage msg)
 {
     // Convert to a MethodCallMessage
     IMethodCallMessage methodMessage = new MethodCallMessageWrapper((IMethodCallMessage)msg);
     MethodInfo methodInfo = this.GetMethodInfoForMethodBase(methodMessage);
     Type[] argumentTypes = CBurlapMethodCaller.GetArgTypes(methodMessage.Args);
     object objReturnValue = null;
     if (methodInfo != null)
     {
         if (methodInfo.Name.Equals("Equals") && argumentTypes != null &&
             argumentTypes.Length == 1 && argumentTypes[0].IsAssignableFrom((typeof(Object))))
         {
             Object value = methodMessage.Args[0];
             if (value == null)
             {
                 objReturnValue = false;
             }
             else if (value.GetType().Equals(typeof(CBurlapProxy))
                 || value.GetType().IsAssignableFrom(typeof(CBurlapProxy)))
             {
                 objReturnValue = this.m_methodCaller.URI.Equals(((CBurlapProxy)value).URI);
             }
             else
             {
                 objReturnValue = false;
             }
         }
         else if (methodInfo.Name.Equals("GetHashCode") && argumentTypes.Length == 0)
         {
             objReturnValue = this.m_methodCaller.URI.GetHashCode();
         }
         else if (methodInfo.Name.Equals("GetBurlapURL"))
         {
             objReturnValue = this.m_methodCaller.URI.ToString();
         }
         else if (methodInfo.Name.Equals("ToString") && argumentTypes.Length == 0)
         {
             objReturnValue = "[BurlapProxy " + this.m_methodCaller.URI + "]";
         }
         else if (methodInfo.Name.Equals("GetType") && argumentTypes.Length == 0)
         {
             objReturnValue = this.m_proxyType;
         }
         else
         {
             objReturnValue = this.m_methodCaller.DoBurlapMethodCall(methodMessage.Args, methodInfo);
         }
     }
     else
     {
         if (methodMessage.MethodName.Equals("GetType") && (methodMessage.ArgCount == 0))
         {
             objReturnValue = this.m_proxyType;
         }
     }
     // Create the return message (ReturnMessage)
     return new ReturnMessage(objReturnValue, methodMessage.Args, methodMessage.ArgCount, methodMessage.LogicalCallContext, methodMessage);
 }
示例#17
0
        public override IMessage Invoke(IMessage msg)
        {
            Exception InnerException;
            msg.Properties["__Uri"] = _TcpUrl;
            IMessage retMsg = _messageSinks[0].SyncProcessMessage(msg);
            // Handle construction call message differently than other method
            // call messages.
            if (msg is IConstructionCallMessage)
            {
                // need to finish CAO activation manually.
                string url = GetUrlForCAO(_serverType);
                if (url.Length > 0)
                {
                    ActivatedCAO((IConstructionCallMessage)msg, url);
                }

                IConstructionReturnMessage crm = EnterpriseServicesHelper.CreateConstructionReturnMessage((IConstructionCallMessage)msg, (MarshalByRefObject)this.GetTransparentProxy());
                return crm;
            }
            else
            {
                if (retMsg is IMethodReturnMessage)
                {
                    IMethodReturnMessage mrm = (IMethodReturnMessage)retMsg;
                    if (mrm.Exception == null) return retMsg;
                    else InnerException = mrm.Exception;
                }
                else
                {
                    MethodCallMessageWrapper mcm = new MethodCallMessageWrapper((IMethodCallMessage)msg);
                    mcm.Uri = RemotingServices.GetObjectUri((MarshalByRefObject)_targetTcp);
                    return RemotingServices.GetEnvoyChainForProxy((MarshalByRefObject)_targetTcp).SyncProcessMessage(msg);
                }
                msg.Properties["__Uri"] = _HttpUrl;
                retMsg = _messageSinks[1].SyncProcessMessage(msg);
                if (retMsg is IMethodReturnMessage)
                {
                    IMethodReturnMessage mrm = (IMethodReturnMessage)retMsg;
                }
                return retMsg;
            }
        }
示例#18
0
        /*
         * This is the main function in the lazy proxy.  Any time a method or property is called
         * within a proxied class this will get called.  The first stage is to check for the 
         * CompleteLazyLoadPriorToCall attribute, if it is there and
         * the load status is only partial and that we are not calling functions to set field
         * values, ie already loading, then establish a select using the 
         * primary keys as parameters to the query, execute it and 
         * load the values into the current table object.  Following this we then check to
         * see if the object is null, if it is simply call the function and return the results.
         * If its not null then attempt to pull the property info, if it is a property and it
         * is a get call, then checks are performed for the object being a lazy loaded object,
         * or the table being lazy loaded and the call not being for a primary key,
         * or it being an array of lazy loaded object, in all cases, complete their
         * loading and set the value of the object, then return the value.  If it is a set call
         * then we need to log if the field has now become set to a null value, or
         * if it has changed at all, in either case mark it for use when update is called
         * on the object.
         * 
         */
		public override IMessage Invoke(System.Runtime.Remoting.Messaging.IMessage msg)
		{
			MethodCallMessageWrapper mc = new MethodCallMessageWrapper((IMethodCallMessage)msg);
			MarshalByRefObject owner = GetUnwrappedServer();
			MethodInfo mi = (MethodInfo)mc.MethodBase;
			
			object outVal=null;
            List<string> fieldsAffected = null;

            foreach (object obj in mi.GetCustomAttributes(true))
            {
                if (obj is CompleteLazyLoadPriorToCall)
                {
                    if ((((Table)owner).LoadStatus == LoadStatus.Partial) && !((mi.Name == "SetField") || (mi.Name == "SetValues")))
                    {
                        List<SelectParameter> pars = new List<SelectParameter>();
                        foreach (string prop in _map.PrimaryKeyProperties)
                            pars.Add(new EqualParameter(prop, ((Table)owner).GetField(prop)));
                        Connection conn = ConnectionPoolManager.GetConnection(owner.GetType());
                        Table tmp = null;
                        try
                        {
                            tmp = conn.Select(owner.GetType(), pars)[0];
                        }
                        catch (Exception e)
                        {
                            Logger.LogLine(e);
                        }
                        conn.CloseConnection();
                        if (tmp == null)
                            throw new Exception("Unable to Load Lazy Porxy Instance of table");
                        List<string> pkeys = new List<string>(_map.PrimaryKeyProperties);
                        foreach (string prop in _map.Properties)
                        {
                            if ((!pkeys.Contains(prop)) && (!tmp.IsFieldNull(prop)))
                                ((Table)owner).SetField(prop, tmp.GetField(prop));
                        }
                        ((Table)owner).LoadStatus = LoadStatus.Complete;
                    }
                }
                else if (obj is MethodInvokeChangesField)
                {
                    if (fieldsAffected == null)
                        fieldsAffected = new List<string>();
                    fieldsAffected.AddRange(((MethodInvokeChangesField)obj).FieldAffected);
                }
            }
			
			if (owner!=null)
			{
				bool isGet=false;
				PropertyInfo pi = GetMethodProperty(mi,owner, out isGet,owner.GetType(),_pool);
                if (pi != null)
                {
                    foreach (object obj in pi.GetCustomAttributes(true))
                    {
                        if (obj is CompleteLazyLoadPriorToCall)
                        {
                            if ((((Table)owner).LoadStatus == LoadStatus.Partial) && !((mi.Name == "SetField") || (mi.Name == "SetValues")))
                            {
                                CompleteLazyLoad(owner);
                            }
                        }
                        else if (obj is PropertySetChangesField)
                        {
                            if (fieldsAffected == null)
                                fieldsAffected = new List<string>();
                            fieldsAffected.AddRange(((PropertySetChangesField)obj).FieldAffected);
                        }
                    }
                }

				if ((pi!=null)&&(_IsParentTableField(pi.Name,owner)||new List<string>(_map.ArrayProperties).Contains(pi.Name)))
				{
					if (pi.Name!="LoadStatus")
					{
						if ((((Table)owner).LoadStatus== LoadStatus.Partial)&&(!new List<string>(_map.PrimaryKeyProperties).Contains(pi.Name)))
						{
                            CompleteLazyLoad(owner);
						}
					}
					if (isGet)
					{
						outVal = mi.Invoke(owner, mc.Args);
					}else
					{
                        sTable map = ConnectionPoolManager.GetPool(owner.GetType()).Mapping[owner.GetType()];
						if (((Table)owner).IsSaved&&new List<string>(map.PrimaryKeyProperties).Contains(pi.Name)&&Utility.StringsEqual(pi.Name,map.AutoGenProperty))
							throw new AlterPrimaryKeyException(owner.GetType().ToString(),pi.Name);
						if (((Table)owner).IsSaved)
						{
							object curVal = pi.GetValue(owner,new object[0]);
                            if (map.ArrayProperties.Contains(pi.Name))
                            {
                                if (!_originalArrayLengths.ContainsKey(pi.Name))
                                    _originalArrayLengths.Add(pi.Name,(curVal==null ? 0 : ((Array)curVal).Length));
                                if (curVal != null && mc.Args[0] != null)
                                {
                                    List<int> indexes = new List<int>();
                                    if (_replacedArrayIndexes.ContainsKey(pi.Name))
                                    {
                                        indexes = _replacedArrayIndexes[pi.Name];
                                        _replacedArrayIndexes.Remove(pi.Name);
                                    }
                                    Array arCur = (Array)curVal;
                                    Array arNew = (Array)mc.Args[0];
                                    for (int x = 0; x < _originalArrayLengths[pi.Name]; x++)
                                    {
                                        if (!indexes.Contains(x) && x<arNew.Length)
                                        {
                                            if (arCur.GetValue(x) is Table)
                                            {
                                                if (!((Table)arNew.GetValue(x)).IsSaved)
                                                    indexes.Add(x);
                                                if (((Table)arNew.GetValue(x)).ChangedFields.Count > 0)
                                                    indexes.Add(x);
                                                else if (!((Table)arCur.GetValue(x)).PrimaryKeysEqual((Table)arNew.GetValue(x)))
                                                    indexes.Add(x);
                                            }
                                            else if (!arCur.GetValue(x).Equals(arNew.GetValue(x)))
                                                indexes.Add(x);
                                        }
                                    }
                                    for (int x = arCur.Length; x < arNew.Length; x++)
                                        indexes.Add(x);
                                    if (indexes.Count > 0 && !_changedFields.Contains(pi.Name))
                                        _changedFields.Add(pi.Name);
                                    else if (arNew.Length!=arCur.Length && !_changedFields.Contains(pi.Name))
                                        _changedFields.Add(pi.Name);
                                    _replacedArrayIndexes.Add(pi.Name, indexes);
                                }
                                else if (!_changedFields.Contains(pi.Name))
                                    _changedFields.Add(pi.Name);
                            }else if (((curVal==null)&&(mc.Args[0]!=null))||
							    ((curVal!=null)&&(mc.Args[0]==null))||
							    ((curVal!=null)&&(mc.Args[0]!=null)&&(!curVal.Equals(mc.Args[0]))))
							{
								if (!_changedFields.Contains(pi.Name))
									_changedFields.Add(pi.Name);
							}
						}
                        foreach (object obj in pi.GetCustomAttributes(true))
                        {
                            if (obj is ValidationAttribute)
                            {
                                ValidationAttribute va = (ValidationAttribute)obj;
                                if (!va.IsValidValue(mc.Args[0]))
                                    va.FailValidation(owner.GetType().ToString(), pi.Name);
                            }
                        }
						outVal = mi.Invoke(owner, mc.Args);
					}
				}else
				{
                    if (mi.Name == "Update")
                        ((Table)owner)._changedFields = _changedFields;
                    if ((pi != null) && (pi.Name == "IsProxied"))
                        outVal = true;
                    if ((pi != null) && (pi.Name == "ChangedFields"))
                        outVal = _changedFields;
                    else if (((pi != null) && (pi.Name == "OriginalArrayLengths")) || mi.Name == "get_OriginalArrayLengths")
                        outVal = _originalArrayLengths;
                    else if (((pi != null) && (pi.Name == "ReplacedArrayIndexes")) || mi.Name == "get_ReplacedArrayIndexes")
                        outVal = _replacedArrayIndexes;
                    else if (mi.Name == "get_ChangedFields")
                        outVal = _changedFields;
                    else if (mi.Name == "GetType")
                        outVal = owner.GetType();
                    else if ((mi.Name == "FieldSetter") && (mc.Args.Length == 3) && (mc.Args[1].ToString().Trim() == "_isSaved"))
                        ((Table)owner)._isSaved = (bool)mc.Args[2];
                    else if ((mi.Name == "FieldGetter") && (mc.Args.Length == 2) && (mc.Args[1].ToString().Trim() == "_isSaved"))
                        outVal = ((Table)owner).IsSaved;
                    else if ((mi.Name == "FieldSetter") && (mc.Args.Length == 3) && (mc.Args[1].ToString().Trim() == "_changedFields"))
                        ((Table)owner)._changedFields = (List<string>)mc.Args[2];
                    else if ((pi != null) && (!isGet) && (fieldsAffected != null) && ((Table)owner)._isSaved)
                    {
                        object curVal = pi.GetValue(owner, new object[0]);
                        if (((curVal == null) && (mc.Args[0] != null)) ||
                            ((curVal != null) && (mc.Args[0] == null)) ||
                            ((curVal != null) && (mc.Args[0] != null) && (!curVal.Equals(mc.Args[0]))))
                        {
                            foreach (string str in fieldsAffected)
                            {
                                if (!_changedFields.Contains(str))
                                    _changedFields.Add(str);
                            }
                        }
                        outVal = mi.Invoke(owner, mc.Args);
                    }
                    else
                    {
                        try
                        {
                            outVal = mi.Invoke(owner, mc.Args);
                            if (fieldsAffected != null)
                            {
                                foreach (string str in fieldsAffected)
                                {
                                    if (!_changedFields.Contains(str))
                                        _changedFields.Add(str);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            Logger.LogLine("Method Call: " + mc.MethodName);
                            Logger.LogLine(ex.Message);
                            Logger.LogLine(ex.Source);
                            Logger.LogLine(ex.StackTrace);
                            Exception e = ex.InnerException;
                            while (e != null)
                            {
                                Logger.LogLine(e.Message);
                                Logger.LogLine(e.Source);
                                Logger.LogLine(e.StackTrace);
                                e = e.InnerException;
                            }
                            throw ex;
                        }
                    }
				}
			}

            if (mi.Name == "Update")
            {
                _changedFields = new List<string>();
                ((Table)owner)._changedFields = null;
            }

			return new ReturnMessage(outVal,mc.Args,mc.Args.Length, mc.LogicalCallContext, mc);
		}
示例#19
0
 public override IMessage Process(MethodCallMessageWrapper mc)
 {
     return new ReturnMessage(returnValue, null, 0, mc.LogicalCallContext, mc);
 }
        public override IMessage Invoke(IMessage message)
        {
            IMethodCallMessage methodMessage = new MethodCallMessageWrapper((IMethodCallMessage)message);

            // Obtain the actual method definition that is being called.
            MethodBase methodBase = methodMessage.MethodBase;
            Object[] args = methodMessage.Args;

            Object result = null;

            int tries = 0;

            if (this.ring == null)
                CheckRing();

            while ((result == null) && (tries++ < maxAttempts))
            {
                if (this.client == null)
                    this.breaker.Failure();

                try
                {
                    if (this.breaker.Allow())
                    {
                        result = methodBase.Invoke(this.client, args);

                        if ((methodBase.Name.ToLower().Equals("set_keyspace")) && (args.Length == 1))
                            this.ringKs = args[0].ToString();

                        this.breaker.Success();

                        return new ReturnMessage(result, methodMessage.Args, methodMessage.ArgCount, methodMessage.LogicalCallContext, methodMessage);
                    }

                    while (!this.breaker.Allow())
                    {
                        Thread.Sleep(1050);
                    }
                    AttemptReconnect();

                    if (this.client != null)
                        tries--;
                }
                catch (TargetInvocationException e)
                {
                    Type exceptionType = e.GetType();
                    if (exceptionType == typeof(UnavailableException) || exceptionType == typeof(TimedOutException) || exceptionType == typeof(TTransportException))
                    {
                        this.breaker.Failure();

                        if (tries >= maxAttempts)
                            throw e;
                    }
                }
                catch (Exception exception)
                {
                    throw exception;
                }
            }

            throw new UnavailableException();
        }