Example #1
0
        public async Task CommandProcedure_ExecuteAsync_ParameterContextWithNullableInputAndOutputParams()
        {
            var procedureContext = new InputOutputProcedureContext();

            var dataComponentFactory = new SqlServerDataComponentFactory(new SqlServerTransientRetryPolicy(60, TimeSpan.FromSeconds(30)), AppState.ConnectionString);

            using (var connection = dataComponentFactory.Open())
                using (var procedure = new CommandProcedure(connection, dataComponentFactory))
                {
                    var result = await procedure.ExecuteAsync(procedureContext);

                    Assert.AreEqual(-1, result);
                }

            Assert.IsTrue(procedureContext.InDate.HasValue);
            Assert.IsTrue(procedureContext.OutDate.HasValue);
            Assert.AreEqual(procedureContext.InDate.Value.ToString(), procedureContext.OutDate.Value.ToString());
        }
Example #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();
        }
Example #3
0
        public void FullTest()
        {
            IDataComponentFactory connectionFactory;
            IDataComponentFactory sqliteConnectionFactory;
            var entFactory = new EntityFactory();

            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 <Table>();

                    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();
                }
            }
        }