Exemple #1
0
        /// <summary>
        /// Insert a topic into the user's combined following topics feed.
        /// This feed consists of topics that a user requests to follow, and topics authored by other users that the specified user is following.
        /// </summary>
        /// <param name="userHandle">User handle</param>
        /// <param name="appHandle">App handle</param>
        /// <param name="topicHandle">Topic handle</param>
        /// <returns>Create following topic task</returns>
        public async Task CreateFollowingTopic(
            string userHandle,
            string appHandle,
            string topicHandle)
        {
            // lookup topic entity
            ITopicEntity topicEntity = await this.topicsStore.QueryTopic(topicHandle);

            // do the insert
            await this.topicsStore.InsertFollowingTopic(StorageConsistencyMode.Strong, userHandle, appHandle, topicHandle, topicEntity.UserHandle);
        }
Exemple #2
0
        /// <summary>
        /// Update topic
        /// </summary>
        /// <param name="storageConsistencyMode">Storage consistency mode</param>
        /// <param name="topicHandle">Topic handle</param>
        /// <param name="topicEntity">Topic entity</param>
        /// <returns>Update topic task</returns>
        public async Task UpdateTopic(
            StorageConsistencyMode storageConsistencyMode,
            string topicHandle,
            ITopicEntity topicEntity)
        {
            CTStore store = await this.tableStoreManager.GetStore(ContainerIdentifier.Topics);

            ObjectTable table     = this.tableStoreManager.GetTable(ContainerIdentifier.Topics, TableIdentifier.TopicsObject) as ObjectTable;
            Operation   operation = Operation.Replace(table, topicHandle, topicHandle, topicEntity as TopicEntity);
            await store.ExecuteOperationAsync(operation, storageConsistencyMode.ToConsistencyMode());
        }
Exemple #3
0
        /// <summary>
        /// Update a topic
        /// </summary>
        /// <param name="processType">Process type</param>
        /// <param name="topicHandle">Topic handle</param>
        /// <param name="title">Topic title</param>
        /// <param name="text">Topic text</param>
        /// <param name="blobType">Blob type</param>
        /// <param name="blobHandle">Blob handle</param>
        /// <param name="categories">Topic categories</param>
        /// <param name="reviewStatus">Review status</param>
        /// <param name="lastUpdatedTime">Last updated time</param>
        /// <param name="topicEntity">Topic entity</param>
        /// <returns>Update topic task</returns>
        public async Task UpdateTopic(
            ProcessType processType,
            string topicHandle,
            string title,
            string text,
            BlobType blobType,
            string blobHandle,
            string categories,
            ReviewStatus reviewStatus,
            DateTime lastUpdatedTime,
            ITopicEntity topicEntity)
        {
            topicEntity.Title           = title;
            topicEntity.Text            = text;
            topicEntity.BlobType        = blobType;
            topicEntity.BlobHandle      = blobHandle;
            topicEntity.Categories      = categories;
            topicEntity.ReviewStatus    = reviewStatus;
            topicEntity.LastUpdatedTime = lastUpdatedTime;

            await this.topicsStore.UpdateTopic(StorageConsistencyMode.Strong, topicHandle, topicEntity);

            await this.searchQueue.SendSearchIndexTopicMessage(topicHandle, lastUpdatedTime);
        }
        /// <summary>
        /// Process message
        /// </summary>
        /// <param name="message">Queue message</param>
        /// <returns>Process message task</returns>
        protected override async Task Process(IMessage message)
        {
            // add a new topic to the search index
            if (message is SearchIndexTopicMessage)
            {
                SearchIndexTopicMessage searchIndexTopicMessage = message as SearchIndexTopicMessage;
                ITopicEntity            topicEntity             = await this.topicsManager.ReadTopic(searchIndexTopicMessage.TopicHandle);

                // the topic may have been deleted before the search index topic message is processed
                if (topicEntity == null)
                {
                    this.Log.LogInformation("Could not find topic " + searchIndexTopicMessage.TopicHandle);
                    return;
                }

                // the topic may have been updated before the search index topic message is processed
                if (topicEntity.LastUpdatedTime > searchIndexTopicMessage.Timestamp)
                {
                    this.Log.LogInformation("Topic " + searchIndexTopicMessage.TopicHandle + " is newer than the queue message.");
                    return;
                }

                await this.searchManager.IndexTopic(
                    searchIndexTopicMessage.TopicHandle,
                    topicEntity.Title,
                    topicEntity.Text,
                    topicEntity.UserHandle,
                    topicEntity.AppHandle,
                    topicEntity.LastUpdatedTime);
            }

            // remove a topic from the search index
            else if (message is SearchRemoveTopicMessage)
            {
                SearchRemoveTopicMessage searchRemoveTopicMessage = message as SearchRemoveTopicMessage;
                await this.searchManager.RemoveTopic(searchRemoveTopicMessage.TopicHandle);
            }

            // add a new user to the search index
            else if (message is SearchIndexUserMessage)
            {
                SearchIndexUserMessage searchIndexUserMessage = message as SearchIndexUserMessage;
                IUserProfileEntity     userProfileEntity      = await this.usersManager.ReadUserProfile(searchIndexUserMessage.UserHandle, searchIndexUserMessage.AppHandle);

                // the user may have been deleted before the search index user message is processed
                if (userProfileEntity == null)
                {
                    this.Log.LogInformation("Could not find user " + searchIndexUserMessage.UserHandle + " for app " + searchIndexUserMessage.AppHandle);
                    return;
                }

                // the user may have been updated before the search index user message is processed
                if (userProfileEntity.LastUpdatedTime > searchIndexUserMessage.Timestamp)
                {
                    this.Log.LogInformation("User " + searchIndexUserMessage.UserHandle + " in app " + searchIndexUserMessage.AppHandle + " is newer than the queue message.");
                    return;
                }

                await this.searchManager.IndexUser(
                    searchIndexUserMessage.UserHandle,
                    userProfileEntity.FirstName,
                    userProfileEntity.LastName,
                    searchIndexUserMessage.AppHandle);
            }

            // remove a user from the search index
            else if (message is SearchRemoveUserMessage)
            {
                SearchRemoveUserMessage searchRemoveUserMessage = message as SearchRemoveUserMessage;
                await this.searchManager.RemoveUser(searchRemoveUserMessage.UserHandle, searchRemoveUserMessage.AppHandle);
            }

            // bad message
            else
            {
                this.Log.LogError("received message of unknown type " + message.ToString());
            }
        }