From e949397d5ad09e7d475a3fc2395c23cb9fd8a620 Mon Sep 17 00:00:00 2001 From: ArtemEmelyanov Date: Tue, 2 May 2023 12:30:31 +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=D0=BE=20=D0=B0=D0=B2=D1=82=D0=BE=D0=B7=D0=B0=D0=BF=D0=BE?= =?UTF-8?q?=D0=BB=D0=BD=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B8=20=D1=82=D0=B5?= =?UTF-8?q?=D1=81=D1=82=D1=8B=20=D0=B7=D0=B0=D0=BC=D0=B5=D1=80=D0=BE=D0=B2?= =?UTF-8?q?=20=D0=B2=D1=80=D0=B5=D0=BC=D0=B5=D0=BD=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Forum/Forum/FormMain.Designer.cs | 12 +- Forum/Forum/FormMain.cs | 10 + Forum/Forum/FormRole.Designer.cs | 33 ++- Forum/Forum/FormRole.cs | 14 ++ Forum/Forum/FormTests.Designer.cs | 229 ++++++++++++++++++ Forum/Forum/FormTests.cs | 75 ++++++ Forum/Forum/FormTests.resx | 60 +++++ Forum/Forum/FormUser.Designer.cs | 64 +++-- Forum/Forum/FormUser.cs | 12 + Forum/Forum/Program.cs | 1 + Forum/ForumBusinessLogic/MessageLogic.cs | 13 + Forum/ForumBusinessLogic/RoleLogic.cs | 5 + Forum/ForumBusinessLogic/UserLogic.cs | 5 + .../BusinessLogicContracts/IMessageLogic.cs | 3 + .../BusinessLogicContracts/IRoleLogic.cs | 1 + .../BusinessLogicContracts/IUserLogic.cs | 1 + .../StoragesContracts/IMessageStorage.cs | 3 + .../StoragesContracts/IRoleStorage.cs | 1 + .../StoragesContracts/IUserStorage.cs | 1 + .../Implements/MessageStorage.cs | 76 ++++++ Forum/ForumDatabase/Implements/RoleStorage.cs | 15 ++ Forum/ForumDatabase/Implements/UserStorage.cs | 20 ++ 22 files changed, 623 insertions(+), 31 deletions(-) create mode 100644 Forum/Forum/FormTests.Designer.cs create mode 100644 Forum/Forum/FormTests.cs create mode 100644 Forum/Forum/FormTests.resx diff --git a/Forum/Forum/FormMain.Designer.cs b/Forum/Forum/FormMain.Designer.cs index e4782be..917641f 100644 --- a/Forum/Forum/FormMain.Designer.cs +++ b/Forum/Forum/FormMain.Designer.cs @@ -36,6 +36,7 @@ this.buttonCreate = new System.Windows.Forms.Button(); this.buttonDelete = new System.Windows.Forms.Button(); this.buttonUpdate = new System.Windows.Forms.Button(); + this.тестыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.menuStrip1.SuspendLayout(); this.SuspendLayout(); @@ -57,7 +58,8 @@ this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.ролиToolStripMenuItem, this.пользователиToolStripMenuItem, - this.категорииToolStripMenuItem}); + this.категорииToolStripMenuItem, + this.тестыToolStripMenuItem}); this.menuStrip1.Location = new System.Drawing.Point(0, 0); this.menuStrip1.Name = "menuStrip1"; this.menuStrip1.Padding = new System.Windows.Forms.Padding(5, 2, 0, 2); @@ -116,6 +118,13 @@ this.buttonUpdate.UseVisualStyleBackColor = true; this.buttonUpdate.Click += new System.EventHandler(this.buttonUpdate_Click); // + // тестыToolStripMenuItem + // + this.тестыToolStripMenuItem.Name = "тестыToolStripMenuItem"; + this.тестыToolStripMenuItem.Size = new System.Drawing.Size(51, 20); + this.тестыToolStripMenuItem.Text = "Тесты"; + this.тестыToolStripMenuItem.Click += new System.EventHandler(this.тестыToolStripMenuItem_Click); + // // FormMain // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); @@ -149,5 +158,6 @@ private Button buttonCreate; private Button buttonDelete; private Button buttonUpdate; + private ToolStripMenuItem тестыToolStripMenuItem; } } \ No newline at end of file diff --git a/Forum/Forum/FormMain.cs b/Forum/Forum/FormMain.cs index a4a617d..f131a73 100644 --- a/Forum/Forum/FormMain.cs +++ b/Forum/Forum/FormMain.cs @@ -133,5 +133,15 @@ namespace Forum } } } + + 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/Forum/Forum/FormRole.Designer.cs b/Forum/Forum/FormRole.Designer.cs index b3df60b..0f47b2b 100644 --- a/Forum/Forum/FormRole.Designer.cs +++ b/Forum/Forum/FormRole.Designer.cs @@ -31,20 +31,23 @@ this.textBoxRoleName = new System.Windows.Forms.TextBox(); this.buttonSave = new System.Windows.Forms.Button(); this.buttonCancel = new System.Windows.Forms.Button(); + this.buttonAddRoles = new System.Windows.Forms.Button(); this.SuspendLayout(); // // textBoxRoleName // - this.textBoxRoleName.Location = new System.Drawing.Point(12, 12); + this.textBoxRoleName.Location = new System.Drawing.Point(10, 9); + this.textBoxRoleName.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.textBoxRoleName.Name = "textBoxRoleName"; - this.textBoxRoleName.Size = new System.Drawing.Size(268, 27); + this.textBoxRoleName.Size = new System.Drawing.Size(218, 23); this.textBoxRoleName.TabIndex = 0; // // buttonSave // - this.buttonSave.Location = new System.Drawing.Point(12, 45); + this.buttonSave.Location = new System.Drawing.Point(10, 34); + this.buttonSave.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.buttonSave.Name = "buttonSave"; - this.buttonSave.Size = new System.Drawing.Size(94, 29); + this.buttonSave.Size = new System.Drawing.Size(82, 22); this.buttonSave.TabIndex = 1; this.buttonSave.Text = "Сохранить"; this.buttonSave.UseVisualStyleBackColor = true; @@ -52,22 +55,35 @@ // // buttonCancel // - this.buttonCancel.Location = new System.Drawing.Point(186, 45); + this.buttonCancel.Location = new System.Drawing.Point(10, 63); + this.buttonCancel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.buttonCancel.Name = "buttonCancel"; - this.buttonCancel.Size = new System.Drawing.Size(94, 29); + this.buttonCancel.Size = new System.Drawing.Size(82, 22); this.buttonCancel.TabIndex = 2; this.buttonCancel.Text = "Отмена"; this.buttonCancel.UseVisualStyleBackColor = true; this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click); // + // buttonAddRoles + // + this.buttonAddRoles.Location = new System.Drawing.Point(153, 34); + this.buttonAddRoles.Name = "buttonAddRoles"; + this.buttonAddRoles.Size = new System.Drawing.Size(75, 54); + this.buttonAddRoles.TabIndex = 3; + this.buttonAddRoles.Text = "Добавить 1000 ролей"; + this.buttonAddRoles.UseVisualStyleBackColor = true; + this.buttonAddRoles.Click += new System.EventHandler(this.buttonAddRoles_Click); + // // FormRole // - this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(292, 81); + this.ClientSize = new System.Drawing.Size(234, 96); + this.Controls.Add(this.buttonAddRoles); this.Controls.Add(this.buttonCancel); this.Controls.Add(this.buttonSave); this.Controls.Add(this.textBoxRoleName); + this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.Name = "FormRole"; this.Text = "Роль"; this.Load += new System.EventHandler(this.FormRole_Load); @@ -81,5 +97,6 @@ private TextBox textBoxRoleName; private Button buttonSave; private Button buttonCancel; + private Button buttonAddRoles; } } \ No newline at end of file diff --git a/Forum/Forum/FormRole.cs b/Forum/Forum/FormRole.cs index 822522e..c68b74e 100644 --- a/Forum/Forum/FormRole.cs +++ b/Forum/Forum/FormRole.cs @@ -1,6 +1,7 @@ using ForumContracts.BindingModels; using ForumContracts.BusinessLogicContracts; using ForumContracts.SearchModels; +using Microsoft.EntityFrameworkCore.Diagnostics; using System; using System.Collections.Generic; using System.ComponentModel; @@ -84,5 +85,18 @@ namespace Forum } } } + + private void buttonAddRoles_Click(object sender, EventArgs e) + { + try + { + _roleLogic.RoleInsertList(1000); + FormRole_Load(sender, e); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } } } diff --git a/Forum/Forum/FormTests.Designer.cs b/Forum/Forum/FormTests.Designer.cs new file mode 100644 index 0000000..5252f3a --- /dev/null +++ b/Forum/Forum/FormTests.Designer.cs @@ -0,0 +1,229 @@ +namespace Forum +{ + 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.buttonInsertTest = new System.Windows.Forms.Button(); + this.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.textBoxInsertTime = new System.Windows.Forms.TextBox(); + this.buttonReadTest = new System.Windows.Forms.Button(); + this.textBoxReadTime = new System.Windows.Forms.TextBox(); + this.label3 = new System.Windows.Forms.Label(); + this.label4 = new System.Windows.Forms.Label(); + this.numericUpDownInsert = new System.Windows.Forms.NumericUpDown(); + this.numericUpDownRead = new System.Windows.Forms.NumericUpDown(); + this.buttonJoinQuery = new System.Windows.Forms.Button(); + this.numericUpDownJoin = new System.Windows.Forms.NumericUpDown(); + this.textBoxJoin = new System.Windows.Forms.TextBox(); + this.label5 = new System.Windows.Forms.Label(); + this.label6 = new System.Windows.Forms.Label(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownInsert)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownRead)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownJoin)).BeginInit(); + this.SuspendLayout(); + // + // buttonInsertTest + // + this.buttonInsertTest.Location = new System.Drawing.Point(12, 12); + this.buttonInsertTest.Name = "buttonInsertTest"; + this.buttonInsertTest.Size = new System.Drawing.Size(86, 61); + this.buttonInsertTest.TabIndex = 0; + this.buttonInsertTest.Text = "Тест вставки сообщений"; + this.buttonInsertTest.UseVisualStyleBackColor = true; + this.buttonInsertTest.Click += new System.EventHandler(this.buttonInsertTest_Click); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(104, 12); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(156, 15); + this.label1.TabIndex = 1; + this.label1.Text = "Введите кол-во элементов:"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(104, 53); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(146, 15); + this.label2.TabIndex = 3; + this.label2.Text = "Итоговое время запроса:"; + // + // textBoxInsertTime + // + this.textBoxInsertTime.Location = new System.Drawing.Point(266, 50); + this.textBoxInsertTime.Name = "textBoxInsertTime"; + this.textBoxInsertTime.ReadOnly = true; + this.textBoxInsertTime.Size = new System.Drawing.Size(100, 23); + this.textBoxInsertTime.TabIndex = 4; + // + // buttonReadTest + // + this.buttonReadTest.Location = new System.Drawing.Point(12, 106); + this.buttonReadTest.Name = "buttonReadTest"; + this.buttonReadTest.Size = new System.Drawing.Size(86, 56); + this.buttonReadTest.TabIndex = 5; + this.buttonReadTest.Text = "Тест чтения сообщений"; + this.buttonReadTest.UseVisualStyleBackColor = true; + this.buttonReadTest.Click += new System.EventHandler(this.buttonReadTest_Click); + // + // textBoxReadTime + // + this.textBoxReadTime.Location = new System.Drawing.Point(266, 144); + this.textBoxReadTime.Name = "textBoxReadTime"; + this.textBoxReadTime.ReadOnly = true; + this.textBoxReadTime.Size = new System.Drawing.Size(100, 23); + this.textBoxReadTime.TabIndex = 9; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(104, 147); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(146, 15); + this.label3.TabIndex = 8; + this.label3.Text = "Итоговое время запроса:"; + // + // label4 + // + this.label4.AutoSize = true; + this.label4.Location = new System.Drawing.Point(104, 106); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(156, 15); + this.label4.TabIndex = 6; + this.label4.Text = "Введите кол-во элементов:"; + // + // numericUpDownInsert + // + this.numericUpDownInsert.Location = new System.Drawing.Point(266, 10); + this.numericUpDownInsert.Name = "numericUpDownInsert"; + this.numericUpDownInsert.Size = new System.Drawing.Size(100, 23); + this.numericUpDownInsert.TabIndex = 10; + // + // numericUpDownRead + // + this.numericUpDownRead.Location = new System.Drawing.Point(266, 104); + this.numericUpDownRead.Name = "numericUpDownRead"; + this.numericUpDownRead.Size = new System.Drawing.Size(100, 23); + this.numericUpDownRead.TabIndex = 11; + // + // buttonJoinQuery + // + this.buttonJoinQuery.Location = new System.Drawing.Point(12, 197); + this.buttonJoinQuery.Name = "buttonJoinQuery"; + this.buttonJoinQuery.Size = new System.Drawing.Size(86, 74); + this.buttonJoinQuery.TabIndex = 12; + this.buttonJoinQuery.Text = "Тест сложного чтения (Join)"; + this.buttonJoinQuery.UseVisualStyleBackColor = true; + this.buttonJoinQuery.Click += new System.EventHandler(this.buttonJoinQuery_Click); + // + // numericUpDownJoin + // + this.numericUpDownJoin.Location = new System.Drawing.Point(266, 195); + this.numericUpDownJoin.Name = "numericUpDownJoin"; + this.numericUpDownJoin.Size = new System.Drawing.Size(100, 23); + this.numericUpDownJoin.TabIndex = 16; + // + // textBoxJoin + // + this.textBoxJoin.Location = new System.Drawing.Point(266, 235); + this.textBoxJoin.Name = "textBoxJoin"; + this.textBoxJoin.ReadOnly = true; + this.textBoxJoin.Size = new System.Drawing.Size(100, 23); + this.textBoxJoin.TabIndex = 15; + // + // label5 + // + this.label5.AutoSize = true; + this.label5.Location = new System.Drawing.Point(104, 238); + this.label5.Name = "label5"; + this.label5.Size = new System.Drawing.Size(146, 15); + this.label5.TabIndex = 14; + this.label5.Text = "Итоговое время запроса:"; + // + // label6 + // + this.label6.AutoSize = true; + this.label6.Location = new System.Drawing.Point(104, 197); + this.label6.Name = "label6"; + this.label6.Size = new System.Drawing.Size(156, 15); + this.label6.TabIndex = 13; + this.label6.Text = "Введите кол-во элементов:"; + // + // FormTests + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(383, 286); + this.Controls.Add(this.numericUpDownJoin); + this.Controls.Add(this.textBoxJoin); + this.Controls.Add(this.label5); + this.Controls.Add(this.label6); + this.Controls.Add(this.buttonJoinQuery); + this.Controls.Add(this.numericUpDownRead); + this.Controls.Add(this.numericUpDownInsert); + this.Controls.Add(this.textBoxReadTime); + this.Controls.Add(this.label3); + this.Controls.Add(this.label4); + this.Controls.Add(this.buttonReadTest); + this.Controls.Add(this.textBoxInsertTime); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.Controls.Add(this.buttonInsertTest); + this.Name = "FormTests"; + this.Text = "Тесты запросов к бд"; + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownInsert)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownRead)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownJoin)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Button buttonInsertTest; + private Label label1; + private Label label2; + private TextBox textBoxInsertTime; + private Button buttonReadTest; + private TextBox textBoxReadTime; + private Label label3; + private Label label4; + private NumericUpDown numericUpDownInsert; + private NumericUpDown numericUpDownRead; + private Button buttonJoinQuery; + private NumericUpDown numericUpDownJoin; + private TextBox textBoxJoin; + private Label label5; + private Label label6; + } +} \ No newline at end of file diff --git a/Forum/Forum/FormTests.cs b/Forum/Forum/FormTests.cs new file mode 100644 index 0000000..f182f51 --- /dev/null +++ b/Forum/Forum/FormTests.cs @@ -0,0 +1,75 @@ +using ForumContracts.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 Forum +{ + public partial class FormTests : Form + { + private readonly IMessageLogic _messageLogic; + private readonly IUserLogic _userLogic; + private readonly ITopicLogic _topicLogic; + public FormTests(IUserLogic userLogic, ITopicLogic topicLogic, IMessageLogic messageLogic) + { + InitializeComponent(); + _userLogic = userLogic; + _topicLogic = topicLogic; + _messageLogic = messageLogic; + numericUpDownInsert.Minimum = 0; + numericUpDownInsert.Maximum = 1000000; + numericUpDownRead.Minimum = 0; + numericUpDownRead.Maximum = 1000000; + numericUpDownJoin.Minimum = 0; + 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()); + + 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 = _messageLogic.TestReadList(Convert.ToInt32(numericUpDownInsert.Value)); + textBoxReadTime.Text = result; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonJoinQuery_Click(object sender, EventArgs e) + { + try + { + var result = _messageLogic.TestJoinReadList(Convert.ToInt32(numericUpDownJoin.Value)); + textBoxJoin.Text = result; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } +} diff --git a/Forum/Forum/FormTests.resx b/Forum/Forum/FormTests.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Forum/Forum/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/Forum/Forum/FormUser.Designer.cs b/Forum/Forum/FormUser.Designer.cs index 44bc943..5b62c92 100644 --- a/Forum/Forum/FormUser.Designer.cs +++ b/Forum/Forum/FormUser.Designer.cs @@ -38,61 +38,66 @@ this.buttonCancel = new System.Windows.Forms.Button(); this.comboBoxSelectRole = new System.Windows.Forms.ComboBox(); this.label4 = new System.Windows.Forms.Label(); + this.buttonAddUsers = new System.Windows.Forms.Button(); this.SuspendLayout(); // // textBoxUsername // - this.textBoxUsername.Location = new System.Drawing.Point(92, 12); + this.textBoxUsername.Location = new System.Drawing.Point(80, 9); + this.textBoxUsername.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.textBoxUsername.Name = "textBoxUsername"; - this.textBoxUsername.Size = new System.Drawing.Size(151, 27); + this.textBoxUsername.Size = new System.Drawing.Size(133, 23); this.textBoxUsername.TabIndex = 0; // // textBoxLogin // - this.textBoxLogin.Location = new System.Drawing.Point(92, 45); + this.textBoxLogin.Location = new System.Drawing.Point(80, 34); + this.textBoxLogin.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.textBoxLogin.Name = "textBoxLogin"; - this.textBoxLogin.Size = new System.Drawing.Size(151, 27); + this.textBoxLogin.Size = new System.Drawing.Size(133, 23); this.textBoxLogin.TabIndex = 1; // // textBoxPassword // - this.textBoxPassword.Location = new System.Drawing.Point(92, 78); + this.textBoxPassword.Location = new System.Drawing.Point(80, 58); + this.textBoxPassword.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.textBoxPassword.Name = "textBoxPassword"; - this.textBoxPassword.Size = new System.Drawing.Size(151, 27); + this.textBoxPassword.Size = new System.Drawing.Size(133, 23); this.textBoxPassword.TabIndex = 2; // // label1 // this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(11, 19); + this.label1.Location = new System.Drawing.Point(10, 14); this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(75, 20); + this.label1.Size = new System.Drawing.Size(60, 15); this.label1.TabIndex = 3; this.label1.Text = "Username"; // // label2 // this.label2.AutoSize = true; - this.label2.Location = new System.Drawing.Point(12, 52); + this.label2.Location = new System.Drawing.Point(10, 39); this.label2.Name = "label2"; - this.label2.Size = new System.Drawing.Size(46, 20); + this.label2.Size = new System.Drawing.Size(37, 15); this.label2.TabIndex = 4; this.label2.Text = "Login"; // // label3 // this.label3.AutoSize = true; - this.label3.Location = new System.Drawing.Point(11, 85); + this.label3.Location = new System.Drawing.Point(10, 64); this.label3.Name = "label3"; - this.label3.Size = new System.Drawing.Size(70, 20); + this.label3.Size = new System.Drawing.Size(57, 15); this.label3.TabIndex = 5; this.label3.Text = "Password"; // // buttonSave // - this.buttonSave.Location = new System.Drawing.Point(12, 160); + this.buttonSave.Location = new System.Drawing.Point(219, 11); + this.buttonSave.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.buttonSave.Name = "buttonSave"; - this.buttonSave.Size = new System.Drawing.Size(94, 29); + this.buttonSave.Size = new System.Drawing.Size(82, 22); this.buttonSave.TabIndex = 6; this.buttonSave.Text = "Сохранить"; this.buttonSave.UseVisualStyleBackColor = true; @@ -100,9 +105,10 @@ // // buttonCancel // - this.buttonCancel.Location = new System.Drawing.Point(149, 160); + this.buttonCancel.Location = new System.Drawing.Point(219, 37); + this.buttonCancel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.buttonCancel.Name = "buttonCancel"; - this.buttonCancel.Size = new System.Drawing.Size(94, 29); + this.buttonCancel.Size = new System.Drawing.Size(82, 22); this.buttonCancel.TabIndex = 7; this.buttonCancel.Text = "Отмена"; this.buttonCancel.UseVisualStyleBackColor = true; @@ -111,25 +117,37 @@ // comboBoxSelectRole // this.comboBoxSelectRole.FormattingEnabled = true; - this.comboBoxSelectRole.Location = new System.Drawing.Point(92, 117); + this.comboBoxSelectRole.Location = new System.Drawing.Point(80, 88); + this.comboBoxSelectRole.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.comboBoxSelectRole.Name = "comboBoxSelectRole"; - this.comboBoxSelectRole.Size = new System.Drawing.Size(151, 28); + this.comboBoxSelectRole.Size = new System.Drawing.Size(133, 23); this.comboBoxSelectRole.TabIndex = 8; // // label4 // this.label4.AutoSize = true; - this.label4.Location = new System.Drawing.Point(11, 120); + this.label4.Location = new System.Drawing.Point(10, 90); this.label4.Name = "label4"; - this.label4.Size = new System.Drawing.Size(39, 20); + this.label4.Size = new System.Drawing.Size(30, 15); this.label4.TabIndex = 9; this.label4.Text = "Role"; // + // buttonAddUsers + // + this.buttonAddUsers.Location = new System.Drawing.Point(219, 64); + this.buttonAddUsers.Name = "buttonAddUsers"; + this.buttonAddUsers.Size = new System.Drawing.Size(82, 77); + this.buttonAddUsers.TabIndex = 10; + this.buttonAddUsers.Text = "Добавить 1000 пользователей"; + this.buttonAddUsers.UseVisualStyleBackColor = true; + this.buttonAddUsers.Click += new System.EventHandler(this.buttonAddUsers_Click); + // // FormUser // - this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(262, 201); + this.ClientSize = new System.Drawing.Size(310, 145); + this.Controls.Add(this.buttonAddUsers); this.Controls.Add(this.label4); this.Controls.Add(this.comboBoxSelectRole); this.Controls.Add(this.buttonCancel); @@ -140,6 +158,7 @@ this.Controls.Add(this.textBoxPassword); this.Controls.Add(this.textBoxLogin); this.Controls.Add(this.textBoxUsername); + this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.Name = "FormUser"; this.Text = "Пользователь"; this.Load += new System.EventHandler(this.FormUser_Load); @@ -160,5 +179,6 @@ private Button buttonCancel; private ComboBox comboBoxSelectRole; private Label label4; + private Button buttonAddUsers; } } \ No newline at end of file diff --git a/Forum/Forum/FormUser.cs b/Forum/Forum/FormUser.cs index aff3e76..c543243 100644 --- a/Forum/Forum/FormUser.cs +++ b/Forum/Forum/FormUser.cs @@ -122,5 +122,17 @@ namespace Forum MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } + + private void buttonAddUsers_Click(object sender, EventArgs e) + { + try + { + _userLogic.UserInsertList(1000, _roleLogic.ReadList(null)); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } } } diff --git a/Forum/Forum/Program.cs b/Forum/Forum/Program.cs index a5bbbf4..3200a7f 100644 --- a/Forum/Forum/Program.cs +++ b/Forum/Forum/Program.cs @@ -49,6 +49,7 @@ namespace Forum services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file diff --git a/Forum/ForumBusinessLogic/MessageLogic.cs b/Forum/ForumBusinessLogic/MessageLogic.cs index cb9684b..b27b545 100644 --- a/Forum/ForumBusinessLogic/MessageLogic.cs +++ b/Forum/ForumBusinessLogic/MessageLogic.cs @@ -64,6 +64,19 @@ namespace ForumBusinessLogic return list; } + public string TestInsertList(int num, List users, List topics) + { + return _messageStorage.TestInsertList(num, users, topics); + } + public string TestReadList(int num) + { + return _messageStorage.TestReadList(num); + } + public string TestJoinReadList(int num) + { + return _messageStorage.TestJoinReadList(num); + } + public bool Update(MessageBindingModel model) { CheckModel(model); diff --git a/Forum/ForumBusinessLogic/RoleLogic.cs b/Forum/ForumBusinessLogic/RoleLogic.cs index 831684f..53c4869 100644 --- a/Forum/ForumBusinessLogic/RoleLogic.cs +++ b/Forum/ForumBusinessLogic/RoleLogic.cs @@ -64,6 +64,11 @@ namespace ForumBusinessLogic return list; } + public void RoleInsertList(int num) + { + _roleStorage.RoleInsertList(num); + } + public bool Update(RoleBindingModel model) { CheckModel(model); diff --git a/Forum/ForumBusinessLogic/UserLogic.cs b/Forum/ForumBusinessLogic/UserLogic.cs index 2d1951c..ffb0454 100644 --- a/Forum/ForumBusinessLogic/UserLogic.cs +++ b/Forum/ForumBusinessLogic/UserLogic.cs @@ -73,6 +73,11 @@ namespace ForumBusinessLogic return true; } + public void UserInsertList(int num, List roles) + { + _userStorage.UserInsertList(num, roles); + } + private void CheckModel(UserBindingModel model, bool withParams = true) { if (model == null) diff --git a/Forum/ForumContracts/BusinessLogicContracts/IMessageLogic.cs b/Forum/ForumContracts/BusinessLogicContracts/IMessageLogic.cs index 85ab235..1b642df 100644 --- a/Forum/ForumContracts/BusinessLogicContracts/IMessageLogic.cs +++ b/Forum/ForumContracts/BusinessLogicContracts/IMessageLogic.cs @@ -16,5 +16,8 @@ namespace ForumContracts.BusinessLogicContracts bool Create(MessageBindingModel model); bool Update(MessageBindingModel model); bool Delete(MessageBindingModel model); + public string TestInsertList(int num, List users, List topics); + string TestReadList(int num); + string TestJoinReadList(int num); } } diff --git a/Forum/ForumContracts/BusinessLogicContracts/IRoleLogic.cs b/Forum/ForumContracts/BusinessLogicContracts/IRoleLogic.cs index 9a7fdaa..b2596ad 100644 --- a/Forum/ForumContracts/BusinessLogicContracts/IRoleLogic.cs +++ b/Forum/ForumContracts/BusinessLogicContracts/IRoleLogic.cs @@ -16,5 +16,6 @@ namespace ForumContracts.BusinessLogicContracts bool Create(RoleBindingModel model); bool Update(RoleBindingModel model); bool Delete(RoleBindingModel model); + void RoleInsertList(int num); } } diff --git a/Forum/ForumContracts/BusinessLogicContracts/IUserLogic.cs b/Forum/ForumContracts/BusinessLogicContracts/IUserLogic.cs index 0919278..6d36dd2 100644 --- a/Forum/ForumContracts/BusinessLogicContracts/IUserLogic.cs +++ b/Forum/ForumContracts/BusinessLogicContracts/IUserLogic.cs @@ -16,5 +16,6 @@ namespace ForumContracts.BusinessLogicContracts bool Create(UserBindingModel model); bool Update(UserBindingModel model); bool Delete(UserBindingModel model); + void UserInsertList(int num, List roles); } } diff --git a/Forum/ForumContracts/StoragesContracts/IMessageStorage.cs b/Forum/ForumContracts/StoragesContracts/IMessageStorage.cs index 8738829..9ad3261 100644 --- a/Forum/ForumContracts/StoragesContracts/IMessageStorage.cs +++ b/Forum/ForumContracts/StoragesContracts/IMessageStorage.cs @@ -17,5 +17,8 @@ namespace ForumContracts.StoragesContracts MessageViewModel? Insert(MessageBindingModel model); MessageViewModel? Update(MessageBindingModel model); MessageViewModel? Delete(MessageBindingModel model); + string TestInsertList(int num, List users, List topics); + string TestReadList(int num); + string TestJoinReadList(int num); } } diff --git a/Forum/ForumContracts/StoragesContracts/IRoleStorage.cs b/Forum/ForumContracts/StoragesContracts/IRoleStorage.cs index 8ac5700..4a98375 100644 --- a/Forum/ForumContracts/StoragesContracts/IRoleStorage.cs +++ b/Forum/ForumContracts/StoragesContracts/IRoleStorage.cs @@ -17,5 +17,6 @@ namespace ForumContracts.StoragesContracts RoleViewModel? Insert(RoleBindingModel model); RoleViewModel? Update(RoleBindingModel model); RoleViewModel? Delete(RoleBindingModel model); + void RoleInsertList(int num); } } diff --git a/Forum/ForumContracts/StoragesContracts/IUserStorage.cs b/Forum/ForumContracts/StoragesContracts/IUserStorage.cs index 3905a35..795d393 100644 --- a/Forum/ForumContracts/StoragesContracts/IUserStorage.cs +++ b/Forum/ForumContracts/StoragesContracts/IUserStorage.cs @@ -17,5 +17,6 @@ namespace ForumContracts.StoragesContracts UserViewModel? Insert(UserBindingModel model); UserViewModel? Update(UserBindingModel model); UserViewModel? Delete(UserBindingModel model); + void UserInsertList(int num, List roles); } } diff --git a/Forum/ForumDatabase/Implements/MessageStorage.cs b/Forum/ForumDatabase/Implements/MessageStorage.cs index 32dace5..156fcb0 100644 --- a/Forum/ForumDatabase/Implements/MessageStorage.cs +++ b/Forum/ForumDatabase/Implements/MessageStorage.cs @@ -6,6 +6,7 @@ using ForumDatabase.Models; using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -73,6 +74,81 @@ namespace ForumDatabase.Implements return newMessage.GetViewModel; } + public string TestInsertList(int num, List users, List topics) + { + Random rnd = new Random(); + using var context = new ForumDatabase(); + for (int i = 0; i < num; ++i) + { + var model = new MessageBindingModel + { + Id = 0, + Text = "hello", + Date = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc), + UserId = users[rnd.Next(users.Count)].Id, + TopicId = topics[rnd.Next(topics.Count)].Id, + }; + context.Messages.Add(Message.Create(model)); + } + Stopwatch stopwatch = new(); + + stopwatch.Start(); + + context.SaveChanges(); + + stopwatch.Stop(); + return stopwatch.ElapsedMilliseconds.ToString(); + } + + public string TestJoinReadList(int num) + { + using var context = new ForumDatabase(); + Stopwatch stopwatch = new(); + + stopwatch.Start(); + + var list = context.Messages + .Include(x => x.User) + .Include(x => x.Topic) + .Join(context.Users, + r => r.UserId, + c => c.Id, + (r, c) => new { Message = r, User = c }) + .Join(context.Topics, + rc => rc.Message.TopicId, + car => car.Id, + (rc, topic) => new { rc.Message, rc.User, Topic = topic }) + .Select(rc => new + { + Message = rc.Message.GetViewModel, + User = rc.User.GetViewModel, + Topic = rc.Topic.GetViewModel, + }) + .Take(num) + .ToList(); + stopwatch.Stop(); + + return stopwatch.ElapsedMilliseconds.ToString(); + } + + public string TestReadList(int num) + { + using var context = new ForumDatabase(); + Stopwatch stopwatch = new(); + + stopwatch.Start(); + + List list = context.Messages + .Include(x => x.User) + .Include(x => x.Topic) + .Take(num) + .Select(x => x.GetViewModel) + .ToList(); + stopwatch.Stop(); + + return stopwatch.ElapsedMilliseconds.ToString(); + } + public MessageViewModel? Update(MessageBindingModel model) { using var context = new ForumDatabase(); diff --git a/Forum/ForumDatabase/Implements/RoleStorage.cs b/Forum/ForumDatabase/Implements/RoleStorage.cs index 7c3b8f1..6e1928e 100644 --- a/Forum/ForumDatabase/Implements/RoleStorage.cs +++ b/Forum/ForumDatabase/Implements/RoleStorage.cs @@ -13,6 +13,21 @@ namespace ForumDatabase.Implements { public class RoleStorage : IRoleStorage { + public void RoleInsertList(int num) + { + Random rnd = new Random(); + using var context = new ForumDatabase(); + for (int i = 0; i < num; ++i) + { + var model = new RoleBindingModel + { + Id = 0, + Name = rnd.Next(1000).ToString(), + }; + context.Roles.Add(Role.Create(model)); + } + context.SaveChanges(); + } public RoleViewModel? Delete(RoleBindingModel model) { using var context = new ForumDatabase(); diff --git a/Forum/ForumDatabase/Implements/UserStorage.cs b/Forum/ForumDatabase/Implements/UserStorage.cs index 12f0b07..56618d1 100644 --- a/Forum/ForumDatabase/Implements/UserStorage.cs +++ b/Forum/ForumDatabase/Implements/UserStorage.cs @@ -7,6 +7,7 @@ using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.ConstrainedExecution; using System.Text; using System.Threading.Tasks; @@ -91,5 +92,24 @@ namespace ForumDatabase.Implements context.SaveChanges(); return component.GetViewModel; } + + public void UserInsertList(int num, List roles) + { + Random rnd = new Random(); + using var context = new ForumDatabase(); + for (int i = 0; i < num; ++i) + { + var model = new UserBindingModel + { + Id = 0, + Username = rnd.Next(1000).ToString(), + Email = rnd.Next(1000).ToString(), + Password = rnd.Next(1000).ToString(), + RoleId = roles[rnd.Next(roles.Count)].Id, + }; + context.Users.Add(User.Create(model)); + } + context.SaveChanges(); + } } }