Ejemplo n.º 1
0
        /// <summary>
        /// Delete popular topic
        /// </summary>
        /// <param name="storageConsistencyMode">Storage consistency mode</param>
        /// <param name="timeRange">Time range</param>
        /// <param name="hostAppHandle">Hosting app handle: Master app or client app</param>
        /// <param name="appHandle">App handle</param>
        /// <param name="topicHandle">Topic handle</param>
        /// <param name="topicUserHandle">User handle</param>
        /// <returns>Delete popular topic task</returns>
        public async Task DeletePopularTopic(
            StorageConsistencyMode storageConsistencyMode,
            TimeRange timeRange,
            string hostAppHandle,
            string appHandle,
            string topicHandle,
            string topicUserHandle)
        {
            TopicRankFeedEntity topicRankFeedEntity = new TopicRankFeedEntity()
            {
                AppHandle   = appHandle,
                TopicHandle = topicHandle,
                UserHandle  = topicUserHandle
            };
            var serializedEntity = StoreSerializers.MinimalTopicRankFeedEntitySerialize(topicRankFeedEntity);

            CTStore store = await this.tableStoreManager.GetStore(ContainerIdentifier.PopularTopics);

            Transaction   transaction = new Transaction();
            RankFeedTable topicsTable = this.tableStoreManager.GetTable(ContainerIdentifier.PopularTopics, TableIdentifier.PopularTopicsFeed) as RankFeedTable;
            string        feedKey     = this.GetPopularTopicsFeedKey(timeRange, hostAppHandle);

            transaction.Add(Operation.DeleteIfExists(topicsTable, ContainerIdentifier.PopularTopics.ToString(), feedKey, serializedEntity));

            if (timeRange != TimeRange.AllTime)
            {
                RankFeedTable expirationsTable = this.tableStoreManager.GetTable(ContainerIdentifier.PopularTopics, TableIdentifier.PopularTopicsExpirationsFeed) as RankFeedTable;
                transaction.Add(Operation.DeleteIfExists(expirationsTable, ContainerIdentifier.PopularTopics.ToString(), feedKey, serializedEntity));
            }

            await store.ExecuteTransactionAsync(transaction, storageConsistencyMode.ToConsistencyMode());
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Delete popular user topic
        /// </summary>
        /// <param name="storageConsistencyMode">Storage consistency mode</param>
        /// <param name="userHandle">User handle</param>
        /// <param name="appHandle">App handle</param>
        /// <param name="topicHandle">Topic handle</param>
        /// <returns>Delete popular user topic task</returns>
        public async Task DeletePopularUserTopic(
            StorageConsistencyMode storageConsistencyMode,
            string userHandle,
            string appHandle,
            string topicHandle)
        {
            TopicRankFeedEntity topicRankFeedEntity = new TopicRankFeedEntity()
            {
                AppHandle   = appHandle,
                TopicHandle = topicHandle,
                UserHandle  = userHandle
            };
            var serializedEntity = StoreSerializers.MinimalTopicRankFeedEntitySerialize(topicRankFeedEntity);

            CTStore store = await this.tableStoreManager.GetStore(ContainerIdentifier.PopularUserTopics);

            RankFeedTable table       = this.tableStoreManager.GetTable(ContainerIdentifier.PopularUserTopics, TableIdentifier.PopularUserTopicsFeed) as RankFeedTable;
            Transaction   transaction = new Transaction();

            transaction.Add(Operation.DeleteIfExists(table, userHandle, appHandle, serializedEntity));
            transaction.Add(Operation.DeleteIfExists(table, userHandle, MasterApp.AppHandle, serializedEntity));
            await store.ExecuteTransactionAsync(transaction, storageConsistencyMode.ToConsistencyMode());
        }
        /// <summary>
        /// Performs partial serialization of a topic rank feed entity.
        /// This routine only serializes the items specific to a topic rank feed entity -- none of the base class
        /// feed entity fields are serialized.
        /// </summary>
        /// <param name="topic">topic rank feed entity to serialize</param>
        /// <returns>a serialized topic rank feed entity</returns>
        public static string MinimalTopicRankFeedEntitySerialize(TopicRankFeedEntity topic)
        {
            if (topic == null)
            {
                return(null);
            }

            if (topic.TopicHandle != null && topic.TopicHandle.Contains(":"))
            {
                throw new InvalidOperationException("Error serialzing " + topic.TopicHandle + " because the topic handle contains the field separator character");
            }

            if (topic.UserHandle != null && topic.UserHandle.Contains(":"))
            {
                throw new InvalidOperationException("Error serialzing " + topic.UserHandle + " because the user handle contains the field separator character");
            }

            if (topic.AppHandle != null && topic.AppHandle.Contains(":"))
            {
                throw new InvalidOperationException("Error serialzing " + topic.AppHandle + " because the app handle contains the field separator character");
            }

            return(topic.TopicHandle + KeySeparator + topic.UserHandle + KeySeparator + topic.AppHandle);
        }
Ejemplo n.º 4
0
        public void TestSerialize()
        {
            // test of MinimalTopicRankFeedEntitySerialize

            // first, check the normal case
            var separator = ":";
            var entity    = new TopicRankFeedEntity()
            {
                TopicHandle = "baz", UserHandle = "bar", AppHandle = "foo"
            };
            var result = StoreSerializers.MinimalTopicRankFeedEntitySerialize(entity);

            Assert.AreEqual("baz" + separator + "bar" + separator + "foo", result);

            // next, try a null input
            result = StoreSerializers.MinimalTopicRankFeedEntitySerialize(null);
            Assert.AreEqual(null, result);

            // next, try null values
            entity = new TopicRankFeedEntity();
            result = StoreSerializers.MinimalTopicRankFeedEntitySerialize(entity);
            Assert.AreEqual(separator + separator, result);

            // next, try inserting a handle with a ":"
            entity = new TopicRankFeedEntity()
            {
                TopicHandle = "ba:z", UserHandle = "bar", AppHandle = "foo"
            };
            try
            {
                result = StoreSerializers.MinimalTopicRankFeedEntitySerialize(entity);
                Assert.Fail("Serialize routine was expected to throw an exception");
            }
            catch (Exception e)
            {
                // check that the operation throws the expected exception
                Assert.AreEqual(e.GetType(), typeof(InvalidOperationException));
            }

            // test of MinimalUserRankFeedEntitySerialize

            // first, test the normal case
            var entity2 = new UserRankFeedEntity()
            {
                UserHandle = "bar", AppHandle = "foo"
            };

            result = StoreSerializers.MinimalUserRankFeedEntitySerialize(entity2);
            Assert.AreEqual("bar" + separator + "foo", result);

            // next, try a null input
            result = StoreSerializers.MinimalUserRankFeedEntitySerialize(null);
            Assert.AreEqual(null, result);

            // next, try null values
            entity2 = new UserRankFeedEntity();
            result  = StoreSerializers.MinimalUserRankFeedEntitySerialize(entity2);
            Assert.AreEqual(separator, result);

            // next, try inserting a handle with a ":"
            entity2 = new UserRankFeedEntity()
            {
                UserHandle = "bar:", AppHandle = "foo"
            };
            try
            {
                result = StoreSerializers.MinimalUserRankFeedEntitySerialize(entity2);
                Assert.Fail("Serialize routine was expected to throw an exception");
            }
            catch (Exception e)
            {
                // check that the operation throws the expected exception
                Assert.AreEqual(e.GetType(), typeof(InvalidOperationException));
            }
        }