예제 #1
0
 private void ProcessDeliveryItem(IDeliveryItem deliveryItem)
 {
     using (DeliverySystem ds = new DeliverySystem())
     {
         ds.Send(deliveryItem);
     }
 }
예제 #2
0
파일: BookStock.cs 프로젝트: rajzon/LibApp
        public BookStock(ActiveDelivery activeDelivery, IDeliveryItem item)
        {
            if (item is not ActiveDeliveryItem)
            {
                throw new ArgumentException($"Passed Delivery Item is not of type {nameof(ActiveDeliveryItem)}");
            }
            if (item is null)
            {
                throw new ArgumentException("DeliveryItem cannot be null");
            }
            if (activeDelivery is null)
            {
                throw new ArgumentException("ActiveDelivery cannot be null");
            }
            if (!activeDelivery.Items.Any(i => i.BookEan.Code.Equals(item.BookEan.Code)))
            {
                throw new ArgumentException($"ActiveDelivery: {activeDelivery.Id} do not contain ean {item.BookEan.Code}");
            }

            BookEan13 = new BookEan13ForStock(item.BookEan.Code);
            BookId    = item.BookId;

            ModificationDate = DateTime.UtcNow;
            CreationDate     = DateTime.UtcNow;
        }
예제 #3
0
        private bool SendSms(IDeliveryItem di, out string errorMsg)
        {
            bool result = false;

            errorMsg = "Not Implemented";

            return(result);
        }
예제 #4
0
        private bool ProcessDigestEventTargetList(INotificationEvent ne, IList <dynamic> payload)
        {
            bool          bResult      = false;
            int           itemCount    = 0;
            IDeliveryItem deliveryItem = EntityFactory.Create <IDeliveryItem>();

            deliveryItem.DeliverySystem = ne.DeliveryMethod;
            deliveryItem.Status         = DeliverySystems.DeliveryItemStatuses.ToBeProcessed;

            try
            {
                // Build Body
                foreach (dynamic item in payload)
                {
                    string body = null;
                    body = GenerateBody(item, ne.EmailTemplate);
                    deliveryItem.Body = String.Format("{0}{1}", deliveryItem.Body, body);
                    itemCount++;
                }

                // Build Subject
                deliveryItem.Subject = GenerateSubject(ne, itemCount);

                // Add Targets
                foreach (INotificationTarget target in ne.Targets)
                {
                    if (target.Target.Type == OwnerType.User)
                    {
                        IDeliveryItemTarget t = EntityFactory.Create <IDeliveryItemTarget>();
                        t.Type         = DeliverySystems.DeliveryItemTargetTypes.To;
                        t.Address      = target.Target.User.UserInfo.Email;
                        t.DeliveryItem = deliveryItem;
                        deliveryItem.DeliveryItemTargets.Add(t);
                    }
                    else
                    {
                        // Get 1st level of Team or Dept members
                        IList <string> emails = GetEmails(target.Target);

                        foreach (string email in emails)
                        {
                            IDeliveryItemTarget t = EntityFactory.Create <IDeliveryItemTarget>();
                            t.Type         = "TO";
                            t.Address      = email;
                            t.DeliveryItem = deliveryItem;
                            deliveryItem.DeliveryItemTargets.Add(t);
                        }
                    }
                }
                deliveryItem.Save();
                bResult = true;
            }
            catch (Exception ex)
            {
                Log.Error(ex.Message);
            }
            return(bResult);
        }
예제 #5
0
        private bool SendSmtp(IDeliveryItem di, out string errorMsg)
        {
            bool result = false;

            errorMsg = null;

            try
            {
                // Create a blank email message
                MailMessage email = new MailMessage();

                // Set the proper properties based on the deliverySystem
                email.From       = new MailAddress(di.DeliverySystem.EmailAddress);
                email.Sender     = email.From;
                email.IsBodyHtml = Convert.ToBoolean(di.DeliverySystem.SmtpIsBodyHtml);

                // Add Targets
                foreach (IDeliveryItemTarget target in di.DeliveryItemTargets)
                {
                    switch (target.Type.ToUpper())
                    {
                    case "TO":
                        email.To.Add(new MailAddress(target.Address));
                        break;

                    case "CC":
                        email.CC.Add(new MailAddress(target.Address));
                        break;

                    case "BCC":
                        email.Bcc.Add(new MailAddress(target.Address));
                        break;
                    }
                }

                // Add Subject
                email.Subject = di.Subject;

                // Add Body
                email.Body = di.Body;

                // Send via Smtp
                SmtpClient smtp = new SmtpClient(di.DeliverySystem.ServerAddress, Convert.ToInt16(di.DeliverySystem.SmtpPort));
                smtp.EnableSsl   = Convert.ToBoolean(di.DeliverySystem.SmtpEnableSsl);
                smtp.Credentials = new System.Net.NetworkCredential(di.DeliverySystem.UserName, di.DeliverySystem.UserPassword);
                smtp.Send(email);
                result = true;
            }
            catch (Exception ex)
            {
                errorMsg = String.Format("Send Smtp - Error\n{0}\n{1}", ex.Message, ex.StackTrace);
            }

            return(result);
        }
예제 #6
0
 static void Main(string[] args)
 {
     for (int i = 0; i < 7; i++)
     {
         object          product        = $"Product {i}";
         IDeliveryMethod deliveryMethod = MatchDeliveryMethod.GetDeliveryMethod(product);
         IDeliveryItem   deliveryItem   = deliveryMethod.GetDeliveryItem(product);
         deliveryItem.StartDelivering();
         Console.WriteLine($"{deliveryItem.Product.ToString()} : {deliveryItem.Status}");
     }
 }
예제 #7
0
        private bool SendExch(IDeliveryItem di, out string errorMsg)
        {
            bool result = false;

            errorMsg = null;

            try
            {
                NetworkCredential creds = new NetworkCredential();
                creds.UserName = di.DeliverySystem.UserName;
                creds.Domain   = di.DeliverySystem.UserDomain;
                creds.Password = di.DeliverySystem.UserPassword;

                using (ExchangeWebServices _exchange = new ExchangeWebServices(creds, di.DeliverySystem.ServerAddress))
                {
                    EmailMessage message = new EmailMessage(_exchange.Service);
                    message.Subject = di.Subject;
                    message.Body    = di.Body;
                    message.From    = di.DeliverySystem.EmailAddress;

                    foreach (IDeliveryItemTarget target in di.DeliveryItemTargets)
                    {
                        switch (target.Type)
                        {
                        case DeliveryItemTargetTypes.To:
                            message.ToRecipients.Add(new EmailAddress(target.Address));
                            break;

                        case DeliveryItemTargetTypes.Cc:
                            message.CcRecipients.Add(new EmailAddress(target.Address));
                            break;

                        case DeliveryItemTargetTypes.Bcc:
                            message.BccRecipients.Add(new EmailAddress(target.Address));
                            break;
                        }
                    }

                    if (message.ToRecipients.Count > 0)
                    {
                        message.Send();
                    }
                }

                result = true;
            }
            catch (Exception ex)
            {
                errorMsg = String.Format("Send Exchange - Error\n{0}\n{1}", ex.Message, ex.StackTrace);
            }

            return(result);
        }
        private void WeeklyForecastSummary(IBulletin bulletin)
        {
            DateTime        today = DateTime.UtcNow;
            ForecastSummary fs    = new ForecastSummary();

            Progress = 0;
            decimal counter = 0;

            using (var session = new SessionScopeWrapper())
            {
                IList <IForecast> forecasts = session.QueryOver <IForecast>()
                                              .Where(x => today >= x.BeginDate && today <= x.EndDate && x.Active == true)
                                              .List <IForecast>();

                foreach (IForecast f in forecasts)
                {
                    ForecastInfo fi = new ForecastInfo();
                    fi.ForecastName = f.Description;
                    fi.AssignedTo   = f.AssignedTo.UserInfo.NameLF;
                    fi.Amount       = Convert.ToDecimal(f.Amount);
                    fi.Pipeline     = (decimal)f.PeriodPipelineAmt("Avg");
                    fi.ClosedWon    = (decimal)f.PeriodClosedWonAmt();
                    fi.Quota        = GetQuotaAmtforUser(f.AssignedTo, today);

                    fs.forecasts.Add(fi);
                    Progress = (100M * ++counter / forecasts.Count) / 2;
                }
            }

            counter = 0;
            if (fs.forecasts.Count > 0)
            {
                string msgBody = BuildMessageBody(fs);
                string subject = "Weekly Forecast Summary";

                IDeliveryItem di = Sage.Platform.EntityFactory.Create <IDeliveryItem>();
                di.Body           = msgBody;
                di.Subject        = subject;
                di.DeliverySystem = bulletin.DeliverySystem;
                di.Status         = "To Be Processed";

                foreach (IBulletinSubscriber subscriber in bulletin.Subscribers)
                {
                    IDeliveryItemTarget target = EntityFactory.Create <IDeliveryItemTarget>();
                    target.DeliveryItem = di;
                    target.Address      = subscriber.Subscriber.UserInfo.Email;
                    target.Type         = "TO";
                    di.DeliveryItemTargets.Add(target);
                    di.Save();
                    Progress = 50M + (50M * ++counter / bulletin.Subscribers.Count);
                }
            }
        }
예제 #9
0
        public void CreateDeliveryItem(string subject, string body, IDeliverySystem ds, IList <string> targets)
        {
            IDeliveryItem deliveryItem = EntityFactory.Create <IDeliveryItem>();

            deliveryItem.Subject        = subject;
            deliveryItem.Body           = body;
            deliveryItem.Status         = DeliverySystems.DeliveryItemStatuses.ToBeProcessed;
            deliveryItem.DeliverySystem = ds;

            foreach (string target in targets)
            {
                IDeliveryItemTarget t = EntityFactory.Create <IDeliveryItemTarget>();
                t.DeliveryItem = deliveryItem;
                t.Address      = target;
                t.Type         = DeliverySystems.DeliveryItemTargetTypes.To;
                deliveryItem.DeliveryItemTargets.Add(t);
            }
            deliveryItem.Save();
        }
예제 #10
0
        public void Send(IDeliveryItem di)
        {
            bool   result   = false;
            string errorMsg = null;

            di.Status = DeliveryItemStatuses.InProcess;
            di.Save();

            switch (di.DeliverySystem.SystemType)
            {
            case DeliverySystemTypes.Smtp:
                result = SendSmtp(di, out errorMsg);
                break;

            case DeliverySystemTypes.Exch:
                result = SendExch(di, out errorMsg);
                break;

            case DeliverySystemTypes.Sms:
                result = SendSms(di, out errorMsg);
                break;
            }

            if (result)
            {
                di.Status        = DeliveryItemStatuses.Completed;
                di.ErrorText     = null;
                di.CompletedDate = DateTime.Now;
                di.Save();
            }
            else
            {
                di.Status    = DeliveryItemStatuses.Error;
                di.ErrorText = errorMsg;
                di.Save();
            }
        }