Ejemplo n.º 1
0
        public override void ReadSchema(DataSet dbSchema)
        {
            try
            {
                string assemblyFile = (fileLink as DiskFileLink).FileName;
                if (assemblyFile == null)
                {
                    throw new Exception($"assemly must be local file, {fileLink}");
                }
                if (!File.Exists(assemblyFile))
                {
                    throw new Exception($"assemly file doesn't exist, {fileLink}");
                }

                string ns   = fileLink.Options.Contains("namespace") ? fileLink.Options["namespace"] as string : null;
                string clss = fileLink.Options.Contains("class") ? fileLink.Options["class"] as string : null;

                bool typeFilter(Type type)
                {
                    if (!type.IsClass)
                    {
                        return(false);
                    }

                    if (ns != null && !type.Namespace.IsMatch(ns))
                    {
                        return(false);
                    }

                    if (clss != null && !type.Name.IsMatch(clss))
                    {
                        return(false);
                    }

                    return(true);
                }

                Assembly assembly = Assembly.LoadFrom(assemblyFile);
                this.data = TypeExtension.CreateDataSet(assembly, typeFilter);

                var schema = new DbSchemaBuilder(dbSchema);
                schema.AddSchema(data);
            }
            catch (Exception ex)
            {
                throw new Exception($"bad data source defined {fileLink}, {ex.Message}");
            }
        }
Ejemplo n.º 2
0
        public override void ReadSchema(DataSet dbSchema)
        {
            try
            {
                string   code     = fileLink.ReadAllText();
                Assembly assembly = Compile(fileLink.Name, code);
                this.data = TypeExtension.CreateDataSet(assembly, type => type.IsClass);

                var schema = new DbSchemaBuilder(dbSchema);
                schema.AddSchema(data);
            }
            catch (Exception ex)
            {
                throw new Exception($"bad data source defined {fileLink}, {ex.Message}");
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Create table schema by rows in data table. It is used to create a table by DataTable
        /// </summary>
        /// <param name="dt"></param>
        private void AddTableSchema(TableName tname, DataTable dt)
        {
            DataSet ds = dt.DataSet;

            if (ds == null)
            {
                ds = new DataSet {
                    DataSetName = tname.DatabaseName.Name,
                };
                ds.Tables.Add(dt);
            }

            DbSchemaBuilder dbb = new DbSchemaBuilder();

            dbb.AddSchema(ds);

            Add(tname, dbb.DbSchmea.Tables[0]);
        }
Ejemplo n.º 4
0
        public override void ReadSchema(DataSet dbSchema)
        {
            try
            {
                fileLink.ReadXml(data);

                var schema = new DbSchemaBuilder(dbSchema);
                schema.AddSchema(data);

                if (dbSchema.Tables.Count == 0)
                {
                    throw new Exception($"error in creating schema: {fileLink}");
                }
            }
            catch (Exception ex)
            {
                throw new Exception($"bad data source defined {fileLink}, {ex.Message}");
            }
        }