/// <summary> /// Fires the Error event. /// </summary> /// <param name="e">Event arguments</param> protected internal void OnError(ZyanErrorEventArgs e) { if (Error != null) { Error(this, e); } }
/// <summary> /// Intercepts the method that is specified in the provided IMessage and/or invokes it on the remote object. /// </summary> /// <remarks>This method is called by <see cref="CallInterceptionData"/>.MakeRemoteCall() method.</remarks> /// <param name="methodCallMessage">Remoting <see cref="IMethodCallMessage"/> that contains information about the method call.</param> /// <param name="allowInterception">Specifies whether call interception is allowed.</param> /// <returns>The message returned by the invoked method, containing the return value and any out or ref parameters.</returns> private IMessage InterceptAndInvoke(IMethodCallMessage methodCallMessage, bool allowInterception) { try { var methodInfo = (MethodInfo)methodCallMessage.MethodBase; return (HandleCallInterception(methodCallMessage, allowInterception) ?? HandleLocalInvocation(methodCallMessage, methodInfo) ?? HandleEventSubscription(methodCallMessage, methodInfo) ?? HandleEventUnsubscription(methodCallMessage, methodInfo) ?? HandleLinqQuery(methodCallMessage, methodInfo) ?? HandleRemoteInvocation(methodCallMessage, methodInfo)); } catch (Exception ex) { if (_connection.ErrorHandlingEnabled) { ZyanErrorEventArgs e = new ZyanErrorEventArgs() { Exception = ex, RemotingMessage = methodCallMessage, ServerComponentType = _interfaceType, RemoteMemberName = methodCallMessage.MethodName }; _connection.OnError(e); switch (e.Action) { case ZyanErrorAction.ThrowException: throw; case ZyanErrorAction.Retry: return(Invoke(methodCallMessage)); case ZyanErrorAction.Ignore: return(new ReturnMessage(null, null, 0, methodCallMessage.LogicalCallContext, methodCallMessage)); } } throw; } }
static void Connection_Error(object sender, ZyanErrorEventArgs e) { if (e.Exception is SocketException || e.Exception is InvalidSessionException || e.Exception is RemotingException) { int retryCount = 0; bool problemSolved = false; while (!problemSolved && retryCount < 10) { Thread.Sleep(5000); problemSolved = Connection.Reconnect(); retryCount++; } if (problemSolved) e.Action = ZyanErrorAction.Retry; else e.Action = ZyanErrorAction.ThrowException; } else e.Action = ZyanErrorAction.ThrowException; }
static void ConnectionErrorHandler(object sender, ZyanErrorEventArgs args) { var exception = args.Exception.InnerException ?? args.Exception; Console.WriteLine("Exception caught: {0}", exception.Message); Console.WriteLine("Retry (default)? Ignore? Throw exception?"); var c = char.ToUpperInvariant(Console.ReadKey(true).KeyChar); switch (c) { case 'I': args.Action = ZyanErrorAction.Ignore; break; case 'T': args.Action = ZyanErrorAction.ThrowException; break; default: args.Action = ZyanErrorAction.Retry; break; } }
/// <summary> /// Intercepts the method that is specified in the provided IMessage and/or invokes it on the remote object. /// </summary> /// <remarks>This method is called by <see cref="CallInterceptionData"/>.MakeRemoteCall() method.</remarks> /// <param name="methodCallMessage">Remoting <see cref="IMethodCallMessage"/> that contains information about the method call.</param> /// <param name="allowInterception">Specifies whether call interception is allowed.</param> /// <returns>The message returned by the invoked method, containing the return value and any out or ref parameters.</returns> private IMessage InterceptAndInvoke(IMethodCallMessage methodCallMessage, bool allowInterception) { try { var methodInfo = (MethodInfo)methodCallMessage.MethodBase; return HandleCallInterception(methodCallMessage, allowInterception) ?? HandleLocalInvocation(methodCallMessage, methodInfo) ?? HandleEventSubscription(methodCallMessage, methodInfo) ?? HandleEventUnsubscription(methodCallMessage, methodInfo) ?? HandleLinqQuery(methodCallMessage, methodInfo) ?? HandleRemoteInvocation(methodCallMessage, methodInfo); } catch (Exception ex) { if (_connection.ErrorHandlingEnabled) { ZyanErrorEventArgs e = new ZyanErrorEventArgs() { Exception = ex, RemotingMessage = methodCallMessage, ServerComponentType = _interfaceType, RemoteMemberName = methodCallMessage.MethodName }; _connection.OnError(e); switch (e.Action) { case ZyanErrorAction.ThrowException: throw; case ZyanErrorAction.Retry: return Invoke(methodCallMessage); case ZyanErrorAction.Ignore: return new ReturnMessage(null, null, 0, methodCallMessage.LogicalCallContext, methodCallMessage); } } throw; } }
/// <summary> /// Fires the Error event. /// </summary> /// <param name="e">Event arguments</param> protected internal void OnError(ZyanErrorEventArgs e) { Error?.Invoke(this, e); }