Esempio n. 1
0
        public void CreateNewCommentNotification(ApplicationUser leftBy, ApplicationUser recipient,
                                                 DataAccess.Entities.Assignment assignment)
        {
            var content = $"A new comment on assignment [ {assignment.Name} ] has been left by: {leftBy.FullName}";

            var notification = new DataAccess.Entities.Notification
            {
                Content   = content,
                CreatedBy = leftBy,
                User      = recipient,
                Project   = assignment.Epic.Project,
                Type      = NotificationType.NewComment
            };

            repository.Create(notification, recipient);
        }
Esempio n. 2
0
        public void CreateAssignedToTaskNotification(ApplicationUser assignedBy, ApplicationUser assignee,
                                                     DataAccess.Entities.Assignment assignment)
        {
            var content = $"You have been assigned to task [ {assignment.Name} ] by: {assignedBy.FullName}";

            var notification = new DataAccess.Entities.Notification
            {
                Content   = content,
                CreatedBy = assignedBy,
                User      = assignee,
                Project   = assignment.Epic.Project,
                Type      = NotificationType.AssigneeChange
            };

            repository.Create(notification, assignee);
        }
Esempio n. 3
0
        public void CreateAssignmentUpdatedNotification(ApplicationUser updatedBy, ApplicationUser recipient,
                                                        DataAccess.Entities.Assignment assignment)
        {
            var content = $"Assignment [ {assignment.Name} ] has been updated by: {updatedBy.FullName}";

            var notification = new DataAccess.Entities.Notification
            {
                Content   = content,
                CreatedBy = updatedBy,
                User      = recipient,
                Project   = assignment.Epic.Project,
                Type      = NotificationType.AssignmentUpdate
            };

            repository.Create(notification, recipient);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="notification"></param>
        /// <returns></returns>
        public bool Notify(Notification notification)
        {
            notification.ReceivedAt            = DateTime.UtcNow;
            notification.NotificationCreatedAt = DateTime.UtcNow;

            var dbNotification = new DataAccess.Entities.Notification
            {
                Body                  = notification.Body ?? "Empty",
                FetchedByShip         = false,
                FetchTime             = null,
                FromOrgId             = notification.FromOrgId,
                FromOrgName           = notification.FromOrgName,
                FromServiceId         = notification.FromServiceId,
                NotificationCreatedAt = notification.NotificationCreatedAt,
                NotificationType      = (DataAccess.Entities.NotificationType)notification.NotificationType,
                NotificationSource    = (DataAccess.Entities.NotificationSource)notification.NotificationSource,
                ReceivedAt            = notification.ReceivedAt,
                Subject               = notification.Subject
            };

            var nrOfNotifications = _notificationService.Get(XmlParsers => XmlParsers.FetchedByShip == false).Count();

            // Write notification to database
            _notificationService.Insert(dbNotification);
            _context.SaveChanges();

            try
            {
                // Try to push notification to client
                if (!string.IsNullOrEmpty(InstanceContext.StmModuleUrl))
                {
                    log.Debug("Trying to send notification to STM module on url: " + InstanceContext.StmModuleUrl);

                    notification.MessageWaiting = nrOfNotifications;

                    WebHeaderCollection h = new WebHeaderCollection();
                    h.Add("content-type", "application/json; charset=utf-8");

                    var response = WebRequestHelper.Post(InstanceContext.StmModuleUrl, notification.ToJson(), h);
                    if (response.HttpStatusCode == HttpStatusCode.OK)
                    {
                        dbNotification.FetchedByShip = true;
                        dbNotification.FetchTime     = DateTime.UtcNow;
                        _notificationService.Update(dbNotification);
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    log.Debug("No push to STM Module becouse no url is configured for the instance");
                    return(false);
                }
            }
            catch (Exception ex)
            {
                log.Error(ex.Message, ex);
                return(false);
            }

            return(true);
        }