Skip to content

Instantly share code, notes, and snippets.

@litichevskiydv
Created July 21, 2017 04:02
Show Gist options
  • Save litichevskiydv/39ad3efb3f0726f84b9ec5aa0c8e1317 to your computer and use it in GitHub Desktop.
Save litichevskiydv/39ad3efb3f0726f84b9ec5aa0c8e1317 to your computer and use it in GitHub Desktop.
namespace ImageValidator
{
using System;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading;
using Dapper;
using JetBrains.Annotations;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Options;
using Skeleton.Dapper.ConnectionsFactory;
[UsedImplicitly]
static class Program
{
private static IConfigurationRoot _configuration;
private static void BuildConfiguration(string[] commandLineArguments)
{
var environmentConfiguration = new ConfigurationBuilder()
.AddCommandLine(commandLineArguments)
.AddEnvironmentVariables("IMAGEVALIDATOR_")
.Build();
var environmentName = environmentConfiguration["environment"];
_configuration = new ConfigurationBuilder()
.SetBasePath(Path.GetDirectoryName(typeof(Program).GetTypeInfo().Assembly.Location))
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddCommandLine(commandLineArguments)
.AddEnvironmentVariables()
.Build();
}
static int Main(string[] args)
{
BuildConfiguration(args);
var connectionsFactory =
new SqlConnectionsFactory(Options.Create(
new SqlConnectionsFactoryOptions {SqlServer = _configuration.GetConnectionString("SqlServer")}));
using (var connection = connectionsFactory.Create())
{
var actualCollation = connection.Query<string>("select collation_name from sys.databases where name = 'tempdb'").Single();
if (string.Equals(_configuration.GetValue<string>("ExpectedCollation"), actualCollation, StringComparison.OrdinalIgnoreCase) == false)
return 1;
}
return 0;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment