コード例 #1
0
        public void TestNew()
        {
            DeliveryRule dr = new DeliveryRule();

            Assert.IsNotNull(dr.TargetEndpoints);
            Assert.IsNotNull(dr.ValidationFailures);
        }
コード例 #2
0
        public IActionResult AddRule(DeliveryRule dr)
        {
            dr.Initialize();

            Router.Instance.DeliveryRules.Add(dr);

            return(new JsonResult(""));
        }
コード例 #3
0
 public static PSDeliveryRule ToPsDeliveryRule(this DeliveryRule deliveryRule)
 {
     return(new PSDeliveryRule
     {
         Order = deliveryRule.Order,
         Actions = deliveryRule.Actions.Select(action => action.ToPsDeliveryRuleAction()).ToList(),
         Conditions = deliveryRule.Conditions.Select(condition => condition.ToPsDeliveryRuleCondition()).ToList()
     });
 }
コード例 #4
0
        public IActionResult removeRule(DeliveryRule dr)
        {
            Router.Instance.DeliveryRules.Remove(Router.Instance.DeliveryRules.Find((rule) =>
            {
                return(dr.Name == rule.Name);
            }));

            return(new JsonResult(""));
        }
コード例 #5
0
        public void TestInitalizationFailureRequiredFields()
        {
            DeliveryRule dr = new DeliveryRule();

            Assert.Throws <Exception>(() => {
                dr.Initialize();
            });

            Assert.AreEqual(3, dr.ValidationFailures.Count);
        }
コード例 #6
0
        public void TestValidationSuccess()
        {
            DeliveryRule dr = new DeliveryRule();

            //the required field for the object.
            dr.Name = "my-delivery-test";
            dr.TargetEndpoints.Add(new Uri("http://test.dev.42n.co"));
            dr.TypeExpression = "/sample-delivery-rule/g";

            Assert.IsTrue(dr.IsValid);
        }
コード例 #7
0
ファイル: Router.cs プロジェクト: 42north/constellation
        public static bool Deliver(Message msg, bool wait)
        {
            DeliveryRule dr = Router.IsMatch(msg);

            if (dr == null)
            {
                return(false);
            }

            return(DeliveryManager.Deliver(msg, dr, wait).Result);
        }
コード例 #8
0
ファイル: Router.cs プロジェクト: 42north/constellation
        //Handles inspection of the Rules
        public static DeliveryRule IsMatch(Message msg)
        {
            DeliveryRule rule = Router.Instance.rules.Find((r) =>
            {
                return(r.IsMatch(msg));
            });

            if (rule != null && !rule.Enabled)
            {
                rule = null;
            }

            return(rule);
        }
コード例 #9
0
        public void TestRuleMatch()
        {
            string rules = File.ReadAllText("tests/sample-data/valid-delivery-rules.json");

            Router.LoadRules(rules);

            Message m = new Message();

            m.Type = "valid-test-1";

            DeliveryRule dr = Router.IsMatch(m);

            Assert.IsNotNull(dr);
            Assert.AreEqual("valid-test-delivery-1", dr.Name);
        }
コード例 #10
0
        public void TestInitalizationFailureRulesExpressionError()
        {
            DeliveryRule dr = new DeliveryRule();

            //the required field for the object.
            dr.Name = "my-name";
            dr.TargetEndpoints.Add(new Uri("http://test.dev.42n.co"));
            dr.TypeExpression = @"\b[a\t]\w+\\\";

            Assert.Throws <Exception>(() => {
                dr.Initialize();
            });

            Assert.AreEqual(1, dr.ValidationFailures.Count);
        }
コード例 #11
0
        public void TestMessageMatchSuccess()
        {
            DeliveryRule dr = new DeliveryRule();

            Message m = new Message();

            m.Type    = "my-name-2";
            m.Payload = new ExpandoObject();

            //the required field for the object.
            dr.Name = "my-rule";
            dr.TargetEndpoints.Add(new Uri("http://test.dev.42n.co"));
            dr.TypeExpression = @"^my-name-2";
            dr.Initialize();

            bool result = dr.IsMatch(m);

            Assert.IsTrue(result);
        }
コード例 #12
0
ファイル: Router.cs プロジェクト: 42north/constellation
        public static async Task <dynamic> DeliverAsync(Message msg)
        {
            DeliveryRule dr = Router.IsMatch(msg);

            try
            {
                await Router.Instance.deliverySemaphore.WaitAsync().ConfigureAwait(false);

                return(DeliveryManager.DeliverAsync(msg, dr).ContinueWith((result) =>
                {
                    Router.Instance.deliverySemaphore.Release();
                }).ConfigureAwait(false));
            }
            catch (Exception ex)
            {
                Router.Instance.deliverySemaphore.Release();
                throw ex;
            }
        }