Beispiel #1
0
        public static string GetXMLString(Block Block)
        {
            List <Condition> BuffConditions = new List <Condition>();

            foreach (var item in Block.settings.Conditions)
            {
                BuffConditions.Add(new Condition()
                {
                    Property = item.Property, Operation = (OperationType)Enum.Parse(typeof(OperationType), item.Operation), Value = item.Value
                });
            }

            #region проверка
            switch (Block.typename)
            {
            case "ConditionBlock":
                block = new ConditionBlockValidator();
                break;

            case "SendSMSBlock":
                block = new SendSMSValidator();
                break;

            case "SubscribtionConfirmBlock":
                block = new SubscribtionConfirmValidator();
                break;

            case "SubscribtionBlock":
                block = new SubscriptionValidator();
                break;
            }

            block.Validate(BuffConditions);
            #endregion

            #region сериализация
            XmlSerializer serializer = new XmlSerializer(typeof(BlockSettings));
            Stream        str        = new MemoryStream();

            serializer.Serialize(str, new BlockSettings()
            {
                Conditions = BuffConditions
            });
            #endregion

            str.Seek(0, SeekOrigin.Begin);
            StreamReader reader = new StreamReader(str);
            string       result = reader.ReadToEnd();
            result = result.Substring(result.IndexOf("<BlockSettings"));
            result = result.Replace(Environment.NewLine, "");

            return(result);
        }
Beispiel #2
0
        public static _BlockSettings GetBlockSettings(string BlockType, string XMLString)
        {
            _BlockSettings bSettings = new _BlockSettings();

            bSettings.Conditions = new List <_Condition>();

            #region десереализация
            XmlSerializer serializer = new XmlSerializer(typeof(BlockSettings));
            string        buffer     = XMLString.Substring(XMLString.IndexOf("<BlockSettings"));
            buffer = buffer.Replace(Environment.NewLine, "");

            Stream XMLStream = new MemoryStream();

            var SetingsInBytes = Encoding.UTF8.GetBytes(buffer);
            XMLStream.Write(SetingsInBytes, 0, SetingsInBytes.Length);

            XMLStream.Seek(0, SeekOrigin.Begin);
            List <Condition> BuffConditions = ((BlockSettings)serializer.Deserialize(XMLStream)).Conditions;
            #endregion

            switch (BlockType)
            {
            case "ConditionBlock":
                block = new ConditionBlockValidator();
                break;

            case "SendSMSBlock":
                block = new SendSMSValidator();
                break;

            case "SubscribtionConfirmBlock":
                block = new SubscribtionConfirmValidator();
                break;

            case "SubscribtionBlock":
                block = new SubscriptionValidator();
                break;
            }

            block.Validate(BuffConditions);

            foreach (var item in BuffConditions)
            {
                bSettings.Conditions.Add(new _Condition()
                {
                    Property = item.Property, Operation = item.Operation.ToString(), Value = item.Value
                });
            }

            return(bSettings);
        }