Пример #1
0
            public ISubscriptionHandler Resolve(HandlerObject handlerObject)
            {
                if (string.IsNullOrEmpty(handlerObject.MaestroAction))
                {
                    Trace.TraceError("All Subscription Handler objects must contain a 'maestroAction' property.");
                    return(null);
                }

                JObject action = _subscriptionsModel.Actions.GetAction(handlerObject.MaestroAction);

                if (action == null)
                {
                    Trace.TraceError($"Could not find a valid action with name '{handlerObject.MaestroAction}'.");
                    return(null);
                }

                if (action.Property("vsoInstance") != null)
                {
                    // It's a VSO build definition
                    return(new VsoBuildHandler()
                    {
                        Delay = handlerObject.MaestroDelay,
                        VsoInstance = action["vsoInstance"].ToString(),
                        VsoProject = action["vsoProject"].ToString(),
                        BuildDefinitionId = action["buildDefinitionId"].Value <int>(),
                        VsoParameters = VsoParameterGenerator.GetParameters(handlerObject.Parameters)
                    });
                }

                Trace.TraceError($"Could not resolve a Handler for Subscription '{JsonConvert.ToString(handlerObject)}'.");
                return(null);
            }
 protected override object InvokeListenerMethod(string methodName, object[] arguments)
 {
     try
     {
         MethodInfo mi = MethodNode.GetBestMethod(HandlerObject.GetType(), methodName, BINDING_FLAGS, arguments);
         if (mi == null)
         {
             throw new ListenerExecutionFailedException("Failed to invoke the target method '" + methodName +
                                                        "' with arguments " +
                                                        StringUtils.CollectionToCommaDelimitedString(arguments));
         }
         try
         {
             return(mi.Invoke(HandlerObject, arguments));
         } catch (Exception e)
         {
             throw new ListenerExecutionFailedException("Listener method '" + methodName + "' threw exception.", e);
         }
     } catch (Exception e)
     {
         throw new ListenerExecutionFailedException("Failed to invoke the target method '" + methodName +
                                                    "' with arguments " +
                                                    StringUtils.CollectionToCommaDelimitedString(arguments), e);
     }
 }
Пример #3
0
    static void Main(string[] args)
    {
        StrClass class1 = new StrClass();
        StrClass class2 = new StrClass();
        StrClass class3 = new StrClass();

        HandlerObject handler = new HandlerObject();

        class1.PropertyChanged += (s, e) => { handler.HandlerMethod1(s.ToString()); };
        class2.PropertyChanged += (s, e) => { handler.HandlerMethod2(s.ToString()); };
        class3.PropertyChanged += (s, e) => { HandlerMethod3(s.ToString()); };
    }
        public void TestAutoSubscription()
        {
            var testHub = new MessagesHub();

            var instance = new HandlerObject();

            var subscriptions = MessagesUtils.AutoSubscribe(instance, testHub);

            using (Disposable.FromAction(() =>
            {
                foreach (var s in subscriptions)
                {
                    s.Subscription.Dispose();
                }
            }))
            {
                string str1  = "value1";
                string str2  = "value2";
                int    ival1 = 77;

                Assert.AreEqual(instance.StrValue, string.Empty);
                Assert.AreEqual(instance.IntValue, 0);

                NotificationMessage1.Broadcast(str1, testHub);

                Assert.AreEqual(instance.StrValue, str1);

                NotificationMessage2.Broadcast(str2, ival1, testHub);

                Assert.AreEqual(instance.StrValue, str2);
                Assert.AreEqual(instance.IntValue, ival1);
            }

            Assert.Throws <Exception>(() =>
            {    // all subscriptions must gone after using (...) block
                NotificationMessage1.Broadcast(string.Empty, testHub);
            });
        }