示例#1
0
        public static Filter ParseFromXElement(XElement xElement)
        {
            var expression = xElement.Element(XName.Get("SqlExpression", ManagementClientConstants.SbNs))?.Value;

            if (string.IsNullOrWhiteSpace(expression))
            {
                return(null);
            }

            var filter = new SqlFilter(expression);

            var parameters = xElement.Element(XName.Get("Parameters", ManagementClientConstants.SbNs));

            if (parameters != null && parameters.HasElements)
            {
                foreach (var param in parameters.Elements(XName.Get("KeyValueOfstringanyType", ManagementClientConstants.SbNs)))
                {
                    var key   = param.Element(XName.Get("Key", ManagementClientConstants.SbNs))?.Value;
                    var value = XmlObjectConvertor.ParseValueObject(param.Element(XName.Get("Value", ManagementClientConstants.SbNs)));
                    filter.Parameters.Add(key, value);
                }
            }

            return(filter);
        }
示例#2
0
        public static XElement Serialize(this RuleAction action)
        {
            if (action is SqlRuleAction sqlRuleAction)
            {
                XElement parameterElement = null;
                if (sqlRuleAction.parameters != null)
                {
                    parameterElement = new XElement(XName.Get("Parameters", ManagementClientConstants.SbNs));
                    foreach (var param in sqlRuleAction.Parameters)
                    {
                        parameterElement.Add(
                            new XElement(XName.Get("KeyValueOfstringanyType", ManagementClientConstants.SbNs),
                                         new XElement(XName.Get("Key", ManagementClientConstants.SbNs), param.Key),
                                         XmlObjectConvertor.SerializeObject(param.Value)));
                    }
                }

                return(new XElement(
                           XName.Get("Action", ManagementClientConstants.SbNs),
                           new XAttribute(XName.Get("type", ManagementClientConstants.XmlSchemaInstanceNs), nameof(SqlRuleAction)),
                           new XElement(XName.Get("SqlExpression", ManagementClientConstants.SbNs), sqlRuleAction.SqlExpression),
                           parameterElement));
            }
            else
            {
                throw new NotImplementedException($"Rule action of type {action.GetType().Name} is not implemented");
            }
        }
        static RuleAction ParseFromXElementSqlRuleAction(XElement xElement)
        {
            var expression = xElement.Element(XName.Get("SqlExpression", ManagementClientConstants.ServiceBusNamespace))?.Value;

            if (string.IsNullOrWhiteSpace(expression))
            {
                return(null);
            }

            var action = new SqlRuleAction(expression);

            var parameters = xElement.Element(XName.Get("Parameters", ManagementClientConstants.ServiceBusNamespace));

            if (parameters != null && parameters.HasElements)
            {
                foreach (var param in parameters.Elements(XName.Get("KeyValueOfstringanyType", ManagementClientConstants.ServiceBusNamespace)))
                {
                    var key   = param.Element(XName.Get("Key", ManagementClientConstants.ServiceBusNamespace))?.Value;
                    var value = XmlObjectConvertor.ParseValueObject(param.Element(XName.Get("Value", ManagementClientConstants.ServiceBusNamespace)));
                    action.Parameters.Add(key, value);
                }
            }

            return(action);
        }
        public static Filter ParseFromXElement(XElement xElement)
        {
            var correlationFilter = new CorrelationFilter();

            foreach (var element in xElement.Elements())
            {
                switch (element.Name.LocalName)
                {
                case "CorrelationId":
                    correlationFilter.CorrelationId = element.Value;
                    break;

                case "MessageId":
                    correlationFilter.MessageId = element.Value;
                    break;

                case "To":
                    correlationFilter.To = element.Value;
                    break;

                case "ReplyTo":
                    correlationFilter.ReplyTo = element.Value;
                    break;

                case "Label":
                    correlationFilter.Label = element.Value;
                    break;

                case "SessionId":
                    correlationFilter.SessionId = element.Value;
                    break;

                case "ReplyToSessionId":
                    correlationFilter.ReplyToSessionId = element.Value;
                    break;

                case "ContentType":
                    correlationFilter.ContentType = element.Value;
                    break;

                case "Properties":
                    foreach (var prop in element.Elements(XName.Get("KeyValueOfstringanyType", ManagementClientConstants.ServiceBusNamespace)))
                    {
                        var key   = prop.Element(XName.Get("Key", ManagementClientConstants.ServiceBusNamespace))?.Value;
                        var value = XmlObjectConvertor.ParseValueObject(prop.Element(XName.Get("Value", ManagementClientConstants.ServiceBusNamespace)));
                        correlationFilter.Properties.Add(key, value);
                    }
                    break;

                default:
                    MessagingEventSource.Log.ManagementSerializationException(
                        $"{nameof(CorrelationFilterExtensions)}_{nameof(ParseFromXElement)}",
                        element.ToString());
                    break;
                }
            }

            return(correlationFilter);
        }
示例#5
0
        public static XElement Serialize(this SqlFilter filter, string filterName)
        {
            XElement parameterElement = null;

            if (filter.parameters != null)
            {
                parameterElement = new XElement(XName.Get("Parameters", ManagementClientConstants.SbNs));
                foreach (var param in filter.Parameters)
                {
                    parameterElement.Add(
                        new XElement(XName.Get("KeyValueOfstringanyType", ManagementClientConstants.SbNs),
                                     new XElement(XName.Get("Key", ManagementClientConstants.SbNs), param.Key),
                                     XmlObjectConvertor.SerializeObject(param.Value)));
                }
            }

            return(new XElement(
                       XName.Get("Filter", ManagementClientConstants.SbNs),
                       new XAttribute(XName.Get("type", ManagementClientConstants.XmlSchemaInstanceNs), filterName),
                       new XElement(XName.Get("SqlExpression", ManagementClientConstants.SbNs), filter.SqlExpression),
                       parameterElement));
        }
        public static XElement Serialize(this CorrelationFilter filter)
        {
            XElement parameterElement = null;

            if (filter.properties != null)
            {
                parameterElement = new XElement(XName.Get("Properties", ManagementClientConstants.ServiceBusNamespace));
                foreach (var param in filter.properties)
                {
                    parameterElement.Add(
                        new XElement(XName.Get("KeyValueOfstringanyType", ManagementClientConstants.ServiceBusNamespace),
                                     new XElement(XName.Get("Key", ManagementClientConstants.ServiceBusNamespace), param.Key),
                                     XmlObjectConvertor.SerializeObject(param.Value)));
                }
            }

            return(new XElement(
                       XName.Get("Filter", ManagementClientConstants.ServiceBusNamespace),
                       new XAttribute(XName.Get("type", ManagementClientConstants.XmlSchemaInstanceNamespace), nameof(CorrelationFilter)),
                       string.IsNullOrWhiteSpace(filter.CorrelationId) ? null :
                       new XElement(XName.Get("CorrelationId", ManagementClientConstants.ServiceBusNamespace), filter.CorrelationId),
                       string.IsNullOrWhiteSpace(filter.MessageId) ? null :
                       new XElement(XName.Get("MessageId", ManagementClientConstants.ServiceBusNamespace), filter.MessageId),
                       string.IsNullOrWhiteSpace(filter.To) ? null :
                       new XElement(XName.Get("To", ManagementClientConstants.ServiceBusNamespace), filter.To),
                       string.IsNullOrWhiteSpace(filter.ReplyTo) ? null :
                       new XElement(XName.Get("ReplyTo", ManagementClientConstants.ServiceBusNamespace), filter.ReplyTo),
                       string.IsNullOrWhiteSpace(filter.Label) ? null :
                       new XElement(XName.Get("Label", ManagementClientConstants.ServiceBusNamespace), filter.Label),
                       string.IsNullOrWhiteSpace(filter.SessionId) ? null :
                       new XElement(XName.Get("SessionId", ManagementClientConstants.ServiceBusNamespace), filter.SessionId),
                       string.IsNullOrWhiteSpace(filter.ReplyToSessionId) ? null :
                       new XElement(XName.Get("ReplyToSessionId", ManagementClientConstants.ServiceBusNamespace), filter.ReplyToSessionId),
                       string.IsNullOrWhiteSpace(filter.ContentType) ? null :
                       new XElement(XName.Get("ContentType", ManagementClientConstants.ServiceBusNamespace), filter.ContentType),
                       parameterElement));
        }
示例#7
0
        public string GetValue(SqliteEntity obj)
        {
            object val        = this.PropertyInfo.GetValue(obj, null);
            string fieldValue = "";

            if (val != null)
            {
                switch (PropertyAttribute.DataType)
                {
                case DataType.Date:
                    fieldValue = "'" + ((DateTime)val).ToString("s") + "'";
                    break;

                case DataType.Interger:
                    if (val is bool)
                    {
                        fieldValue = ((bool)val) ? "1" : "0";
                    }
                    else
                    {
                        fieldValue = val.ToString();
                    }
                    break;

                case DataType.Varchar2:
                    fieldValue = "'" + DB.ReplaceInvalidSQL(val.ToString()) + "'";
                    //fieldValue = DB.DBManager.FormatEscapeChar(fieldValue);
                    break;

                case DataType.Boolean:
                    fieldValue = ((bool)val) ? "1" : "0";
                    break;

                case DataType.LongString:
                    fieldValue = DB.ReplaceInvalidSQL(val.ToString());
                    break;

                case DataType.Enum:
                    fieldValue = ((int)val).ToString();
                    break;

                case DataType.XmlObject:
                    fieldValue = "'" + DB.ReplaceInvalidSQL(XmlObjectConvertor.GetXml(val)) + "'";
                    fieldValue = DB.DBManager.FormatEscapeChar(fieldValue);
                    break;

                case DataType.Double:
                    fieldValue = ((double)val).ToString();
                    break;

                case DataType.Byte:
                    fieldValue = val.ToString();
                    break;

                case DataType.Long:
                    fieldValue = ((long)val).ToString();
                    break;

                case DataType.Decimal:
                    fieldValue = ((decimal)val).ToString();
                    break;

                default:
                    fieldValue = "";
                    break;
                }
            }
            else
            {
                fieldValue = "NULL";
            }
            return(fieldValue);
        }