generated from stho32/BP001-ProjectTemplate-CSharp
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from naseif/main
First implementation of OptimalDB
- Loading branch information
Showing
11 changed files
with
416 additions
and
19 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using optimalDb.Interfaces; | ||
|
||
namespace optimalDb.BL; | ||
public class DatabaseConnection : IDatabaseConnection | ||
{ | ||
public string Name { get; } | ||
public string ConnectionString { get; } | ||
|
||
public DatabaseConnection(string name, string connectionString) | ||
{ | ||
Name = name; | ||
ConnectionString = connectionString; | ||
} | ||
} | ||
|
||
|
||
public class ViewPerformanceTestResult : IViewPerformanceTestResult | ||
{ | ||
public string ViewName { get; } | ||
|
||
public decimal DurationInSeconds { get; } | ||
|
||
public ViewPerformanceTestResult(string viewName, decimal durationInSeconds) | ||
{ | ||
ViewName = viewName; | ||
DurationInSeconds = durationInSeconds; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
12 changes: 12 additions & 0 deletions
12
Source/optimalDb/optimalDb.Interfaces/IDatabaseConnection.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
namespace optimalDb.Interfaces; | ||
public interface IDatabaseConnection | ||
{ | ||
string Name { get; } | ||
string ConnectionString { get; } | ||
} | ||
|
||
public interface IViewPerformanceTestResult | ||
{ | ||
string ViewName { get; } // SCHEMA.VIEWNAME | ||
decimal DurationInSeconds { get; } // 0.5s oder 30s ... | ||
} |
156 changes: 156 additions & 0 deletions
156
Source/optimalDb/optimalDb.WinForms/MainForm.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
using optimalDb.BL; | ||
using System.Data; | ||
using System.Data.SqlClient; | ||
|
||
namespace optimalDb.WinForms | ||
{ | ||
public partial class MainForm : Form | ||
{ | ||
public MainForm() | ||
{ | ||
InitializeComponent(); | ||
} | ||
|
||
private void openToolStripMenuItem_Click(object sender, EventArgs e) | ||
{ | ||
if (openFileDialog1.ShowDialog() == DialogResult.OK) | ||
{ | ||
var content = File.ReadAllText(openFileDialog1.FileName); | ||
var connections = new List<DatabaseConnection>(); | ||
connections.Add(new DatabaseConnection("Naseif", "https:ASd234f233cv2fasdf")); | ||
connections.Add(new DatabaseConnection("Stefan", "https:ASd234f233cv2fasdf")); | ||
|
||
for (var i = 0; i < connections.Count; i++) | ||
{ | ||
connectionsComboBox.Items.Add(connections[i].Name); | ||
} | ||
|
||
|
||
} | ||
} | ||
|
||
private void testButton_Click(object sender, EventArgs e) | ||
{ | ||
DataTable alleViews; | ||
var connectionString = "Server = .\\SQLEXPRESS; Database = AdventureWorks2019; Trusted_Connection = True;"; | ||
using (SqlConnection connection = new SqlConnection(connectionString)) | ||
{ | ||
connection.Open(); | ||
|
||
var sql = @" | ||
SELECT t.TABLE_SCHEMA, t.TABLE_NAME | ||
FROM INFORMATION_SCHEMA.TABLES t | ||
WHERE t.TABLE_TYPE = 'VIEW'"; | ||
|
||
using (SqlCommand command = new SqlCommand(sql, connection)) | ||
{ | ||
SqlDataAdapter adapter = new SqlDataAdapter(command); | ||
DataSet dataset = new DataSet(); | ||
adapter.Fill(dataset); | ||
alleViews = dataset.Tables[0]; | ||
} | ||
} | ||
|
||
var result = new List<ViewPerformanceTestResult>(); | ||
foreach(DataRow row in alleViews.Rows) | ||
{ | ||
result.Add( | ||
new ViewPerformanceTestResult( | ||
row["TABLE_SCHEMA"].ToString() + "." + row["TABLE_NAME"].ToString(), | ||
GetDurationOfViewExecution(row["TABLE_SCHEMA"].ToString() + "." + row["TABLE_NAME"].ToString()) | ||
)); | ||
} | ||
|
||
dataGridView1.DataSource = result; | ||
} | ||
|
||
protected decimal GetDurationOfViewExecution(string viewName) | ||
{ | ||
DateTime start = DateTime.Now; | ||
|
||
try | ||
{ | ||
var connectionString = "Server = .\\SQLEXPRESS; Database = AdventureWorks2019; Trusted_Connection = True;"; | ||
using (SqlConnection connection = new SqlConnection(connectionString)) | ||
{ | ||
connection.Open(); | ||
|
||
var sql = @"SELECT * FROM " + viewName; | ||
|
||
using (SqlCommand command = new SqlCommand(sql, connection)) | ||
{ | ||
SqlDataAdapter adapter = new SqlDataAdapter(command); | ||
DataSet dataset = new DataSet(); | ||
adapter.Fill(dataset); | ||
} | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
return 999; | ||
} | ||
|
||
return (decimal)(DateTime.Now - start).TotalSeconds; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<root> | ||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> | ||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" /> | ||
<xsd:element name="root" msdata:IsDataSet="true"> | ||
<xsd:complexType> | ||
<xsd:choice maxOccurs="unbounded"> | ||
<xsd:element name="metadata"> | ||
<xsd:complexType> | ||
<xsd:sequence> | ||
<xsd:element name="value" type="xsd:string" minOccurs="0" /> | ||
</xsd:sequence> | ||
<xsd:attribute name="name" use="required" type="xsd:string" /> | ||
<xsd:attribute name="type" type="xsd:string" /> | ||
<xsd:attribute name="mimetype" type="xsd:string" /> | ||
<xsd:attribute ref="xml:space" /> | ||
</xsd:complexType> | ||
</xsd:element> | ||
<xsd:element name="assembly"> | ||
<xsd:complexType> | ||
<xsd:attribute name="alias" type="xsd:string" /> | ||
<xsd:attribute name="name" type="xsd:string" /> | ||
</xsd:complexType> | ||
</xsd:element> | ||
<xsd:element name="data"> | ||
<xsd:complexType> | ||
<xsd:sequence> | ||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> | ||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" /> | ||
</xsd:sequence> | ||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" /> | ||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" /> | ||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" /> | ||
<xsd:attribute ref="xml:space" /> | ||
</xsd:complexType> | ||
</xsd:element> | ||
<xsd:element name="resheader"> | ||
<xsd:complexType> | ||
<xsd:sequence> | ||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> | ||
</xsd:sequence> | ||
<xsd:attribute name="name" type="xsd:string" use="required" /> | ||
</xsd:complexType> | ||
</xsd:element> | ||
</xsd:choice> | ||
</xsd:complexType> | ||
</xsd:element> | ||
</xsd:schema> | ||
<resheader name="resmimetype"> | ||
<value>text/microsoft-resx</value> | ||
</resheader> | ||
<resheader name="version"> | ||
<value>2.0</value> | ||
</resheader> | ||
<resheader name="reader"> | ||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> | ||
</resheader> | ||
<resheader name="writer"> | ||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> | ||
</resheader> | ||
<metadata name="menuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> | ||
<value>17, 17</value> | ||
</metadata> | ||
<metadata name="openFileDialog1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> | ||
<value>132, 17</value> | ||
</metadata> | ||
</root> |
Oops, something went wrong.