Exemplo n.º 1
0
        protected override void OnSerializaing(SerializationInfo info, StreamingContext context)
        {
            base.OnSerializaing(info, context);

            info.AddValue(TablesRevisionKey, GetTablesRevisionXml());
            info.AddValue(TypesRevisionKey, GetTypesRevisionXml());

            string GetTablesRevisionXml()
            {
                var list = new List <SerializableKeyValuePair <string, long> >();

                if (this.Source is CremaDataSet dataSet)
                {
                    foreach (var table in dataSet.Tables)
                    {
                        list.Add(new SerializableKeyValuePair <string, long>(table.Name, table.Revision));
                    }
                }
                return(XmlSerializerUtility.GetString(list));
            }

            string GetTypesRevisionXml()
            {
                var list = new List <SerializableKeyValuePair <string, long> >();

                if (this.Source is CremaDataSet dataSet)
                {
                    foreach (var type in dataSet.Types)
                    {
                        list.Add(new SerializableKeyValuePair <string, long>(type.Name, type.Revision));
                    }
                }
                return(XmlSerializerUtility.GetString(list));
            }
        }
Exemplo n.º 2
0
 protected override byte[] SerializeSource(object source)
 {
     if (this.data == null)
     {
         var xml = XmlSerializerUtility.GetString(source);
         this.data = Encoding.UTF8.GetBytes(xml.Compress());
     }
     return(this.data);
 }
        public void XmlSerializing()
        {
            var dataSet = CremaDataSetExtensions.CreateRandomSet();

            foreach (var item in dataSet.Types)
            {
                string xml     = XmlSerializerUtility.GetString(item);
                var    newType = XmlSerializerUtility.ReadString <CremaDataType>(xml);

                CremaComparer.CompareType(item, newType);
            }
        }
        public static void SetValue <T>(this IRepositoryConfiguration config, Type section, string key, T value)
        {
            var configItem = new ConfigurationItem(section.Name, key);

            if (ConfigurationBase.CanSupportType(typeof(T)) == true)
            {
                config[configItem] = value;
            }
            else
            {
                config[configItem] = XmlSerializerUtility.GetString(value).Encrypt();
            }
        }
Exemplo n.º 5
0
        protected virtual void OnSerializaing(SerializationInfo info, StreamingContext context)
        {
            info.AddValue(typeof(DomainInfo).Name, base.DomainInfo);
            info.AddValue(dataKey, this.SerializeSource());
            info.AddValue(usersKey, GetUsersXml());

            string GetUsersXml()
            {
                var query     = from DomainUser item in this.Users select item.DomainUserInfo;
                var userInfos = query.ToArray();

                return(XmlSerializerUtility.GetString(userInfos));
            }
        }
Exemplo n.º 6
0
        public static void SetValue <T>(this IUserConfiguration config, Type section, string key, T value)
        {
#pragma warning disable CS0612 // 'ConfigurationItem'은(는) 사용되지 않습니다.
            var configItem = new ConfigurationItem(section.Name, key);
#pragma warning restore CS0612 // 'ConfigurationItem'은(는) 사용되지 않습니다.
            if (ConfigurationBase.CanSupportType(typeof(T)) == true)
            {
                config[configItem] = value;
            }
            else
            {
                config[configItem] = XmlSerializerUtility.GetString(value).Encrypt();
            }
        }
Exemplo n.º 7
0
 public static string Serialize(object obj, TextSerializerType type)
 {
     if (type == TextSerializerType.Yaml)
     {
         return(yamlSerializer.Serialize(obj));
     }
     else if (type == TextSerializerType.Json)
     {
         return(JsonConvert.SerializeObject(obj, Formatting.Indented));
     }
     else if (type == TextSerializerType.Xml)
     {
         return(XmlSerializerUtility.GetString(obj, true));
     }
     throw new NotImplementedException();
 }
Exemplo n.º 8
0
 protected override byte[] SerializeSource(object source)
 {
     if (this.data == null)
     {
         if (source is CremaDataType dataType)
         {
             var text = dataType.Path + ";" + XmlSerializerUtility.GetString(dataType.DataSet);
             this.data = Encoding.UTF8.GetBytes(text.Compress());
         }
         else
         {
             throw new NotImplementedException();
         }
     }
     return(this.data);
 }
        public void XmlSerializing()
        {
            var table     = this.dataSet.Tables.Random(item => item.TemplatedParent == null);
            var template1 = new CremaTemplate(table);

            //CremaRandomUtility.RandomTask(template1, 30);

            var xml1      = XmlSerializerUtility.GetString(template1, true);
            var template2 = XmlSerializerUtility.ReadString <CremaTemplate>(xml1);
            var xml2      = XmlSerializerUtility.GetString(template2, true);

            try
            {
                Assert.AreEqual(xml1, xml2);
            }
            catch
            {
                File.WriteAllText(Path.Combine(Directory.GetCurrentDirectory(), template1.TableName + "_template1" + CremaSchema.SchemaExtension), xml1);
                File.WriteAllText(Path.Combine(Directory.GetCurrentDirectory(), template2.TableName + "_template2" + CremaSchema.SchemaExtension), xml2);
                throw;
            }
        }
Exemplo n.º 10
0
        protected override byte[] SerializeSource()
        {
            var text = this.dataType.Path + ";" + XmlSerializerUtility.GetString(this.dataType.DataSet);

            return(Encoding.UTF8.GetBytes(text.Compress()));
        }
Exemplo n.º 11
0
        protected override byte[] SerializeSource()
        {
            var xml = XmlSerializerUtility.GetString(this.dataSet);

            return(Encoding.UTF8.GetBytes(xml.Compress()));
        }
Exemplo n.º 12
0
        public object this[Type type, string key]
        {
            get
            {
                if (this.ContainsSection(type) == false)
                {
                    return(null);
                }

                var section = this.GetSection(type);
                var element = section.Settings.Get(key);

                if (element == null)
                {
                    return(null);
                }

                var valueXml = element.Value.ValueXml;

                var typeValue = valueXml.Attributes["type"];
                var valueType = typeValue == null ? typeof(string) : Type.GetType(typeValue.Value);
                if (element.SerializeAs == SettingsSerializeAs.String)
                {
                    var converter = TypeDescriptor.GetConverter(valueType);
                    return(converter.ConvertFromString(element.Value.ValueXml.InnerText));
                }

                if (typeof(IXmlSerializable).IsAssignableFrom(valueType) == true)
                {
                    return(element.Value.ValueXml.InnerXml);
                }

                return(XmlSerializerUtility.ReadString(element.Value.ValueXml.InnerXml, valueType));
            }
            set
            {
                var section = this.GetSection(type);
                var element = section.Settings.Get(key);

                if (value == null && element != null)
                {
                    section.Settings.Remove(element);
                    return;
                }

                if (element == null)
                {
                    element = new SettingElement(key, SettingsSerializeAs.String);
                    section.Settings.Add(element);
                }

                var doc      = new XmlDocument();
                var textNode = doc.CreateElement("value");
                doc.AppendChild(textNode);

                var converter = TypeDescriptor.GetConverter(value);
                if (converter.CanConvertFrom(typeof(string)) == true)
                {
                    var textValue = converter.ConvertToString(value);
                    if (textValue != string.Empty)
                    {
                        textNode.AppendChild(doc.CreateTextNode(textValue));
                    }
                    element.SerializeAs = SettingsSerializeAs.String;
                }
                else if (value is IXmlSerializable)
                {
                    var s        = value as IXmlSerializable;
                    var settings = new XmlWriterSettings()
                    {
                        Indent = true, Encoding = Encoding.UTF8, OmitXmlDeclaration = true
                    };
                    using (var sw = new Utf8StringWriter())
                        using (var writer = XmlWriter.Create(sw, settings))
                        {
                            s.WriteXml(writer);
                            writer.Close();
                            textNode.InnerXml   = sw.ToString();
                            element.SerializeAs = SettingsSerializeAs.Xml;
                        }
                }
                else
                {
                    textNode.InnerXml   = XmlSerializerUtility.GetString(value, true, true);
                    element.SerializeAs = SettingsSerializeAs.Xml;
                }

                if (value is string == false)
                {
                    var attribute = doc.CreateAttribute("type");
                    attribute.Value = value.GetType().AssemblyQualifiedName;
                    textNode.Attributes.Append(attribute);
                }

                element.Value = new SettingValueElement()
                {
                    ValueXml = textNode
                };
                ConfigurationManager.RefreshSection(section.SectionInformation.SectionName);
            }
        }