コード例 #1
0
        private DateTime GetNextTimeToCheck(INotificationEvent ne, DateTime fromTime)
        {
            DateTime         nextCheck = fromTime;
            List <DayOfWeek> days      = Days(ne);

            switch (ne.CheckIntervalType)
            {
            case "Timer":
                nextCheck = nextCheck.AddMinutes((int)ne.CheckInterval);
                while (!days.Contains(nextCheck.DayOfWeek))
                {
                    nextCheck = nextCheck.AddDays(1);
                }
                break;

            case "Daily":
                TimeSpan x = ne.TimeOfDayToCheck.Value - ne.TimeOfDayToCheck.Value.Date;
                nextCheck = nextCheck.Date + x;
                while (!days.Contains(nextCheck.DayOfWeek))
                {
                    nextCheck = nextCheck.AddDays(1);
                }
                break;
            }
            return(nextCheck);
        }
コード例 #2
0
ファイル: OrderManager.cs プロジェクト: benshyuv/Workshop
 public void notifyEvent(INotificationEvent notificationEvent, MarketDbContext context)
 {
     foreach (NotificationObserver observer in observers)
     {
         observer.NotifyEvent(notificationEvent, context);
     }
 }
コード例 #3
0
        public void Publish(INotificationEvent evt)
        {
            if (this.bus != null)
            {
                this.bus.Publish(evt);
            }

            var builders = this.context.GetReadModelBuilders <T>(this.bus);

            var updatedReadModels = new List <IDataChangeEvent>();

            // todo: this coud be done async, but because we should only have one thread to the db at any one time it's not really worth it.
            // just don't take too long in any one builder and don't make assumptions on the order of builders being executed.
            foreach (var builder in builders)
            {
                updatedReadModels.AddRange(builder.Handle(evt));
            }

            if (this.bus != null)
            {
                foreach (var readModel in updatedReadModels)
                {
                    this.bus.Publish(new NotificationEvent(readModel.DataType, readModel.DataId, readModel));
                }
            }
        }
コード例 #4
0
        IEnumerator DisplayNotification()
        {
            if (!notificationActive)
            {
                if (_pendingQueue.Count > 0)
                {
                    INotificationEvent message = _pendingQueue.Peek();
                    if (notificationpopup == null)
                    {
                        GameObject notificationObject = (GameObject)Instantiate(notificationPrefab, notificationAnchor.position, Quaternion.identity) as GameObject;
                        notificationObject.transform.SetParent(notificationAnchor);
                        notificationpopup = notificationObject.GetComponent <NotificationPopup>();
                        notificationRect  = notificationObject.GetComponent <RectTransform>();
                    }
                    if (notificationRect != null)
                    {
                        notificationRect.anchoredPosition = new Vector2(0, notificationRect.sizeDelta.y);
                    }
                    notificationpopup.SetContext(message);
                    notificationActive = true;
                }
            }
            yield return(null);

            StartCoroutine(DisplayNotification());
        }
コード例 #5
0
 internal void AddMessageToRecipients(INotificationEvent notification, MarketDbContext context)
 {
     foreach (Guid userID in notification.getRecipientsIDs())
     {
         if (TryGetRegistered(userID, out RegisteredUser registered, context))
         {
             registered.AddNotificationMessage(notification.GetMessage());
         }
コード例 #6
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);
        }
コード例 #7
0
 public void NotifyEvent(INotificationEvent notification, MarketDbContext context)
 {
     userManager.AddMessageToRecipients(notification, context);
     if (communicationNotificationAlerter != null)
     {
         foreach (Guid userID in notification.getRecipientsIDs())
         {
             this.communicationNotificationAlerter.AlertUser(userID);
         }
     }
 }
コード例 #8
0
ファイル: ReadModelBuilder.cs プロジェクト: tilemapjp/MonoKit
        public IEnumerable <IDataChangeEvent> Handle(INotificationEvent evt)
        {
            this.updatedReadModels.Clear();

            // now, for each domain event, call a method that takes the event and call it
            // todo: should we check for not handling the event or not.  read model builders probably don't need to
            // handle *everthing*
            MethodExecutor.ExecuteMethodForParams(this, evt.Event);

            return(this.updatedReadModels);
        }
コード例 #9
0
 private bool ProcessDigestEvent(INotificationEvent ne, IList <dynamic> payload)
 {
     if (ne.DynamicNotification == false)
     {
         return(ProcessDigestEventTargetList(ne, payload));
     }
     else
     {
         return(ProcessDigestEventDynamicTargetList(ne, payload));
     }
 }
        private string GetTemplateName(INotificationEvent notificationEvent)
        {
            switch (notificationEvent.GetType().Name)
            {
            case nameof(ReservationCreatedNotificationEvent): return(TemplateIds.ReservationCreated);

            case nameof(ReservationDeletedNotificationEvent): return(TemplateIds.ReservationDeleted);

            default: throw new NotImplementedException("No template found for this event.");
            }
        }
コード例 #11
0
        public void SendNotification(INotificationEvent notification)
        {
            _pendingQueue.Enqueue(notification);

            Debug.Log(_pendingQueue.Count);

            if (logToConsole)
            {
                Debug.Log("Message Recieved [" + System.DateTime.Now + "]: " + notification.message.ToString());
            }
        }
コード例 #12
0
 public void SetContext(object context)
 {
     if (context != null)
     {
         if (context is INotificationEvent)
         {
             notificationEventData = (INotificationEvent)context;
             SetData();
         }
     }
 }
コード例 #13
0
        private string ParseQueryForLiterals(INotificationEvent ne)
        {
            string query = ne.Query;

            if (!String.IsNullOrEmpty(query))
            {
                query = query.Replace(QueryLiterals.LastChecked, "'" + ne.LastChecked.Value.ToString() + "'");
                query = query.Replace(QueryLiterals.Today, "'" + DateTime.UtcNow.Date + "'");
                query = query.Replace(QueryLiterals.Tomorrow, "'" + DateTime.UtcNow.Date.AddDays(1) + "'");
                query = query.Replace(QueryLiterals.Yesterday, "'" + DateTime.UtcNow.Date.AddDays(-1) + "'");
            }

            return(query);
        }
コード例 #14
0
        private async Task RunForEachNotifier(Func <INotifier, Task> action, INotificationEvent @event)
        {
            foreach (var notifier in _notifiers)
            {
                try
                {
                    _logger.LogTrace("Started notifying for {@NotificationEvent} for notifier {NotifierType}", @event,
                                     notifier.Type);

                    await action(notifier);

                    _logger.LogTrace("Finished notifying for {@NotificationEvent} for notifier {NotifierType}", @event,
                                     notifier.Type);
                }
                catch (Exception e)
                {
                    _logger.LogError(e, "Error for event: {@NotificationEvent} for notifier: {NotifierType}", @event,
                                     notifier.Type);
                }
            }
        }
コード例 #15
0
        private string GenerateSubject(INotificationEvent ne, int itemCount, string name = null)
        {
            string subject = ne.EmailSubjectTemplate;

            string entityName = ne.EntityName;
            string isare      = "is";
            string hashave    = "has";

            if (itemCount > 1)
            {
                isare   = "are";
                hashave = "have";
                if (entityName.EndsWith("s"))
                {
                    entityName = entityName + "es";
                }
                else
                {
                    entityName = entityName + "s";
                }
            }

            try
            {
                subject = subject.Replace("<%:ISARE%>", isare);
                subject = subject.Replace("<%:NOW%>", DateTime.Now.ToShortDateString());
                subject = subject.Replace("<%:TODAY%>", DateTime.Today.ToShortDateString());
                subject = subject.Replace("<%:ITEMCOUNT%>", itemCount.ToString());
                subject = subject.Replace("<%:NAME%>", name);
                subject = subject.Replace("<%:ENTITY%>", entityName);
                subject = subject.Replace("<%:HASHAVE%>", hashave);
            }
            catch { }

            return(subject);
        }
コード例 #16
0
        private static List <DayOfWeek> Days(INotificationEvent notificationEvent)
        {
            List <DayOfWeek> result = new List <DayOfWeek>();

            // I'm sure there is a better way of doing this.  Just hacking it in for now.
            if (notificationEvent.DaysOfWeek.Contains("Sun"))
            {
                result.Add(DayOfWeek.Sunday);
            }
            if (notificationEvent.DaysOfWeek.Contains("Mon"))
            {
                result.Add(DayOfWeek.Monday);
            }
            if (notificationEvent.DaysOfWeek.Contains("Tues"))
            {
                result.Add(DayOfWeek.Tuesday);
            }
            if (notificationEvent.DaysOfWeek.Contains("Wed"))
            {
                result.Add(DayOfWeek.Wednesday);
            }
            if (notificationEvent.DaysOfWeek.Contains("Thurs"))
            {
                result.Add(DayOfWeek.Thursday);
            }
            if (notificationEvent.DaysOfWeek.Contains("Fri"))
            {
                result.Add(DayOfWeek.Friday);
            }
            if (notificationEvent.DaysOfWeek.Contains("Sat"))
            {
                result.Add(DayOfWeek.Saturday);
            }

            return(result);
        }
 private static bool EventIsNotFromProvider(INotificationEvent notificationEvent)
 {
     return(!notificationEvent.ProviderId.HasValue);
 }
コード例 #18
0
 public void Publish(INotificationEvent evt)
 {
     this.eventPublisher.OnNext(evt);
 }
コード例 #19
0
        private bool ProcessSingleEvent(INotificationEvent ne, IList <dynamic> payload)
        {
            bool bResult = false;

            try
            {
                foreach (dynamic item in payload)
                {
                    IList <string> targets = new List <string>();

                    if (ne.Digest == false)
                    {
                        // Add Targets
                        foreach (INotificationTarget target in ne.Targets)
                        {
                            if (target.Target.Type == OwnerType.User)
                            {
                                targets.Add(target.Target.User.UserInfo.Email);
                            }
                            else
                            {
                                // Get 1st level of Team or Dept members
                                targets = GetEmails(target.Target);
                            }
                        }
                        CreateDeliveryItem(GenerateSubject(ne, 1), GenerateBody(item, ne.EmailTemplate), ne.DeliveryMethod, targets);
                    }
                    else
                    {
                        string targetName = null;

                        // Get the Dynamic Field to send to
                        dynamic dynamicField = item.GetType().GetProperty(ne.DynamicNotificationField).GetValue(item, null);

                        if (dynamicField is IContact)
                        {
                            targets.Add(dynamicField.GetType().GetProperty("Email").GetValue(dynamicField, null));
                            targetName = dynamicField.GetType().GetProperty("FullName").GetValue(dynamicField, null);
                        }
                        else if (dynamicField is IUser)
                        {
                            targets.Add(dynamicField.GetType().GetProperty("Email").GetValue(dynamicField, null));
                            targetName = dynamicField.GetType().GetProperty("UserName").GetValue(dynamicField, null);
                        }
                        else if (dynamicField is IOwner)
                        {
                            targets    = GetEmails(dynamicField);
                            targetName = dynamicField.GetType().GetProperty("OwnerDescription").GetValue(dynamicField, null);
                        }

                        CreateDeliveryItem(GenerateSubject(ne, 1, targetName), GenerateBody(item, ne.EmailTemplate), ne.DeliveryMethod, targets);
                    }
                }
                bResult = true;
            }
            catch (Exception ex)
            {
                Log.Error(ex.Message);
            }
            return(bResult);
        }
コード例 #20
0
        private bool ProcessDigestEventDynamicTargetList(INotificationEvent ne, IList <dynamic> payload)
        {
            bool           bResult           = false;
            IList <string> currentEmails     = new List <string>();
            int            itemCount         = 0;
            string         body              = null;
            string         currentTargetName = null;

            try
            {
                foreach (dynamic item in payload)
                {
                    IList <string> theseEmails    = new List <string>();
                    string         thisTargetName = null;

                    // Get the Dynamic Field to send to
                    dynamic dynamicField = item.GetType().GetProperty(ne.DynamicNotificationField).GetValue(item, null);

                    if (dynamicField is IContact)
                    {
                        theseEmails.Add(dynamicField.GetType().GetProperty("Email").GetValue(dynamicField, null));
                        thisTargetName = dynamicField.GetType().GetProperty("FullName").GetValue(dynamicField, null);
                    }
                    else if (dynamicField is IUser)
                    {
                        theseEmails.Add(dynamicField.GetType().GetProperty("Email").GetValue(dynamicField, null));
                        thisTargetName = dynamicField.GetType().GetProperty("UserName").GetValue(dynamicField, null);
                    }
                    else if (dynamicField is IOwner)
                    {
                        theseEmails    = GetEmails(dynamicField);
                        thisTargetName = dynamicField.GetType().GetProperty("OwnerDescription").GetValue(dynamicField, null);
                    }

                    if (currentTargetName == null || (String.Compare(currentTargetName, thisTargetName) != 0))
                    {
                        // Build up message body
                        string tempBody = GenerateBody(item, ne.EmailTemplate);
                        body = String.Format("{0}{1}", body, tempBody);
                        itemCount++;
                    }
                    else
                    {
                        // Deliver current one
                        CreateDeliveryItem(GenerateSubject(ne, itemCount, currentTargetName), body, ne.DeliveryMethod, currentEmails);

                        // Set up new one
                        currentTargetName = thisTargetName;
                        currentEmails     = theseEmails;
                        body      = GenerateBody(item, ne.EmailTemplate);
                        itemCount = 1;
                    }
                }
                bResult = true;
            }
            catch (Exception ex)
            {
                Log.Error(ex.Message);
            }

            // Send last one
            CreateDeliveryItem(GenerateSubject(ne, itemCount, currentTargetName), body, ne.DeliveryMethod, currentEmails);
            return(bResult);
        }
コード例 #21
0
 protected void AddEvent(INotificationEvent @event)
 {
     _events ??= new List <INotificationEvent>();
     _events.Add(@event);
 }
コード例 #22
0
 public void notifyEvent(INotificationEvent notificationEvent, DomainLayer.DbAccess.MarketDbContext context)
 {
 }
コード例 #23
0
 public void Publish(INotificationEvent evt)
 {
     this.events.Add(evt);
 }
コード例 #24
0
 public void Publish(INotificationEvent evt)
 {
     this.eventPublisher.OnNext(evt);
 }
 private static bool EventIsFromLevyAccount(INotificationEvent notificationEvent)
 {
     return(notificationEvent.CourseId == null && notificationEvent.StartDate == DateTime.MinValue);
 }
 private static bool EventIsFromEmployerDelete(INotificationEvent notificationEvent)
 {
     return(notificationEvent.ProviderId.HasValue && notificationEvent.EmployerDeleted);
 }
コード例 #27
0
 public void RemoveEvent(INotificationEvent @event) => _events.Remove(@event);
コード例 #28
0
ファイル: UnitOfWorkEventBus.cs プロジェクト: nagyist/MonoKit
 public void Publish(INotificationEvent evt)
 {
     this.events.Add(evt);
 }