From 9fed8d43c48730845fb4808d61e2b226125e0425 Mon Sep 17 00:00:00 2001 From: Anastasia Date: Thu, 18 May 2023 23:07:48 +0400 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D1=8B=20=D1=82=D0=B5=D1=81=D1=82=D1=8B.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- RouteGuide/RouteGuide/FormMain.Designer.cs | 12 +- RouteGuide/RouteGuide/FormMain.cs | 10 ++ RouteGuide/RouteGuide/FormTests.Designer.cs | 166 ++++++++++++++++++ RouteGuide/RouteGuide/FormTests.cs | 57 ++++++ RouteGuide/RouteGuide/FormTests.resx | 60 +++++++ RouteGuide/RouteGuide/Program.cs | 2 +- .../BusinessLogic/RouteLogic.cs | 10 ++ .../BusinessLogicContracts/IRouteLogic.cs | 3 + .../StoragesModels/IRouteStorage.cs | 3 + .../Implements/RouteStorage.cs | 73 ++++++++ 10 files changed, 394 insertions(+), 2 deletions(-) create mode 100644 RouteGuide/RouteGuide/FormTests.Designer.cs create mode 100644 RouteGuide/RouteGuide/FormTests.cs create mode 100644 RouteGuide/RouteGuide/FormTests.resx diff --git a/RouteGuide/RouteGuide/FormMain.Designer.cs b/RouteGuide/RouteGuide/FormMain.Designer.cs index 411795a..ff00308 100644 --- a/RouteGuide/RouteGuide/FormMain.Designer.cs +++ b/RouteGuide/RouteGuide/FormMain.Designer.cs @@ -33,6 +33,7 @@ this.транспортToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.остановкиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.маршрутыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.тестыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.menuStrip.SuspendLayout(); this.SuspendLayout(); // @@ -43,7 +44,8 @@ this.типыТранспортаToolStripMenuItem, this.транспортToolStripMenuItem, this.остановкиToolStripMenuItem, - this.маршрутыToolStripMenuItem}); + this.маршрутыToolStripMenuItem, + this.тестыToolStripMenuItem}); this.menuStrip.Location = new System.Drawing.Point(0, 0); this.menuStrip.Name = "menuStrip"; this.menuStrip.Size = new System.Drawing.Size(800, 33); @@ -78,6 +80,13 @@ this.маршрутыToolStripMenuItem.Text = "Маршруты"; this.маршрутыToolStripMenuItem.Click += new System.EventHandler(this.МаршрутыToolStripMenuItem_Click); // + // тестыToolStripMenuItem + // + this.тестыToolStripMenuItem.Name = "тестыToolStripMenuItem"; + this.тестыToolStripMenuItem.Size = new System.Drawing.Size(74, 29); + this.тестыToolStripMenuItem.Text = "Тесты"; + this.тестыToolStripMenuItem.Click += new System.EventHandler(this.ТестыToolStripMenuItem_Click); + // // FormMain // this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); @@ -101,5 +110,6 @@ private ToolStripMenuItem транспортToolStripMenuItem; private ToolStripMenuItem остановкиToolStripMenuItem; private ToolStripMenuItem маршрутыToolStripMenuItem; + private ToolStripMenuItem тестыToolStripMenuItem; } } \ No newline at end of file diff --git a/RouteGuide/RouteGuide/FormMain.cs b/RouteGuide/RouteGuide/FormMain.cs index 9d7a5c4..acdc3db 100644 --- a/RouteGuide/RouteGuide/FormMain.cs +++ b/RouteGuide/RouteGuide/FormMain.cs @@ -51,5 +51,15 @@ namespace RouteGuide form.ShowDialog(); } } + + private void ToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormTests)); + + if (service is FormTests form) + { + form.ShowDialog(); + } + } } } \ No newline at end of file diff --git a/RouteGuide/RouteGuide/FormTests.Designer.cs b/RouteGuide/RouteGuide/FormTests.Designer.cs new file mode 100644 index 0000000..72e714b --- /dev/null +++ b/RouteGuide/RouteGuide/FormTests.Designer.cs @@ -0,0 +1,166 @@ +namespace RouteGuide +{ + partial class FormTests + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.label3 = new System.Windows.Forms.Label(); + this.numericUpDownInsert = new System.Windows.Forms.NumericUpDown(); + this.numericUpDownRead = new System.Windows.Forms.NumericUpDown(); + this.textBoxInsertTime = new System.Windows.Forms.TextBox(); + this.buttonInsertTest = new System.Windows.Forms.Button(); + this.buttonReadTest = new System.Windows.Forms.Button(); + this.label7 = new System.Windows.Forms.Label(); + this.textBoxReadTime = new System.Windows.Forms.TextBox(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownInsert)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownRead)).BeginInit(); + this.SuspendLayout(); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(12, 9); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(165, 25); + this.label1.TabIndex = 0; + this.label1.Text = "Кол-во элементов:"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(12, 67); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(139, 25); + this.label2.TabIndex = 1; + this.label2.Text = "Время запроса:"; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(321, 9); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(165, 25); + this.label3.TabIndex = 2; + this.label3.Text = "Кол-во элементов:"; + // + // numericUpDownInsert + // + this.numericUpDownInsert.Location = new System.Drawing.Point(183, 7); + this.numericUpDownInsert.Name = "numericUpDownInsert"; + this.numericUpDownInsert.Size = new System.Drawing.Size(119, 31); + this.numericUpDownInsert.TabIndex = 6; + // + // numericUpDownRead + // + this.numericUpDownRead.Location = new System.Drawing.Point(492, 7); + this.numericUpDownRead.Name = "numericUpDownRead"; + this.numericUpDownRead.Size = new System.Drawing.Size(119, 31); + this.numericUpDownRead.TabIndex = 7; + // + // textBoxInsertTime + // + this.textBoxInsertTime.Location = new System.Drawing.Point(183, 64); + this.textBoxInsertTime.Name = "textBoxInsertTime"; + this.textBoxInsertTime.Size = new System.Drawing.Size(119, 31); + this.textBoxInsertTime.TabIndex = 10; + // + // buttonInsertTest + // + this.buttonInsertTest.Location = new System.Drawing.Point(96, 127); + this.buttonInsertTest.Name = "buttonInsertTest"; + this.buttonInsertTest.Size = new System.Drawing.Size(112, 34); + this.buttonInsertTest.TabIndex = 12; + this.buttonInsertTest.Text = "INSERT"; + this.buttonInsertTest.UseVisualStyleBackColor = true; + this.buttonInsertTest.Click += new System.EventHandler(this.ButtonInsertTest_Click); + // + // buttonReadTest + // + this.buttonReadTest.Location = new System.Drawing.Point(422, 127); + this.buttonReadTest.Name = "buttonReadTest"; + this.buttonReadTest.Size = new System.Drawing.Size(112, 34); + this.buttonReadTest.TabIndex = 13; + this.buttonReadTest.Text = "READ"; + this.buttonReadTest.UseVisualStyleBackColor = true; + this.buttonReadTest.Click += new System.EventHandler(this.ButtonReadTest_Click); + // + // label7 + // + this.label7.AutoSize = true; + this.label7.Location = new System.Drawing.Point(321, 67); + this.label7.Name = "label7"; + this.label7.Size = new System.Drawing.Size(139, 25); + this.label7.TabIndex = 15; + this.label7.Text = "Время запроса:"; + // + // textBoxReadTime + // + this.textBoxReadTime.Location = new System.Drawing.Point(492, 64); + this.textBoxReadTime.Name = "textBoxReadTime"; + this.textBoxReadTime.Size = new System.Drawing.Size(119, 31); + this.textBoxReadTime.TabIndex = 16; + // + // FormTests + // + this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(626, 187); + this.Controls.Add(this.textBoxReadTime); + this.Controls.Add(this.label7); + this.Controls.Add(this.buttonReadTest); + this.Controls.Add(this.buttonInsertTest); + this.Controls.Add(this.textBoxInsertTime); + this.Controls.Add(this.numericUpDownRead); + this.Controls.Add(this.numericUpDownInsert); + this.Controls.Add(this.label3); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.Name = "FormTests"; + this.Text = "Тесты"; + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownInsert)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownRead)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label label1; + private Label label2; + private Label label3; + private NumericUpDown numericUpDownInsert; + private NumericUpDown numericUpDownRead; + private TextBox textBoxInsertTime; + private Button buttonInsertTest; + private Button buttonReadTest; + private Label label7; + private TextBox textBoxReadTime; + } +} \ No newline at end of file diff --git a/RouteGuide/RouteGuide/FormTests.cs b/RouteGuide/RouteGuide/FormTests.cs new file mode 100644 index 0000000..d6a0f41 --- /dev/null +++ b/RouteGuide/RouteGuide/FormTests.cs @@ -0,0 +1,57 @@ +using RouteGuideContracts.BusinessLogicContracts; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace RouteGuide +{ + public partial class FormTests : Form + { + private readonly IRouteLogic _routeLogic; + + public FormTests(IRouteLogic routeLogic) + { + InitializeComponent(); + + _routeLogic = routeLogic; + numericUpDownInsert.Minimum = 0; + numericUpDownInsert.Maximum = 1000; + numericUpDownRead.Minimum = 0; + numericUpDownRead.Maximum = 1000; + + } + + private void ButtonInsertTest_Click(object sender, EventArgs e) + { + try + { + var result = _routeLogic.TestInsertList(Convert.ToInt32(numericUpDownInsert.Value)); + + textBoxInsertTime.Text = result; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonReadTest_Click(object sender, EventArgs e) + { + try + { + var result = _routeLogic.TestReadList(Convert.ToInt32(numericUpDownRead.Value)); + textBoxReadTime.Text = result; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } +} diff --git a/RouteGuide/RouteGuide/FormTests.resx b/RouteGuide/RouteGuide/FormTests.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/RouteGuide/RouteGuide/FormTests.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/RouteGuide/RouteGuide/Program.cs b/RouteGuide/RouteGuide/Program.cs index 4eadeae..0ff5abc 100644 --- a/RouteGuide/RouteGuide/Program.cs +++ b/RouteGuide/RouteGuide/Program.cs @@ -54,7 +54,7 @@ namespace RouteGuide services.AddTransient(); services.AddTransient(); services.AddTransient(); - //services.AddTransient(); + services.AddTransient(); } } diff --git a/RouteGuide/RouteGuideBusinessLogic/BusinessLogic/RouteLogic.cs b/RouteGuide/RouteGuideBusinessLogic/BusinessLogic/RouteLogic.cs index 7241558..7bde61e 100644 --- a/RouteGuide/RouteGuideBusinessLogic/BusinessLogic/RouteLogic.cs +++ b/RouteGuide/RouteGuideBusinessLogic/BusinessLogic/RouteLogic.cs @@ -110,5 +110,15 @@ namespace RouteGuideBusinessLogic.BusinessLogic throw new InvalidOperationException("Route с таким названием уже есть"); } } + + public string TestInsertList(int num) + { + return _routeStorage.TestInsertList(num); + } + + public string TestReadList(int num) + { + return _routeStorage.TestReadList(num); + } } } diff --git a/RouteGuide/RouteGuideContracts/BusinessLogicContracts/IRouteLogic.cs b/RouteGuide/RouteGuideContracts/BusinessLogicContracts/IRouteLogic.cs index 32c3bdf..82d8c1b 100644 --- a/RouteGuide/RouteGuideContracts/BusinessLogicContracts/IRouteLogic.cs +++ b/RouteGuide/RouteGuideContracts/BusinessLogicContracts/IRouteLogic.cs @@ -18,5 +18,8 @@ namespace RouteGuideContracts.BusinessLogicContracts bool Create(RouteBindingModel model); bool Update(RouteBindingModel model); bool Delete(RouteBindingModel model); + + string TestInsertList(int num); + string TestReadList(int num); } } diff --git a/RouteGuide/RouteGuideContracts/StoragesModels/IRouteStorage.cs b/RouteGuide/RouteGuideContracts/StoragesModels/IRouteStorage.cs index f643bb5..a9add38 100644 --- a/RouteGuide/RouteGuideContracts/StoragesModels/IRouteStorage.cs +++ b/RouteGuide/RouteGuideContracts/StoragesModels/IRouteStorage.cs @@ -20,5 +20,8 @@ namespace RouteGuideContracts.StoragesModels RouteViewModel? Insert(RouteBindingModel model); RouteViewModel? Update(RouteBindingModel model); RouteViewModel? Delete(RouteBindingModel model); + + string TestInsertList(int num); + string TestReadList(int num); } } diff --git a/RouteGuide/RouteGuideDatabaseImplement/Implements/RouteStorage.cs b/RouteGuide/RouteGuideDatabaseImplement/Implements/RouteStorage.cs index 81bcf1c..a8ed4e7 100644 --- a/RouteGuide/RouteGuideDatabaseImplement/Implements/RouteStorage.cs +++ b/RouteGuide/RouteGuideDatabaseImplement/Implements/RouteStorage.cs @@ -108,5 +108,78 @@ namespace RouteGuideDatabaseImplements.Implements throw; } } + + public string TestInsertList(int num) + { + var context = new RouteGuideDatabase(); + Stopwatch stopwatch = new(); + Random rnd = new Random(); + long[] res = new long[num * 2]; + + + for (int i = 0; i < num; ++i) + { + int rndId = rnd.Next(); + var model = new StopBindingModel + { + Id = rndId, + Name = "Остановка " + 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 = "Maршрут №" + rndId.ToString(), + }; + 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) + { + var context = new RouteGuideDatabase(); + Stopwatch stopwatch = new(); + + long[] res = new long[num]; + + for (int i = 0; i < num; i++) + { + + stopwatch.Start(); + List list = context.Routes.Include(x => x.Stops).ThenInclude(x => x.Stop).ToList().Select(x => x.GetViewModel).ToList(); + 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(); + } } }