Esempio n. 1
0
        /*Section="CustomCodeRegion"*/
        #region Customized
        // Keep your custom code in this region.
        public void AddNotificationStores(NotificationStore notificationStore)
        {
            using (IDAL dal = this.DAL)
            {
                try
                {
                    dal.BeginTransaction();

                    IUniParameter prmNotificationId           = dal.CreateParameter("Notification", notificationStore.Notification);
                    IUniParameter prmStoreId                  = dal.CreateParameter("Store", null);
                    IEnumerable <NotificationStore> notStores = dal.List <NotificationStore>("ANN_LST_NOTIFICATIONSTORE_SP", prmNotificationId, prmStoreId).ToList();
                    var notStoreIds = notStores.Select(x => x.Store).ToArray();

                    foreach (int storeId in notificationStore.StoreList)
                    {
                        if (notStoreIds.Contains(storeId) == false)
                        {
                            notificationStore.Store = storeId;
                            dal.Create <NotificationStore>(notificationStore);
                        }
                    }
                    dal.CommitTransaction();
                }
                catch (Exception ex)
                {
                    dal.RollbackTransaction();
                    throw ex;
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Syncs all tables.
        /// </summary>
        /// <returns>The all async.</returns>
        /// <param name="syncUserSpecific">If set to <c>true</c> sync user specific.</param>
        public async Task <bool> SyncAllAsync(bool syncUserSpecific)
        {
            if (!IsInitialized)
            {
                await InitializeAsync();
            }

            var taskList = new List <Task <bool> >();

            taskList.Add(CategoryStore.SyncAsync());
            taskList.Add(NotificationStore.SyncAsync());
            taskList.Add(SpeakerStore.SyncAsync());
            taskList.Add(SessionStore.SyncAsync());
            taskList.Add(WorkshopStore.SyncAsync());
            taskList.Add(SponsorStore.SyncAsync());
            taskList.Add(EventStore.SyncAsync());
            taskList.Add(ApplicationDataStore.SyncAsync());


            if (syncUserSpecific)
            {
                taskList.Add(FeedbackStore.SyncAsync());
                taskList.Add(FavoriteStore.SyncAsync());
            }

            var successes = await Task.WhenAll(taskList).ConfigureAwait(false);

            return(successes.Any(x => !x));//if any were a failure.
        }
Esempio n. 3
0
        public virtual async Task HandleEventAsync(NotificationEventData eventData)
        {
            var notification = NotificationDefinitionManager.Get(eventData.Name);

            var notificationInfo = new NotificationInfo
            {
                Name         = notification.Name,
                CreationTime = eventData.CreationTime,
                Data         = eventData.Data,
                Severity     = eventData.Severity,
                Lifetime     = notification.NotificationLifetime,
                TenantId     = eventData.TenantId,
                Type         = notification.NotificationType
            };

            notificationInfo.SetId(SnowflakeIdGenerator.Create());

            notificationInfo.Data = NotificationDataConverter.Convert(notificationInfo.Data);

            Logger.LogDebug($"Persistent notification {notificationInfo.Name}");

            // 持久化通知
            await NotificationStore.InsertNotificationAsync(notificationInfo);

            var providers = Enumerable
                            .Reverse(NotificationPublishProviderManager.Providers);

            await PublishFromProvidersAsync(providers, eventData.Users, notificationInfo);
        }
        /// <summary>
        /// 指定提供者发布通知
        /// </summary>
        /// <param name="providers">提供者列表</param>
        /// <param name="notificationInfo">通知信息</param>
        /// <returns></returns>
        protected async Task PublishFromProvidersAsync(IEnumerable <INotificationPublishProvider> providers,
                                                       NotificationInfo notificationInfo)
        {
            Logger.LogDebug($"Persistent notification {notificationInfo.Name}");

            // 持久化通知
            await NotificationStore.InsertNotificationAsync(notificationInfo);

            Logger.LogDebug($"Gets a list of user subscriptions {notificationInfo.Name}");
            // 获取用户订阅列表
            var userSubscriptions = await NotificationStore.GetSubscriptionsAsync(notificationInfo.TenantId, notificationInfo.Name);

            Logger.LogDebug($"Persistent user notifications {notificationInfo.Name}");
            // 持久化用户通知
            var subscriptionUserIdentifiers = userSubscriptions.Select(us => new UserIdentifier(us.UserId, us.UserName));

            await NotificationStore.InsertUserNotificationsAsync(notificationInfo,
                                                                 subscriptionUserIdentifiers.Select(u => u.UserId));

            // 发布通知
            foreach (var provider in providers)
            {
                await PublishAsync(provider, notificationInfo, subscriptionUserIdentifiers);
            }

            if (notificationInfo.Lifetime == NotificationLifetime.OnlyOne)
            {
                // 一次性通知在发送完成后就取消用户订阅
                await NotificationStore.DeleteAllUserSubscriptionAsync(notificationInfo.TenantId,
                                                                       notificationInfo.Name);
            }
        }
Esempio n. 5
0
        public NotificationViewModel(NotificationStore notificationStore,
                                     IOptions <Settings> settings)
        {
            _notificationStore = notificationStore;
            _settings          = settings.Value;

            _notificationStore.NotificationUpdated += OnNotificationUpdated;
        }
        public SelectScheduleForCourseCommand(NavigationStore navigationStore,
                                              NotificationStore notificationStore,
                                              TimeTableDto timeTableData)
        {
            var groupViewModel = new ScheduleForCourseViewModel(timeTableData);

            _navigationService = new NavigationService <ScheduleForCourseViewModel>(navigationStore, groupViewModel);
        }
Esempio n. 7
0
        public SelectDegreeCommand(NavigationStore navigationStore, ScheduleManager scheduleManager,
                                   TimeTableDto timeTableData, NotificationStore notificationStore)
        {
            var courseViewModel = new CoursesViewModel(scheduleManager, navigationStore, notificationStore);

            courseViewModel.SetTimeTableData(timeTableData);

            _navigationService = new NavigationService <CoursesViewModel>(navigationStore, courseViewModel);
        }
 private void StoreCleanup()
 {
     foreach (var list in NotificationStore)
     {
         if (list.Value.LastUpdate.AddMilliseconds(DELAY_BEFORE_CLEANUP) < DateTime.Now)
         {
             NotificationStore.Remove(list.Key);
         }
     }
 }
Esempio n. 9
0
 public SelectScheduleTypeCommand(NavigationStore navigationStore,
                                  NotificationStore notificationStore,
                                  ScheduleManager scheduleManager,
                                  TimeTableDto timeTableData)
 {
     _navigationStore   = navigationStore;
     _notificationStore = notificationStore;
     _scheduleManager   = scheduleManager;
     _timeTableData     = timeTableData;
 }
Esempio n. 10
0
        public SelectGroupCommand(NavigationStore navigationStore,
                                  NotificationStore notificationStore,
                                  ScheduleManager scheduleManager,
                                  TimeTableDto timeTableData)
        {
            var groupsViewModel = new ScheduleTypeViewModel(scheduleManager, navigationStore, notificationStore);

            groupsViewModel.SetTimeTableData(timeTableData);

            _navigationService = new NavigationService <ScheduleTypeViewModel>(navigationStore, groupsViewModel);
        }
Esempio n. 11
0
        public void Add(string message, NotificationType type)
        {
            HttpCookie notificationClientCookie = HttpContext.Current.Request.Cookies.Get(guidCookieName);
            Guid       clientGuid = new Guid(notificationClientCookie.Value);

            if (!NotificationStore.ContainsKey(clientGuid))
            {
                NotificationStore[clientGuid] = new TimedList <Notification>();
            }

            NotificationStore[clientGuid].Add(new Notification(message, type));
        }
Esempio n. 12
0
        /// <summary>
        /// 指定提供者发布通知
        /// </summary>
        /// <param name="providers">提供者列表</param>
        /// <param name="notificationInfo">通知信息</param>
        /// <returns></returns>
        protected async Task PublishFromProvidersAsync(
            IEnumerable <INotificationPublishProvider> providers,
            IEnumerable <UserIdentifier> users,
            NotificationInfo notificationInfo)
        {
            // 检查是够已订阅消息
            Logger.LogDebug($"Gets a list of user subscriptions {notificationInfo.Name}");
            List <NotificationSubscriptionInfo> userSubscriptions;

            if (users == null)
            {
                // 获取用户订阅列表
                userSubscriptions = await NotificationSubscriptionManager
                                    .GetUserSubscriptionsAsync(notificationInfo.TenantId, notificationInfo.Name);
            }
            else
            {
                // 过滤未订阅的用户
                userSubscriptions = await NotificationSubscriptionManager
                                    .GetUsersSubscriptionsAsync(notificationInfo.TenantId, notificationInfo.Name, users);
            }

            users = userSubscriptions.Select(us => new UserIdentifier(us.UserId, us.UserName));

            if (users.Count() > 0)
            {
                // 持久化用户通知
                Logger.LogDebug($"Persistent user notifications {notificationInfo.Name}");
                await NotificationStore
                .InsertUserNotificationsAsync(
                    notificationInfo,
                    users.Select(u => u.UserId));

                // 2020-11-02 fix bug, 多个发送提供者处于同一个工作单元之下,不能把删除用户订阅写入到单个通知提供者完成事件中
                // 而且为了确保一致性,删除订阅移动到发布通知之前
                if (notificationInfo.Lifetime == NotificationLifetime.OnlyOne)
                {
                    // 一次性通知在发送完成后就取消用户订阅
                    await NotificationStore
                    .DeleteUserSubscriptionAsync(
                        notificationInfo.TenantId,
                        users,
                        notificationInfo.Name);
                }

                // 发布通知
                foreach (var provider in providers)
                {
                    await PublishAsync(provider, notificationInfo, users);
                }
            }
        }
Esempio n. 13
0
        public string GetContent(ClientState state)
        {
            Guid clientGuid = new Guid(state.ClientGuid);

            if (!NotificationStore.ContainsKey(clientGuid))
            {
                return("");
            }

            string result = new JavaScriptSerializer().Serialize(NotificationStore[clientGuid]);

            NotificationStore[clientGuid].Clear();
            return(result);
        }
Esempio n. 14
0
        protected virtual async Task <Guid[]> GetUsersAsync(
            NotificationInfo notificationInfo,
            Guid[] userIds         = null,
            Guid[] excludedUserIds = null)
        {
            List <Guid> distributeUserIds;

            if (!userIds.IsNullOrEmpty())
            {
                //Directly get from UserIds
                distributeUserIds = new List <Guid>(userIds);
            }
            else
            {
                using (CurrentTenant.Change(notificationInfo.TenantId))
                {
                    //Get subscribed users
                    List <NotificationSubscriptionInfo> subscriptions = await NotificationStore.GetSubscriptionsAsync(
                        notificationInfo.NotificationName,
                        notificationInfo.EntityTypeName,
                        notificationInfo.EntityId
                        );

                    //Remove invalid subscriptions
                    foreach (var subscription in subscriptions)
                    {
                        if (
                            !await NotificationDefinitionManager.IsAvailableAsync(notificationInfo.NotificationName, subscription.UserId)
                            )
                        {
                            subscriptions.RemoveAll(s => s.UserId == subscription.UserId);
                        }
                    }

                    //Get user ids
                    distributeUserIds = subscriptions
                                        .Select(s => s.UserId)
                                        .ToList();
                }
            }

            if (!excludedUserIds.IsNullOrEmpty())
            {
                //Exclude specified users.
                distributeUserIds.RemoveAll(uid => excludedUserIds.Any(euid => euid.Equals(uid)));
            }

            return(distributeUserIds.ToArray());
        }
Esempio n. 15
0
 /// <summary>
 /// Drops all tables from the database and updated DB Id
 /// </summary>
 /// <returns>The everything async.</returns>
 public Task DropEverythingAsync()
 {
     Settings.UpdateDatabaseId();
     CategoryStore.DropTable();
     EventStore.DropTable();
     NotificationStore.DropTable();
     SessionStore.DropTable();
     WorkshopStore.DropTable();
     SpeakerStore.DropTable();
     SponsorStore.DropTable();
     FeedbackStore.DropTable();
     FavoriteStore.DropTable();
     ApplicationDataStore.DropTable();
     IsInitialized = false;
     return(Task.FromResult(true));
 }
Esempio n. 16
0
        protected virtual async Task <List <UserNotificationInfo> > SaveUserNotificationsAsync(Guid[] users, NotificationInfo notificationInfo)
        {
            await NotificationStore.InsertNotificationAsync(notificationInfo);

            await UnitOfWorkManager.Current.SaveChangesAsync();

            var userNotifications = new List <UserNotificationInfo>();

            foreach (var user in users)
            {
                var userNotification = new UserNotificationInfo(user, notificationInfo.Id, notificationInfo.TenantId);
                await NotificationStore.InsertUserNotificationAsync(userNotification);

                userNotifications.Add(userNotification);
            }

            return(userNotifications);
        }
Esempio n. 17
0
 public void UpdateNotificationStore(NotificationStore dataModel, IDAL dal)
 {
     //using (IDAL dal = this.DAL)
     //{
     //dal.BeginTransaction();
     try
     {
         IUniParameter prmNotificationId  = dal.CreateParameter("Notification", dataModel.Notification);
         IUniParameter prmStoreId         = dal.CreateParameter("Store", dataModel.Store);
         IUniParameter prmProcessInstance = dal.CreateParameter("ProcessInstance", dataModel.ProcessInstance);
         dal.ExecuteNonQuery("ANN_UPD_NOTIFICATIONSTORE_SP", prmNotificationId, prmStoreId, prmProcessInstance);
         //dal.CommitTransaction();
     }
     catch (Exception e)
     {
         //dal.RollbackTransaction();
         throw;
     }
     //}
 }
Esempio n. 18
0
        public void UpdateRemindingsCountersStart()
        {
            bool isTestFeatureEnabled           = UserConnection.GetIsFeatureEnabled("TestNotificationOnWork");
            bool isNotificationV2FeatureEnabled = UserConnection.GetIsFeatureEnabled("NotificationV2");

            if (isTestFeatureEnabled || isNotificationV2FeatureEnabled)
            {
                return;
            }

            bool isFeatureEnabled = UserConnection.GetIsFeatureEnabled("NotificationsOnOneClassJob");
            var  store            = new NotificationStore();
            var  helper           = new ImplementedNotificationProviderHelper(UserConnection, store);

            if (isFeatureEnabled && !helper.IsUsedProviderNotImplementedNotification())
            {
                return;
            }
            UpdateCountersStart();
        }
Esempio n. 19
0
        public virtual async Task HandleEventAsync(NotificationEventData eventData)
        {
            // 这样做的话就要注意了
            // 当只有一个消费者订阅时,事件总线会认为消息已经处理,从而发布Ack指令,从消息队列中移除此消息
            // 可能造成通知数据丢失
            var application = Options.Application ?? "Abp";

            if (!string.Equals(application, eventData.Application, StringComparison.InvariantCultureIgnoreCase))
            {
                // 不是当前监听应用的消息不做处理
                return;
            }
            // 如果上面过滤了应用程序,这里可以使用Get方法,否则,最好使用GetOrNull加以判断
            var notification = NotificationDefinitionManager.Get(eventData.Name);

            var notificationInfo = new NotificationInfo
            {
                Name         = notification.Name,
                CreationTime = eventData.CreationTime,
                Data         = eventData.Data,
                Severity     = eventData.Severity,
                Lifetime     = notification.NotificationLifetime,
                TenantId     = eventData.TenantId,
                Type         = notification.NotificationType
            };

            notificationInfo.SetId(SnowflakeIdGenerator.Create());

            // TODO: 可以做成一个接口来序列化消息
            notificationInfo.Data = NotificationDataConverter.Convert(notificationInfo.Data);

            Logger.LogDebug($"Persistent notification {notificationInfo.Name}");

            // 持久化通知
            await NotificationStore.InsertNotificationAsync(notificationInfo);

            var providers = Enumerable
                            .Reverse(NotificationPublishProviderManager.Providers);

            await PublishFromProvidersAsync(providers, eventData.Users, notificationInfo);
        }
Esempio n. 20
0
        /// <summary>
        /// 指定提供者发布通知
        /// </summary>
        /// <param name="providers">提供者列表</param>
        /// <param name="notificationInfo">通知信息</param>
        /// <returns></returns>
        protected async Task PublishFromProvidersAsync(IEnumerable <INotificationPublishProvider> providers,
                                                       NotificationInfo notificationInfo)
        {
            Logger.LogDebug($"Persistent notification {notificationInfo.Name}");

            // 持久化通知
            await NotificationStore.InsertNotificationAsync(notificationInfo);

            // TODO: 某些情况下,不能直接在服务内订阅消息,目前只能通过将订阅内容放进消息内部,需要重构通知系统设计了
            if (notificationInfo.Data.HasUserNotification(out Guid userId, out string userName))
            {
                await NotificationSubscriptionManager.SubscribeAsync(notificationInfo.TenantId,
                                                                     new UserIdentifier(userId, userName), notificationInfo.Name);
            }

            Logger.LogDebug($"Gets a list of user subscriptions {notificationInfo.Name}");
            // 获取用户订阅列表
            var userSubscriptions = await NotificationSubscriptionManager.GetSubscriptionsAsync(notificationInfo.TenantId, notificationInfo.Name);

            Logger.LogDebug($"Persistent user notifications {notificationInfo.Name}");
            // 持久化用户通知
            var subscriptionUserIdentifiers = userSubscriptions.Select(us => new UserIdentifier(us.UserId, us.UserName));

            await NotificationStore.InsertUserNotificationsAsync(notificationInfo,
                                                                 subscriptionUserIdentifiers.Select(u => u.UserId));

            // 发布通知
            foreach (var provider in providers)
            {
                await PublishAsync(provider, notificationInfo, subscriptionUserIdentifiers);
            }

            if (notificationInfo.Lifetime == NotificationLifetime.OnlyOne)
            {
                // 一次性通知在发送完成后就取消用户订阅
                await NotificationStore.DeleteAllUserSubscriptionAsync(notificationInfo.TenantId,
                                                                       notificationInfo.Name);
            }
        }
Esempio n. 21
0
        public virtual async Task HandleEventAsync(NotificationEto <NotificationData> eventData)
        {
            // 如果上面过滤了应用程序,这里可以使用Get方法,否则,最好使用GetOrNull加以判断
            var notification = NotificationDefinitionManager.GetOrNull(eventData.Name);

            if (notification == null)
            {
                return;
            }

            var notificationInfo = new NotificationInfo
            {
                Name         = notification.Name,
                CreationTime = eventData.CreationTime,
                Data         = eventData.Data,
                Severity     = eventData.Severity,
                Lifetime     = notification.NotificationLifetime,
                TenantId     = eventData.TenantId,
                Type         = notification.NotificationType
            };

            notificationInfo.SetId(eventData.Id);

            // TODO: 可以做成一个接口来序列化消息
            notificationInfo.Data = NotificationDataConverter.Convert(notificationInfo.Data);

            Logger.LogDebug($"Persistent notification {notificationInfo.Name}");

            // 持久化通知
            await NotificationStore.InsertNotificationAsync(notificationInfo);

            var providers = Enumerable
                            .Reverse(NotificationPublishProviderManager.Providers);

            await PublishFromProvidersAsync(providers, eventData.Users, notificationInfo);
        }
Esempio n. 22
0
 public ScheduleViewModel(ScheduleManager scheduleManager,
                          NotificationStore notificationStore)
 {
     _scheduleManager   = scheduleManager;
     _notificationStore = notificationStore;
 }