示例#1
0
    public EntityDefinitionFactoryTests_DefaultModules()
    {
        var entityModules = new IEntityModule[]
        {
            new AttributeBasedEntityModule(),
            new CoreEntityModule(),
            new CrudAdminEntityModule(),
        };

        var fieldModules = new IEntityFieldModule[]
        {
            new AttributeBasedEntityFieldModule(),
            new CoreEntityFieldModule(),
            new CrudAdminEntityFieldModule(),
        };

        factory = new EntityDefinitionFactory(entityModules, fieldModules);
    }
示例#2
0
        static void Main(string[] args)
        {
            IDataComponentFactory connectionFactory;
            var entFactory = new EntityDefinitionFactory();
            var codeGen    = new CSharpCodeGen();

            //Add your SQLServer Connection String as environment variable "TESTCONNSTRING"
            connectionFactory = new SqlServerDataComponentFactory(Environment.GetEnvironmentVariable("TESTCONNSTRING"));

            var prm = new UspMOBGetSyncData()
            {
                ClientId          = "CAFEFRESH",
                LastSync          = DateTime.Now,
                UserId            = 44720,
                PreviousSyncApiId = 0.0f
            };

            using (var proc = new ReadProcedure(connectionFactory))
            {
                var     readResult = proc.Read(prm);
                DataSet ds         = readResult.DataSet;

                var tables = new List <TableDefinition>();

                var rows     = ds.Tables[ds.Tables.Count - 1];
                var manifest = ds.Tables[ds.Tables.Count - 1].Rows.ToArray <Models.Manifest>();
                foreach (var manifestTbl in manifest)
                {
                    var dataTable   = ds.Tables[manifestTbl.table_index];
                    var outputTable = entFactory.ToTable(dataTable, manifestTbl.table_name);
                    var pkeyColumn  = outputTable.Columns.Where(col => col.Name == manifestTbl.primary_key).FirstOrDefault();
                    if (pkeyColumn != null)
                    {
                        pkeyColumn.IsPrimaryKey = true;
                    }
                    tables.Add(outputTable);
                }

                System.IO.File.WriteAllText("L:\\foo.cs", codeGen.ToFile(tables, "GSP.X.Repository.Local", true));
            }

            Console.ReadKey();
        }
示例#3
0
 public EntityDefinitionFactoryTests_NoModules()
 {
     factory = new EntityDefinitionFactory(new IEntityModule[0], new IEntityFieldModule[0]);
 }
示例#4
0
        public void FullTest()
        {
            IDataComponentFactory connectionFactory;
            IDataComponentFactory sqliteConnectionFactory;
            var entFactory = new EntityDefinitionFactory();

            var outputFileName          = OUTPUT_FILENAME;
            var sqlLiteConnectionString = $"Data Source={outputFileName}";

            if (System.IO.File.Exists(outputFileName))
            {
                //   System.IO.File.Delete(outputFileName);
            }

            //Add your SQLServer Connection string as environment variable "TESTCONNSTRING"
            connectionFactory       = new SqlServerDataComponentFactory(Environment.GetEnvironmentVariable("TESTCONNSTRING"));
            sqliteConnectionFactory = new SqliteDataComponentFactory(sqlLiteConnectionString);

            var prm = new SyncProcParams()
            {
                ClientId          = "CAFEFRESH",
                LastSync          = DateTime.Now,
                UserId            = 44720,
                PreviousSyncApiId = 0.0f
            };

            using (var outputStream = new MemoryStream())
            {
                using (var proc = new ReadProcedure(connectionFactory))
                {
                    var readResult = proc.Read(prm);
                    var ds         = readResult.DataSet;

                    var rows     = ds.Tables[ds.Tables.Count - 1];
                    var manifest = ds.Tables[ds.Tables.Count - 1].Rows.ToArray <Manifest>();

                    var binaryWriter = new BinaryWriter(outputStream);
                    var count        = manifest.Length;
                    binaryWriter.Write(count);

                    foreach (var manifestTbl in manifest)
                    {
                        var dataTable   = ds.Tables[manifestTbl.table_index];
                        var outputTable = entFactory.ToTable(dataTable, manifestTbl.table_name);
                        var pkeyColumn  = outputTable.Columns.Where(col => col.Name == manifestTbl.primary_key).FirstOrDefault();
                        if (pkeyColumn != null)
                        {
                            pkeyColumn.IsPrimaryKey = true;
                        }
                        outputStream.Write(outputTable);
                        binaryWriter.Write(dataTable.Rows.Count);
                        binaryWriter.WriteToStream(outputTable, dataTable.Rows);
                    }
                }

                outputStream.Seek(0, SeekOrigin.Begin);

                var recordCount = 0;

                var sqliteConnection = sqliteConnectionFactory.Open();

                var binaryReader = new BinaryReader(outputStream);
                var tableCount   = binaryReader.ReadInt32();
                for (var idx = 0; idx < tableCount; ++idx)
                {
                    var batchWriter = new BatchWriter();

                    var tbl = outputStream.ReadFromStream <TableDefinition>();

                    batchWriter.Init(tbl, sqliteConnection, truncate: true);
                    batchWriter.Begin();
                    var rowCount = binaryReader.ReadInt32();
                    for (var rowIdx = 0; rowIdx < rowCount; ++rowIdx)
                    {
                        var values = binaryReader.ReadRowFromStream(tbl);
                        batchWriter.Execute(values);
                        recordCount++;
                        /* Code to write the object array  to SQLite in a transaction */
                    }
                    batchWriter.End();
                }
            }
        }