public string GetNotificationTopic(NotificationTopic topic)
        {
            string phrase;

            switch (topic)
            {
            case NotificationTopic.BLOG_NAME:
                phrase = "has changed the name of its blog!!";
                break;

            case NotificationTopic.ARTICLE_NAME:
                phrase = "has changed the name of its article";
                break;

            case NotificationTopic.NEW_ARTICLE:
                phrase = "has written a newx article";
                break;

            case NotificationTopic.IMPORTANT_UPDATE:
                phrase = "has achieved something important";
                break;

            case NotificationTopic.ANNIVERSARY:
                phrase = "has its bithday";
                break;

            default:
                throw DbEx.Instance.GetThrowable <UnknownTopicException>();
            }

            return(phrase);
        }
        public void NotifyAllowedAccountOf <T>(T item, NotificationTopic topic) where T : IHaveAccount
        {
            Blog        blog    = Wrapper.Blog.GetBlogOfAccount(item.Account.Id);
            ICollection allowed = Wrapper.Blog.GetAllowedAccounts(blog);

            Account author  = blog.Account;
            string  subject = GetNotificationTopic(topic);

            foreach (Account account in allowed)
            {
                Create(GetNewNotificaion(n =>
                {
                    n.AccountId = account.Id;
                    n.Content   = $"{author.FirstName} {author.LastName} {subject}";
                }));
            }

            TrySave();
        }
示例#3
0
        static void Main()
        {
            AppDomain.CurrentDomain.ProcessExit += CurrentDomain_ProcessExit;


            //TODO: Add security
            var namespaceManager = NamespaceManager.Create();
            var messagingFactory = MessagingFactory.Create();

            //Only uncomment below if you want to delete the subcription and start over
            //namespaceManager.DeleteSubscription(TopicName,SubscriptionName);

            try
            {
                if (!namespaceManager.SubscriptionExists(TopicName, SubscriptionName))
                {
                    //Create a new filter
                    var filter = new SqlFilter(string.Format("{0} = '{1}'", "Type", NotificationMessageType.Important));

                    //Create the subscription (including the filter)
                    namespaceManager.CreateSubscription(TopicName, SubscriptionName, filter);
                }
            }
            catch (MessagingEntityAlreadyExistsException)
            {
                throw new InvalidOperationException(string.Format("Subscription named {0} already exists for topic {1}. Please change the subscription name and try again.", SubscriptionName, TopicName));
            }

            var subscriptionClient = messagingFactory.CreateSubscriptionClient(TopicName, SubscriptionName, ReceiveMode.PeekLock);

            _notifier = new NotificationTopic(TopicName);
            _notifier.StartReceiving(NotificationReceived, subscriptionClient);

            while (true)
            {
                Thread.Sleep(10000);
            }
        }
        static void Main()
        {
            const string topicName = "PushNotificationDemoTopic";

            int msgCnt = 0;

            var notifier = new NotificationTopic(topicName);

            // cleanup
            //tmpNotifier.DeleteTopic(); // only uncomment this if you're running this first and want to reset the topic

            while (true)                            // loop to send messages every 3 seconds
            {
                var msg = "Message #: " + msgCnt++; // uniquely ID each message
                NotificationMessageType type;

                //TODO: make sure to set a reasonable time-to-live
                //Send a message with "Important" type
                type = NotificationMessageType.Important;
                notifier.SendMessage(msg, type, new TimeSpan(1000, 0, 0, 0));

                Console.WriteLine(@"Sent Message - {0}, Type={1}", msg, type);



                msg = "Message #: " + msgCnt++; // uniquely ID each message

                //TODO: make sure to set a reasonable time-to-live
                //Send a message with "Unimportant" type
                type = NotificationMessageType.Unimportant;
                notifier.SendMessage(msg, type, new TimeSpan(1000, 0, 0, 0));

                Console.WriteLine(@"Received Message - {0}, Type={1}", msg, type);


                System.Threading.Thread.Sleep(1000); // sleep for 1 second
            }
        }
示例#5
0
        public Article UpdateArticle(Article changed)
        {
            Article oldest = Util.GetCopyOf(GetArticle(changed, RecordKind.OLDEST));
            Article actual = Util.GetCopyOf(GetArticle(changed, RecordKind.UPTODATE));

            // remove dependencies
            oldest.Shares   = null;
            oldest.Comments = null;
            oldest.Blog     = null;

            // create an archive (of version ++)
            ++oldest.VDepth;
            Create(oldest);
            TrySave();

            UdateArchieve(changed);

            // merge changes with the depth 0
            Reflector.Merge(GetArticle(changed), changed);
            TrySave();

            changed = Util.GetCopyOf(GetArticle(changed, RecordKind.UPTODATE));

            if (!actual.Title.Equals(changed.Title))
            {
                int similarity = new Comparator().SentenceCompare(actual.Title, changed.Title);

                if (similarity <= 50)
                {
                    NotificationTopic topic = NotificationTopic.ARTICLE_NAME;
                    Wrapper
                    .Notificaton
                    .NotifyAllowedAccountOf(changed.Blog, topic);
                }
            }
            return(GetArticle(changed));
        }