From d77bffabdda887a198a7d2920eb0a6af786bbde7 Mon Sep 17 00:00:00 2001 From: SamSys Date: Wed, 24 Dec 2025 15:56:00 +0330 Subject: [PATCH] add SeriLog on Backgroundtask InstitutionContract --- .../BackgroundInstitutionContract.Task.csproj | 5 + .../Jobs/JobSchedulerRegistrator.cs | 46 +- .../Program.cs | 33 + .../appsettings.Development.json | 4 +- .../InstitutionContractRepository.cs | 11 +- .../Services/SmsService.cs | 891 +++++++++--------- 6 files changed, 522 insertions(+), 468 deletions(-) diff --git a/BackgroundInstitutionContract/BackgroundInstitutionContract.Task/BackgroundInstitutionContract.Task.csproj b/BackgroundInstitutionContract/BackgroundInstitutionContract.Task/BackgroundInstitutionContract.Task.csproj index 3032b3a1..22ef8bc5 100644 --- a/BackgroundInstitutionContract/BackgroundInstitutionContract.Task/BackgroundInstitutionContract.Task.csproj +++ b/BackgroundInstitutionContract/BackgroundInstitutionContract.Task/BackgroundInstitutionContract.Task.csproj @@ -17,4 +17,9 @@ + + + + + diff --git a/BackgroundInstitutionContract/BackgroundInstitutionContract.Task/Jobs/JobSchedulerRegistrator.cs b/BackgroundInstitutionContract/BackgroundInstitutionContract.Task/Jobs/JobSchedulerRegistrator.cs index b4487ac7..7c6847af 100644 --- a/BackgroundInstitutionContract/BackgroundInstitutionContract.Task/Jobs/JobSchedulerRegistrator.cs +++ b/BackgroundInstitutionContract/BackgroundInstitutionContract.Task/Jobs/JobSchedulerRegistrator.cs @@ -15,41 +15,43 @@ public class JobSchedulerRegistrator private static DateTime? _lastRunCreateTransaction; private static DateTime? _lastRunSendMonthlySms; private readonly ISmsService _smsService; + private readonly ILogger _logger; - public JobSchedulerRegistrator(SmsReminder smsReminder, IBackgroundJobClient backgroundJobClient, IInstitutionContractRepository institutionContractRepository, ISmsService smsService) + public JobSchedulerRegistrator(SmsReminder smsReminder, IBackgroundJobClient backgroundJobClient, IInstitutionContractRepository institutionContractRepository, ISmsService smsService, ILogger logger) { _smsReminder = smsReminder; _backgroundJobClient = backgroundJobClient; _institutionContractRepository = institutionContractRepository; _smsService = smsService; + _logger = logger; } public void Register() { + _logger.LogInformation("hangfire Started"); + //RecurringJob.AddOrUpdate( + // "InstitutionContract.CreateFinancialTransaction", + // () => CreateFinancialTransaction(), + // "*/30 * * * *" // هر 30 دقیقه یکبار چک کن + //); - RecurringJob.AddOrUpdate( - "InstitutionContract.CreateFinancialTransaction", - () => CreateFinancialTransaction(), - "*/30 * * * *" // هر 30 دقیقه یکبار چک کن - ); + //RecurringJob.AddOrUpdate( + // "InstitutionContract.SendMonthlySms", + // () => SendFirstDayOfMonthSms(), + // "*/20 * * * *" // هر 30 دقیقه یکبار چک کن + //); - RecurringJob.AddOrUpdate( - "InstitutionContract.SendMonthlySms", - () => SendFirstDayOfMonthSms(), - "*/20 * * * *" // هر 30 دقیقه یکبار چک کن - ); - - RecurringJob.AddOrUpdate( - "InstitutionContract.SendReminderSms", - () => SendReminderSms(), - "*/1 * * * *" // هر 1 دقیقه یکبار چک کن - ); - RecurringJob.AddOrUpdate( - "InstitutionContract.SendBlockSms", - () => SendBlockSms(), - "*/1 * * * *" // هر 1 دقیقه یکبار چک کن - ); + //RecurringJob.AddOrUpdate( + // "InstitutionContract.SendReminderSms", + // () => SendReminderSms(), + // "*/1 * * * *" // هر 1 دقیقه یکبار چک کن + //); + //RecurringJob.AddOrUpdate( + // "InstitutionContract.SendBlockSms", + // () => SendBlockSms(), + // "*/1 * * * *" // هر 1 دقیقه یکبار چک کن + //); RecurringJob.AddOrUpdate( "InstitutionContract.SendInstitutionContractConfirmSms", () => SendInstitutionContractConfirmSms(), diff --git a/BackgroundInstitutionContract/BackgroundInstitutionContract.Task/Program.cs b/BackgroundInstitutionContract/BackgroundInstitutionContract.Task/Program.cs index c08fcf29..1319cee2 100644 --- a/BackgroundInstitutionContract/BackgroundInstitutionContract.Task/Program.cs +++ b/BackgroundInstitutionContract/BackgroundInstitutionContract.Task/Program.cs @@ -17,9 +17,37 @@ using Microsoft.AspNetCore.Identity; using MongoDB.Driver; using PersonalContractingParty.Config; using Query.Bootstrapper; +using Serilog; +using Serilog.Events; using Shared.Contracts.PmUser.Queries; using WorkFlow.Infrastructure.Config; +var logDirectory = @"C:\Logs\Hangfire\BackgroundInstitutionContract\"; + +if (!Directory.Exists(logDirectory)) +{ + Directory.CreateDirectory(logDirectory); +} + +Log.Logger = new LoggerConfiguration() + //NO EF Core log + .MinimumLevel.Override("Microsoft.EntityFrameworkCore", LogEventLevel.Warning) + + //NO DbCommand log + .MinimumLevel.Override("Microsoft.EntityFrameworkCore.Database.Command", LogEventLevel.Warning) + + //NO Microsoft Public log + .MinimumLevel.Override("Microsoft", LogEventLevel.Warning) + + .WriteTo.File( + path: Path.Combine(logDirectory, "institution-contract-log-.txt"), + rollingInterval: RollingInterval.Day, + retainedFileCountLimit: 30, + shared: true, + outputTemplate: + "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level}] {Message}{NewLine}{Exception}" + ).CreateLogger(); + var builder = WebApplication.CreateBuilder(args); var hangfireConnectionString = builder.Configuration.GetConnectionString("HangfireDb"); builder.Services.AddHangfire(x => x.UseSqlServerStorage(hangfireConnectionString)); @@ -59,7 +87,12 @@ builder.Services.AddHttpClient(); builder.Services.AddHttpContextAccessor(); builder.Services.AddSignalR(); + +builder.Host.UseSerilog(); + + var app = builder.Build(); + app.MapHub("/sendSmsHub"); app.MapHangfireDashboard(); diff --git a/BackgroundInstitutionContract/BackgroundInstitutionContract.Task/appsettings.Development.json b/BackgroundInstitutionContract/BackgroundInstitutionContract.Task/appsettings.Development.json index 07d44356..539c3b25 100644 --- a/BackgroundInstitutionContract/BackgroundInstitutionContract.Task/appsettings.Development.json +++ b/BackgroundInstitutionContract/BackgroundInstitutionContract.Task/appsettings.Development.json @@ -25,8 +25,8 @@ //mahan Docker //"MesbahDb": "Data Source=localhost,5069;Initial Catalog=mesbah_db;User ID=sa;Password=YourPassword123;TrustServerCertificate=True;", - //"HangfireDb": "Data Source=.;Initial Catalog=hangfire_db;Integrated Security=True;TrustServerCertificate=true;", - "HangfireDb": "Data Source=185.208.175.186;Initial Catalog=hangfire_db;Persist Security Info=False;User ID=ir_db;Password=R2rNp[170]18[3019]#@ATt;TrustServerCertificate=true;" + "HangfireDb": "Data Source=.;Initial Catalog=hangfire_db;Integrated Security=True;TrustServerCertificate=true;", + //"HangfireDb": "Data Source=185.208.175.186;Initial Catalog=hangfire_db;Persist Security Info=False;User ID=ir_db;Password=R2rNp[170]18[3019]#@ATt;TrustServerCertificate=true;" }, "GoogleRecaptchaV3": { diff --git a/CompanyManagment.EFCore/Repository/InstitutionContractRepository.cs b/CompanyManagment.EFCore/Repository/InstitutionContractRepository.cs index 8e6e4c18..bc82722e 100644 --- a/CompanyManagment.EFCore/Repository/InstitutionContractRepository.cs +++ b/CompanyManagment.EFCore/Repository/InstitutionContractRepository.cs @@ -25,6 +25,7 @@ using CompanyManagment.App.Contracts.TemporaryClientRegistration; using CompanyManagment.App.Contracts.Workshop; using Microsoft.AspNetCore.SignalR; using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Logging; using MongoDB.Driver; using PersianTools.Core; using System; @@ -54,6 +55,7 @@ public class InstitutionContractRepository : RepositoryBase _hubContext; + private readonly ILogger _logger; private readonly InstitutionContratVerificationParty _firstParty = new() { @@ -69,7 +71,7 @@ public class InstitutionContractRepository : RepositoryBase hubContext) : base(context) + IFinancialStatmentRepository financialStatmentRepository, IHubContext hubContext, ILogger logger) : base(context) { _context = context; _employerRepository = employerRepository; @@ -80,6 +82,7 @@ public class InstitutionContractRepository : RepositoryBase("InstitutionContractExtensionTemp"); _institutionAmendmentTemp = @@ -4378,7 +4381,7 @@ public class InstitutionContractRepository : RepositoryBase _testNumbers; - public SmsIr SmsIr { get; set; } + private readonly IConfiguration _configuration; + private readonly ISmsResultRepository _smsResultRepository; + private readonly bool _isDevEnvironment; + private readonly List _testNumbers; + private readonly ILogger _logger; + public SmsIr SmsIr { get; set; } - public SmsService(IConfiguration configuration, ISmsResultRepository smsResultRepository) - { - _configuration = configuration; - _smsResultRepository = smsResultRepository; - SmsIr = new SmsIr("Og5M562igmzJRhQPnq0GdtieYdLgtfikjzxOmeQBPxJjZtyge5Klc046Lfw1mxSa"); + public SmsService(IConfiguration configuration, ISmsResultRepository smsResultRepository, ILogger logger) + { + _configuration = configuration; + _smsResultRepository = smsResultRepository; + _logger = logger; + SmsIr = new SmsIr("Og5M562igmzJRhQPnq0GdtieYdLgtfikjzxOmeQBPxJjZtyge5Klc046Lfw1mxSa"); - // خواندن تنظیمات SMS از appsettings - var smsSettings = _configuration.GetSection("SmsSettings"); - _isDevEnvironment = smsSettings.GetValue("IsTestMode"); - _testNumbers = smsSettings.GetSection("TestNumbers").Get>() ?? new List(); - } + // خواندن تنظیمات SMS از appsettings + var smsSettings = _configuration.GetSection("SmsSettings"); + _isDevEnvironment = smsSettings.GetValue("IsTestMode"); + _testNumbers = smsSettings.GetSection("TestNumbers").Get>() ?? new List(); + } - /// - /// متد مرکزی برای ارسال پیامک که محیط dev را چک می‌کند - /// - private async Task> VerifySendSmsAsync(string number, int templateId, VerifySendParameter[] parameters) - { - // اگر محیط dev است و شماره‌های تست وجود دارد، به شماره‌های تست ارسال می‌شود - if (_isDevEnvironment && _testNumbers is { Count: > 0 }) - { - // ارسال به همه شماره‌های تست - SmsIrResult lastResult = null; - foreach (var testNumber in _testNumbers) - { - lastResult = await SmsIr.VerifySendAsync(testNumber, templateId, parameters); - } - return lastResult; // برگرداندن نتیجه آخرین ارسال - } - else - { - // ارسال به شماره واقعی - return await SmsIr.VerifySendAsync(number, templateId, parameters); - } - } + /// + /// متد مرکزی برای ارسال پیامک که محیط dev را چک می‌کند + /// + private async Task> VerifySendSmsAsync(string number, int templateId, VerifySendParameter[] parameters) + { + // اگر محیط dev است و شماره‌های تست وجود دارد، به شماره‌های تست ارسال می‌شود + if (_isDevEnvironment && _testNumbers is { Count: > 0 }) + { + // ارسال به همه شماره‌های تست + SmsIrResult lastResult = null; + foreach (var testNumber in _testNumbers) + { + lastResult = await SmsIr.VerifySendAsync(testNumber, templateId, parameters); + } + return lastResult; // برگرداندن نتیجه آخرین ارسال + } + else + { + // ارسال به شماره واقعی + return await SmsIr.VerifySendAsync(number, templateId, parameters); + } + } - public void Send(string number, string message) - { - //var token = GetToken(); - //var lines = new SmsLine().GetSmsLines(token); - //if (lines == null) return; + public void Send(string number, string message) + { + //var token = GetToken(); + //var lines = new SmsLine().GetSmsLines(token); + //if (lines == null) return; - //var line = lines.SMSLines.Last().LineNumber.ToString(); - //var data = new MessageSendObject - //{ - // Messages = new List - // {message}.ToArray(), - // MobileNumbers = new List {number}.ToArray(), - // LineNumber = line, - // SendDateTime = DateTime.Now, - // CanContinueInCaseOfError = true - //}; - //var messageSendResponseObject = - // new MessageSend().Send(token, data); + //var line = lines.SMSLines.Last().LineNumber.ToString(); + //var data = new MessageSendObject + //{ + // Messages = new List + // {message}.ToArray(), + // MobileNumbers = new List {number}.ToArray(), + // LineNumber = line, + // SendDateTime = DateTime.Now, + // CanContinueInCaseOfError = true + //}; + //var messageSendResponseObject = + // new MessageSend().Send(token, data); - //if (messageSendResponseObject.IsSuccessful) return; + //if (messageSendResponseObject.IsSuccessful) return; - //line = lines.SMSLines.First().LineNumber.ToString(); - //data.LineNumber = line; - //new MessageSend().Send(token, data); - } - public bool VerifySend(string number, string message) - { - var verificationSendResult = VerifySendSmsAsync(number, 768382, new VerifySendParameter[] { new VerifySendParameter("VerificationCode", message) }); - Thread.Sleep(2000); - if (verificationSendResult.IsCompletedSuccessfully) - { + //line = lines.SMSLines.First().LineNumber.ToString(); + //data.LineNumber = line; + //new MessageSend().Send(token, data); + } + public bool VerifySend(string number, string message) + { + var verificationSendResult = VerifySendSmsAsync(number, 768382, new VerifySendParameter[] { new VerifySendParameter("VerificationCode", message) }); + Thread.Sleep(2000); + if (verificationSendResult.IsCompletedSuccessfully) + { - var resStartStatus = verificationSendResult.Result; - var b = resStartStatus.Status; - var resResult = verificationSendResult.Status; - var a = verificationSendResult.IsCompleted; - var reseExceptiont = verificationSendResult.Exception; - return true; - } - else - { + var resStartStatus = verificationSendResult.Result; + var b = resStartStatus.Status; + var resResult = verificationSendResult.Status; + var a = verificationSendResult.IsCompleted; + var reseExceptiont = verificationSendResult.Exception; + return true; + } + else + { - var resStartStatus = verificationSendResult.Status; - var resResult = verificationSendResult.Status; - var reseExceptiont = verificationSendResult.Exception; + var resStartStatus = verificationSendResult.Status; + var resResult = verificationSendResult.Status; + var reseExceptiont = verificationSendResult.Exception; - return false; - } + return false; + } - } + } - public bool LoginSend(string number, string message) - { - var verificationSendResult = VerifySendSmsAsync(number, 635330, new VerifySendParameter[] { new VerifySendParameter("LOGINCODE", message) }); - Thread.Sleep(2000); - if (verificationSendResult.IsCompletedSuccessfully) - { + public bool LoginSend(string number, string message) + { + var verificationSendResult = VerifySendSmsAsync(number, 635330, new VerifySendParameter[] { new VerifySendParameter("LOGINCODE", message) }); + Thread.Sleep(2000); + if (verificationSendResult.IsCompletedSuccessfully) + { - var resStartStatus = verificationSendResult.Result; - var b = resStartStatus.Status; - var resResult = verificationSendResult.Status; - var a = verificationSendResult.IsCompleted; - var reseExceptiont = verificationSendResult.Exception; - return true; - } - else - { + var resStartStatus = verificationSendResult.Result; + var b = resStartStatus.Status; + var resResult = verificationSendResult.Status; + var a = verificationSendResult.IsCompleted; + var reseExceptiont = verificationSendResult.Exception; + return true; + } + else + { - var resStartStatus = verificationSendResult.Status; - var resResult = verificationSendResult.Status; - var reseExceptiont = verificationSendResult.Exception; + var resStartStatus = verificationSendResult.Status; + var resResult = verificationSendResult.Status; + var reseExceptiont = verificationSendResult.Exception; - return false; - } - } + return false; + } + } - public async Task SendVerifyCodeToClient(string number, string code) - { - var result = new SentSmsViewModel(); - var sendResult = await VerifySendSmsAsync(number, 768382, new VerifySendParameter[] { new VerifySendParameter("VerificationCode", code) }); - Thread.Sleep(2000); + public async Task SendVerifyCodeToClient(string number, string code) + { + var result = new SentSmsViewModel(); + var sendResult = await VerifySendSmsAsync(number, 768382, new VerifySendParameter[] { new VerifySendParameter("VerificationCode", code) }); + Thread.Sleep(2000); - if (sendResult.Message == "موفق") - { - var status = sendResult.Status; - var message = sendResult.Message; - var messaeId = sendResult.Data.MessageId; - return result.Succedded(status, message, messaeId); - } - else - { - var status = sendResult.Status; - var message = sendResult.Message; - var messaeId = sendResult.Data.MessageId; - return result.Failed(status, message, messaeId); - } - } + if (sendResult.Message == "موفق") + { + var status = sendResult.Status; + var message = sendResult.Message; + var messaeId = sendResult.Data.MessageId; + return result.Succedded(status, message, messaeId); + } + else + { + var status = sendResult.Status; + var message = sendResult.Message; + var messaeId = sendResult.Data.MessageId; + return result.Failed(status, message, messaeId); + } + } - public bool SendAccountsInfo(string number, string fullName, string userName) - { + public bool SendAccountsInfo(string number, string fullName, string userName) + { - var checkLength = fullName.Length; - if (checkLength > 25) - fullName = fullName.Substring(0, 24); + var checkLength = fullName.Length; + if (checkLength > 25) + fullName = fullName.Substring(0, 24); - var sendResult = VerifySendSmsAsync(number, 725814, new VerifySendParameter[] { new VerifySendParameter("FULLNAME", fullName), new VerifySendParameter("USERNAME", userName), new VerifySendParameter("PASSWORD", userName) }); + var sendResult = VerifySendSmsAsync(number, 725814, new VerifySendParameter[] { new VerifySendParameter("FULLNAME", fullName), new VerifySendParameter("USERNAME", userName), new VerifySendParameter("PASSWORD", userName) }); - Console.WriteLine(userName + " - " + sendResult.Result.Status); - if (sendResult.IsCompletedSuccessfully) - { - return true; - } - else - { - return false; - } + Console.WriteLine(userName + " - " + sendResult.Result.Status); + if (sendResult.IsCompletedSuccessfully) + { + return true; + } + else + { + return false; + } - } + } - public async Task GetByMessageId(int messId) - { + public async Task GetByMessageId(int messId) + { - SmsIr smsIr = new SmsIr("Og5M562igmzJRhQPnq0GdtieYdLgtfikjzxOmeQBPxJjZtyge5Klc046Lfw1mxSa"); - var response = await smsIr.GetReportAsync(messId); - MessageReportResult messages = response.Data; + SmsIr smsIr = new SmsIr("Og5M562igmzJRhQPnq0GdtieYdLgtfikjzxOmeQBPxJjZtyge5Klc046Lfw1mxSa"); + var response = await smsIr.GetReportAsync(messId); + MessageReportResult messages = response.Data; - var appendData = new ApiResultViewModel() - { - MessageId = messages.MessageId, - LineNumber = messages.LineNumber, - Mobile = messages.Mobile, - MessageText = messages.MessageText, - SendUnixTime = UnixTimeStampToDateTime(messages.SendDateTime), - DeliveryState = DeliveryStatus(messages.DeliveryState), - DeliveryUnixTime = UnixTimeStampToDateTime(messages.DeliveryDateTime), - DeliveryColor = DeliveryColorStatus(messages.DeliveryState), - }; - return appendData; - } - public async Task> GetApiResult(string startDate, string endDate) - { - var st = new DateTime(2024, 6, 2); - var ed = new DateTime(2024, 7, 1); - if (!string.IsNullOrWhiteSpace(startDate) && startDate.Length == 10) - { - st = startDate.ToGeorgianDateTime(); - } - if (!string.IsNullOrWhiteSpace(endDate) && endDate.Length == 10) - { - ed = endDate.ToGeorgianDateTime(); - } - var res = new List(); - Int32 unixTimestamp = (int)st.Subtract(new DateTime(1970, 1, 1)).TotalSeconds; - Int32 unixTimestamp2 = (int)ed.Subtract(new DateTime(1970, 1, 1)).TotalSeconds; - // int? fromDateUnixTime = null; // unix time - for instance: 1700598600 - //int? toDateUnixTime = null; // unix time - for instance: 1703190600 - int pageNumber = 2; - int pageSize = 100; // max: 100 - SmsIr smsIr = new SmsIr("Og5M562igmzJRhQPnq0GdtieYdLgtfikjzxOmeQBPxJjZtyge5Klc046Lfw1mxSa"); - var response = await smsIr.GetArchivedReportAsync(pageNumber, pageSize, unixTimestamp, unixTimestamp2); + var appendData = new ApiResultViewModel() + { + MessageId = messages.MessageId, + LineNumber = messages.LineNumber, + Mobile = messages.Mobile, + MessageText = messages.MessageText, + SendUnixTime = UnixTimeStampToDateTime(messages.SendDateTime), + DeliveryState = DeliveryStatus(messages.DeliveryState), + DeliveryUnixTime = UnixTimeStampToDateTime(messages.DeliveryDateTime), + DeliveryColor = DeliveryColorStatus(messages.DeliveryState), + }; + return appendData; + } + public async Task> GetApiResult(string startDate, string endDate) + { + var st = new DateTime(2024, 6, 2); + var ed = new DateTime(2024, 7, 1); + if (!string.IsNullOrWhiteSpace(startDate) && startDate.Length == 10) + { + st = startDate.ToGeorgianDateTime(); + } + if (!string.IsNullOrWhiteSpace(endDate) && endDate.Length == 10) + { + ed = endDate.ToGeorgianDateTime(); + } + var res = new List(); + Int32 unixTimestamp = (int)st.Subtract(new DateTime(1970, 1, 1)).TotalSeconds; + Int32 unixTimestamp2 = (int)ed.Subtract(new DateTime(1970, 1, 1)).TotalSeconds; + // int? fromDateUnixTime = null; // unix time - for instance: 1700598600 + //int? toDateUnixTime = null; // unix time - for instance: 1703190600 + int pageNumber = 2; + int pageSize = 100; // max: 100 + SmsIr smsIr = new SmsIr("Og5M562igmzJRhQPnq0GdtieYdLgtfikjzxOmeQBPxJjZtyge5Klc046Lfw1mxSa"); + var response = await smsIr.GetArchivedReportAsync(pageNumber, pageSize, unixTimestamp, unixTimestamp2); - MessageReportResult[] messages = response.Data; - foreach (var message in messages) - { - var appendData = new ApiResultViewModel() - { - MessageId = message.MessageId, - LineNumber = message.LineNumber, - Mobile = message.Mobile, - MessageText = message.MessageText, - SendUnixTime = UnixTimeStampToDateTime(message.SendDateTime), - DeliveryState = DeliveryStatus(message.DeliveryState), - DeliveryUnixTime = UnixTimeStampToDateTime(message.DeliveryDateTime), - DeliveryColor = DeliveryColorStatus(message.DeliveryState), - }; - res.Add(appendData); - } + MessageReportResult[] messages = response.Data; + foreach (var message in messages) + { + var appendData = new ApiResultViewModel() + { + MessageId = message.MessageId, + LineNumber = message.LineNumber, + Mobile = message.Mobile, + MessageText = message.MessageText, + SendUnixTime = UnixTimeStampToDateTime(message.SendDateTime), + DeliveryState = DeliveryStatus(message.DeliveryState), + DeliveryUnixTime = UnixTimeStampToDateTime(message.DeliveryDateTime), + DeliveryColor = DeliveryColorStatus(message.DeliveryState), + }; + res.Add(appendData); + } - return res; - } + return res; + } - public string DeliveryStatus(byte? dv) - { - string mess = ""; - switch (dv) - { - case 1: - mess = "رسیده به گوشی"; - break; - case 2: - mess = "نرسیده به گوشی"; - break; - case 3: - mess = "پردازش در مخابرات"; - break; - case 4: - mess = "نرسیده به مخابرات"; - break; - case 5: - mess = "سیده به مخابرات"; - break; - case 6: - mess = "خطا"; - break; - case 7: - mess = "لیست سیاه"; - break; - default: - mess = ""; - break; + public string DeliveryStatus(byte? dv) + { + string mess = ""; + switch (dv) + { + case 1: + mess = "رسیده به گوشی"; + break; + case 2: + mess = "نرسیده به گوشی"; + break; + case 3: + mess = "پردازش در مخابرات"; + break; + case 4: + mess = "نرسیده به مخابرات"; + break; + case 5: + mess = "سیده به مخابرات"; + break; + case 6: + mess = "خطا"; + break; + case 7: + mess = "لیست سیاه"; + break; + default: + mess = ""; + break; - } + } - return mess; - } - public string DeliveryColorStatus(byte? dv) - { - string mess = ""; - switch (dv) - { - case 1: - mess = "successSend"; - break; - case 2: - mess = "errSend"; - break; - case 3: - mess = "pSend"; - break; - case 4: - mess = "noSend"; - break; - case 5: - mess = "itcSend"; - break; - case 6: - mess = "redSend"; - break; - case 7: - mess = "blockSend"; - break; - default: - mess = ""; - break; + return mess; + } + public string DeliveryColorStatus(byte? dv) + { + string mess = ""; + switch (dv) + { + case 1: + mess = "successSend"; + break; + case 2: + mess = "errSend"; + break; + case 3: + mess = "pSend"; + break; + case 4: + mess = "noSend"; + break; + case 5: + mess = "itcSend"; + break; + case 6: + mess = "redSend"; + break; + case 7: + mess = "blockSend"; + break; + default: + mess = ""; + break; - } + } - return mess; - } - public string UnixTimeStampToDateTime(int? unixTimeStamp) - { - if (unixTimeStamp != null) - { - // Unix timestamp is seconds past epoch - DateTime dateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc); - dateTime = dateTime.AddSeconds(Convert.ToDouble(unixTimeStamp)).ToLocalTime(); - var time = dateTime.ToFarsiFull(); - return time; - } + return mess; + } + public string UnixTimeStampToDateTime(int? unixTimeStamp) + { + if (unixTimeStamp != null) + { + // Unix timestamp is seconds past epoch + DateTime dateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc); + dateTime = dateTime.AddSeconds(Convert.ToDouble(unixTimeStamp)).ToLocalTime(); + var time = dateTime.ToFarsiFull(); + return time; + } - return ""; - } - private string GetToken() - { - return ""; - //var smsSecrets = _configuration.GetSection("SmsSecrets"); - //var tokenService = new Token(); - //return tokenService.GetToken("x-api-key", "Og5M562igmzJRhQPnq0GdtieYdLgtfikjzxOmeQBPxJjZtyge5Klc046Lfw1mxSa"); - } + return ""; + } + private string GetToken() + { + return ""; + //var smsSecrets = _configuration.GetSection("SmsSecrets"); + //var tokenService = new Token(); + //return tokenService.GetToken("x-api-key", "Og5M562igmzJRhQPnq0GdtieYdLgtfikjzxOmeQBPxJjZtyge5Klc046Lfw1mxSa"); + } - #region Mahan + #region Mahan - public async Task GetCreditAmount() - { - try - { - var credit = await SmsIr.GetCreditAsync(); - return (double)credit.Data; - } - catch - { - return -1; - } + public async Task GetCreditAmount() + { + try + { + var credit = await SmsIr.GetCreditAsync(); + return (double)credit.Data; + } + catch + { + return -1; + } - } + } - public async Task SendInstitutionCreationVerificationLink(string number, string fullName, Guid institutionId, long contractingPartyId, long institutionContractId, string typeOfSms) - { + public async Task SendInstitutionCreationVerificationLink(string number, string fullName, Guid institutionId, long contractingPartyId, long institutionContractId, string typeOfSms) + { typeOfSms = string.IsNullOrWhiteSpace(typeOfSms) ? "لینک تاییدیه ایجاد قرارداد مالی" : typeOfSms; - - + + var full = fullName; - var fullName1 = fullName; - if (fullName.Length >= 25) - { - fullName1 = fullName.Substring(0, 25); - } - var fullName2 = ""; - if (full.Length > 25) - { - fullName2 = full.Substring(25); - if (fullName2.Length>25) - { - fullName2 = fullName2.Substring(0, 25); - } - } - var guidStr = institutionId.ToString(); - var firstPart = guidStr.Substring(0, 15); - var secondPart = guidStr.Substring(15); - var verificationSendResult = await VerifySendSmsAsync(number, 527519, new VerifySendParameter[] - { - new("FULLNAME1", fullName1), - new("FULLNAME2", fullName2), - new("CODE1",firstPart), - new("CODE2",secondPart) - }); - + var fullName1 = fullName; + if (fullName.Length >= 25) + { + fullName1 = fullName.Substring(0, 25); + } + var fullName2 = ""; + if (full.Length > 25) + { + fullName2 = full.Substring(25); + if (fullName2.Length > 25) + { + fullName2 = fullName2.Substring(0, 25); + } + } + var guidStr = institutionId.ToString(); + var firstPart = guidStr.Substring(0, 15); + var secondPart = guidStr.Substring(15); + var verificationSendResult = await VerifySendSmsAsync(number, 527519, new VerifySendParameter[] + { + new("FULLNAME1", fullName1), + new("FULLNAME2", fullName2), + new("CODE1",firstPart), + new("CODE2",secondPart) + }); + if (verificationSendResult.Status == 1) + { + _logger.LogInformation("ارسال لینک قراداد مالی موفق بود"); + } + else + { + _logger.LogError("خطا در ارسال لینک قراداد مالی"); + } var smsResult = new SmsResult(verificationSendResult.Data.MessageId, verificationSendResult.Message, typeOfSms, - fullName, number, contractingPartyId, institutionContractId); - await _smsResultRepository.CreateAsync(smsResult); - await _smsResultRepository.SaveChangesAsync(); - return verificationSendResult.Status == 0; - } + fullName, number, contractingPartyId, institutionContractId); + await _smsResultRepository.CreateAsync(smsResult); + await _smsResultRepository.SaveChangesAsync(); + _logger.LogInformation("ذخیره در دیتابیس موفق بود"); + return verificationSendResult.Status == 0; + } - public async Task SendInstitutionAmendmentVerificationLink(string number, string fullName, Guid institutionId, - long contractingPartyId, long institutionContractId) - { - var guidStr = institutionId.ToString(); - var firstPart = guidStr.Substring(0, 15); - var secondPart = guidStr.Substring(15); - var verificationSendResult = await VerifySendSmsAsync(number, 527519, new VerifySendParameter[] - { - new("FULLNAME", fullName), - new("CODE1",firstPart), - new("CODE2",secondPart) - }); - var smsResult = new SmsResult(verificationSendResult.Data.MessageId, verificationSendResult.Message, "لینک تاییدیه ارتقا قرارداد مالی", - fullName, number, contractingPartyId, institutionContractId); - await _smsResultRepository.CreateAsync(smsResult); - await _smsResultRepository.SaveChangesAsync(); - return verificationSendResult.Status == 0; - } + public async Task SendInstitutionAmendmentVerificationLink(string number, string fullName, Guid institutionId, + long contractingPartyId, long institutionContractId) + { + var guidStr = institutionId.ToString(); + var firstPart = guidStr.Substring(0, 15); + var secondPart = guidStr.Substring(15); + var verificationSendResult = await VerifySendSmsAsync(number, 527519, new VerifySendParameter[] + { + new("FULLNAME", fullName), + new("CODE1",firstPart), + new("CODE2",secondPart) + }); + var smsResult = new SmsResult(verificationSendResult.Data.MessageId, verificationSendResult.Message, "لینک تاییدیه ارتقا قرارداد مالی", + fullName, number, contractingPartyId, institutionContractId); + await _smsResultRepository.CreateAsync(smsResult); + await _smsResultRepository.SaveChangesAsync(); + return verificationSendResult.Status == 0; + } - public async Task SendInstitutionVerificationCode(string number, string code, string contractingPartyFullName, - long contractingPartyId, long institutionContractId) - { - var verificationSendResult = await VerifySendSmsAsync(number, 965348, new VerifySendParameter[] - { - new("VERIFYCODE", code) - }); + public async Task SendInstitutionVerificationCode(string number, string code, string contractingPartyFullName, + long contractingPartyId, long institutionContractId) + { + var verificationSendResult = await VerifySendSmsAsync(number, 965348, new VerifySendParameter[] + { + new("VERIFYCODE", code) + }); - var smsResult = new SmsResult(verificationSendResult.Data.MessageId, verificationSendResult.Message, "کد تاییدیه قرارداد مالی", - contractingPartyFullName, number, contractingPartyId, institutionContractId); - await _smsResultRepository.CreateAsync(smsResult); - await _smsResultRepository.SaveChangesAsync(); - return verificationSendResult.Status == 0; - } + var smsResult = new SmsResult(verificationSendResult.Data.MessageId, verificationSendResult.Message, "کد تاییدیه قرارداد مالی", + contractingPartyFullName, number, contractingPartyId, institutionContractId); + await _smsResultRepository.CreateAsync(smsResult); + await _smsResultRepository.SaveChangesAsync(); + return verificationSendResult.Status == 0; + } - public _0_Framework.Application.Sms.SmsResult TaskReminderSms(string number, string taskCount) - { - throw new NotImplementedException(); - } + public _0_Framework.Application.Sms.SmsResult TaskReminderSms(string number, string taskCount) + { + throw new NotImplementedException(); + } - #endregion + #endregion - #region InstitutionContractSMS + #region InstitutionContractSMS - public async Task<(byte status, string message, int messaeId, bool isSucceded)> MonthlyBillNew(string number, int tamplateId, string fullname, string amount, string code1, - string code2) - { + public async Task<(byte status, string message, int messaeId, bool isSucceded)> MonthlyBillNew(string number, int tamplateId, string fullname, string amount, string code1, + string code2) + { - var smsIr = new SmsIr("Og5M562igmzJRhQPnq0GdtieYdLgtfikjzxOmeQBPxJjZtyge5Klc046Lfw1mxSa"); - var result = new ValueTuple(); - var sendResult = await smsIr.VerifySendAsync(number, tamplateId, - new VerifySendParameter[] - { new("FULLNAME", fullname), new("AMOUNT", amount), new("CODE1", code1), new("CODE2", code2) }); - Thread.Sleep(500); + var smsIr = new SmsIr("Og5M562igmzJRhQPnq0GdtieYdLgtfikjzxOmeQBPxJjZtyge5Klc046Lfw1mxSa"); + var result = new ValueTuple(); + var sendResult = await smsIr.VerifySendAsync(number, tamplateId, + new VerifySendParameter[] + { new("FULLNAME", fullname), new("AMOUNT", amount), new("CODE1", code1), new("CODE2", code2) }); + Thread.Sleep(500); - if (sendResult.Message == "موفق") - { + if (sendResult.Message == "موفق") + { - result = (sendResult.Status, sendResult.Message, sendResult.Data.MessageId, true); - return result; - } + result = (sendResult.Status, sendResult.Message, sendResult.Data.MessageId, true); + return result; + } - result = (sendResult.Status, sendResult.Message, sendResult.Data.MessageId, false); - return result; + result = (sendResult.Status, sendResult.Message, sendResult.Data.MessageId, false); + return result; - } + } - public async Task<(byte status, string message, int messaeId, bool isSucceded)> MonthlyBill(string number, int tamplateId, string fullname, string amount, string id, - string aprove) - { + public async Task<(byte status, string message, int messaeId, bool isSucceded)> MonthlyBill(string number, int tamplateId, string fullname, string amount, string id, + string aprove) + { - var smsIr = new SmsIr("Og5M562igmzJRhQPnq0GdtieYdLgtfikjzxOmeQBPxJjZtyge5Klc046Lfw1mxSa"); - var result = new ValueTuple(); - var sendResult = await smsIr.VerifySendAsync(number, tamplateId, - new VerifySendParameter[] - { new("FULLNAME", fullname), new("AMOUNT", amount), new("ID", id), new("APROVE", aprove) }); - Thread.Sleep(500); + var smsIr = new SmsIr("Og5M562igmzJRhQPnq0GdtieYdLgtfikjzxOmeQBPxJjZtyge5Klc046Lfw1mxSa"); + var result = new ValueTuple(); + var sendResult = await smsIr.VerifySendAsync(number, tamplateId, + new VerifySendParameter[] + { new("FULLNAME", fullname), new("AMOUNT", amount), new("ID", id), new("APROVE", aprove) }); + Thread.Sleep(500); - if (sendResult.Message == "موفق") - { + if (sendResult.Message == "موفق") + { - result = (sendResult.Status, sendResult.Message, sendResult.Data.MessageId, true); - return result; - } + result = (sendResult.Status, sendResult.Message, sendResult.Data.MessageId, true); + return result; + } - result = (sendResult.Status, sendResult.Message, sendResult.Data.MessageId, false); - return result; - } + result = (sendResult.Status, sendResult.Message, sendResult.Data.MessageId, false); + return result; + } - public async Task<(byte status, string message, int messaeId, bool isSucceded)> BlockMessage(string number, string fullname, string amount, string accountType, string id, - string aprove) - { - var tamplateId = 117946; - var result = new ValueTuple(); - var smsIr = new SmsIr("Og5M562igmzJRhQPnq0GdtieYdLgtfikjzxOmeQBPxJjZtyge5Klc046Lfw1mxSa"); + public async Task<(byte status, string message, int messaeId, bool isSucceded)> BlockMessage(string number, string fullname, string amount, string accountType, string id, + string aprove) + { + var tamplateId = 117946; + var result = new ValueTuple(); + var smsIr = new SmsIr("Og5M562igmzJRhQPnq0GdtieYdLgtfikjzxOmeQBPxJjZtyge5Klc046Lfw1mxSa"); - var sendResult = await smsIr.VerifySendAsync(number, tamplateId, - new VerifySendParameter[] - { - new("FULLNAME", fullname), new("AMOUNT", amount), new("ACCOUNTTYPE", accountType), new("ID", id), - new("APROVE", aprove) - }); - Thread.Sleep(500); + var sendResult = await smsIr.VerifySendAsync(number, tamplateId, + new VerifySendParameter[] + { + new("FULLNAME", fullname), new("AMOUNT", amount), new("ACCOUNTTYPE", accountType), new("ID", id), + new("APROVE", aprove) + }); + Thread.Sleep(500); - if (sendResult.Message == "موفق") - { + if (sendResult.Message == "موفق") + { - result = (sendResult.Status, sendResult.Message, sendResult.Data.MessageId, true); - return result; - } + result = (sendResult.Status, sendResult.Message, sendResult.Data.MessageId, true); + return result; + } - result = (sendResult.Status, sendResult.Message, sendResult.Data.MessageId, false); - return result; - } + result = (sendResult.Status, sendResult.Message, sendResult.Data.MessageId, false); + return result; + } - #endregion + #endregion - #region AlarmMessage + #region AlarmMessage - public async Task Alarm(string number, string message) - { - var smsIr = new SmsIr("Og5M562igmzJRhQPnq0GdtieYdLgtfikjzxOmeQBPxJjZtyge5Klc046Lfw1mxSa"); + public async Task Alarm(string number, string message) + { + var smsIr = new SmsIr("Og5M562igmzJRhQPnq0GdtieYdLgtfikjzxOmeQBPxJjZtyge5Klc046Lfw1mxSa"); - //var bulkSendResult = smsIr.BulkSendAsync(95007079000006, "your text message", new string[] { "9120000000" }); + //var bulkSendResult = smsIr.BulkSendAsync(95007079000006, "your text message", new string[] { "9120000000" }); - var verificationSendResult = - smsIr.VerifySendAsync(number, 662874, new VerifySendParameter[] { new("ALARM", message) }); - Thread.Sleep(1000); - var status = verificationSendResult.Result.Status; - var mess = verificationSendResult.Result.Message; - var messaeId = verificationSendResult.Result.Data.MessageId; - if (verificationSendResult.IsCompletedSuccessfully) return true; + var verificationSendResult = + smsIr.VerifySendAsync(number, 662874, new VerifySendParameter[] { new("ALARM", message) }); + Thread.Sleep(1000); + var status = verificationSendResult.Result.Status; + var mess = verificationSendResult.Result.Message; + var messaeId = verificationSendResult.Result.Data.MessageId; + if (verificationSendResult.IsCompletedSuccessfully) return true; - var resStartStatus = verificationSendResult.Result; - var resResult = verificationSendResult.Status; - var reseExceptiont = verificationSendResult.Exception; + var resStartStatus = verificationSendResult.Result; + var resResult = verificationSendResult.Status; + var reseExceptiont = verificationSendResult.Exception; - return false; - } + return false; + } - #endregion + #endregion }