Ejemplo n.º 1
0
        static AmqpMap GetRuleActionMap(SqlRuleAction sqlRuleAction)
        {
            AmqpMap ruleActionMap = null;

            if (sqlRuleAction != null)
            {
                ruleActionMap = new AmqpMap {
                    [ManagementConstants.Properties.Expression] = sqlRuleAction.SqlExpression
                };
            }

            return(ruleActionMap);
        }
        public void CanCreateRulePropertiesFromFactory()
        {
            var filter     = new SqlRuleFilter("PROPERTY(@propertyName) = @stringPropertyValue");
            var action     = new SqlRuleAction("SET a='b'");
            var properties = ServiceBusModelFactory.RuleProperties(
                "ruleName",
                filter,
                action);

            Assert.AreEqual("ruleName", properties.Name);
            Assert.AreEqual(filter, properties.Filter);
            Assert.AreEqual(action, properties.Action);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates the action which xml definition is contained in the element parameter.
        /// </summary>
        /// <param name="serviceBusHelper">A ServiceBusHelper object.</param>
        /// <param name="action">The XElement containing the action definition.</param>
        /// <returns>The action.</returns>
        private static RuleAction CreateAction(ServiceBusHelper serviceBusHelper, XElement action)
        {
            if (action == null)
            {
                return(null);
            }
            string fullName = null;

            if (action.Name == string.Format(NodeNameFormat, Namespace, SqlRuleActionEntity))
            {
                fullName = typeof(SqlRuleAction).FullName;
            }
            if (string.IsNullOrEmpty(fullName) ||
                !propertyCache.ContainsKey(fullName))
            {
                return(null);
            }
            var propertyDictionary = propertyCache[fullName];
            var propertyValue      = new Dictionary <string, object>();
            var properties         = action.Elements();

            foreach (var property in properties)
            {
                var xmlReader = property.CreateReader();
                GetPropertyValue(propertyDictionary,
                                 propertyValue,
                                 xmlReader);
            }
            RuleAction ruleAction = null;

            if (action.Name == string.Format(NodeNameFormat, Namespace, SqlRuleActionEntity) &&
                propertyValue.ContainsKey(SqlExpression))
            {
                ruleAction = new SqlRuleAction(propertyValue[SqlExpression] as string);
            }
            if (ruleAction != null)
            {
                SetPropertyValue(propertyDictionary,
                                 propertyValue,
                                 ruleAction);
            }
            return(ruleAction);
        }
Ejemplo n.º 4
0
        static RuleAction GetRuleAction(AmqpRuleActionCodec amqpAction)
        {
            RuleAction action;

            if (amqpAction.DescriptorCode == AmqpEmptyRuleActionCodec.Code)
            {
                action = null;
            }
            else if (amqpAction.DescriptorCode == AmqpSqlRuleActionCodec.Code)
            {
                var amqpSqlAction = (AmqpSqlRuleActionCodec)amqpAction;
                var sqlAction     = new SqlRuleAction(amqpSqlAction.SqlExpression);

                action = sqlAction;
            }
            else
            {
                throw new NotSupportedException($"Unknown action descriptor code: {amqpAction.DescriptorCode}");
            }

            return(action);
        }
Ejemplo n.º 5
0
        private static AmqpRuleAction GetRuleAction(RuleAction ruleAction)
        {
            AmqpRuleAction amqpEmptyRuleAction = null;

            if (ruleAction == null || ruleAction is EmptyRuleAction)
            {
                amqpEmptyRuleAction = new AmqpEmptyRuleAction();
            }
            else
            {
                if (!(ruleAction is SqlRuleAction))
                {
                    throw new NotSupportedException();
                }
                AmqpSqlRuleAction amqpSqlRuleAction = new AmqpSqlRuleAction();
                SqlRuleAction     sqlRuleAction     = (SqlRuleAction)ruleAction;
                amqpSqlRuleAction.SqlExpression      = sqlRuleAction.SqlExpression;
                amqpSqlRuleAction.CompatibilityLevel = new int?(sqlRuleAction.CompatibilityLevel);
                amqpEmptyRuleAction = amqpSqlRuleAction;
            }
            return(amqpEmptyRuleAction);
        }