removing app.config and web.config and putting in code

starting support for mysql (for linux)
This commit is contained in:
RaidMax 2018-04-06 19:15:17 -05:00
parent b6f490be9c
commit 466b273736
15 changed files with 1097 additions and 102 deletions

File diff suppressed because it is too large Load Diff

View File

@ -72,6 +72,6 @@
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup> <PropertyGroup>
<PostBuildEvent>copy /Y "$(TargetDir)$(TargetName).dll" "$(SolutionDir)BUILD\plugins\"</PostBuildEvent> <PostBuildEvent Condition=" '$(OS)' != 'Unix' ">copy /Y "$(TargetDir)$(TargetName).dll" "$(SolutionDir)BUILD\plugins\"</PostBuildEvent>
</PropertyGroup> </PropertyGroup>
</Project> </Project>

View File

@ -156,7 +156,7 @@
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup> <PropertyGroup>
<PostBuildEvent>copy /Y "$(TargetDir)$(TargetName).dll" "$(SolutionDir)BUILD\plugins\"</PostBuildEvent> <PostBuildEvent Condition=" '$(OS)' != 'Unix' ">copy /Y "$(TargetDir)$(TargetName).dll" "$(SolutionDir)BUILD\plugins\"</PostBuildEvent>
</PropertyGroup> </PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets. Other similar extension points exist, see Microsoft.Common.targets.

View File

@ -135,7 +135,7 @@
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup> <PropertyGroup>
<PostBuildEvent>copy /Y "$(TargetDir)$(TargetName).dll" "$(SolutionDir)BUILD\plugins\$(TargetName).dll" <PostBuildEvent Condition=" '$(OS)' != 'Unix' ">copy /Y "$(TargetDir)$(TargetName).dll" "$(SolutionDir)BUILD\plugins\$(TargetName).dll"
copy /Y "$(ProjectDir)GeoIP.dat" "$(SolutionDir)BUILD\plugins\GeoIP.dat"</PostBuildEvent> copy /Y "$(ProjectDir)GeoIP.dat" "$(SolutionDir)BUILD\plugins\GeoIP.dat"</PostBuildEvent>
</PropertyGroup> </PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- To modify your build process, add your task inside one of the targets below and uncomment it.

View File

@ -1,36 +0,0 @@
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2"/>
</startup>
<runtime>
<assemblyBinding>
<!-- <probing privatePath="lib"/>-->
</assemblyBinding>
</runtime>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlCeConnectionFactory, EntityFramework">
<parameters>
<parameter value="System.Data.SqlServerCe.4.0" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlServerCe.4.0" type="System.Data.Entity.SqlServerCompact.SqlCeProviderServices, EntityFramework.SqlServerCompact" />
</providers>
</entityFramework>
<system.data>
<DbProviderFactories>
<remove invariant="System.Data.SqlServerCe.4.0" />
<add name="Microsoft SQL Server Compact Data Provider 4.0" invariant="System.Data.SqlServerCe.4.0" description=".NET Framework Data Provider for Microsoft SQL Server Compact" type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" />
</DbProviderFactories>
</system.data>
<connectionStrings>
<add name="DefaultConnection"
providerName="System.Data.SqlServerCe.4.0"
connectionString="Data Source=|DataDirectory|\Database.sdf"/>
</connectionStrings>
</configuration>

View File

@ -0,0 +1,30 @@
using System;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Data.Entity.SqlServerCompact;
using System.Data.SqlServerCe;
namespace SharedLibrary.Database
{
class ContextConfiguration : DbConfiguration
{
public ContextConfiguration()
{
if (!Utilities.IsRunningOnMono())
{
SetExecutionStrategy("System.Data.SqlServerCe.4.0", () => new DefaultExecutionStrategy());
SetProviderFactory("System.Data.SqlServerCe.4.0", new SqlCeProviderFactory());
SetProviderServices("System.Data.SqlServerCe.4.0", SqlCeProviderServices.Instance);
SetDefaultConnectionFactory(new SqlCeConnectionFactory("System.Data.SqlServerCe.4.0"));
}
else
{
/* SetExecutionStrategy("MySql.Data.MySqlClient", () => new DefaultExecutionStrategy());
SetProviderFactory("MySql.Data.MySqlClient", new MySql.Data.MySqlClient.MySqlClientFactory());
SetProviderServices("MySql.Data.MySqlClient", new MySql.Data.MySqlClient.MySqlProviderServices());
SetDefaultConnectionFactory(new MySql.Data.Entity.MySqlConnectionFactory());*/
}
}
}
}

View File

@ -11,10 +11,12 @@ using System.Reflection;
using System.Data.Entity.Infrastructure; using System.Data.Entity.Infrastructure;
using System.Data.Entity.SqlServerCompact; using System.Data.Entity.SqlServerCompact;
using System.IO; using System.IO;
using System.Data.Common;
namespace SharedLibrary.Database namespace SharedLibrary.Database
{ {
[DbConfigurationType(typeof(ContextConfiguration))]
public class DatabaseContext : DbContext public class DatabaseContext : DbContext
{ {
public DbSet<EFClient> Clients { get; set; } public DbSet<EFClient> Clients { get; set; }
@ -22,7 +24,9 @@ namespace SharedLibrary.Database
public DbSet<EFAliasLink> AliasLinks { get; set; } public DbSet<EFAliasLink> AliasLinks { get; set; }
public DbSet<EFPenalty> Penalties { get; set; } public DbSet<EFPenalty> Penalties { get; set; }
public DatabaseContext() : base("DefaultConnection") public static string ConnectionString;
public DatabaseContext() : base(ConnectionString)
{ {
System.Data.Entity.Database.SetInitializer(new MigrateDatabaseToLatestVersion<DatabaseContext, Migrations.Configuration>()); System.Data.Entity.Database.SetInitializer(new MigrateDatabaseToLatestVersion<DatabaseContext, Migrations.Configuration>());
//Database.CreateIfNotExists(); //Database.CreateIfNotExists();
@ -62,7 +66,7 @@ namespace SharedLibrary.Database
directoryFiles = Directory.GetFiles($@"{Environment.CurrentDirectory}\bin\x86\Debug\Plugins").Where(f => f.Contains(".dll")); directoryFiles = Directory.GetFiles($@"{Environment.CurrentDirectory}\bin\x86\Debug\Plugins").Where(f => f.Contains(".dll"));
} }
catch(Exception) catch (Exception)
{ {
directoryFiles = Directory.GetFiles($@"{Environment.CurrentDirectory}\Plugins").Where(f => f.Contains(".dll")); directoryFiles = Directory.GetFiles($@"{Environment.CurrentDirectory}\Plugins").Where(f => f.Contains(".dll"));
} }

View File

@ -148,6 +148,7 @@
<ItemGroup> <ItemGroup>
<Compile Include="Configuration\MapConfiguration.cs" /> <Compile Include="Configuration\MapConfiguration.cs" />
<Compile Include="Configuration\ServerConfiguration.cs" /> <Compile Include="Configuration\ServerConfiguration.cs" />
<Compile Include="Database\ContextConfiguration.cs" />
<Compile Include="Database\Importer.cs" /> <Compile Include="Database\Importer.cs" />
<Compile Include="Database\DatabaseContext.cs" /> <Compile Include="Database\DatabaseContext.cs" />
<Compile Include="Database\Models\EFAlias.cs" /> <Compile Include="Database\Models\EFAlias.cs" />
@ -209,7 +210,6 @@
<Compile Include="Utilities.cs" /> <Compile Include="Utilities.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Content Include="app.config" />
<Compile Include="Dtos\EventInfo.cs" /> <Compile Include="Dtos\EventInfo.cs" />
<Content Include="LibSQLCe\x86\Microsoft.VC90.CRT\msvcr90.dll" /> <Content Include="LibSQLCe\x86\Microsoft.VC90.CRT\msvcr90.dll" />
<Content Include="LibSQLCe\x86\Microsoft.VC90.CRT\README_ENU.txt" /> <Content Include="LibSQLCe\x86\Microsoft.VC90.CRT\README_ENU.txt" />
@ -240,6 +240,12 @@
<PackageReference Include="Microsoft.Extensions.Configuration.Json"> <PackageReference Include="Microsoft.Extensions.Configuration.Json">
<Version>1.1.2</Version> <Version>1.1.2</Version>
</PackageReference> </PackageReference>
<PackageReference Include="MySql.Data">
<Version>6.10.6</Version>
</PackageReference>
<PackageReference Include="MySql.Data.Entity">
<Version>6.10.6</Version>
</PackageReference>
<PackageReference Include="Newtonsoft.Json"> <PackageReference Include="Newtonsoft.Json">
<Version>11.0.1</Version> <Version>11.0.1</Version>
</PackageReference> </PackageReference>
@ -261,12 +267,12 @@
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup> <PropertyGroup>
<PostBuildEvent>if not exist "$(ProjectDir)LibSQLCE\x86" md "$(TargetDir)x86" <PostBuildEvent Condition=" '$(OS)' != 'Unix' ">if not exist "$(ProjectDir)LibSQLCE\x86" md "$(TargetDir)x86"
xcopy /y "$(ProjectDir)LibSQLCE\x86" "$(TargetDir)x86\" xcopy /y "$(ProjectDir)LibSQLCE\x86" "$(TargetDir)x86\"
</PostBuildEvent> </PostBuildEvent>
</PropertyGroup> </PropertyGroup>
<PropertyGroup> <PropertyGroup>
<PreBuildEvent>if not exist "$(SolutionDir)BUILD" mkdir "$(SolutionDir)BUILD" <PreBuildEvent Condition=" '$(OS)' != 'Unix' ">if not exist "$(SolutionDir)BUILD" mkdir "$(SolutionDir)BUILD"
if not exist "$(SolutionDir)BUILD\userraw\scripts" mkdir "$(SolutionDir)BUILD\userraw\scripts"</PreBuildEvent> if not exist "$(SolutionDir)BUILD\userraw\scripts" mkdir "$(SolutionDir)BUILD\userraw\scripts"</PreBuildEvent>
</PropertyGroup> </PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- To modify your build process, add your task inside one of the targets below and uncomment it.

View File

@ -434,5 +434,7 @@ namespace SharedLibrary
#endif #endif
return Utilities.PlayersFromStatus(response); return Utilities.PlayersFromStatus(response);
} }
public static bool IsRunningOnMono() => Type.GetType("Mono.Runtime") != null;
} }
} }

View File

@ -16,7 +16,19 @@ namespace WebfrontCore
.SetBasePath(env.ContentRootPath) .SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: false) .AddJsonFile("appsettings.json", optional: true, reloadOnChange: false)
.AddEnvironmentVariables(); .AddEnvironmentVariables();
Configuration = builder.Build(); Configuration = builder.Build();
// fixme: this is really really terrible
if (!SharedLibrary.Utilities.IsRunningOnMono())
{
SharedLibrary.Database.DatabaseContext.ConnectionString = Configuration["ConnectionStrings:WindowsConnection"];
}
else
{
SharedLibrary.Database.DatabaseContext.ConnectionString = Configuration["ConnectionStrings:LinuxConnection"];
}
if (!IW4MAdmin.Program.Start()) if (!IW4MAdmin.Program.Start())
Environment.Exit(-1); Environment.Exit(-1);

View File

@ -1,4 +1,4 @@
<h3 class="pb-2 text-center ">@ViewBag.Title</h3> <h4 class="pb-2 text-center ">@ViewBag.Title</h4>
<div class="row"> <div class="row">
<table class="table table-striped"> <table class="table table-striped">
<thead class="d-none d-md-table-header-group"> <thead class="d-none d-md-table-header-group">

View File

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk.Web"> <Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net452</TargetFramework> <TargetFramework>net452</TargetFramework>
@ -33,7 +33,6 @@
<Content Remove="bower.json" /> <Content Remove="bower.json" />
<Content Remove="bundleconfig.json" /> <Content Remove="bundleconfig.json" />
<Content Remove="compilerconfig.json" /> <Content Remove="compilerconfig.json" />
<Content Remove="web.config" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
@ -77,7 +76,6 @@
<None Include="bower.json" /> <None Include="bower.json" />
<None Include="bundleconfig.json" /> <None Include="bundleconfig.json" />
<None Include="compilerconfig.json" /> <None Include="compilerconfig.json" />
<None Include="web.config" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
@ -96,7 +94,11 @@
<Folder Include="Views\Account\" /> <Folder Include="Views\Account\" />
</ItemGroup> </ItemGroup>
<Target Name="PreBuild" BeforeTargets="PreBuildEvent"> <PropertyGroup>
<Exec Command="if not &quot;$(SolutionDir)&quot;==&quot;*Undefined*&quot; (&#xD;&#xA; xcopy /Y &quot;$(SolutionDir)BUILD\Plugins&quot; &quot;$(TargetDir)Plugins\&quot;&#xD;&#xA;)" /> <PostBuildEvent Condition=" '$(OS)' != 'Unix' ">if not exist "$(ProjectDir)LibSQLCE\x86" md "$(TargetDir)x86" xcopy /y "$(ProjectDir)LibSQLCE\x86" "$(TargetDir)x86\"</PostBuildEvent>
</Target> </PropertyGroup>
<PropertyGroup>
<PreBuildEvent Condition=" '$(OS)' != 'Unix' ">if not exist "$(SolutionDir)BUILD" mkdir "$(SolutionDir)BUILD" if not exist "$(SolutionDir)BUILD\userraw\scripts" mkdir "$(SolutionDir)BUILD\userraw\scripts"</PreBuildEvent>
</PropertyGroup>
</Project> </Project>

View File

@ -1,37 +0,0 @@
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2"/>
</startup>
<runtime>
<loadFromRemoteSources enabled="true"/>
<assemblyBinding>
<!-- <probing privatePath="lib"/>-->
</assemblyBinding>
</runtime>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlCeConnectionFactory, EntityFramework">
<parameters>
<parameter value="System.Data.SqlServerCe.4.0" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlServerCe.4.0" type="System.Data.Entity.SqlServerCompact.SqlCeProviderServices, EntityFramework.SqlServerCompact" />
</providers>
</entityFramework>
<system.data>
<DbProviderFactories>
<remove invariant="System.Data.SqlServerCe.4.0" />
<add name="Microsoft SQL Server Compact Data Provider 4.0" invariant="System.Data.SqlServerCe.4.0" description=".NET Framework Data Provider for Microsoft SQL Server Compact" type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" />
</DbProviderFactories>
</system.data>
<connectionStrings>
<add name="DefaultConnection"
providerName="System.Data.SqlServerCe.4.0"
connectionString="Data Source=|DataDirectory|\Database.sdf"/>
</connectionStrings>
</configuration>

View File

@ -9,5 +9,9 @@
}, },
"Web": { "Web": {
"Address": "http://127.0.0.1:5000" "Address": "http://127.0.0.1:5000"
},
"ConnectionStrings": {
"WindowsConnection": "Data Source=|DataDirectory|\\Database.sdf",
"LinuxConnection": "server=server;user=user;database=db;password=pass"
} }
} }

View File

@ -1,14 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<!--
Configure your application settings in appsettings.json. Learn more at http://go.microsoft.com/fwlink/?LinkId=786380
-->
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified"/>
</handlers>
<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false"/>
</system.webServer>
</configuration>