Skip to content

Commit b70e95d

Browse files
authored
Merge pull request #39 from ChaosEngine/dev
bump dependencies
2 parents 1f88313 + 77b8b36 commit b70e95d

File tree

14 files changed

+450
-121
lines changed

14 files changed

+450
-121
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
language: csharp
22
mono: none
3-
dotnet: 5.0.100
3+
dotnet: 7.0.100
44
dist: bionic
55
addons:
66
apt:

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ build_script:
1313
clone_depth: 1
1414
test: off
1515
deploy: off
16-
os: Visual Studio 2019
16+
os: Visual Studio 2022

src/Pomelo.Extensions.Caching.MySql/Pomelo.Extensions.Caching.MySql.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
</PropertyGroup>
2323

2424
<ItemGroup>
25-
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="5.0.0" />
26-
<PackageReference Include="Microsoft.Extensions.Options" Version="5.0.0" />
27-
<PackageReference Include="MySqlConnector" Version="1.3.10" />
25+
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="7.0.0" />
26+
<PackageReference Include="Microsoft.Extensions.Options" Version="7.0.1" />
27+
<PackageReference Include="MySqlConnector" Version="2.2.5" />
2828
</ItemGroup>
2929

3030
</Project>

src/Pomelo.Extensions.Caching.MySqlConfig.Tools/Pomelo.Extensions.Caching.MySqlConfig.Tools.csproj

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<Description>Command line tool to create tables and indexes in a MySql Server database for distributed caching.</Description>
5-
<TargetFramework>net5.0</TargetFramework>
5+
<TargetFramework>net7.0</TargetFramework>
66
<NoWarn>$(NoWarn);CS1591</NoWarn>
77
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
88
<GenerateDocumentationFile>true</GenerateDocumentationFile>
@@ -25,6 +25,8 @@
2525
<IsPackable>true</IsPackable>
2626
<ToolCommandName>dotnet-mysql-cache</ToolCommandName>
2727
<PackAsTool>true</PackAsTool>
28+
<SignAssembly>true</SignAssembly>
29+
<AssemblyOriginatorKeyFile>Pomelo.snk</AssemblyOriginatorKeyFile>
2830
</PropertyGroup>
2931

3032
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
@@ -35,7 +37,7 @@
3537

3638
<ItemGroup>
3739
<PackageReference Include="Microsoft.Extensions.CommandLineUtils" Version="1.1.1" />
38-
<PackageReference Include="MySqlConnector" Version="1.3.10" />
40+
<PackageReference Include="MySqlConnector" Version="2.2.5" />
3941
</ItemGroup>
4042

4143
</Project>
596 Bytes
Binary file not shown.

src/Pomelo.Extensions.Caching.MySqlConfig.Tools/Program.cs

Lines changed: 81 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,34 @@
55
using MySqlConnector;
66
using System;
77
using System.Data;
8+
using System.IO;
89
using System.Reflection;
910
using System.Threading;
1011
using System.Threading.Tasks;
1112

1213
namespace Pomelo.Extensions.Caching.MySqlConfig.Tools
1314
{
14-
public class Program : IDisposable
15+
/// <summary>
16+
/// Based (if not entirely) of off https://github.com/dotnet/aspnetcore/blob/main/src/Tools/dotnet-sql-cache/src/Program.cs
17+
/// </summary>
18+
public class Program
1519
{
1620
private string _connectionString = null;
1721
private string _databaseName = null;
1822
private string _tableName = null;
1923

24+
internal TextWriter Error { get; set; } = Console.Error;
25+
internal TextWriter Out { get; set; } = Console.Out;
26+
2027
public Program()
2128
{
2229
}
2330

2431
public static int Main(string[] args)
2532
{
26-
using (var p = new Program())
27-
{
28-
return p.Run(args);
29-
}
33+
var p = new Program();
34+
35+
return p.Run(args);
3036
}
3137

3238
public int Run(string[] args)
@@ -36,11 +42,14 @@ public int Run(string[] args)
3642
var description = "Creates table and indexes in MySQL Server database " +
3743
"to be used for distributed caching";
3844

39-
var app = new CommandLineApplication();
40-
app.FullName = "MySQL Server Cache Command Line Tool";
41-
app.Name = "dotnet-mysql-cache";
42-
app.Description = description;
43-
app.ShortVersionGetter = () =>
45+
var cliApp = new CommandLineApplication();
46+
cliApp.Error = Error;
47+
cliApp.Out = Out;
48+
49+
cliApp.FullName = "MySQL Server Cache Command Line Tool";
50+
cliApp.Name = "dotnet-mysql-cache";
51+
cliApp.Description = description;
52+
cliApp.ShortVersionGetter = () =>
4453
{
4554
var assembly = typeof(Program).GetTypeInfo().Assembly;
4655
var infoVersion = assembly
@@ -50,10 +59,13 @@ public int Run(string[] args)
5059
? assembly?.GetName().Version.ToString()
5160
: infoVersion;
5261
};
53-
app.HelpOption("-?|-h|--help");
62+
cliApp.HelpOption("-?|-h|--help");
5463

55-
app.Command("create", command =>
64+
cliApp.Command("create", command =>
5665
{
66+
command.Error = Error;//internal command Out/Erro are not yet changed, possible shortcomming
67+
command.Out = Out;
68+
5769
command.Description = description;
5870
var connectionStringArg = command.Argument(
5971
"[connectionString]",
@@ -65,11 +77,11 @@ public int Run(string[] args)
6577
command.OnExecute(async () =>
6678
{
6779
if (string.IsNullOrEmpty(connectionStringArg.Value)
68-
|| string.IsNullOrEmpty(databaseNameArg.Value)
69-
|| string.IsNullOrEmpty(tableNameArg.Value))
80+
|| string.IsNullOrEmpty(databaseNameArg.Value)
81+
|| string.IsNullOrEmpty(tableNameArg.Value))
7082
{
71-
await Console.Error.WriteLineAsync("Invalid input");
72-
app.ShowHelp();
83+
await Error.WriteLineAsync("Invalid input");
84+
cliApp.ShowHelp(command.Name);
7385
return 2;
7486
}
7587

@@ -81,18 +93,45 @@ public int Run(string[] args)
8193
});
8294
});
8395

96+
cliApp.Command("script", command =>
97+
{
98+
command.Error = Error;//internal command Out/Erro are not yet changed, possible shortcomming
99+
command.Out = Out;
100+
101+
command.Description = "Generate creation script";
102+
var databaseNameArg = command.Argument("[databaseName]", "Name of the database.");
103+
var tableNameArg = command.Argument("[tableName]", "Name of the table to be created.");
104+
command.HelpOption("-?|-h|--help");
105+
106+
command.OnExecute(async () =>
107+
{
108+
if (string.IsNullOrEmpty(databaseNameArg.Value)
109+
|| string.IsNullOrEmpty(tableNameArg.Value))
110+
{
111+
await Error.WriteLineAsync("Invalid input");
112+
cliApp.ShowHelp(command.Name);
113+
return 2;
114+
}
115+
116+
_databaseName = databaseNameArg.Value;
117+
_tableName = tableNameArg.Value;
118+
119+
return await GenerateScript();
120+
});
121+
});
122+
84123
// Show help information if no subcommand/option was specified.
85-
app.OnExecute(() =>
124+
cliApp.OnExecute(() =>
86125
{
87-
app.ShowHelp();
126+
cliApp.ShowHelp();
88127
return 2;
89128
});
90129

91-
return app.Execute(args);
130+
return cliApp.Execute(args);
92131
}
93-
catch (Exception exception)
132+
catch (Exception ex)
94133
{
95-
Console.Error.WriteLine($"An error occurred. {exception.Message}");
134+
Error.WriteLine($"An error occurred. {ex.Message}");
96135
return 1;
97136
}
98137
}
@@ -112,7 +151,7 @@ public int Run(string[] args)
112151
{
113152
if (await reader.ReadAsync(token))
114153
{
115-
Console.Error.WriteLine(
154+
Error.WriteLine(
116155
$"Table '{_tableName}' from database '{_databaseName}' already exists. " +
117156
"Provide a different table name and try again.");
118157
return 1;
@@ -138,11 +177,11 @@ public int Run(string[] args)
138177

139178
transaction.Commit();
140179

141-
await Console.Out.WriteLineAsync("Table and index were created successfully.");
180+
await Out.WriteLineAsync("Table and index were created successfully.");
142181
}
143182
catch (Exception ex)
144183
{
145-
await Console.Error.WriteLineAsync(
184+
await Error.WriteLineAsync(
146185
$"An error occurred while trying to create the table and index. {ex.Message}");
147186
transaction.Rollback();
148187

@@ -154,52 +193,36 @@ await Console.Error.WriteLineAsync(
154193
return 0;
155194
}
156195

157-
private void ValidateConnectionString()
196+
private async Task<int> GenerateScript(CancellationToken token = default(CancellationToken))
158197
{
159198
try
160199
{
161-
new MySqlConnectionStringBuilder(_connectionString);
200+
var sqlQueries = new MySqlQueries(_databaseName, _tableName);
201+
string cmd = sqlQueries.CreateTable;
202+
203+
await Out.WriteLineAsync($"{Environment.NewLine}{cmd}{Environment.NewLine}");
162204
}
163205
catch (Exception ex)
164206
{
165-
throw new ArgumentException(
166-
$"Invalid MySql server connection string '{_connectionString}'. {ex.Message}", ex);
207+
await Error.WriteLineAsync($"An error occurred while trying to create the table and index. {ex.Message}");
208+
209+
return 1;
167210
}
168-
}
169211

170-
#region IDisposable Support
171-
private bool disposedValue = false; // To detect redundant calls
212+
return 0;
213+
}
172214

173-
protected virtual void Dispose(bool disposing)
215+
private void ValidateConnectionString()
174216
{
175-
if (!disposedValue)
217+
try
176218
{
177-
if (disposing)
178-
{
179-
// TODO: dispose managed state (managed objects).
180-
}
181-
182-
// TODO: free unmanaged resources (unmanaged objects) and override a finalizer below.
183-
// TODO: set large fields to null.
184-
185-
disposedValue = true;
219+
new MySqlConnectionStringBuilder(_connectionString);
220+
}
221+
catch (Exception ex)
222+
{
223+
throw new ArgumentException(
224+
$"Invalid MySql server connection string '{_connectionString}'. {ex.Message}", ex);
186225
}
187226
}
188-
189-
// TODO: override a finalizer only if Dispose(bool disposing) above has code to free unmanaged resources.
190-
// ~Program() {
191-
// // Do not change this code. Put cleanup code in Dispose(bool disposing) above.
192-
// Dispose(false);
193-
// }
194-
195-
// This code added to correctly implement the disposable pattern.
196-
public void Dispose()
197-
{
198-
// Do not change this code. Put cleanup code in Dispose(bool disposing) above.
199-
Dispose(true);
200-
// TODO: uncomment the following line if the finalizer is overridden above.
201-
// GC.SuppressFinalize(this);
202-
}
203-
#endregion
204227
}
205228
}

src/Pomelo.Extensions.Caching.MySqlConfig.Tools/Properties/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@
1010
[assembly: AssemblyCompany("Pomelo Foundation")]
1111
[assembly: AssemblyCopyright("© Pomelo Foundation. All rights reserved.")]
1212
[assembly: AssemblyProduct("Pomelo MySql Caching")]
13-
[assembly: InternalsVisibleTo("Pomelo.Extensions.Caching.MySql.Tests")]
13+
[assembly: InternalsVisibleTo("Pomelo.Extensions.Caching.MySql.Tests, PublicKey=00240000048000009400000006020000002400005253413100040000010001002d40e2372e6f611238ace2bf7c80546c03a568c471495b6c91b89de694de5413b25ac77a005a371c46f15ab87f13d49ec7aa9bbd9fa99d8f51deb1d87c42d81047aa118519d9813bd5973e8cc8d17d8e5e5e865bce62518aa46e2348dac3db3638b00b9a8df69e1158e4ea82913b6a14c19c07fe473e7511ce91c1b7f41155cf")]

src/Pomelo.Extensions.Caching.MySqlConfig.Tools/SqlQueries.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ internal class MySqlQueries
1212
// That is why we are using 'CHARACTER SET ascii COLLATE ascii_bin' column and index
1313
// https://dev.mysql.com/doc/refman/5.7/en/innodb-restrictions.html
1414
// - Add collation to the key column to make it case-sensitive
15-
"CREATE TABLE IF NOT EXISTS `{0}` (" +
15+
"CREATE TABLE IF NOT EXISTS {0} (" +
1616
"`Id` varchar(449) CHARACTER SET ascii COLLATE ascii_bin NOT NULL," +
1717
"`AbsoluteExpiration` datetime(6) DEFAULT NULL," +
1818
"`ExpiresAtTime` datetime(6) NOT NULL," +
@@ -22,8 +22,8 @@ internal class MySqlQueries
2222
"KEY `Index_ExpiresAtTime` (`ExpiresAtTime`)" +
2323
")";
2424

25-
private const string CreateNonClusteredIndexOnExpirationTimeFormat
26-
= "CREATE NONCLUSTERED INDEX Index_ExpiresAtTime ON {0}(ExpiresAtTime)";
25+
//private const string CreateNonClusteredIndexOnExpirationTimeFormat
26+
// = "CREATE NONCLUSTERED INDEX Index_ExpiresAtTime ON {0}(ExpiresAtTime)";
2727

2828
private const string TableInfoFormat =
2929
"SELECT TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME, TABLE_TYPE " +
@@ -43,24 +43,24 @@ public MySqlQueries(string databaseName, string tableName)
4343
}
4444

4545
var tableNameWithDatabase = string.Format(
46-
"{1}", DelimitIdentifier(databaseName), DelimitIdentifier(tableName));
46+
"{0}.{1}", DelimitIdentifier(databaseName), DelimitIdentifier(tableName));
4747
CreateTable = string.Format(CreateTableFormat, tableNameWithDatabase);
48-
CreateNonClusteredIndexOnExpirationTime = string.Format(
49-
CreateNonClusteredIndexOnExpirationTimeFormat,
50-
tableNameWithDatabase);
48+
//CreateNonClusteredIndexOnExpirationTime = string.Format(
49+
// CreateNonClusteredIndexOnExpirationTimeFormat,
50+
// tableNameWithDatabase);
5151
TableInfo = string.Format(TableInfoFormat, EscapeLiteral(databaseName), EscapeLiteral(tableName));
5252
}
5353

5454
public string CreateTable { get; }
5555

56-
public string CreateNonClusteredIndexOnExpirationTime { get; }
56+
//public string CreateNonClusteredIndexOnExpirationTime { get; }
5757

5858
public string TableInfo { get; }
5959

6060
// From EF's SqlServerQuerySqlGenerator
6161
private string DelimitIdentifier(string identifier)
6262
{
63-
return identifier;
63+
return $"`{identifier}`";
6464
}
6565

6666
private string EscapeLiteral(string literal)

0 commit comments

Comments
 (0)