Exemple #1
0
        private static void TestChanges()
        {
            Models.IUserEntity entity = new Models.UserEntity();

            Console.WriteLine($"HasChanges: {entity.HasChanges()}");

            entity.UserId      = 100;
            entity.UserId      = 200;
            entity.Name        = "Popeye";
            entity.Namespace   = "Zongsoft";
            entity.Avatar      = ":smile:";
            entity.CreatedTime = DateTime.Now;

            Console.WriteLine("HasChanges(Name, Email): {0}", entity.HasChanges("Email", "Name"));

            entity.TrySetValue("Email", "*****@*****.**");
            entity.TrySetValue("PhoneNumber", "+86.13812345678");

            Console.WriteLine($"HasChanges: {entity.HasChanges()}");
            DisplayChanges(entity);
        }
Exemple #2
0
        private static void Performance(int count)
        {
            Console.WriteLine($"To run performance {count.ToString("#,##0")} times.");
            Console.WriteLine("**********************************");

            Func <Models.UserEntity> creator = new Func <Models.UserEntity>(() => new Models.UserEntity());

            var stopwatch = new Stopwatch();

            stopwatch.Start();

            for (var i = 0; i < count; i++)
            {
                var user = new Models.User()
                {
                    UserId          = (uint)i,
                    Avatar          = ":smile:",
                    Name            = "Name: " + i.ToString(),
                    FullName        = "FullName",
                    Namespace       = "Zongsoft",
                    Status          = (byte)(i % byte.MaxValue),
                    StatusTimestamp = (i % 11 == 0) ? DateTime.Now : DateTime.MinValue,
                    CreatedTime     = DateTime.Now,
                };
            }

            Console.WriteLine($"Native Object: {stopwatch.ElapsedMilliseconds}");

            stopwatch.Restart();

            for (var i = 0; i < count; i++)
            {
                var user = new Models.UserEntity()
                {
                    UserId          = (uint)i,
                    Avatar          = ":smile:",
                    Name            = "Name: " + i.ToString(),
                    FullName        = "FullName",
                    Namespace       = "Zongsoft",
                    Status          = (byte)(i % byte.MaxValue),
                    StatusTimestamp = (i % 11 == 0) ? DateTime.Now : DateTime.MinValue,
                    CreatedTime     = DateTime.Now,
                };
            }

            Console.WriteLine($"Data Entity: {stopwatch.ElapsedMilliseconds}");

            stopwatch.Restart();

            for (var i = 0; i < count; i++)
            {
                var user = creator();

                user.UserId          = (uint)i;
                user.Avatar          = ":smile:";
                user.Name            = "Name: " + i.ToString();
                user.FullName        = "FullName";
                user.Namespace       = "Zongsoft";
                user.Status          = (byte)(i % byte.MaxValue);
                user.StatusTimestamp = (i % 11 == 0) ? DateTime.Now : DateTime.MinValue;
                user.CreatedTime     = DateTime.Now;
            }

            Console.WriteLine($"Data Entity(Creator): {stopwatch.ElapsedMilliseconds}");

            stopwatch.Restart();

            for (var i = 0; i < count; i++)
            {
                Models.IUserEntity user = new Models.UserEntity();

                user.TrySetValue("UserId", (uint)i);
                user.TrySetValue("Avatar", ":smile:");
                user.TrySetValue("Name", "Name: " + i.ToString());
                user.TrySetValue("FullName", "FullName");
                user.TrySetValue("Namespace", "Zongsoft");
                user.TrySetValue("Status", (byte)(i % byte.MaxValue));
                user.TrySetValue("StatusTimestamp", (i % 11 == 0) ? DateTime.Now : DateTime.MinValue);
                user.TrySetValue("CreatedTime", DateTime.Now);
            }

            Console.WriteLine($"Data Entity(TrySet): {stopwatch.ElapsedMilliseconds}");
        }