74 lines
3.0 KiB
C#
74 lines
3.0 KiB
C#
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)
|
|
{
|
|
ConfigLogger();
|
|
|
|
_logger.LogInformation("Start sync student orders");
|
|
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)
|
|
{
|
|
_logger.LogInformation("Student orders sync success");
|
|
}
|
|
else
|
|
{
|
|
_logger.LogInformation("Student orders sync fail");
|
|
}
|
|
}
|
|
catch(Exception ex)
|
|
{
|
|
_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>();
|
|
}
|
|
}
|
|
} |