예제 #1
0
        public void LoadSettings(string XMLSettings)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(BlockSettings));
            string        buffer     = XMLSettings.Substring(XMLSettings.IndexOf("<BlockSettings"));

            buffer = buffer.Replace(Environment.NewLine, "");

            Stream XMLStream = new MemoryStream();

            var SetingsInBytes = Encoding.Default.GetBytes(buffer);

            XMLStream.Write(SetingsInBytes, 0, SetingsInBytes.Length);

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

            validator.Validate(BuffConditions);
            this.Conditions = BuffConditions;
        }
예제 #2
0
        //public void LoadSettings(string XMLSettings)
        //{
        //    XmlSerializer serializer = new XmlSerializer(typeof(BlockSettings));
        //    string buffer = XMLSettings.Substring(XMLSettings.IndexOf("<BlockSettings"));
        //    buffer = buffer.Replace(Environment.NewLine, "");

        //    Stream XMLStream = new MemoryStream();

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

        //    XMLStream.Seek(0, SeekOrigin.Begin);
        //    List < Condition > BuffConditions = ((BlockSettings)serializer.Deserialize(XMLStream)).Conditions;
        //    validator.Validate(BuffConditions);
        //    this.Conditions = BuffConditions;
        //}

        public string SaveSettings(BlockSettings Settings)
        {
            validator.Validate(Settings.Conditions);
            this.Conditions = Settings.Conditions;

            XmlSerializer serializer = new XmlSerializer(typeof(BlockSettings));
            Stream        str        = new MemoryStream();

            serializer.Serialize(str, Settings);

            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);
        }