Skip to content

Commit

Permalink
clean up the project
Browse files Browse the repository at this point in the history
  • Loading branch information
lamondlu committed Jul 25, 2020
1 parent 2f498d8 commit 5efa891
Show file tree
Hide file tree
Showing 13 changed files with 22 additions and 58 deletions.
7 changes: 3 additions & 4 deletions DemoPlugin1/Controllers/Plugin1Controller.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
using DemoPlugin1.Models;
using DemoReferenceLibrary;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.DependencyInjection;
using Mystique.Core.Attributes;
using Mystique.Core.Contracts;
using Mystique.Core.Mvc.Infrastructure;
using Newtonsoft.Json;
using System;
using Microsoft.Extensions.DependencyInjection;

namespace DemoPlugin1.Controllers
{
Expand Down Expand Up @@ -48,9 +47,9 @@ public IActionResult Register()
public IActionResult Show()
{
ServiceProvider provider = MystiqueStartup.Services.BuildServiceProvider();
using (var scope = provider.CreateScope())
using (IServiceScope scope = provider.CreateScope())
{
var handler = scope.ServiceProvider.GetService<IHandler>();
IHandler handler = scope.ServiceProvider.GetService<IHandler>();
return Content(handler.Work());
}

Expand Down
9 changes: 1 addition & 8 deletions Mystique.Core.Mvc/Infrastructure/MystiqueStartup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using Mystique.Core.BusinessLogic;
using Mystique.Core.Contracts;
using Mystique.Core.Helpers;
using Mystique.Core.Models;
using Mystique.Core.Repositories;
using Mystique.Mvc.Infrastructure;
using System;
Expand All @@ -24,13 +23,7 @@ public static class MystiqueStartup
private static readonly IList<string> _presets = new List<string>();
private static IServiceCollection _serviceCollection;

public static IServiceCollection Services
{
get
{
return _serviceCollection;
}
}
public static IServiceCollection Services => _serviceCollection;

public static void MystiqueSetup(this IServiceCollection services, IConfiguration configuration)
{
Expand Down
3 changes: 1 addition & 2 deletions Mystique.Core.Repository.MySql/UnitOfWork.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Microsoft.Extensions.Options;
using Mystique.Core.Models;
using Mystique.Core.Repositories;
using System;
using System.Collections.Generic;
using MySqlClient = MySql.Data.MySqlClient;

Expand Down Expand Up @@ -41,7 +40,7 @@ public void Commit()

public bool CheckDatabase()
{
var o = _dbHelper.ExecuteScalarWithObjReturn("SELECT `Value` FROM GlobalSettings WHERE `Key` = @key", new List<MySqlClient.MySqlParameter> {
object o = _dbHelper.ExecuteScalarWithObjReturn("SELECT `Value` FROM GlobalSettings WHERE `Key` = @key", new List<MySqlClient.MySqlParameter> {
new MySqlClient.MySqlParameter { ParameterName = "@key", Value = "SYSTEM_INSTALLED"}
}.ToArray());

Expand Down
6 changes: 1 addition & 5 deletions Mystique.Core/Contracts/IAuthorization.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Mystique.Core.Contracts
namespace Mystique.Core.Contracts
{
public interface IAuthorization
{
Expand Down
6 changes: 1 addition & 5 deletions Mystique.Core/Contracts/ISystemManager.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Mystique.Core.Contracts
namespace Mystique.Core.Contracts
{
public interface ISystemManager
{
Expand Down
4 changes: 1 addition & 3 deletions Mystique.Core/DomainModel/BaseMigration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
using Mystique.Core.Helpers;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;

namespace Mystique.Core.DomainModel
{
Expand Down Expand Up @@ -58,7 +56,7 @@ private void RemoveMigrationScripts(Guid pluginId)
new MySqlParameter{ ParameterName = "@version", MySqlDbType = MySqlDbType.VarChar, Value = _version.VersionNumber }
}.ToArray());


}

private void WriteMigrationScripts(Guid pluginId)
Expand Down
1 change: 0 additions & 1 deletion Mystique.Core/Helpers/DbHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;

namespace Mystique.Core.Helpers
{
Expand Down
4 changes: 0 additions & 4 deletions Mystique/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
using Microsoft.AspNetCore.Mvc;
using Mystique.Core.Contracts;
using Mystique.Core.Mvc.Extensions;
using Mystique.Core.ViewModels;
using Mystique.Models;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace Mystique.Controllers
{
Expand Down
14 changes: 6 additions & 8 deletions Mystique/Controllers/SystemController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;

namespace Mystique.Controllers
{
public class SystemController : Controller
{
private ISystemManager _systemManager;
private IPluginManager _pluginManager;
private readonly ISystemManager _systemManager;
private readonly IPluginManager _pluginManager;


public SystemController(ISystemManager systemManager, IPluginManager pluginManager)
Expand All @@ -24,8 +22,8 @@ public SystemController(ISystemManager systemManager, IPluginManager pluginManag

public IActionResult Setup()
{
var presetPluginLoader = new PresetPluginLoader();
var plugins = presetPluginLoader.LoadPlugins();
PresetPluginLoader presetPluginLoader = new PresetPluginLoader();
List<string> plugins = presetPluginLoader.LoadPlugins();

if (plugins.Count == 0)
{
Expand All @@ -41,9 +39,9 @@ public IActionResult Install([FromBody]SetupModulesModel model)
{
if (model != null && model.Modules != null)
{
foreach (var module in model.Modules)
foreach (string module in model.Modules)
{
using (var fs = new FileStream(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "PresetModules", module), FileMode.Open))
using (FileStream fs = new FileStream(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "PresetModules", module), FileMode.Open))
{
_pluginManager.AddPlugins(new Core.DomainModel.PluginPackage(fs));
}
Expand Down
4 changes: 0 additions & 4 deletions Mystique/Controllers/UserController.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Mystique.Controllers
{
Expand Down
5 changes: 1 addition & 4 deletions Mystique/Models/SetupModulesModel.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Collections.Generic;

namespace Mystique.Models
{
Expand Down
12 changes: 5 additions & 7 deletions Mystique/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.IO;
using FluentMigrator.Runner;
using FluentMigrator.Runner;
using FluentMigrator.Runner.Initialization;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
Expand All @@ -11,7 +9,7 @@
using Mystique.Core.Models;
using Mystique.Core.Mvc.Infrastructure;
using Mystique.Core.Repository.MySql.Migrations;
using Mystique.Models;
using System;

namespace Mystique
{
Expand All @@ -30,13 +28,13 @@ public void ConfigureServices(IServiceCollection services)
services.AddOptions();
services.Configure<ConnectionStringSetting>(Configuration.GetSection("ConnectionStringSetting"));

var siteSettings = new ConnectionStringSetting();
ConnectionStringSetting siteSettings = new ConnectionStringSetting();

Configuration.Bind("ConnectionStringSetting", siteSettings);

using (var scope = CreateServices(siteSettings).CreateScope())
using (IServiceScope scope = CreateServices(siteSettings).CreateScope())
{
var runner = scope.ServiceProvider.GetRequiredService<IMigrationRunner>();
IMigrationRunner runner = scope.ServiceProvider.GetRequiredService<IMigrationRunner>();
runner.MigrateUp();
}

Expand Down
5 changes: 2 additions & 3 deletions Mystique/Utilities/PresetPluginLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;

namespace Mystique.Utilities
{
public class PresetPluginLoader
{
public List<string> LoadPlugins()
{
var di = new DirectoryInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "PresetModules"));
DirectoryInfo di = new DirectoryInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "PresetModules"));

var files = di.GetFiles("*.zip");
FileInfo[] files = di.GetFiles("*.zip");

return files.Select(p => p.Name).ToList();
}
Expand Down

0 comments on commit 5efa891

Please sign in to comment.