예제 #1
0
        protected override void Ondeserializing(SerializationInfo info)
        {
            base.Ondeserializing(info);

            var tablesRevisionXml = info.GetValue(TablesRevisionKey, typeof(string)) as string;
            var tablesRevision    = XmlSerializerUtility.ReadString(tablesRevisionXml, typeof(List <SerializableKeyValuePair <string, long> >));

            if (tablesRevision != null && tablesRevision is List <SerializableKeyValuePair <string, long> > tables)
            {
                foreach (var table in tables)
                {
                    if (table.Key != null && this.dataSet.Tables.Contains(table.Key))
                    {
                        this.dataSet.Tables[table.Key].UpdateRevision(table.Value);
                    }
                }
            }

            var typesRevisionXml = info.GetValue(TypesRevisionKey, typeof(string)) as string;
            var typesRevision    = XmlSerializerUtility.ReadString(typesRevisionXml, typeof(List <SerializableKeyValuePair <string, long> >));

            if (typesRevision != null && typesRevision is List <SerializableKeyValuePair <string, long> > types)
            {
                foreach (var type in types)
                {
                    if (type.Key != null && this.dataSet.Types.Contains(type.Key))
                    {
                        this.dataSet.Types[type.Key].UpdateRevision(type.Value);
                    }
                }
            }
        }
        public static bool TryGetValue <T>(this IRepositoryConfiguration config, Type section, string key, out T value)
        {
            var configItem = new ConfigurationItem(section.Name, key);

            if (config.Contains(configItem) == true)
            {
                try
                {
                    if (ConfigurationBase.CanSupportType(typeof(T)) == true)
                    {
                        value = (T)config[configItem];
                        return(true);
                    }
                    else
                    {
                        var text = (string)config[configItem];
                        value = XmlSerializerUtility.ReadString <T>(text.Decrypt());
                        return(true);
                    }
                }
                catch
                {
                }
            }

            value = default;
            return(false);
        }
예제 #3
0
        private void InitializeUsers(SerializationInfo info)
        {
            DomainUserInfo[] FindUsersValue()
            {
                var enumerator = info.GetEnumerator();

                while (enumerator.MoveNext())
                {
                    var item = enumerator.Current;
                    if (item.Name == usersKey)
                    {
                        return(XmlSerializerUtility.ReadString <DomainUserInfo[]>(item.Value as string));
                    }
                }
                return(null);
            }

            var users = FindUsersValue();

            if (users == null)
            {
                return;
            }

            foreach (var item in users)
            {
                this.users.Add(new DomainUser(this, item.UserID, item.UserName, item.AccessType));
            }
        }
예제 #4
0
        public static bool TryGetValue <T>(this IUserConfiguration config, Type section, string key, out T value)
        {
#pragma warning disable CS0612 // 'ConfigurationItem'은(는) 사용되지 않습니다.
            var configItem = new ConfigurationItem(section.Name, key);
#pragma warning restore CS0612 // 'ConfigurationItem'은(는) 사용되지 않습니다.
            if (config.Contains(configItem) == true)
            {
                try
                {
                    if (ConfigurationBase.CanSupportType(typeof(T)) == true)
                    {
                        value = (T)config[configItem];
                        return(true);
                    }
                    else
                    {
                        var text = (string)config[configItem];
                        value = XmlSerializerUtility.ReadString <T>(text.Decrypt());
                        return(true);
                    }
                }
                catch
                {
                }
            }

            value = default;
            return(false);
        }
예제 #5
0
        protected override void OnInitialize(DomainMetaData metaData)
        {
            base.OnInitialize(metaData);

            var xml = Encoding.UTF8.GetString(metaData.Data).Decompress();

            this.template = XmlSerializerUtility.ReadString <CremaTemplate>(xml);
            this.view     = this.template.View;
        }
예제 #6
0
        protected override void OnInitialize(byte[] data)
        {
            base.OnInitialize(data);

            var xml = Encoding.UTF8.GetString(data).Decompress();

            this.TemplateSource = XmlSerializerUtility.ReadString <CremaTemplate>(xml);
            this.view           = this.TemplateSource.View;
        }
예제 #7
0
        protected override void DerializeSource(byte[] data)
        {
            var text     = Encoding.UTF8.GetString(data).Decompress();
            var index    = text.IndexOf(";");
            var path     = text.Remove(index);
            var itemName = new ItemName(path);
            var xml      = text.Substring(index + 1);
            var dataSet  = XmlSerializerUtility.ReadString <CremaDataSet>(xml);

            this.dataType = dataSet.Types[itemName.Name];
        }
        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);
            }
        }
예제 #9
0
        protected override void DerializeSource(byte[] data)
        {
            var xml = Encoding.UTF8.GetString(data).Decompress();

            this.dataSet = XmlSerializerUtility.ReadString <CremaDataSet>(xml);

            foreach (var item in this.dataSet.Tables)
            {
                var view = item.AsDataView();
                this.views.Add(item.TableName, view);
            }
        }
예제 #10
0
        protected override void OnInitialize(DomainMetaData metaData)
        {
            base.OnInitialize(metaData);

            var text     = Encoding.UTF8.GetString(metaData.Data).Decompress();
            var index    = text.IndexOf(";");
            var path     = text.Remove(index);
            var itemName = new ItemName(path);
            var xml      = text.Substring(index + 1);
            var dataSet  = XmlSerializerUtility.ReadString <CremaDataSet>(xml);

            this.dataType = dataSet.Types[itemName.Name];
            this.view     = this.dataType.AsDataView();
        }
예제 #11
0
        protected override void OnInitialize(DomainMetaData metaData)
        {
            base.OnInitialize(metaData);

            var xml = Encoding.UTF8.GetString(metaData.Data).Decompress();

            this.dataSet = XmlSerializerUtility.ReadString <CremaDataSet>(xml);
            this.dataSet.AcceptChanges();
            this.views.Clear();
            foreach (var item in this.dataSet.Tables)
            {
                var view = item.AsDataView();
                //view.AllowDelete = false;
                //view.AllowEdit = false;
                //view.AllowNew = false;
                this.views.Add(item.TableName, view);
                this.tables.Add(view, item);
            }
        }
        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;
            }
        }
예제 #13
0
        protected override void DerializeSource(byte[] data)
        {
            var xml = Encoding.UTF8.GetString(data).Decompress();

            this.template = XmlSerializerUtility.ReadString <CremaTemplate>(xml);
        }
예제 #14
0
        protected override object DerializeSource(byte[] data)
        {
            var xml = Encoding.UTF8.GetString(data).Decompress();

            return(XmlSerializerUtility.ReadString <CremaTemplate>(xml));
        }
예제 #15
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);
            }
        }