From 75a6b87680fcc15dbbb5ae28ec800bf2adbea2a8 Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Fri, 5 May 2023 23:52:14 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BE=D1=81=D1=82=D0=B0=D0=BB=D0=BE=D1=81?= =?UTF-8?q?=D1=8C=20=D0=BC=D0=B0=D0=BB=D0=BE=D1=81=D1=82=D1=8C=20=D0=BF?= =?UTF-8?q?=D0=BE=D1=84=D0=B8=D0=BA=D1=81=D0=B8=D1=82=D1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BusinessLogic/BusinessLogic/RouteLogic.cs | 2 +- TransportGuide/FormTests.cs | 28 +++++------ .../Implements/RouteStorage.cs | 49 ++++++++++++++++++- 3 files changed, 61 insertions(+), 18 deletions(-) diff --git a/BusinessLogic/BusinessLogic/RouteLogic.cs b/BusinessLogic/BusinessLogic/RouteLogic.cs index ed08761..b849b7a 100644 --- a/BusinessLogic/BusinessLogic/RouteLogic.cs +++ b/BusinessLogic/BusinessLogic/RouteLogic.cs @@ -78,7 +78,7 @@ namespace BusinessLogic.BusinessLogic public string TestInsertList(int num) { - throw new NotImplementedException(); + return _routeStorage.TestInsertList(num); } public string TestReadList(int num) diff --git a/TransportGuide/FormTests.cs b/TransportGuide/FormTests.cs index d64b79c..7f563ce 100644 --- a/TransportGuide/FormTests.cs +++ b/TransportGuide/FormTests.cs @@ -19,31 +19,27 @@ namespace TransportGuide public FormTests(IRouteLogic routeLogic)//IUserLogic userLogic, ITopicLogic topicLogic, IMessageLogic messageLogic) { InitializeComponent(); - //_userLogic = userLogic; - //_topicLogic = topicLogic; _routeLogic= routeLogic; - numericUpDownInsert.Minimum = 0; + numericUpDownInsert.Minimum = 1; numericUpDownInsert.Maximum = 1000000; - numericUpDownRead.Minimum = 0; + numericUpDownRead.Minimum = 1; numericUpDownRead.Maximum = 1000000; - numericUpDownJoin.Minimum = 0; + numericUpDownJoin.Minimum = 1; numericUpDownJoin.Maximum = 1000000; } private void buttonInsertTest_Click(object sender, EventArgs e) { - //try - //{ - // var result = _messageLogic.TestInsertList(Convert.ToInt32(numericUpDownInsert.Value), - // _userLogic.ReadList(null) ?? new(), - // _topicLogic.ReadList(null) ?? new()); + try + { + var result = _routeLogic.TestInsertList(Convert.ToInt32(numericUpDownInsert.Value)); - // textBoxInsertTime.Text = result; - //} - //catch (Exception ex) - //{ - // MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - //} + textBoxInsertTime.Text = result; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } } private void buttonReadTest_Click(object sender, EventArgs e) diff --git a/TransportGuideDatabaseImplements/Implements/RouteStorage.cs b/TransportGuideDatabaseImplements/Implements/RouteStorage.cs index 923bba2..623b3c8 100644 --- a/TransportGuideDatabaseImplements/Implements/RouteStorage.cs +++ b/TransportGuideDatabaseImplements/Implements/RouteStorage.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Diagnostics; using System.Linq; +using System.Net; using System.Text; using System.Threading.Tasks; using TransportGuideContracts.BindingModels; @@ -82,7 +83,53 @@ namespace TransportGuideDatabaseImplements.Implements public string TestInsertList(int num) { - throw new NotImplementedException(); + var context = new TransportGuideDB(); + Stopwatch stopwatch = new(); + Random rnd = new Random(); + long[] res = new long[num * 2]; + List _types = context.TransportTypes.ToList().Select(x => x.GetViewModel).ToList(); + + + for (int i = 0; i < num; ++i) + { + int rndId = rnd.Next(); + var model = new StopBindingModel + { + Id = rndId, + Name = "Stop" + rndId.ToString(), + }; + context.Stops.Add(Stop.Create(model)); + stopwatch.Start(); + context.SaveChanges(); + stopwatch.Stop(); + res[i] = stopwatch.ElapsedMilliseconds; + } + List _stops = context.Stops.Select(x => x.GetViewModel).ToList(); + + for (int i = 0; i < num; ++i) + { + int rndId = rnd.Next(); + var model = new RouteBindingModel + { + Id = rndId, + Name = "Route" + rndId.ToString(), + IP = "IP" + rndId.ToString(), + TransportTypeId = _types[rnd.Next(_types.Count)].Id + }; + context.Routes.Add(Route.Create(context, model)); + stopwatch.Start(); + context.SaveChanges(); + stopwatch.Stop(); + res[i] = stopwatch.ElapsedMilliseconds; + } + + long sum = 0; + for (int i = 0; i < num; i++) + { + sum += res[i]; + } + int result = Convert.ToInt32(sum / num); + return result.ToString(); } public string TestReadList(int num)