コード例 #1
0
        public virtual PartialViewResult Subscribe(Guid activityId)
        {
            var userId       = _intranetMemberService.GetCurrentMemberId();
            var service      = _activitiesServiceFactory.GetService <ISubscribableService>(activityId);
            var subscribable = service.Subscribe(userId, activityId);
            var subscribe    = subscribable.Subscribers.Single(s => s.UserId == userId);

            return(Index(activityId, subscribe, subscribable.Type));
        }
コード例 #2
0
        public virtual IEnumerable <string> Subscribe(Guid activityId)
        {
            var userId  = _intranetMemberService.GetCurrentMemberId();
            var service = _activitiesServiceFactory.GetService <ISubscribableService>(activityId);

            service.Subscribe(userId, activityId);

            return(List(activityId));
        }
コード例 #3
0
ファイル: MyLinksHelper.cs プロジェクト: umbracouser7/Uintra
        private string GetActivityLink(Guid entityId)
        {
            var service = _activitiesServiceFactory.GetService <IIntranetActivityService <IIntranetActivity> >(entityId);

            var activity = service.Get(entityId);

            if (activity.Type is IntranetActivityTypeEnum.Social)
            {
                var lengthForPreview = _navigationApplicationSettings.MyLinksActivityTitleLength;
                var description      = activity.Description.StripHtml();
                return(description.Length > lengthForPreview?description.Substring(0, lengthForPreview) + "..." : description);
            }

            return(activity.Title);
        }
コード例 #4
0
        protected virtual EditViewModel GetEditViewModel(Guid id)
        {
            var service  = _activitiesServiceFactory.GetService <IIntranetActivityService>(id);
            var links    = _feedLinkService.GetLinks(id);
            var settings = _centralFeedService.GetSettings(service.Type);

            var viewModel = new EditViewModel()
            {
                Id       = id,
                Links    = links,
                Settings = settings
            };

            return(viewModel);
        }
コード例 #5
0
        public virtual OpenGraphObject GetOpenGraphObject(Guid activityId, string defaultUrl = null)
        {
            var graph = GetDefaultObject(defaultUrl);

            var intranetActivityService = (IIntranetActivityService <IIntranetActivity>)
                                          _activitiesServiceFactory.GetService <IIntranetActivityService>(activityId);

            var currentActivity = intranetActivityService.Get(activityId);

            if (currentActivity == null)
            {
                return(graph);
            }

            graph.Title       = currentActivity.Title.IfNullOrWhiteSpace("Social");
            graph.Description = StringExtensions.StripHtml(currentActivity.Description).TrimByWordEnd(100);

            if (!currentActivity.MediaIds.Any())
            {
                return(graph);
            }

            var list = new List <IMediaModel>();

            currentActivity.MediaIds.ToList().ForEach(i => list.Add(_mediaProvider.GetById(i)));

            var image = list.FirstOrDefault(m => m is ImageModel);

            graph.MediaId = image?.Id;
            graph.Image   = image?.Url;

            return(graph);
        }
コード例 #6
0
        public virtual bool IsUserHasAccess(IIntranetUser user, Enum activityType, IntranetActivityActionEnum action, Guid?activityId = null)
        {
            if (user == null)
            {
                return(false);
            }

            if (IsUserWebmaster(user))
            {
                return(true);
            }

            var permission         = $"{activityType.ToString()}{action}";
            var userHasPermissions = IsRoleHasPermissions(user.Role, permission);

            if (userHasPermissions && activityId.HasValue)
            {
                var service  = _activitiesServiceFactory.GetService <IIntranetActivityService <IIntranetActivity> >(activityType);
                var activity = service.Get(activityId.Value);

                if (activity is IHaveOwner owner)
                {
                    return(owner.OwnerId == user.Id);
                }
            }

            return(userHasPermissions);
        }
コード例 #7
0
        public void Run()
        {
            var correlationId = Guid.NewGuid();

            if (_isRunning)
            {
                _logger.Info <ReminderRunner>("Previous reminder is still running...");
                return;
            }

            _logger.Info <ReminderRunner>($"Reminder {correlationId} starts running...");
            _isRunning = true;

            try
            {
                var reminders = _reminderService.GetAllNotDelivered();
                _logger.Info <ReminderRunner>($"{reminders.Count()} activities to remind");
                foreach (var reminder in reminders)
                {
                    var service           = _activitiesServiceFactory.GetService <IIntranetActivityService>(reminder.ActivityId);
                    var reminderService   = service as IReminderableService <IReminderable>;
                    var notifiableService = service as INotifyableService;

                    if (reminderService == null || notifiableService == null)
                    {
                        continue;
                    }

                    var activity = reminderService.GetActual(reminder.ActivityId);
                    if (activity != null)
                    {
                        var configuration = GetConfiguration(reminder.Type);
                        if (ShouldNotify(configuration.Time, activity.StartDate))
                        {
                            _logger.Info <ReminderRunner>($"{activity.Id} activity needs to remind");
                            foreach (var notificationTypeName in configuration.NotificationTypes)
                            {
                                var notificationType = _notificationTypeProvider[notificationTypeName];
                                notifiableService.Notify(activity.Id, notificationType);
                            }

                            _reminderService.SetAsDelivered(reminder.Id);
                            _logger.Info <ReminderRunner>($"{activity.Id} set as delivered");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.Error <ReminderRunner>(ex.Message);
                _logger.Error <ReminderRunner>(ex.StackTrace);
            }
            finally
            {
                _isRunning = false;
                _logger.Info <ReminderRunner>($"Reminder {correlationId} finished");
            }
        }
コード例 #8
0
        public void Run()
        {
            if (_isRunning)
            {
                return;
            }
            _isRunning = true;

            try
            {
                var reminders = _reminderService.GetAllNotDelivered();
                foreach (var reminder in reminders)
                {
                    var service           = _activitiesServiceFactory.GetService <IIntranetActivityService>(reminder.ActivityId);
                    var reminderService   = service as IReminderableService <IReminderable>;
                    var notifiableService = service as INotifyableService;

                    if (reminderService == null || notifiableService == null)
                    {
                        continue;
                    }

                    var activity = reminderService.GetActual(reminder.ActivityId);
                    if (activity != null)
                    {
                        var configuration = GetConfiguration(reminder.Type);
                        if (ShouldNotify(configuration.Time, activity.StartDate))
                        {
                            foreach (var notificationTypeName in configuration.NotificationTypes)
                            {
                                var notificationType = _notificationTypeProvider[notificationTypeName];
                                notifiableService.Notify(activity.Id, notificationType);
                            }
                            _reminderService.SetAsDelivered(reminder.Id);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _exceptionLogger.Log(ex);
            }
            finally
            {
                _isRunning = false;
            }
        }
コード例 #9
0
 private IIntranetActivityService <IIntranetActivity> GetActivityService(Enum activityType)
 {
     return(_activitiesServiceFactory.GetService <IIntranetActivityService <IIntranetActivity> >(activityType));
 }
コード例 #10
0
 public static INotifyableService GetNotifyableService(this IActivitiesServiceFactory activitiesServiceFactory, Guid activityId)
 {
     return(activitiesServiceFactory.GetService <INotifyableService>(activityId));
 }
コード例 #11
0
 public static ICacheableIntranetActivityService <IIntranetActivity> GetCacheableIntranetActivityService(this IActivitiesServiceFactory activitiesServiceFactory, Guid activityId)
 {
     return(activitiesServiceFactory.GetService <ICacheableIntranetActivityService <IIntranetActivity> >(activityId));
 }
コード例 #12
0
        protected virtual ICommentable GetActivityComments(Guid activityId)
        {
            var service = _activitiesServiceFactory.GetService <IIntranetActivityService <IIntranetActivity> >(activityId);

            return((ICommentable)service.Get(activityId));
        }
コード例 #13
0
        public virtual OpenGraphObject GetOpenGraphObject(Guid activityId, string defaultUrl = null)
        {
            var obj = GetDefaultObject(defaultUrl);

            var intranetActivityService = (IIntranetActivityService <IIntranetActivity>)_activitiesServiceFactory
                                          .GetService <IIntranetActivityService>(activityId);
            var currentActivity = intranetActivityService?.Get(activityId);

            if (currentActivity == null)
            {
                return(obj);
            }

            obj.Title       = currentActivity.Title.IfNullOrWhiteSpace("Bulletin");
            obj.Description = Extensions.StringExtensions.StripHtml(currentActivity.Description).TrimByWordEnd(100);

            if (currentActivity.MediaIds.Any())
            {
                foreach (var mediaId in currentActivity.MediaIds)
                {
                    var media = _umbracoHelper.TypedMedia(mediaId);
                    if (media.GetMediaType().Equals(MediaTypeEnum.Image))
                    {
                        obj.MediaId = mediaId;
                        obj.Image   = GetAbsoluteImageUrl(media);
                        break;
                    }
                }
            }

            return(obj);
        }
コード例 #14
0
        private ILikeable GetActivityLikes(Guid activityId)
        {
            var service = _activitiesServiceFactory.GetService <IIntranetActivityService <IIntranetActivity> >(activityId);

            return((ILikeable)service.Get(activityId));
        }