public override IMessage Invoke(IMessage msg) { var _msg = msg as IMethodCallMessage; try { var _args = _msg.Args; TwainCommand _command; var _result = this._aux.Execute(_command = new MethodTwainCommand { Member = _msg.MethodBase, Parameters = _args }); for (Exception _ex = _result as Exception, _ex2 = _result as TargetInvocationException; _ex != null;) { return(new ReturnMessage(_ex2 != null?_ex2.InnerException:_ex, _msg)); } return(new ReturnMessage(_result, _args, 0, _msg.LogicalCallContext, _msg)); } catch (Exception ex) { return(new ReturnMessage(ex, _msg)); } }
public override IMessage Invoke(IMessage msg) { var _msg = msg as IMethodCallMessage; try { var _args = _msg.Args; #region SpecialName if (_msg.MethodBase.IsSpecialName) { var _name = _msg.MethodBase.Name.Split(new string[] { "_" }, 2, StringSplitOptions.None); switch (_name[0]) { case "get": switch (_name[1]) { case "Capabilities": return(new ReturnMessage(this.Capabilities, _args, 0, _msg.LogicalCallContext, _msg)); case "Palette": return(new ReturnMessage(this.Palette, _args, 0, _msg.LogicalCallContext, _msg)); } break; case "add": switch (_name[1]) { case Twain32Events.AcquireCompleted: this.AcquireCompleted += _args[0] as EventHandler; break; case Twain32Events.AcquireError: this.AcquireError += _args[0] as EventHandler <Twain32.AcquireErrorEventArgs>; break; case Twain32Events.XferDone: this.XferDone += _args[0] as EventHandler <Twain32.XferDoneEventArgs>; break; case Twain32Events.EndXfer: this.EndXfer += _args[0] as EventHandler <Twain32.EndXferEventArgs>; break; case Twain32Events.SetupMemXferEvent: this.SetupMemXferEvent += _args[0] as EventHandler <Twain32.SetupMemXferEventArgs>; break; case Twain32Events.MemXferEvent: this.MemXferEvent += _args[0] as EventHandler <Twain32.MemXferEventArgs>; break; case Twain32Events.SetupFileXferEvent: this.SetupFileXferEvent += _args[0] as EventHandler <Twain32.SetupFileXferEventArgs>; break; case Twain32Events.FileXferEvent: this.FileXferEvent += _args[0] as EventHandler <Twain32.FileXferEventArgs>; break; case Twain32Events.TwainStateChanged: this.TwainStateChanged += _args[0] as EventHandler <Twain32.TwainStateEventArgs>; break; default: return(new ReturnMessage(new NotImplementedException(), _msg)); } return(new ReturnMessage(null, _args, 0, _msg.LogicalCallContext, _msg)); case "remove": switch (_name[1]) { case Twain32Events.AcquireCompleted: this.AcquireCompleted -= _args[0] as EventHandler; break; case Twain32Events.AcquireError: this.AcquireError -= _args[0] as EventHandler <Twain32.AcquireErrorEventArgs>; break; case Twain32Events.XferDone: this.XferDone -= _args[0] as EventHandler <Twain32.XferDoneEventArgs>; break; case Twain32Events.EndXfer: this.EndXfer -= _args[0] as EventHandler <Twain32.EndXferEventArgs>; break; case Twain32Events.SetupMemXferEvent: this.SetupMemXferEvent -= _args[0] as EventHandler <Twain32.SetupMemXferEventArgs>; break; case Twain32Events.MemXferEvent: this.MemXferEvent -= _args[0] as EventHandler <Twain32.MemXferEventArgs>; break; case Twain32Events.SetupFileXferEvent: this.SetupFileXferEvent -= _args[0] as EventHandler <Twain32.SetupFileXferEventArgs>; break; case Twain32Events.FileXferEvent: this.FileXferEvent -= _args[0] as EventHandler <Twain32.FileXferEventArgs>; break; case Twain32Events.TwainStateChanged: this.TwainStateChanged -= _args[0] as EventHandler <Twain32.TwainStateEventArgs>; break; default: return(new ReturnMessage(new NotImplementedException(), _msg)); } return(new ReturnMessage(null, _args, 0, _msg.LogicalCallContext, _msg)); } } #endregion TwainCommand _command; var _result = this._aux.Execute(_command = new MethodTwainCommand { Member = _msg.MethodBase, Parameters = _args }); for (Exception _ex = _result as Exception, _ex2 = _result as TargetInvocationException; _ex != null;) { return(new ReturnMessage(_ex2 != null?_ex2.InnerException:_ex, _msg)); } return(new ReturnMessage(_result, _args, 0, _msg.LogicalCallContext, _msg)); } catch (Exception ex) { return(new ReturnMessage(ex, _msg)); } }