Esempio n. 1
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);
        }
Esempio n. 2
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);
                    }
                }
            }
        }
Esempio n. 3
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));
            }
        }
Esempio n. 4
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));
            }
        }
        private void Deserialize(XmlReader reader, IDictionary <string, object> properties)
        {
            reader.ReadStartElement();
            reader.MoveToContent();

            while (reader.NodeType == XmlNodeType.Element)
            {
                if (reader.IsEmptyElement == false)
                {
                    var name = reader.GetAttribute("name");
                    var type = reader.GetAttribute("type");
                    try
                    {
                        var runtimeType = Type.GetType(type);
                        reader.ReadStartElement();
                        var value = XmlSerializerUtility.Read(reader, runtimeType);
                        reader.ReadEndElement();
                        properties.Add(name, value);
                    }
                    catch
                    {
                        reader.Skip();
                    }
                }
                else
                {
                    reader.Skip();
                }
                reader.MoveToContent();
            }
        }
Esempio n. 6
0
        public void Post(DomainActionBase action)
        {
            if (this.isEnabled == false)
            {
                return;
            }

            var message = string.Empty;

            this.current = action;
            action.ID    = this.id++;

            var s = XmlSerializerUtility.GetSerializer(action.GetType());

            var ns = new XmlSerializerNamespaces();

            ns.Add(string.Empty, string.Empty);
            ns.Add("fn", action.GetType().AssemblyQualifiedName);

            using (var sw = new Utf8StringWriter())
                using (var writer = XmlWriter.Create(sw, writerSettings))
                {
                    DataContractSerializerUtility.Write(writer, action);
                    writer.Close();
                    message = sw.ToString();
                }

            this.postedWriter.WriteLine(message);
        }
 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);
 }
        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;
        }
Esempio n. 9
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;
        }
Esempio n. 10
0
 void IXmlSerializable.WriteXml(XmlWriter writer)
 {
     writer.WriteAttributeString("Name", this.TargetTable.Name);
     writer.WriteAttributeString("CategoryPath", this.TargetTable.CategoryPath);
     writer.WriteAttributeString("BaseNamespace", this.TargetTable.DataSet.Namespace);
     this.template.WriteXml(writer, XmlWriteMode.DiffGram);
     this.TargetTable.DataSet.WriteXmlSchema(writer);
     this.TargetTable.DataSet.WriteXml(writer);
     XmlSerializerUtility.Write(writer, this.Types);
 }
Esempio n. 11
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);
            }
        }
 private void Serialize(XmlWriter writer, IReadOnlyDictionary <string, object> properties)
 {
     writer.WriteStartElement(SerializableElement);
     foreach (var item in properties)
     {
         writer.WriteStartElement("item");
         writer.WriteAttributeString("name", item.Key);
         writer.WriteAttributeString("type", item.Value.GetType().AssemblyQualifiedName);
         XmlSerializerUtility.Write(writer, item.Value);
         writer.WriteEndElement();
     }
     writer.WriteEndElement();
 }
Esempio n. 13
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));
            }
        }
Esempio n. 14
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();
            }
        }
Esempio n. 15
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();
        }
Esempio n. 16
0
        public static ResXInfo GetSettings(this Solution solution)
        {
            var fullName = solution.GetFullName();
            var xmlPath  = fullName + ".cremaresx";

            if (File.Exists(xmlPath) == true)
            {
                if (XmlSerializerUtility.Read(xmlPath, typeof(ResXInfo)) is ResXInfo obj)
                {
                    return(obj);
                }
            }

            throw new InvalidOperationException();
        }
Esempio n. 17
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);
 }
Esempio n. 18
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();
 }
 public static ConnectionItem LoadConnection(string dbcFile)
 {
     if (System.IO.File.Exists(dbcFile))
     {
         try
         {
             ConnectionItem ci = XmlSerializerUtility.LoadFromXmlFile <ConnectionItem>(dbcFile);
             ci.SetLoaded();
             return(ci);
         }
         catch (Exception err)
         {
             FormLog.NotifyException(true, err, "Invalid connection file [{0}]", dbcFile);
         }
     }
     return(null);
 }
Esempio n. 20
0
 public void OnChangeWithinMethod(bool withinmethod)
 {
     if (_writer == null)
     {
         _writer = XmlSerializerUtility.GetWriter(_reader) as XmlObjectWriter;
     }
     if (_writer != null && _xmlNode != null)
     {
         if (withinmethod)
         {
             _xmlNodeChanged = _xmlNode.OwnerDocument.CreateElement(_xmlNode.Name);
             _writer.WriteObjectToNode(_xmlNodeChanged, this);
         }
         else
         {
             _writer.WriteObjectToNode(_xmlNode, this);
         }
     }
 }
        public void MergeFromFile()
        {
            string f = GetConnectionFilename(this.ConnectionGuid);

            if (System.IO.File.Exists(f))
            {
                ConnectionItem ci = XmlSerializerUtility.LoadFromXmlFile <ConnectionItem>(f);
                if (ci != null)
                {
                    ci.SetDataFolder();
                    if (!string.IsNullOrEmpty(ci._name))
                    {
                        _name = ci._name;
                    }
                    if (ci._cnn != null)
                    {
                        _cnn = ci._cnn;
                    }
                }
            }
        }
Esempio n. 22
0
 public void UpdateXmlNode(XmlObjectWriter writer)
 {
     if (_xmlNode != null)
     {
         if (writer != null)
         {
             writer.WriteObjectToNode(_xmlNode, this);
         }
         else
         {
             if (_writer == null)
             {
                 _writer = XmlSerializerUtility.GetWriter(_reader) as XmlObjectWriter;
             }
             if (_writer != null)
             {
                 _writer.WriteObjectToNode(_xmlNode, this);
             }
         }
     }
 }
        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;
            }
        }
Esempio n. 24
0
        void IXmlSerializable.ReadXml(XmlReader reader)
        {
            var dataSet = new CremaDataSet();

            var name          = reader.GetAttribute("Name");
            var categoryPath  = reader.GetAttribute(nameof(CategoryPath));
            var baseNamespace = reader.GetAttribute("BaseNamespace");

            dataSet.Namespace = baseNamespace;

            reader.ReadStartElement();
            reader.MoveToContent();
            this.template.TargetTable       = null;
            this.template.OmitSignatureDate = true;
            this.template.ReadXml(reader);
            this.template.OmitSignatureDate = false;
            reader.MoveToContent();
            dataSet.ReadXmlSchema(reader);
            reader.MoveToContent();
            dataSet.ReadXml(reader);
            reader.MoveToContent();
            this.template.InternalTypes = XmlSerializerUtility.Read <string[]>(reader);
            reader.MoveToContent();
            reader.ReadEndElement();

            this.template.InternalTargetTable = (InternalDataTable)dataSet.Tables[name, categoryPath];

            foreach (var item in this.template.Rows)
            {
                if (item is InternalTemplateColumn rowItem)
                {
                    if (rowItem.RowState == DataRowState.Deleted)
                    {
                        continue;
                    }
                    rowItem.TargetColumn = (InternalDataColumn)this.template.InternalTargetTable.Columns[rowItem.ColumnName];
                }
            }
        }