Exemplo n.º 1
0
    public static void Sendnow(object param)
    {
        object[] parameters             = (object[])param;
        List <Model_SendingJobItem> cli = (List <Model_SendingJobItem>)parameters[0];
        Model_Setting s = (Model_Setting)parameters[1];

        Model_SendingJob ms = (Model_SendingJob)parameters[2];

        HttpContext context = (HttpContext)parameters[3];
        //Model_SendingJob ms = new Model_SendingJob();

        //var groupCampaignCID = cli.Where(cam => cam.CType == 1).GroupBy(c => c.CID);
        //var groupMailboxCID = cli.Where(cam => cam.CType == 2).GroupBy(c => c.CID);

        //StringBuilder strCam = new StringBuilder();
        //StringBuilder strMailBox = new StringBuilder();
        //foreach (var ss in groupCampaignCID)
        //{
        //    int propertyIntOfClassA = ss.Key;
        //    strCam.Append(propertyIntOfClassA + ",");
        //}
        //strCam.Append("0");
        //foreach (var ss in groupMailboxCID)
        //{
        //    int propertyIntOfClassA = ss.Key;
        //    strMailBox.Append(propertyIntOfClassA + ",");
        //}
        //strMailBox.Append("0");


        IList <Model_Campaign> mdc = CampaignController.GetCampaign(ms.CID.ToString());
        IList <Model_Mailbox>  mdm = MailboxController.GetMailbox(ms.CID.ToString());

        MailSenderOption option = new MailSenderOption
        {
            MailSetting = s,
            context     = context
        };
        EmailEelements e = new EmailEelements();

        // _el = (EModel)e.model_GetElementBYID(this.EID).Eelement.JsonToObject(new EModel());
        int count = 1;

        foreach (Model_SendingJobItem c in cli)
        {
            if (c.CType == 1)
            {
                Model_Campaign cam = mdc.SingleOrDefault(r => r.CID == c.CID);
                EModel         el  = (EModel)cam.ELRaw.JsonToObject(new EModel());
                option.Subject = cam.Subject;

                string bodymail = el.html;
                if (cam.Unsub)
                {
                    bodymail = bodymail.Replace("</body>", appendSubscription(c.SID));
                }

                option.Mailbody = bodymail;

                if (!string.IsNullOrEmpty(cam.FileMail))
                {
                    option.Attachment = GetFileMail(cam.FileMail);
                }
            }
            else
            {
                Model_Mailbox cam = mdm.SingleOrDefault(r => r.CID == c.CID);
                EModel        el  = (EModel)cam.ELRaw.JsonToObject(new EModel());
                option.Subject = cam.Subject;

                string bodymail = appendHtmlforMailbox(el.html);
                if (cam.Unsub && c.SID != 0)
                {
                    bodymail = bodymail.Replace("</body>", appendSubscription(c.SID));
                }

                option.Mailbody = bodymail;

                if (!string.IsNullOrEmpty(cam.FileMail))
                {
                    option.Attachment = GetFileMail(cam.FileMail);
                }
            }
            option.mailTo = c.Email;

            //"*****@*****.**", "Gosolve", c.Email, "Thread Sending", "", "Thread Sending Thread Sending"
            if (MAilSender.SendMailEngine(option))
            {
                c.UpdateStatus(c.SDIID, true);
            }



            // Lock.AcquireWriterLock(Timeout.Infinite);

            //SendingEngineController.SendResponse.SingleOrDefault(ii => ii.CID == c.CID).TotalSent += 1;
            // Lock.ReleaseWriterLock();



            ms.UpdateTotalSentAndISDone(c.SDID);
            count = count + 1;
        }

        Lock.AcquireWriterLock(Timeout.Infinite);
        SendingEngineController.Onprocess = false;
        Lock.ReleaseWriterLock();
    }