Beispiel #1
0
        static void Main2()
        {
            SimpleStreamDemo demo = new SimpleStreamDemo();
            //const int COUNT = 1000000;
            const bool RUN_LEGACY = true;
            //demo.PerfTestSimple(COUNT, RUN_LEGACY);
            //demo.PerfTestString(COUNT, RUN_LEGACY);
            //demo.PerfTestEmbedded(COUNT, RUN_LEGACY);
            //demo.PerfTestEnum(COUNT, true);
            //demo.PerfTestArray(COUNT, true);

            const int NWIND_COUNT = 1000;

            DAL.Database db = DAL.NWindTests.LoadDatabaseFromFile <DAL.Database>(RuntimeTypeModel.Default);
            Console.WriteLine("Sub-object format: {0}", DAL.Database.SubObjectFormat);
            SimpleStreamDemo.LoadTestItem(db, NWIND_COUNT, NWIND_COUNT, false, false, false, true, false, false, null);

            DatabaseCompat compat = DAL.NWindTests.LoadDatabaseFromFile <DatabaseCompat>(RuntimeTypeModel.Default);

            SimpleStreamDemo.LoadTestItem(compat, NWIND_COUNT, NWIND_COUNT, RUN_LEGACY, false, RUN_LEGACY, true, false, true, null);

            DatabaseCompatRem compatRem = DAL.NWindTests.LoadDatabaseFromFile <DatabaseCompatRem>(RuntimeTypeModel.Default);

            SimpleStreamDemo.LoadTestItem(compatRem, NWIND_COUNT, NWIND_COUNT, true, false, true, false, false, false, null);
        }
Beispiel #2
0
        public void LargePayload()
        {
            DAL.Database      db     = DAL.NWindTests.LoadDatabaseFromFile <DAL.Database>(RuntimeTypeModel.Default);
            DatabaseCompat    compat = Serializer.ChangeType <Database, DatabaseCompat>(db);
            DatabaseCompatRem rem    = Serializer.ChangeType <Database, DatabaseCompatRem>(db);

            AppDomain app = AppDomain.CreateDomain("Isolated", null,
                                                   AppDomain.CurrentDomain.BaseDirectory,
                                                   AppDomain.CurrentDomain.RelativeSearchPath, false);

            try
            {
                DbServer server = (DbServer)app.CreateInstanceAndUnwrap(
                    typeof(DbServer).Assembly.FullName, typeof(DbServer).FullName);

                const int LOOP    = 5;
                Stopwatch dbTimer = Stopwatch.StartNew();
                for (int i = 0; i < LOOP; i++)
                {
                    compat = server.Roundtrip(compat);
                }
                dbTimer.Stop();
                Stopwatch remTimer = Stopwatch.StartNew();
                for (int i = 0; i < LOOP; i++)
                {
                    rem = server.Roundtrip(rem);
                }
                remTimer.Stop();
                // want to aim for twice the speed
                decimal factor = 0.50M;
#if DEBUG
                factor = 1.2M; // be realistic in debug...
#endif
                long target = (long)(dbTimer.ElapsedTicks * factor);
                Assert.LessOrEqual(3, 5, "args wrong way around!");
                Assert.LessOrEqual(remTimer.ElapsedTicks, target);
            }
            finally
            {
                AppDomain.Unload(app);
            }
        }
Beispiel #3
0
        public void TestCallTestMethodWithDatabase()
        {
            using (var server = CreateServer())
                using (var client = new BasicServiceHttpClient())
                {
                    server.Start();
                    DAL.Database request  = NWindTests.LoadDatabaseFromFile <DAL.Database>();
                    DAL.Database response = client.TestMethod(request);

                    Assert.IsNotNull(response);
                    Assert.AreNotSame(request, response);

                    Assert.AreEqual(request.Orders.Count, response.Orders.Count, "Orders");
                    Assert.AreEqual(
                        request.Orders.SelectMany(ord => ord.Lines).Count(),
                        response.Orders.SelectMany(ord => ord.Lines).Count(), "Lines");
                    Assert.AreEqual(
                        request.Orders.SelectMany(ord => ord.Lines).Sum(line => line.Quantity),
                        response.Orders.SelectMany(ord => ord.Lines).Sum(line => line.Quantity), "Quantity");
                    Assert.AreEqual(
                        request.Orders.SelectMany(ord => ord.Lines).Sum(line => line.Quantity * line.UnitPrice),
                        response.Orders.SelectMany(ord => ord.Lines).Sum(line => line.Quantity * line.UnitPrice), "Value");
                }
        }
Beispiel #4
0
 public ManagerBase(string conString, string providerName)
 {
     _db = new Database(conString, providerName);
 }
Beispiel #5
0
        static Database ReadFromDatabase(this NorthwindDataContext ctx, string path) {
            Database db = new Database();
        
            DataLoadOptions opt = new DataLoadOptions();
            opt.AssociateWith<Order>(order => order.Lines);
            ctx.LoadOptions = opt;
            db.Orders.AddRange(ctx.Orders);

            using (FileStream fs = File.Create(path))
            {
                Serializer.Serialize(fs, db);
            }
            return db;            
        }
Beispiel #6
0
 static void WriteToFile(string path, Database database)
 {
     using (Stream fs = File.Create(path))
     {
         Serializer.Serialize(fs, database);
         fs.Close();
     }
 }
Beispiel #7
0
        static void DbMetrics(string caption, Database database)
        {
            int orders = database.Orders.Count;
            int lines = database.Orders.SelectMany(ord => ord.Lines).Count();
            int totalQty = database.Orders.SelectMany(ord => ord.Lines)
                    .Sum(line => line.Quantity);
            decimal totalValue = database.Orders.SelectMany(ord => ord.Lines)
                    .Sum(line => line.Quantity * line.UnitPrice);

            Console.WriteLine("{0}\torders {1}; lines {2}; units {3}; value {4:C}",
                caption, orders, lines, totalQty, totalValue);

        }
Beispiel #8
0
 public DAL.Database TestMethod(DAL.Database request)
 {
     return((DAL.Database)Invoke("TestMethod", request));
 }
Beispiel #9
0
 public void TestMethod(DAL.Database request, Action <DAL.Database> callback)
 {
     InvokeAsync("TestMethod", delegate(AsyncResult result) { callback((DAL.Database)result()); }, request);
 }
Beispiel #10
0
 public DAL.Database TestMethod(DAL.Database request)
 {
     return(request);
 }
Beispiel #11
0
        public DataSource(string table_name, string connection_string, DBEngineType tip, bool s_auto, bool u_auto, bool d_auto, bool i_auto, byte r)
        {
            select = " "; insert = " "; update = " "; delete = " ";
            StringBuilder str = new StringBuilder();
            StringBuilder str_param = new StringBuilder();
            identity = new StringBuilder();
            identities = new ArrayList();

            identities.Clear();
            dbtype = tip;
            con_string = connection_string;
            var db = new Database(tip);
            db.con_string = connection_string;
            if (tip == DBEngineType.MsSql)
                db.text = "select  syscolumns.name as [Column]  from    sysobjects, syscolumns where sysobjects.id = syscolumns.id and   lower(sysobjects.xtype) = 'u'and   sysobjects.name = @t_name order by syscolumns.name";
            else if (tip == DBEngineType.MySql)
                db.text = "SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS  WHERE table_name  = @t_name";
            else if (tip == DBEngineType.DB2)
                db.text = "select colname from  syscat.columns where tabname= @t_name";

            db.add_parameter("@t_name", table_name);

            var db2 = new Database(tip);
            db2.con_string = connection_string;
            if (tip == DBEngineType.MsSql)
                db2.text = "select  syscolumns.name as [Column]  from    sysobjects, syscolumns where sysobjects.id = syscolumns.id and syscolumns.colstat=1 and   lower(sysobjects.xtype) = 'u' and   sysobjects.name = @t_name order by syscolumns.name";
            else if (tip == DBEngineType.MySql)
                db2.text = "SELECT COLUMN_NAME  FROM INFORMATION_SCHEMA.COLUMNS  WHERE table_name  = @t_name and COlUMN_KEY='PRI'";
            else if (tip == DBEngineType.DB2)
                db2.text = "select colname from  syscat.columns where tabname= @t_name and (KEYSEQ is not null)";

            db2.add_parameter("@t_name", table_name);
            foreach (DataRow dare in db2.table.Rows)
            {
                identities.Add(dare[0].ToString());
                if (identity.Length == 0)
                    identity.Append(String.Format("{0}=@{0}", dare[0].ToString()));
                else
                    identity.Append(String.Format(" and {0}=@{0} ", dare[0].ToString()));
            }
            if (identity.Length > 0)
                delete = String.Format("delete from {0} where {1} ", table_name, identity.ToString());
            else
            {

                foreach (DataRow dare in db.table.Rows)
                {
                    identities.Add(dare[0].ToString());
                    if (identity.Length == 0)
                        identity.Append(String.Format("{0}=@{0}", dare[0].ToString()));
                    else
                        identity.Append(String.Format(" and {0}=@{0} ", dare[0].ToString()));
                }
            }
            delete = String.Format("delete from {0} where {1} ", table_name, identity.ToString());

            foreach (DataRow dr in db.table.Rows)
            {
                if (str.Length == 0)
                {
                    str.Append(dr[0]);
                }
                else
                    str.Append("," + dr[0]);
            }
            select = String.Format("select {0} from {1}", str.ToString(), table_name);
            str_param = new StringBuilder();
            str = new StringBuilder();

            foreach (DataRow dr in db.table.Rows)
            {

                if (!identities.Contains(dr[0].ToString()))
                {
                    if (str.Length == 0)
                    {
                        str.Append(dr[0]);
                        str_param.Append(String.Format("@{0}", dr[0]));
                    }
                    else
                    {
                        str.Append("," + dr[0]);
                        str_param.Append(String.Format(",@{0}", dr[0]));
                    }
                }
            }
            columns = str.ToString();

            insert = (String.Format("insert into {1} ({0}) values({2})", str.ToString(), table_name, str_param.ToString()));

            str_param = new StringBuilder();
            str = new StringBuilder();

            foreach (DataRow dr in db.table.Rows)
            {
                if (!identities.Contains(dr[0].ToString()))
                {
                    if (str_param.Length == 0)
                    {
                        str_param.Append(String.Format("{0}=@{0}", dr[0]));
                    }
                    else
                    {
                        str_param.Append(String.Format(",{0}=@{0}", dr[0]));
                    }
                }
            }

            update = (String.Format("update {1} set {2} where {0}", identity, table_name, str_param.ToString()));
            //else
            //    update = (String.Format("update {1} set {2} ", table_name, str_param.ToString()));
        }
Beispiel #12
0
        public DataSource(string table_name, string cstr_name, DBEngineType tip, bool s_auto, bool u_auto, bool d_auto, bool i_auto)
        {
            select = " "; insert = " "; update = " "; delete = " ";
            StringBuilder str = new StringBuilder();
            StringBuilder str_param = new StringBuilder();
            identity = new StringBuilder();
            identities = new ArrayList();
            var db = new Database(DBEngineType.MsSql);
            identities.Clear();
            db.con_name = cstr_name;
            db.text = "select  syscolumns.name as [Column]  from    sysobjects, syscolumns where sysobjects.id = syscolumns.id and   lower(sysobjects.xtype) = 'u'and   sysobjects.name = @t_name order by syscolumns.name";
            db.add_parameter("@t_name", table_name);
            var db2 = new Database(DBEngineType.MsSql);
            db2.con_name = cstr_name;
            db2.text = "select  syscolumns.name as [Column]  from    sysobjects, syscolumns where sysobjects.id = syscolumns.id and syscolumns.colstat=1 and  lower(sysobjects.xtype) = 'u' and   sysobjects.name = @t_name order by syscolumns.name";
            db2.add_parameter("@t_name", table_name);
            foreach (DataRow dare in db2.table.Rows)
            {
                identities.Add(dare[0].ToString());
                if (identity.Length == 0)
                    identity.Append(String.Format("{0}=@{0}", dare[0].ToString()));
                else
                    identity.Append(String.Format(" and {0}=@{0} ", dare[0].ToString()));
            }
            if (identity.Length > 0)
                delete = String.Format("delete from {0} where {1} ", table_name, identity.ToString());
            else
            {
                foreach (DataRow dare in db.table.Rows)
                {
                    identities.Add(dare[0].ToString());
                    if (identity.Length == 0)
                        identity.Append(String.Format("{0}=@{0}", dare[0].ToString()));
                    else
                        identity.Append(String.Format(" and {0}=@{0} ", dare[0].ToString()));
                }
            }
            delete = String.Format("delete from {0} where {1} ", table_name, identity.ToString());

            foreach (DataRow dr in db.table.Rows)
            {
                if (str.Length == 0)
                {
                    str.Append(dr[0]);
                }
                else
                    str.Append("," + dr[0]);
            }
            select = String.Format("select {0} from {1}", str.ToString(), table_name);
            str_param = new StringBuilder();
            str = new StringBuilder();

            foreach (DataRow dr in db.table.Rows)
            {

                if (!identities.Contains(dr[0].ToString()))
                {
                    if (str.Length == 0)
                    {
                        str.Append(dr[0]);
                        str_param.Append(String.Format("@{0}", dr[0]));
                    }
                    else
                    {
                        str.Append("," + dr[0]);
                        str_param.Append(String.Format(",@{0}", dr[0]));
                    }
                }
            }
            columns = str.ToString();

            insert = (String.Format("insert into {1} ({0}) values({2})", str.ToString(), table_name, str_param.ToString()));
            str_param = new StringBuilder();
            str = new StringBuilder();

            foreach (DataRow dr in db.table.Rows)
            {
                if (!identities.Contains(dr[0].ToString()))
                {
                    if (str_param.Length == 0)
                    {
                        str_param.Append(String.Format("{0}=@{0}", dr[0]));
                    }
                    else
                    {
                        str_param.Append(String.Format(",{0}=@{0}", dr[0]));
                    }
                }
            }

            update = (String.Format("update {1} set {2} where {0}", identity, table_name, str_param.ToString()));
            //else
            //    update = (String.Format("update {1} set {2} ", table_name, str_param.ToString()));
        }