Пример #1
0
        public override void Run()
        {
            Trace.WriteLine("WorkerRole.EmailNotification entry point called", "Information");

            while (true)
            {
                // Clean Up The Unfinished Jobs
                CleanUp();

                DateTimeOffset nextExecutionTime = new DateTime(
                    DateTime.UtcNow.Year,
                    DateTime.UtcNow.Month,
                    DateTime.UtcNow.Day,
                    3, 0, 0);
                if (DateTimeOffset.UtcNow > nextExecutionTime)
                {
                   //if(LoadTrialExpirations())
                 //  {
                        using (Model.Entities ctx = new Model.Entities())
                        {
                            foreach (var job in ctx.vwJobsToExecutes)
                            {
                                //  Try to Get a Job Id.
                                Guid? jobId = StartJob(job);
                                if (jobId.HasValue)
                                {
                                    Trace.WriteLine("Working", "Information");
                                    // This Method Has the Code That Execute
                                    // A Stored Procedure, The Actual Job
                                    ExecuteJob(job);
                                    StopJob(jobId.Value);
                                }
                            }
                        }
                       SendTrialNotificationEmails();
                   //}

                    Thread.Sleep(new TimeSpan(0, 0, 10));
                }
                else
                {

                    Thread.Sleep(new TimeSpan(0, 0, 10));
                }
            }
        }
Пример #2
0
        private void SendTrialNotificationEmails()
        {
            using (Model.Entities ctx = new Model.Entities())
            {
                foreach (var sendEmail in ctx.sysmail_mailitems.Where(a=>a.sent_status==0))
                {

                    try
                    {

                        Trace.WriteLine("Email Working", "Information");
                        Thread.Sleep(ConfigSettings.EmailQueueInterval);

                        var selectedProfileAccount = ctx.sysmail_profileaccount.Where(a => a.profile_id == sendEmail.profile_id).SingleOrDefault();
                        var selectedSystemAccount =ctx.sysmail_account.Where(a => a.account_id == selectedProfileAccount.account_id).SingleOrDefault();
                        var selectedAccountCredential = ctx.sysmail_account_credential.Where(a => a.credential_id == selectedSystemAccount.account_id).SingleOrDefault();
                        var server = selectedSystemAccount.sysmail_server.SingleOrDefault();

                        EmailManager.EmailAddress = selectedSystemAccount.email_address;
                        EmailManager.EmailDisplayName = selectedSystemAccount.display_name;
                        EmailManager.EmailHost = server.servername;
                        EmailManager.EmailPort = server.port;
                        EmailManager.EmailUser = selectedAccountCredential.username;
                        string encriptedPassword = Util.Encrypt("Pinkman1!x", "flumiwes");

                        EmailManager.EmailPassword = encriptedPassword;    //selectedAccountCredential.cyphertext;
                        EmailManager.QueueEmailMessage(selectedSystemAccount.email_address, selectedSystemAccount.display_name, sendEmail.recipients, "", "", "", sendEmail.subject, sendEmail.body, DateTime.Now, 1, true);

                        EmailManager.SendQueuedEmail(sendEmail.mailitem_id, selectedSystemAccount.account_id);

                    }
                    catch (Exception e)
                    {
                        Trace.TraceError("Email Error: " + e.Message);
                    }

                }
            }
        }
Пример #3
0
 private Guid? StartJob(vwJobsToExecute job)
 {
     Guid? retValue = null;
     using (Entities ctx = new Entities())
     {
         var activityIdParam =
             new ObjectParameter("ActivityId", typeof(Guid?));
         ctx.StartJob(job.JobId, activityIdParam);
         if (activityIdParam.Value != null
             && activityIdParam.Value.GetType()
             != typeof(System.DBNull))
         {
             retValue = (Guid)activityIdParam.Value;
         }
     }
     return retValue;
 }
Пример #4
0
 private void CleanUp()
 {
     using (Entities ctx = new Entities())
     {
         ctx.CleanUp();
     }
 }