CreateUserAsync() public method

public CreateUserAsync ( int uid, TrackableUser user ) : Task
uid int
user TrackableUser
return Task
Example #1
0
        public static async Task DuplicateAsync(bool parallel)
        {
            var mongoDriver = new MongoDbDriver(
                ConfigurationManager.ConnectionStrings["MongoDb"].ConnectionString, "User");

            var mongoDriver2 = new MongoDbDriver(
                ConfigurationManager.ConnectionStrings["MongoDb"].ConnectionString, "User2");

            await mongoDriver2.Database.DropCollectionAsync("User2");

            var timer = new Stopwatch();

            timer.Start();

            var tasks = Enumerable.Range(0, 128).Select(async i =>
            {
                var uids = await LoadUids(mongoDriver.Collection, i);
                foreach (var uid in uids)
                {
                    var user = await mongoDriver.LoadUserAsync(uid);
                    await mongoDriver2.CreateUserAsync(uid, user);
                }
                return(uids.Count);
            });

            var totalCount = await WaitForComplete(tasks, parallel);

            var elapsed   = timer.Elapsed.TotalSeconds;
            var rowPerSec = totalCount / timer.Elapsed.TotalSeconds;

            Console.WriteLine($"Elapsed: {(int)elapsed}s RowPerSec: {(int)rowPerSec}");
        }
Example #2
0
        public static async Task MigrateAsync()
        {
            var sqlConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["SqlDb"].ConnectionString);

            sqlConnection.Open();
            var sqlDriver = new SqlDriver(MsSqlProvider.Instance, sqlConnection);

            var mongoDriver = new MongoDbDriver(
                ConfigurationManager.ConnectionStrings["MongoDb"].ConnectionString, "User");

            mongoDriver.Database.DropCollectionAsync("User").Wait();

            for (int i = 0; i < 128; i++)
            {
                var uid0 = i * 0x1000000;
                var uid1 = uid0 + 0xFFFFFF;

                var uids = new List <int>();

                mongoDriver.Database.GetCollection <BsonDocument>("User");

                var sql = $"SELECT [Uid] FROM tblUser WHERE [Uid] BETWEEN ${uid0} AND ${uid1}";
                using (var command = new SqlCommand(sql, sqlConnection))
                {
                    using (var reader = command.ExecuteReader())
                    {
                        while (await reader.ReadAsync())
                        {
                            var uid = (int)reader.GetValue(0);
                            uids.Add(uid);
                        }
                    }
                }

                var timer = new Stopwatch();
                timer.Start();
                Console.Write($"[Step ({i + 1}/128)] Count:{uids.Count} ");
                foreach (var uid in uids)
                {
                    var user = await sqlDriver.LoadUserAsync(uid);

                    await mongoDriver.CreateUserAsync(uid, user);
                }
                timer.Stop();

                var elapsed = timer.Elapsed.TotalSeconds;
                if (uids.Count > 0 && elapsed > 0)
                {
                    var rowPerSec = uids.Count / timer.Elapsed.TotalSeconds;
                    Console.WriteLine($"Elapsed: {(int)elapsed}s RowPerSec: {(int)rowPerSec}");
                }
                else
                {
                    Console.WriteLine();
                }
            }
        }
        public static async Task MigrateAsync()
        {
            var sqlConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["SqlDb"].ConnectionString);
            sqlConnection.Open();
            var sqlDriver = new SqlDriver(MsSqlProvider.Instance, sqlConnection);

            var mongoDriver = new MongoDbDriver(
                ConfigurationManager.ConnectionStrings["MongoDb"].ConnectionString, "User");

            mongoDriver.Database.DropCollectionAsync("User").Wait();

            for (int i = 0; i < 128; i++)
            {
                var uid0 = i * 0x1000000;
                var uid1 = uid0 + 0xFFFFFF;

                var uids = new List<int>();

                mongoDriver.Database.GetCollection<BsonDocument>("User");

                var sql = $"SELECT [Uid] FROM tblUser WHERE [Uid] BETWEEN ${uid0} AND ${uid1}";
                using (var command = new SqlCommand(sql, sqlConnection))
                {
                    using (var reader = command.ExecuteReader())
                    {
                        while (await reader.ReadAsync())
                        {
                            var uid = (int)reader.GetValue(0);
                            uids.Add(uid);
                        }
                    }
                }

                var timer = new Stopwatch();
                timer.Start();
                Console.Write($"[Step ({i + 1}/128)] Count:{uids.Count} ");
                foreach (var uid in uids)
                {
                    var user = await sqlDriver.LoadUserAsync(uid);
                    await mongoDriver.CreateUserAsync(uid, user);
                }
                timer.Stop();

                var elapsed = timer.Elapsed.TotalSeconds;
                if (uids.Count > 0 && elapsed > 0)
                {
                    var rowPerSec = uids.Count / timer.Elapsed.TotalSeconds;
                    Console.WriteLine($"Elapsed: {(int)elapsed}s RowPerSec: {(int)rowPerSec}");
                }
                else
                {
                    Console.WriteLine();
                }
            }
        }
Example #4
0
        public static async Task DuplicateAsync(bool parallel)
        {
            var mongoDriver = new MongoDbDriver(
                ConfigurationManager.ConnectionStrings["MongoDb"].ConnectionString, "User");

            var mongoDriver2 = new MongoDbDriver(
                ConfigurationManager.ConnectionStrings["MongoDb"].ConnectionString, "User2");

            await mongoDriver2.Database.DropCollectionAsync("User2");

            var timer = new Stopwatch();
            timer.Start();

            var tasks = Enumerable.Range(0, 128).Select(async i =>
            {
                var uids = await LoadUids(mongoDriver.Collection, i);
                foreach (var uid in uids)
                {
                    var user = await mongoDriver.LoadUserAsync(uid);
                    await mongoDriver2.CreateUserAsync(uid, user);
                }
                return uids.Count;
            });

            var totalCount = await WaitForComplete(tasks, parallel);

            var elapsed = timer.Elapsed.TotalSeconds;
            var rowPerSec = totalCount / timer.Elapsed.TotalSeconds;
            Console.WriteLine($"Elapsed: {(int)elapsed}s RowPerSec: {(int)rowPerSec}");
        }