Пример #1
0
 public SenderThread(MassSender massSender,PendingJobStatus pendingJobStatus,OpenMassSenderCore.OpenMassSenderDBDataSet.MessageRow message,Sender sender, List<OpenMassSenderCore.OpenMassSenderDBDataSet.ReceiverRow> receivers, Action<SendStatusChanged> statusCallback)
 {
     this.massSender = massSender;
     this.pendingJobStatus = pendingJobStatus;
     this.message = message;
     this.receivers = receivers;
     this.sender = sender;
     this.statusCallback = statusCallback;
 }
Пример #2
0
            //<summary>execute the job, aka send the message to the receivers</summary>
            //<returns>a PendingJobStatus object,the main idea is that this method will be called from the JobExecutionaire service
            //and the status of the executing job will be available to the desktop program via the JobExecutionaireInterface</returns>
            public PendingJobStatus execute()
            {
                JobScheduleRow schedule = JobScheduleTableAdapter.getInstance().GetDataByID(this.schedule)[0];
                if(massSenders.ContainsKey(this.ID))massSenders.Remove(ID);
                massSender=new MassSender();
                massSenders.Add(ID,massSender);

                List<OpenMassSenderCore.OpenMassSenderDBDataSet.ReceiverRow> receiversList = ReceiverTableAdapter.getInstance().searchReceivers(group, query);

                MessageRow message = (MessageRow)MessageTableAdapter.getInstance().GetDataById(this.message).Rows[0];
                SenderAccountRow sender = (SenderAccountRow)SenderAccountTableAdapter.getInstance().GetDataById(this.sender_account).Rows[0];

                Logger.log("creating mass sender for " + sender.ID + " message " + message.ID);
                this.status = JobStatus.PENDING;
                JobTableAdapter.getInstance().Update(this);
                massSender.send(sender,
                    message, receiversList, (SendStatusChanged status) =>
                {
                    try
                    {
                        if (massSender.sendsTried == massSender.totalSends)
                        {
                            if (schedule != null)
                            {
                                if (schedule.repeatable == RepeatableJob.NON_REPEATABLE)
                                {
                                    this.status = JobStatus.FINISHED;
                                }
                                else
                                {
                                    this.status = JobStatus.SHEDULED;
                                }
                                schedule.jobExecutionFinished();
                            }
                            Logger.log("job " + this.ID + " finished, next execution is " + schedule.nextExecution);
                            if (jobFinished != null) jobFinished(this);
                            JobTableAdapter.getInstance().Update(this);
                            JobScheduleTableAdapter.getInstance().Update(schedule);
                        }
                    }
                    catch (Exception ex)
                    {
                        Logger.error(ex.StackTrace);
                    }
                });

                return massSender.status;
            }