2022-03-20 21:23:42 +04:00
|
|
|
|
using CoreDatabase;
|
|
|
|
|
using DepartmentContract.Logics.IGenericEntityLogic;
|
2022-03-26 21:51:15 +04:00
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using NLog;
|
|
|
|
|
using NLog.Extensions.Logging;
|
2022-03-20 21:23:42 +04:00
|
|
|
|
using System;
|
2022-03-26 21:51:15 +04:00
|
|
|
|
using System.IO;
|
2022-03-20 21:23:42 +04:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using ToolsModule.ManagmentDependency;
|
|
|
|
|
using ToolsModule.ManagmentSecurity;
|
|
|
|
|
|
|
|
|
|
namespace WindowServiceSyncStudentOrders
|
|
|
|
|
{
|
2022-03-26 21:51:15 +04:00
|
|
|
|
/// <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>
|
2022-03-20 21:23:42 +04:00
|
|
|
|
class Program
|
|
|
|
|
{
|
2022-03-26 21:51:15 +04:00
|
|
|
|
private static Microsoft.Extensions.Logging.ILogger _logger;
|
|
|
|
|
|
2022-03-20 21:23:42 +04:00
|
|
|
|
static void Main(string[] args)
|
|
|
|
|
{
|
2022-03-26 21:51:15 +04:00
|
|
|
|
ConfigLogger();
|
|
|
|
|
|
|
|
|
|
_logger.LogInformation("Start sync student orders");
|
2022-03-20 21:23:42 +04:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
DependencyManager.Instance.RegisterType<ISecurityManager, SecurityManager>();
|
|
|
|
|
DependencyManager.InitDependency();
|
|
|
|
|
var logic = DependencyManager.Instance.Resolve<IOrderSyncHistoryLogic>();
|
|
|
|
|
var task = Task.Run(() => logic.SyncOrders());
|
|
|
|
|
Task.WaitAll(new Task[] { task });
|
|
|
|
|
if (task.Result)
|
|
|
|
|
{
|
2022-03-26 21:51:15 +04:00
|
|
|
|
_logger.LogInformation("Student orders sync success");
|
2022-03-20 21:23:42 +04:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2022-03-26 21:51:15 +04:00
|
|
|
|
_logger.LogInformation("Student orders sync fail");
|
2022-03-20 21:23:42 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch(Exception ex)
|
|
|
|
|
{
|
2022-03-26 21:51:15 +04:00
|
|
|
|
_logger.LogError(ex, "Ошибка");
|
2022-03-20 21:23:42 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-03-26 21:51:15 +04:00
|
|
|
|
|
|
|
|
|
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>();
|
|
|
|
|
}
|
2022-03-20 21:23:42 +04:00
|
|
|
|
}
|
|
|
|
|
}
|