Exemplo n.º 1
0
        private DatasetSchema GetSchema(DataSet ds)
        {
            if (ds == null)
            {
                return(null);
            }

            DatasetSchema m = new DatasetSchema();

            m.Info = new List <string>();
            m.Name = ds.DataSetName;

            foreach (DataTable t in ds.Tables)
            {
                foreach (DataColumn c in t.Columns)
                {
                    m.Info.Add(t.TableName);
                    m.Info.Add(c.ColumnName);
                    m.Info.Add(c.DataType.ToString());
                }
            }
            // FEATURE : serialize relations and constraints here

            return(m);
        }
Exemplo n.º 2
0
        private DatasetSchema GetSchema(DataTable ds)
        {
            if (ds == null)
            {
                return(null);
            }

            DatasetSchema m = new DatasetSchema();

            m.Info = new List <string>();
            m.Name = ds.TableName;

            foreach (DataColumn c in ds.Columns)
            {
                m.Info.Add(ds.TableName);
                m.Info.Add(c.ColumnName);
                if (_params.FullyQualifiedDataSetSchema)
                {
                    m.Info.Add(c.DataType.AssemblyQualifiedName);
                }
                else
                {
                    m.Info.Add(c.DataType.ToString());
                }
            }
            // FEATURE : serialize relations and constraints here

            return(m);
        }
Exemplo n.º 3
0
        private DataSet CreateDataset(Dictionary <string, object> reader, Dictionary <string, object> globalTypes)
        {
            DataSet ds = new DataSet();

            ds.EnforceConstraints = false;
            ds.BeginInit();

            // read dataset schema here
            var schema = reader["$schema"];

            if (schema is string)
            {
                TextReader tr = new StringReader((string)schema);
                ds.ReadXmlSchema(tr);
            }
            else
            {
                DatasetSchema ms = (DatasetSchema)ParseDictionary((Dictionary <string, object>)schema, globalTypes, typeof(DatasetSchema), null);
                ds.DataSetName = ms.Name;
                for (int i = 0; i < ms.Info.Count; i += 3)
                {
                    if (ds.Tables.Contains(ms.Info[i]) == false)
                    {
                        ds.Tables.Add(ms.Info[i]);
                    }
                    // blacklist checking
                    var t = //Type.GetType(ms.Info[i + 2]);
                            Reflection.Instance.GetTypeFromCache(ms.Info[i + 2], true);
                    ds.Tables[ms.Info[i]].Columns.Add(ms.Info[i + 1], t);
                }
            }

            foreach (KeyValuePair <string, object> pair in reader)
            {
                if (pair.Key == "$type" || pair.Key == "$schema")
                {
                    continue;
                }

                List <object> rows = (List <object>)pair.Value;
                if (rows == null)
                {
                    continue;
                }

                DataTable dt = ds.Tables[pair.Key];
                ReadDataTable(rows, dt);
            }

            ds.EndInit();

            return(ds);
        }
Exemplo n.º 4
0
        DataSet CreateDataSet(JsonDict reader)
        {
            DataSet ds = new DataSet();

            ds.EnforceConstraints = false;
            ds.BeginInit();

            // read dataset schema here
            var schema = reader.Schema;

            if (schema is string)
            {
                TextReader tr = new StringReader((string)schema);
                ds.ReadXmlSchema(tr);
            }
            else
            {
                DatasetSchema ms = (DatasetSchema)CreateObject((JsonDict)schema, _manager.GetReflectionCache(typeof(DatasetSchema)), null);
                ds.DataSetName = ms.Name;
                for (int i = 0; i < ms.Info.Count; i += 3)
                {
                    if (ds.Tables.Contains(ms.Info[i]) == false)
                    {
                        ds.Tables.Add(ms.Info[i]);
                    }
                    ds.Tables[ms.Info[i]].Columns.Add(ms.Info[i + 1], Type.GetType(ms.Info[i + 2]));
                }
            }

            foreach (KeyValuePair <string, object> pair in reader)
            {
                //if (pair.Key == "$type" || pair.Key == "$schema") continue;

                JsonArray rows = (JsonArray)pair.Value;
                if (rows == null)
                {
                    continue;
                }

                DataTable dt = ds.Tables[pair.Key];
                ReadDataTable(rows, dt);
            }

            ds.EndInit();

            return(ds);
        }
Exemplo n.º 5
0
        private DatasetSchema GetSchema(DataSet ds)
        {
            if (ds == null) return null;

            DatasetSchema m = new DatasetSchema();
            m.Info = new List<string>();
            m.Name = ds.DataSetName;

            foreach (DataTable t in ds.Tables)
            {
                foreach (DataColumn c in t.Columns)
                {
                    m.Info.Add(t.TableName);
                    m.Info.Add(c.ColumnName);
                    m.Info.Add(c.DataType.ToString());
                }
            }
            // TODO : serialize relations and constraints here

            return m;
        }
Exemplo n.º 6
0
        static DatasetSchema GetSchema(DataTable ds)
        {
            if (ds == null)
            {
                return(null);
            }

            var m = new DatasetSchema {
                Info = new List <string> (),
                Name = ds.TableName
            };

            foreach (DataColumn c in ds.Columns)
            {
                m.Info.Add(ds.TableName);
                m.Info.Add(c.ColumnName);
                m.Info.Add(c.DataType.ToString());
            }
            // FEATURE : serialize relations and constraints here

            return(m);
        }
Exemplo n.º 7
0
        private void ReadSchema(Dictionary <string, object> reader, DataSet ds, Dictionary <string, object> globalTypes)
        {
            var schema = reader["$schema"];

            if (schema is string)
            {
                TextReader tr = new StringReader((string)schema);
                ds.ReadXmlSchema(tr);
            }
            else
            {
                DatasetSchema ms = (DatasetSchema)ParseDictionary((Dictionary <string, object>)schema, globalTypes, typeof(DatasetSchema), null);
                ds.DataSetName = ms.Name;
                for (int i = 0; i < ms.Info.Count; i += 3)
                {
                    if (ds.Tables.Contains(ms.Info[i]) == false)
                    {
                        ds.Tables.Add(ms.Info[i]);
                    }
                    ds.Tables[ms.Info[i]].Columns.Add(ms.Info[i + 1], Type.GetType(ms.Info[i + 2]));
                }
            }
        }
Exemplo n.º 8
0
        static DatasetSchema GetSchema(DataSet ds)
        {
            if (ds == null) return null;

            var m = new DatasetSchema {
                Info = new List<string> (),
                Name = ds.DataSetName
            };

            foreach (DataTable t in ds.Tables) {
                foreach (DataColumn c in t.Columns) {
                    m.Info.Add (t.TableName);
                    m.Info.Add (c.ColumnName);
                    m.Info.Add (c.DataType.ToString ());
                }
            }
            // FEATURE : serialize relations and constraints here

            return m;
        }
Exemplo n.º 9
0
        private DataSet CreateDataset(Dictionary <string, object> reader)
        {
            DataSet ds = new DataSet();

            ds.EnforceConstraints = false;
            ds.BeginInit();

            // read dataset schema here
            var schema = reader["$schema"];

            if (schema is string)
            {
                TextReader tr = new StringReader((string)schema);
                ds.ReadXmlSchema(tr);
            }
            else
            {
                DatasetSchema ms = (DatasetSchema)ParseDictionary((Dictionary <string, object>)schema);
                ds.DataSetName = ms.Name;
                for (int i = 0; i < ms.Info.Count; i += 3)
                {
                    if (ds.Tables.Contains(ms.Info[i]) == false)
                    {
                        ds.Tables.Add(ms.Info[i]);
                    }
                    ds.Tables[ms.Info[i]].Columns.Add(ms.Info[i + 1], Type.GetType(ms.Info[i + 2]));
                }
            }

            foreach (KeyValuePair <string, object> pair in reader)
            {
                if (pair.Key == "$type" || pair.Key == "$schema")
                {
                    continue;
                }

                ArrayList rows = (ArrayList)pair.Value;
                if (rows == null)
                {
                    continue;
                }

                DataTable dt = ds.Tables[pair.Key];
                dt.BeginInit();
                dt.BeginLoadData();
                List <int> guidcols = new List <int>();

                foreach (DataColumn c in dt.Columns)
                {
                    if (c.DataType == typeof(Guid) || c.DataType == typeof(Guid?))
                    {
                        guidcols.Add(c.Ordinal);
                    }
                }

                foreach (ArrayList row in rows)
                {
                    object[] v = new object[row.Count];
                    row.CopyTo(v, 0);
                    foreach (int i in guidcols)
                    {
                        string s = (string)v[i];
                        if (s != null && s.Length < 36)
                        {
                            v[i] = new Guid(Convert.FromBase64String(s));
                        }
                    }
                    dt.Rows.Add(v);
                }

                dt.EndLoadData();
                dt.EndInit();
            }

            ds.EndInit();

            return(ds);
        }