сервис для синхронизации приказов студентов

This commit is contained in:
kotcheshir73 2022-03-26 21:51:15 +04:00
parent 9df61f850d
commit 58cdb371c5
60 changed files with 1940 additions and 24 deletions

View File

@ -13,7 +13,7 @@ namespace CoreDatabase
if (optionsBuilder.IsConfigured == false)
{
#if RELEASE
var connectionString = ToolsModule.ServiceProvider.ServiceProviderLoader.GetConfigData("connectionString");
var connectionString = ToolsModule.ManagmentDependency.ServiceProviderLoader.GetConfigData("connectionString");
optionsBuilder.UseSqlServer(connectionString);
#endif

View File

@ -13,8 +13,27 @@ namespace ToolsModule.ManagmentDependency
/// </summary>
public static partial class ServiceProviderLoader
{
private static readonly string _pathToImplementationExt = "..\\..\\..\\..\\ImplementationExtensions\\";
private static readonly string _configFileName = "DepartmentPortal.config";
/// <summary>
/// Получение данных с файла настроек (для releaze версии сборки)
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public static string GetConfigData(string key)
{
var fileName = GetFile(_configFileName);
if (!File.Exists(fileName))
{
return string.Empty;
}
var doc = new XPathDocument(fileName);
var nav = doc.CreateNavigator();
var data = nav.SelectDescendants(key, "", false);
data.MoveNext();
return data.Current.Value;
}
/// <summary>
/// Загрузка всех классов-реализаций IImplementationExtension
/// </summary>
@ -22,13 +41,11 @@ namespace ToolsModule.ManagmentDependency
public static List<IDependencyRegistration> GetImplementationExtensions()
{
var list = new List<IDependencyRegistration>();
if(Directory.Exists(_pathToImplementationExt))
{
var files = Directory.GetFiles(_pathToImplementationExt, "*.dll", SearchOption.AllDirectories);
var files = Directory.GetFiles(TryGetImplementationExtensionsFolder(), "*.dll", SearchOption.AllDirectories);
var loadedFiles = new List<string>();
foreach(var file in files.Distinct())
foreach (var file in files.Distinct())
{
if(loadedFiles.Contains(file.GetFileName()))
if (loadedFiles.Contains(file.GetFileName()))
{
continue;
}
@ -42,7 +59,6 @@ namespace ToolsModule.ManagmentDependency
}
loadedFiles.Add(file.GetFileName());
}
}
return list;
}
@ -52,5 +68,16 @@ namespace ToolsModule.ManagmentDependency
/// <param name="fileName"></param>
/// <returns></returns>
private static string GetFile(string fileName) => Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), fileName);
private static string TryGetImplementationExtensionsFolder()
{
var directory = new DirectoryInfo(Directory.GetCurrentDirectory());
while (directory != null && !directory.GetDirectories("ImplementationExtensions", SearchOption.AllDirectories).Any(x => x.Name == "ImplementationExtensions"))
{
directory = directory.Parent;
}
return $"{directory.FullName}\\ImplementationExtensions";
}
}
}

View File

@ -268,7 +268,6 @@ namespace DepartmentBusinessLogic.BusinessLogics.GenericBusinessLogic
private void InitLogics()
{
_recordLogic = DependencyManager.Instance.Resolve<IOrderSyncHistoryRecordLogic>();
_enviromentSettingLogic = DependencyManager.Instance.Resolve<IEnviromentSettingLogic>();
_groupsLogic = DependencyManager.Instance.Resolve<IStudentGroupLogic>();

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionString>Data Source=10.3.1.13\SQLEXPRESS;Initial Catalog=DepartmentDatabasePortal;persist security info=True;user id=sa;password=isadmin;MultipleActiveResultSets=True;</connectionString>
</configuration>

View File

@ -1,17 +1,39 @@
using CoreDatabase;
using DepartmentContract.Logics.IGenericEntityLogic;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using NLog;
using NLog.Extensions.Logging;
using System;
using System.IO;
using System.Threading.Tasks;
using ToolsModule.ManagmentDependency;
using ToolsModule.ManagmentSecurity;
namespace WindowServiceSyncStudentOrders
{
/// <summary>
/// 1. Find Task Scheduler (Press the Windows + R keys on your keyboard to open Run, and then type taskschd.msc)
/// 2. If Not Exsist folder DepartmentPortal:
/// 2.1. Right-click on the "Task Scheduler Library" and click on the "New Folder" option.
/// 2.2. Enter the name of the new folder "DepartmentPortal" and click on the "OK" button.
/// 3. Navigate the following: Task Scheduler Library > New Folder (DepartmentPortal), then click on "Create Basic Task".
/// 4. Provide the Task Name such as "SyncStudentOrders" and click next.
/// 5. Choose when would you like your task to start (Weekly) and click next.
/// 6. Set the Start date and time of the task and click Next.
/// 7. Select "Start a program" option from a various list of actions and then click next.
/// 8. Click on Browse Button and choose "WindowServiceSyncStudentOrders.exe" from folder.
/// 9. Click the Finish button to complete the task.
/// </summary>
class Program
{
private static Microsoft.Extensions.Logging.ILogger _logger;
static void Main(string[] args)
{
Console.WriteLine("Start sync student orders");
ConfigLogger();
_logger.LogInformation("Start sync student orders");
try
{
DependencyManager.Instance.RegisterType<ISecurityManager, SecurityManager>();
@ -21,17 +43,32 @@ namespace WindowServiceSyncStudentOrders
Task.WaitAll(new Task[] { task });
if (task.Result)
{
Console.WriteLine("Student orders sync success");
_logger.LogInformation("Student orders sync success");
}
else
{
Console.WriteLine("Student orders sync fail");
_logger.LogInformation("Student orders sync fail");
}
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
_logger.LogError(ex, "Ошибка");
}
}
private static void ConfigLogger()
{
using ILoggerFactory loggerFactory =
LoggerFactory.Create(builder =>
{
builder.ClearProviders();
var config = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile($"appsettings.json", true, true).Build();
LogManager.Configuration = new NLogLoggingConfiguration(config.GetSection("NLog"));
builder.AddNLog();
});
_logger = loggerFactory.CreateLogger<Program>();
}
}
}

View File

@ -5,10 +5,25 @@
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0" />
<PackageReference Include="NLog.Extensions.Logging" Version="1.7.4" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Common\CoreDatabase\CoreDatabase.csproj" />
<ProjectReference Include="..\..\Common\ToolsModule\ToolsModule.csproj" />
<ProjectReference Include="..\..\Department\DepartmentContract\DepartmentContract.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="appsettings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="DepartmentPortal.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

View File

@ -0,0 +1,24 @@
{
"Logging": {
"LogLevel": {
"Default": "Debug"
}
},
"NLog": {
"throwConfigExceptions": true,
"targets": {
"logfile": {
"type": "File",
"fileName": "c:/temp/nlog.log"
}
},
"rules": [
{
"logger": "*",
"minLevel": "Debug",
"writeTo": "logfile"
}
]
}
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionString>Data Source=10.3.1.13\SQLEXPRESS;Initial Catalog=DepartmentDatabasePortal;persist security info=True;user id=sa;password=isadmin;MultipleActiveResultSets=True;</connectionString>
</configuration>

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,9 @@
{
"runtimeOptions": {
"tfm": "net5.0",
"framework": {
"name": "Microsoft.NETCore.App",
"version": "5.0.0"
}
}
}