Ejemplo n.º 1
0
 private void MergeInto(CallbackSemantics semantics, CallbackOptions option)
 {
     if (IsSpecified(option) && !semantics.IsSpecified(option))
     {
         semantics.SetOption(option, HasOption(option));
     }
 }
Ejemplo n.º 2
0
 public void MergeInto(CallbackSemantics semantics)
 {
     MergeInto(semantics, CallbackOptions.Duck);
     MergeInto(semantics, CallbackOptions.Strict);
     MergeInto(semantics, CallbackOptions.Resolve);
     MergeInto(semantics, CallbackOptions.BestEffot);
     MergeInto(semantics, CallbackOptions.Broadcast);
 }
Ejemplo n.º 3
0
 public HandleMethod(Type protocol, IMethodMessage methodCall,
                     CallbackSemantics semantics = null)
 {
     _semantics = semantics;
     Method     = (MethodInfo)methodCall.MethodBase;
     Arguments  = methodCall.Args;
     Protocol   = protocol ?? Method.ReflectedType;
     ResultType = Method.ReturnType == typeof(void) ? null
                : Method.ReturnType;
 }
Ejemplo n.º 4
0
        object IProtocolAdapter.Dispatch(Type protocol, IMethodCallMessage message)
        {
            IHandler handler = this;

            protocol = protocol ?? message.MethodBase.ReflectedType;

            var options   = CallbackOptions.None;
            var semantics = new CallbackSemantics();

            handler.Handle(semantics, true);

            if (!semantics.IsSpecified(CallbackOptions.Duck) &&
                typeof(IDuck).IsAssignableFrom(protocol))
            {
                options |= CallbackOptions.Duck;
            }

            if (!semantics.IsSpecified(CallbackOptions.Strict) &&
                typeof(IStrict).IsAssignableFrom(protocol))
            {
                options |= CallbackOptions.Strict;
            }

            if (!semantics.IsSpecified(CallbackOptions.Resolve) &&
                typeof(IResolving).IsAssignableFrom(protocol))
            {
                options |= CallbackOptions.Resolve;
            }

            if (options != CallbackOptions.None)
            {
                semantics.SetOption(options, true);
                handler = this.Semantics(options);
            }

            var broadcast    = semantics.HasOption(CallbackOptions.Broadcast);
            var handleMethod = new HandleMethod(protocol, message, semantics);
            var callback     = semantics.HasOption(CallbackOptions.Resolve)
                             ? new ResolveMethod(protocol, broadcast, handleMethod)
                             : (object)handleMethod;

            var handled = handler.Handle(callback, broadcast);

            if (!(handled || semantics.HasOption(CallbackOptions.BestEffot)))
            {
                throw new MissingMethodException(
                          $"Method '{message.MethodName}' on {message.TypeName} not handled");
            }

            var result = handleMethod.Result;

            return(handled || result != null ? result
                 : RuntimeHelper.GetDefault(handleMethod.ResultType));
        }
Ejemplo n.º 5
0
        protected override bool HandleCallback(
            object callback, bool greedy, IHandler composer)
        {
            var handled = false;

            if (Composition.IsComposed <CallbackSemantics>(callback))
            {
                return(false);
            }

            var semantics = callback as CallbackSemantics;

            if (semantics != null)
            {
                _semantics.MergeInto(semantics);
                handled = true;
            }
            else if (!greedy)
            {
                if (_semantics.IsSpecified(CallbackOptions.Broadcast))
                {
                    greedy = _semantics.HasOption(CallbackOptions.Broadcast);
                }
                else
                {
                    var cs = new CallbackSemantics();
                    if (Handle(cs, true) && cs.IsSpecified(CallbackOptions.Broadcast))
                    {
                        greedy = cs.HasOption(CallbackOptions.Broadcast);
                    }
                }
            }

            if (greedy || !handled)
            {
                handled = base.HandleCallback(callback, greedy, composer) || handled;
            }

            return(handled);
        }
Ejemplo n.º 6
0
 public SemanticsHandler(
     IHandler handler, CallbackOptions options)
     : base(handler)
 {
     _semantics = new CallbackSemantics(options);
 }