Exemplo n.º 1
0
 public int Calculate(int amount, int rate)
 {
     try
     {
         int r = amount / rate;
         return(r);
     }
     catch (Exception ex)
     {
         if (this.GetLog == LogType.TXT)
         {
             TxtLogger txf = new TxtLogger();
             txf.Log(ex.Message);
             return(-1);
         }
         XmlLogger xm = new XmlLogger();
         xm.Log(ex.Message);
         return(-1);
     }
 }
Exemplo n.º 2
0
        async public Task Execute(IJobExecutionContext context)
        {
            DbContextOptionsBuilder <ApplicationDbContext> optionbuilder = new DbContextOptionsBuilder <ApplicationDbContext>();

            optionbuilder.UseSqlServer("Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=SmsServiceAppDB;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False");
            ApplicationDbContext db = new ApplicationDbContext(optionbuilder.Options);

            var senderManager = new SenderManager(db);
            var messageLogger = new XmlLogger("XmlLog.xml");
            var smsSender     = new ConsoleSmsSender();

            var messages = await senderManager.GetMessagesToSend();

            foreach (var message in messages)
            {
                await smsSender.Send(message.Sender, message.Reciever, message.Text, "");

                messageLogger.Log(message.Sender, message.Reciever, message.Text, DateTime.UtcNow);
            }
            var Ids = from i in messages
                      select i.TimeId;
            await senderManager.SetTimesAsSent(Ids);
        }