Example #1
0
 public async Task AddNotification(string body, EmailConf emailGeneral, string subject, string attachment = null)
 {
     try
     {
         var notification = new NotificationQueue
         {
             Subject          = subject,
             Body             = body,
             Attachment       = attachment,
             To               = emailGeneral.Email,
             ToName           = emailGeneral.FullName,
             From             = _settings.Value.From,
             FromName         = _settings.Value.FromName,
             ReplyTo          = _settings.Value.ReplyTo,
             ReplyToName      = _settings.Value.ReplyToName,
             Priority         = emailGeneral.Priority,
             CreatedTimestamp = DateTime.Now,
             FailCount        = 0
         };
         _notificationDbContext.NotificationQueues.Add(notification);
         await _notificationDbContext.SaveChangesAsync();
     }
     catch (Exception e)
     {
         _logger.LogError(e.Message);
     }
 }
Example #2
0
 private static void EmailKuldes(EmailConf ec, string cimzett, string tema, string uzenet)
 {
     using (var smtpClient = SmtpClientFactory.GetClient(SmtpClientFactory.ClientType.Gmail,
                                                         new NetworkCredential(ec.Azonosito, ec.Jelszo), ec.Ssl, "", 0))
     {
         var mailMessage = new MailMessage
         {
             From       = new MailAddress(ec.KuldoEmailcime, ec.KuldoNeve),
             IsBodyHtml = true,
             Body       = uzenet,
             Subject    = tema
         };
         mailMessage.To.Add(cimzett);
         smtpClient.Send(mailMessage);
     }
 }
Example #3
0
        static void Main(string[] args)
        {
            System.Threading.Mutex mtx = null;

            //connect to D365
            var context = ImportCommon.Connect();

            //read config
            string strFilePath    = ImportCommon.GetAppSetting(BusinessConst.CSV_FILE_PATH);
            string strSuccessPath = ImportCommon.GetAppSetting(BusinessConst.SUC_FILE_PATH);
            string strErrorPath   = ImportCommon.GetAppSetting(BusinessConst.ERR_FILE_PATH);
            string strLogPath     = ImportCommon.GetAppSetting(BusinessConst.LOG_FILE_PATH);

            //log file
            StringBuilder logMsg      = new System.Text.StringBuilder();
            string        strLogName  = ImportCommon.GetLogFileName(BusinessConst.REDAC_NAME_INVOICE);
            string        strfileName = "";
            int           iFileCnt    = 0;

            Console.WriteLine("logName : {0}", strLogName);
            Console.WriteLine("FilePath :  {0}", strFilePath);

            //mail set
            Console.WriteLine("mail setting :::");
            EmailConf emailConf = new EmailConf();

            try
            {
                string mutextName = "SanImportAccountCsv";

                mtx = new System.Threading.Mutex(false, mutextName);

                mtx.WaitOne();

                //open file
                ImportCommon.Writelog(logMsg, BusinessConst.LOG_INFO, BusinessConst.LOG_ST);
                IEnumerable <System.IO.FileInfo> targetCsvfiles = ImportCommon.GetCsvFile(strFilePath);

                Console.WriteLine("start loop  ");

                //import data
                foreach (System.IO.FileInfo targetCsvfile in targetCsvfiles)
                {
                    iFileCnt++;
                    strfileName = targetCsvfile.Name;
                    ImportCommon.Writelog(logMsg, BusinessConst.LOG_INFO, "File name:" + targetCsvfile.Name);
                    Console.WriteLine("strfileName : {0}", strfileName);

                    //write import data
                    List <string> accRecords = ImportCommon.WriteCsvFile(targetCsvfile);

                    var wkLine = ImportCommon.TrimDoubleQuotationMarks(accRecords[1].Replace("\",\"", "\t")).Split('\t');
                    Console.WriteLine("create customer : ");

                    string comId = wkLine[25];
                    if (wkLine[27].Equals("Tenant"))
                    {
                        comId = comId.Replace(",", "");
                    }

                    if (SanODataQuerys.CheckByCustomId(context, comId))
                    {
                        SanODataChangesets.CreateCustomAdv(wkLine, context);
                    }
                    else
                    {
                        Console.WriteLine("customer aleady exist: ");
                        SanODataChangesets.AddCustomAddress(wkLine, context);
                    }

                    Console.WriteLine("create journal : ");
                    SanODataChangesets.CreateGeneralJournalAdv(accRecords, context, logMsg);
                    Console.WriteLine("create done !!");

                    //move file
                    ImportCommon.Writelog(logMsg, BusinessConst.LOG_INFO, "Done:" + strfileName);
                    ImportCommon.MoveCsvFile(strFilePath + "/" + strfileName, strSuccessPath + "/" + strfileName);
                }


                ImportCommon.Writelog(logMsg, BusinessConst.LOG_INFO, "File count:" + iFileCnt);
                ImportCommon.Writelog(logMsg, BusinessConst.LOG_INFO, BusinessConst.LOG_EN);
            }
            catch (System.Exception e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine("err somthing  : {0}", e.InnerException);
                //move file
                ImportCommon.Writelog(logMsg, BusinessConst.LOG_ERROR, "Detail1:" + e.Message);
                ImportCommon.Writelog(logMsg, BusinessConst.LOG_ERROR, "Detail2:" + e.InnerException);
                ImportCommon.MoveCsvFile(strFilePath + "/" + strfileName, strErrorPath + "/" + strfileName);

                SendEmail email = new SendEmail(emailConf);
                email.SendException(e, strLogName);

                if (mtx != null)
                {
                    mtx.ReleaseMutex();
                    mtx = null;
                }
            }
            finally
            {
                Console.WriteLine("check log : {0} ", logMsg.ToString());
                if (iFileCnt > 0)
                {
                    ImportCommon.CreatelogFile(strLogPath + "/" + strLogName, logMsg.ToString());
                }
                Console.WriteLine("end  ");

                if (mtx != null)
                {
                    mtx.ReleaseMutex();
                }
            }
        }