/// <summary>
        /// Performs partial serialization of a user rank feed entity.
        /// This routine only serializes the items specific to a user rank feed entity -- none of the base class
        /// feed entity fields are serialized.
        /// </summary>
        /// <param name="user">user rank feed entity to serialize</param>
        /// <returns>a serialized user rank feed entity</returns>
        public static string MinimalUserRankFeedEntitySerialize(UserRankFeedEntity user)
        {
            if (user == null)
            {
                return(null);
            }

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

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

            return(user.UserHandle + KeySeparator + user.AppHandle);
        }
Example #2
0
        /// <summary>
        /// Delete popular user
        /// </summary>
        /// <param name="storageConsistencyMode">Storage consistency mode</param>
        /// <param name="userHandle">User handle</param>
        /// <param name="appHandle">App handle</param>
        /// <returns>Delete popular user topic task</returns>
        public async Task DeletePopularUser(
            StorageConsistencyMode storageConsistencyMode,
            string userHandle,
            string appHandle)
        {
            UserRankFeedEntity userRankFeedEntity = new UserRankFeedEntity()
            {
                AppHandle  = appHandle,
                UserHandle = userHandle
            };
            var serializedEntity = StoreSerializers.MinimalUserRankFeedEntitySerialize(userRankFeedEntity);

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

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

            transaction.Add(Operation.DeleteIfExists(table, ContainerIdentifier.PopularUsers.ToString(), appHandle, serializedEntity));
            transaction.Add(Operation.DeleteIfExists(table, ContainerIdentifier.PopularUsers.ToString(), MasterApp.AppHandle, serializedEntity));
            await store.ExecuteTransactionAsync(transaction, storageConsistencyMode.ToConsistencyMode());
        }
Example #3
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));
            }
        }