/// <summary>
        /// Update notifications status
        /// </summary>
        /// <param name="storageConsistencyMode">Storage consistency mode</param>
        /// <param name="userHandle">User handle</param>
        /// <param name="appHandle">App handle</param>
        /// <param name="readActivityHandle">Read activity handle</param>
        /// <param name="readNotificationsStatusEntity">Read notifications status entity</param>
        /// <returns>Update notifications status task</returns>
        public async Task UpdateNotificationsStatus(
            StorageConsistencyMode storageConsistencyMode,
            string userHandle,
            string appHandle,
            string readActivityHandle,
            INotificationsStatusEntity readNotificationsStatusEntity)
        {
            CTStore store = await this.tableStoreManager.GetStore(ContainerIdentifier.Notifications);

            ObjectTable statusTable = this.tableStoreManager.GetTable(ContainerIdentifier.Notifications, TableIdentifier.NotificationsStatus) as ObjectTable;
            CountTable  countTable  = this.tableStoreManager.GetTable(ContainerIdentifier.Notifications, TableIdentifier.NotificationsCount) as CountTable;

            Transaction transaction = new Transaction();

            if (readNotificationsStatusEntity == null)
            {
                NotificationsStatusEntity notificationsStatusEntity = new NotificationsStatusEntity()
                {
                    ReadActivityHandle = readActivityHandle
                };

                transaction.Add(Operation.Insert(statusTable, userHandle, appHandle, notificationsStatusEntity));
            }
            else
            {
                readNotificationsStatusEntity.ReadActivityHandle = readActivityHandle;
                transaction.Add(Operation.Replace(statusTable, userHandle, appHandle, readNotificationsStatusEntity as NotificationsStatusEntity));
            }

            transaction.Add(Operation.InsertOrReplace(countTable, userHandle, appHandle, 0));
            await store.ExecuteTransactionAsync(transaction, storageConsistencyMode.ToConsistencyMode());
        }
Exemplo n.º 2
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());
        }
Exemplo n.º 3
0
        /// <summary>
        /// Insert 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>Insert user topic task</returns>
        public async Task InsertUserTopic(
            StorageConsistencyMode storageConsistencyMode,
            string userHandle,
            string appHandle,
            string topicHandle)
        {
            TopicFeedEntity topicFeedEntity = new TopicFeedEntity()
            {
                AppHandle   = appHandle,
                TopicHandle = topicHandle,
                UserHandle  = userHandle
            };

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

            FeedTable  feedTable  = this.tableStoreManager.GetTable(ContainerIdentifier.UserTopics, TableIdentifier.UserTopicsFeed) as FeedTable;
            CountTable countTable = this.tableStoreManager.GetTable(ContainerIdentifier.UserTopics, TableIdentifier.UserTopicsCount) as CountTable;

            Transaction transaction = new Transaction();

            transaction.Add(Operation.Insert(feedTable, userHandle, appHandle, topicHandle, topicFeedEntity));
            transaction.Add(Operation.Insert(feedTable, userHandle, MasterApp.AppHandle, topicHandle, topicFeedEntity));
            transaction.Add(Operation.InsertOrIncrement(countTable, userHandle, appHandle));
            transaction.Add(Operation.InsertOrIncrement(countTable, userHandle, MasterApp.AppHandle));
            await store.ExecuteTransactionAsync(transaction, storageConsistencyMode.ToConsistencyMode());
        }
Exemplo n.º 4
0
        /// <summary>
        /// Insert a response from AVERT into the store
        /// </summary>
        /// <param name="storageConsistencyMode">consistency to use</param>
        /// <param name="reportHandle">uniquely identifies this report</param>
        /// <param name="responseTime">when the response was received from AVERT</param>
        /// <param name="responseBody">body of the response from AVERT</param>
        /// <param name="entity">AVERT transaction entity to update</param>
        /// <returns>a task that inserts the response into the store</returns>
        public async Task InsertResponse(
            StorageConsistencyMode storageConsistencyMode,
            string reportHandle,
            DateTime responseTime,
            string responseBody,
            IAVERTTransactionEntity entity)
        {
            // check inputs
            if (string.IsNullOrWhiteSpace(reportHandle))
            {
                throw new ArgumentNullException("reportHandle");
            }

            if (entity == null)
            {
                throw new ArgumentNullException("entity");
            }

            // get the table interface
            CTStore store = await this.tableStoreManager.GetStore(ContainerIdentifier.AVERT);

            ObjectTable lookupTable = this.tableStoreManager.GetTable(ContainerIdentifier.AVERT, TableIdentifier.AVERTLookup) as ObjectTable;

            // update the entity
            entity.ResponseTime = responseTime;
            entity.ResponseBody = responseBody;

            // update it in the store
            await store.ExecuteOperationAsync(Operation.Replace(lookupTable, reportHandle, reportHandle, entity as AVERTTransactionEntity), storageConsistencyMode.ToConsistencyMode());
        }
Exemplo n.º 5
0
        /// <summary>
        /// Insert a new user-generated report of another user into the store
        /// </summary>
        /// <param name="storageConsistencyMode">consistency to use</param>
        /// <param name="reportHandle">uniquely identifies this report</param>
        /// <param name="reportedUserHandle">uniquely identifies the user who is being reported</param>
        /// <param name="reportingUserHandle">uniquely identifies the user doing the reporting</param>
        /// <param name="appHandle">uniquely identifies the app that the user is in</param>
        /// <param name="reason">the complaint against the content</param>
        /// <param name="lastUpdatedTime">when the report was received</param>
        /// <param name="hasComplainedBefore">has the reporting user complained about this user before?</param>
        /// <returns>a task that inserts the report into the store</returns>
        public async Task InsertUserReport(
            StorageConsistencyMode storageConsistencyMode,
            string reportHandle,
            string reportedUserHandle,
            string reportingUserHandle,
            string appHandle,
            ReportReason reason,
            DateTime lastUpdatedTime,
            bool hasComplainedBefore)
        {
            // get all the table interfaces
            CTStore store = await this.tableStoreManager.GetStore(ContainerIdentifier.UserReports);

            ObjectTable lookupTable               = this.tableStoreManager.GetTable(ContainerIdentifier.UserReports, TableIdentifier.UserReportsLookup) as ObjectTable;
            ObjectTable lookupUniquenessTable     = this.tableStoreManager.GetTable(ContainerIdentifier.UserReports, TableIdentifier.UserReportsLookupUniquenessByReportingUser) as ObjectTable;
            FeedTable   feedByAppTable            = this.tableStoreManager.GetTable(ContainerIdentifier.UserReports, TableIdentifier.UserReportsRecentFeedByApp) as FeedTable;
            FeedTable   feedByReportedUserTable   = this.tableStoreManager.GetTable(ContainerIdentifier.UserReports, TableIdentifier.UserReportsRecentFeedByReportedUser) as FeedTable;
            FeedTable   feedByReportingUserTable  = this.tableStoreManager.GetTable(ContainerIdentifier.UserReports, TableIdentifier.UserReportsRecentFeedByReportingUser) as FeedTable;
            CountTable  countByReportedUserTable  = this.tableStoreManager.GetTable(ContainerIdentifier.UserReports, TableIdentifier.UserReportsCountByReportedUser) as CountTable;
            CountTable  countByReportingUserTable = this.tableStoreManager.GetTable(ContainerIdentifier.UserReports, TableIdentifier.UserReportsCountByReportingUser) as CountTable;

            // create the two entities that will be inserted into the tables
            UserReportEntity userReportEntity = new UserReportEntity()
            {
                ReportedUserHandle  = reportedUserHandle,
                ReportingUserHandle = reportingUserHandle,
                AppHandle           = appHandle,
                Reason      = reason,
                CreatedTime = lastUpdatedTime
            };

            UserReportFeedEntity userReportFeedEntity = new UserReportFeedEntity()
            {
                ReportHandle        = reportHandle,
                ReportedUserHandle  = reportedUserHandle,
                ReportingUserHandle = reportingUserHandle,
                AppHandle           = appHandle
            };

            // do the inserts and increments as a transaction
            Transaction transaction = new Transaction();

            // the partition key is app handle for all tables so that a transaction can be achieved
            transaction.Add(Operation.Insert(lookupTable, appHandle, reportHandle, userReportEntity));
            transaction.Add(Operation.Insert(feedByAppTable, appHandle, appHandle, reportHandle, userReportFeedEntity));
            transaction.Add(Operation.Insert(feedByReportedUserTable, appHandle, reportedUserHandle, reportHandle, userReportFeedEntity));
            transaction.Add(Operation.Insert(feedByReportingUserTable, appHandle, reportingUserHandle, reportHandle, userReportFeedEntity));

            // if the reporting user has not previously reported this user, then increment counts
            if (!hasComplainedBefore)
            {
                string uniquenessKey = UniquenessObjectKey(reportedUserHandle, reportingUserHandle);
                transaction.Add(Operation.Insert(lookupUniquenessTable, appHandle, uniquenessKey, new ObjectEntity()));
                transaction.Add(Operation.InsertOrIncrement(countByReportedUserTable, appHandle, reportedUserHandle));
                transaction.Add(Operation.InsertOrIncrement(countByReportingUserTable, appHandle, reportingUserHandle));
            }

            // execute the transaction
            await store.ExecuteTransactionAsync(transaction, storageConsistencyMode.ToConsistencyMode());
        }
Exemplo n.º 6
0
        /// <summary>
        /// Update following relationship.
        /// Following user : someone who i am following.
        /// </summary>
        /// <param name="storageConsistencyMode">Consistency mode</param>
        /// <param name="relationshipHandle">Relationship handle</param>
        /// <param name="userHandle">User handle</param>
        /// <param name="relationshipUserHandle">Relationship user handle</param>
        /// <param name="appHandle">App handle</param>
        /// <param name="userRelationshipStatus">User relationship status</param>
        /// <param name="lastUpdatedTime">Last updated time</param>
        /// <param name="readUserRelationshipLookupEntity">Read user relationship lookup entity</param>
        /// <returns>Update following relationship task</returns>
        public async Task UpdateFollowingRelationship(
            StorageConsistencyMode storageConsistencyMode,
            string relationshipHandle,
            string userHandle,
            string relationshipUserHandle,
            string appHandle,
            UserRelationshipStatus userRelationshipStatus,
            DateTime lastUpdatedTime,
            IUserRelationshipLookupEntity readUserRelationshipLookupEntity)
        {
            CTStore store = await this.tableStoreManager.GetStore(ContainerIdentifier.UserFollowing);

            ObjectTable lookupTable = this.tableStoreManager.GetTable(ContainerIdentifier.UserFollowing, TableIdentifier.FollowingLookup) as ObjectTable;
            FeedTable   feedTable   = this.tableStoreManager.GetTable(ContainerIdentifier.UserFollowing, TableIdentifier.FollowingFeed) as FeedTable;
            CountTable  countTable  = this.tableStoreManager.GetTable(ContainerIdentifier.UserFollowing, TableIdentifier.FollowingCount) as CountTable;

            await this.UpdateUserRelationship(
                storageConsistencyMode,
                relationshipHandle,
                userHandle,
                relationshipUserHandle,
                appHandle,
                userRelationshipStatus,
                lastUpdatedTime,
                readUserRelationshipLookupEntity,
                store,
                lookupTable,
                feedTable,
                countTable);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Insert a new submission to AVERT into the store
        /// </summary>
        /// <param name="storageConsistencyMode">consistency to use</param>
        /// <param name="reportHandle">uniquely identifies this report</param>
        /// <param name="appHandle">uniquely identifies the app that the user is in</param>
        /// <param name="reportType">is the complaint against a user or content?</param>
        /// <param name="requestTime">when the request was submitted to AVERT</param>
        /// <param name="requestBody">body of the request to AVERT</param>
        /// <returns>a task that inserts the submission into the store</returns>
        public async Task InsertSubmission(
            StorageConsistencyMode storageConsistencyMode,
            string reportHandle,
            string appHandle,
            ReportType reportType,
            DateTime requestTime,
            string requestBody)
        {
            // check input
            if (string.IsNullOrWhiteSpace(reportHandle))
            {
                throw new ArgumentNullException("reportHandle");
            }

            // get the table interface
            CTStore store = await this.tableStoreManager.GetStore(ContainerIdentifier.AVERT);

            ObjectTable lookupTable = this.tableStoreManager.GetTable(ContainerIdentifier.AVERT, TableIdentifier.AVERTLookup) as ObjectTable;

            // create the entity that will be inserted into the table
            AVERTTransactionEntity avertTransactionEntity = new AVERTTransactionEntity()
            {
                ReportHandle = reportHandle,
                AppHandle    = appHandle,
                ReportType   = reportType,
                RequestTime  = requestTime,
                RequestBody  = requestBody,
                ResponseTime = TimeUtils.BeginningOfUnixTime,
                ResponseBody = null
            };

            // insert it
            await store.ExecuteOperationAsync(Operation.Insert(lookupTable, reportHandle, reportHandle, avertTransactionEntity), storageConsistencyMode.ToConsistencyMode());
        }
        /// <summary>
        /// Insert push registrations
        /// </summary>
        /// <param name="storageConsistencyMode">Consistency mode</param>
        /// <param name="userHandle">User handle</param>
        /// <param name="appHandle">App handle</param>
        /// <param name="platformType">Platform type</param>
        /// <param name="registrationId">OS registration id</param>
        /// <param name="hubRegistrationId">Hub registration id</param>
        /// <param name="language">Client language</param>
        /// <param name="lastUpdatedTime">Last updated time</param>
        /// <returns>Insert push registration task</returns>
        public async Task InsertPushRegistration(
            StorageConsistencyMode storageConsistencyMode,
            string userHandle,
            string appHandle,
            PlatformType platformType,
            string registrationId,
            string hubRegistrationId,
            string language,
            DateTime lastUpdatedTime)
        {
            PushRegistrationFeedEntity entity = new PushRegistrationFeedEntity()
            {
                UserHandle        = userHandle,
                AppHandle         = appHandle,
                PlatformType      = platformType,
                OSRegistrationId  = registrationId,
                HubRegistrationId = hubRegistrationId,
                Language          = language,
                LastUpdatedTime   = lastUpdatedTime
            };

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

            FeedTable table     = this.tableStoreManager.GetTable(ContainerIdentifier.PushRegistrations, TableIdentifier.PushRegistrationsFeed) as FeedTable;
            Operation operation = Operation.InsertOrReplace(table, userHandle, appHandle, registrationId, entity);
            await store.ExecuteOperationAsync(operation, storageConsistencyMode.ToConsistencyMode());
        }
        /// <summary>
        /// Updates content moderation entity
        /// </summary>
        /// <param name="storageConsistencyMode">consistency to use</param>
        /// <param name="moderationHandle">uniquely identifies this moderation request</param>
        /// <param name="moderationStatus">Moderation status</param>
        /// <param name="entity"><see cref="IModerationEntity"/> to update</param>
        /// <returns>Content moderation entity update task</returns>
        public async Task UpdateModerationStatus(
            StorageConsistencyMode storageConsistencyMode,
            string moderationHandle,
            ModerationStatus moderationStatus,
            IModerationEntity entity)
        {
            if (string.IsNullOrWhiteSpace(moderationHandle))
            {
                throw new ArgumentNullException("moderationHandle");
            }

            if (entity == null)
            {
                throw new ArgumentNullException("entity");
            }

            // get content moderation table
            CTStore store = await this.tableStoreManager.GetStore(ContainerIdentifier.Moderation);

            ObjectTable lookupTable = this.tableStoreManager.GetTable(
                ContainerIdentifier.Moderation,
                TableIdentifier.ModerationObject) as ObjectTable;

            // update the entity
            entity.ModerationStatus = moderationStatus;

            // update it in the store
            var operation = Operation.Replace(lookupTable, entity.AppHandle, moderationHandle, entity as ModerationEntity);
            await store.ExecuteOperationAsync(operation, storageConsistencyMode.ToConsistencyMode());
        }
Exemplo n.º 10
0
        /// <summary>
        /// Insert reply
        /// </summary>
        /// <param name="storageConsistencyMode">Storage consistency mode</param>
        /// <param name="replyHandle">Reply handle</param>
        /// <param name="commentHandle">Comment handle</param>
        /// <param name="topicHandle">Topic handle</param>
        /// <param name="text">Reply text</param>
        /// <param name="language">Reply language</param>
        /// <param name="userHandle">User handle</param>
        /// <param name="createdTime">Created time</param>
        /// <param name="reviewStatus">Review status</param>
        /// <param name="appHandle">App handle</param>
        /// <param name="requestId">Request id associated with the create reply request</param>
        /// <returns>Insert reply task</returns>
        public async Task InsertReply(
            StorageConsistencyMode storageConsistencyMode,
            string replyHandle,
            string commentHandle,
            string topicHandle,
            string text,
            string language,
            string userHandle,
            DateTime createdTime,
            ReviewStatus reviewStatus,
            string appHandle,
            string requestId)
        {
            ReplyEntity replyEntity = new ReplyEntity()
            {
                CommentHandle   = commentHandle,
                TopicHandle     = topicHandle,
                Text            = text,
                Language        = language,
                UserHandle      = userHandle,
                CreatedTime     = createdTime,
                LastUpdatedTime = createdTime,
                AppHandle       = appHandle,
                ReviewStatus    = reviewStatus,
                RequestId       = requestId
            };

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

            ObjectTable table     = this.tableStoreManager.GetTable(ContainerIdentifier.Replies, TableIdentifier.RepliesObject) as ObjectTable;
            Operation   operation = Operation.Insert(table, replyHandle, replyHandle, replyEntity);
            await store.ExecuteOperationAsync(operation, storageConsistencyMode.ToConsistencyMode());
        }
        /// <summary>
        /// Insert following activity
        /// </summary>
        /// <param name="storageConsistencyMode">Storage consistency mode</param>
        /// <param name="userHandle">User handle</param>
        /// <param name="appHandle">App handle</param>
        /// <param name="activityHandle">Activity handle</param>
        /// <param name="activityType">Activity type</param>
        /// <param name="actorUserHandle">Actor user handle</param>
        /// <param name="actedOnUserHandle">Acted on user handle</param>
        /// <param name="actedOnContentType">Acted on content type</param>
        /// <param name="actedOnContentHandle">Acted on content handle</param>
        /// <param name="createdTime">Created time</param>
        /// <returns>Insert activity task</returns>
        public async Task InsertFollowingActivity(
            StorageConsistencyMode storageConsistencyMode,
            string userHandle,
            string appHandle,
            string activityHandle,
            ActivityType activityType,
            string actorUserHandle,
            string actedOnUserHandle,
            ContentType actedOnContentType,
            string actedOnContentHandle,
            DateTime createdTime)
        {
            // Insert an activity into a user's following activities feed
            //
            // PartitionKey: UserHandle
            // FeedKey: AppHandle
            // ItemKey: ActivityHandle (reverse sorted by time). We use LikeHandle, CommentHandle, ReplyHandle, and RelationshipHandle as activity handles
            ActivityFeedEntity activityFeedEntity = new ActivityFeedEntity()
            {
                ActivityHandle       = activityHandle,
                AppHandle            = appHandle,
                ActivityType         = activityType,
                ActorUserHandle      = actorUserHandle,
                ActedOnUserHandle    = actedOnUserHandle,
                ActedOnContentType   = actedOnContentType,
                ActedOnContentHandle = actedOnContentHandle,
                CreatedTime          = createdTime
            };

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

            FeedTable feedTable = this.tableStoreManager.GetTable(ContainerIdentifier.FollowingActivities, TableIdentifier.FollowingActivitiesFeed) as FeedTable;
            Operation operation = Operation.InsertOrReplace(feedTable, userHandle, appHandle, activityHandle, activityFeedEntity);
            await store.ExecuteOperationAsync(operation, storageConsistencyMode.ToConsistencyMode());
        }
        /// <summary>
        /// Update a comment
        /// </summary>
        /// <param name="storageConsistencyMode">Storage consistency mode</param>
        /// <param name="commentHandle">Comment handle</param>
        /// <param name="commentEntity">Comment entity</param>
        /// <returns>Update comment task</returns>
        public async Task UpdateComment(StorageConsistencyMode storageConsistencyMode, string commentHandle, ICommentEntity commentEntity)
        {
            CTStore store = await this.tableStoreManager.GetStore(ContainerIdentifier.Comments);

            ObjectTable table     = this.tableStoreManager.GetTable(ContainerIdentifier.Comments, TableIdentifier.CommentsObject) as ObjectTable;
            Operation   operation = Operation.Replace(table, commentHandle, commentHandle, commentEntity as CommentEntity);
            await store.ExecuteOperationAsync(operation, storageConsistencyMode.ToConsistencyMode());
        }
Exemplo n.º 13
0
        /// <summary>
        /// Delete blob metadata
        /// </summary>
        /// <param name="storageConsistencyMode">Storage consistency mode</param>
        /// <param name="appHandle">App handle</param>
        /// <param name="userHandle">User handle</param>
        /// <param name="blobHandle">Blob handle</param>
        /// <returns>Delete blob metadata task</returns>
        public async Task DeleteBlobMetadata(StorageConsistencyMode storageConsistencyMode, string appHandle, string userHandle, string blobHandle)
        {
            CTStore store = await this.tableStoreManager.GetStore(ContainerIdentifier.Blobs);

            ObjectTable table        = this.tableStoreManager.GetTable(ContainerIdentifier.Blobs, TableIdentifier.BlobsMetadata) as ObjectTable;
            string      partitionKey = this.GetPartitionKey(appHandle, userHandle);
            Operation   operation    = Operation.Delete(table, partitionKey, blobHandle);
            await store.ExecuteOperationAsync(operation, storageConsistencyMode.ToConsistencyMode());
        }
Exemplo n.º 14
0
        /// <summary>
        /// Delete topic
        /// </summary>
        /// <param name="storageConsistencyMode">Storage consistency mode</param>
        /// <param name="topicHandle">Topic handle</param>
        /// <returns>Delete topic task</returns>
        public async Task DeleteTopic(
            StorageConsistencyMode storageConsistencyMode,
            string topicHandle)
        {
            CTStore store = await this.tableStoreManager.GetStore(ContainerIdentifier.Topics);

            ObjectTable table     = this.tableStoreManager.GetTable(ContainerIdentifier.Topics, TableIdentifier.TopicsObject) as ObjectTable;
            Operation   operation = Operation.Delete(table, topicHandle, topicHandle);
            await store.ExecuteOperationAsync(operation, storageConsistencyMode.ToConsistencyMode());
        }
Exemplo n.º 15
0
        /// <summary>
        /// Delete app key index
        /// </summary>
        /// <param name="storageConsistencyMode">Storage consistency mode</param>
        /// <param name="appKey">App key</param>
        /// <returns>Delete app key index task</returns>
        public async Task DeleteAppKeyIndex(
            StorageConsistencyMode storageConsistencyMode,
            string appKey)
        {
            CTStore store = await this.tableStoreManager.GetStore(ContainerIdentifier.AppKeys);

            ObjectTable table     = this.tableStoreManager.GetTable(ContainerIdentifier.AppKeys, TableIdentifier.AppKeysIndex) as ObjectTable;
            Operation   operation = Operation.Delete(table, appKey, appKey);
            await store.ExecuteOperationAsync(operation, storageConsistencyMode.ToConsistencyMode());
        }
        /// <summary>
        /// Delete a CVS transaction
        /// </summary>
        /// <param name="storageConsistencyMode">consistency to use</param>
        /// <param name="moderationHandle">moderation handle</param>
        /// <returns>a task that deletes the CVS transaction</returns>
        public async Task DeleteTransaction(StorageConsistencyMode storageConsistencyMode, string moderationHandle)
        {
            // get the table interface
            CTStore store = await this.tableStoreManager.GetStore(ContainerIdentifier.CVS);

            ObjectTable lookupTable = this.tableStoreManager.GetTable(ContainerIdentifier.CVS, TableIdentifier.CVSLookup) as ObjectTable;

            var operation = Operation.Delete(lookupTable, moderationHandle, moderationHandle);
            await store.ExecuteOperationAsync(operation, storageConsistencyMode.ToConsistencyMode());
        }
Exemplo n.º 17
0
        /// <summary>
        /// Delete all app
        /// </summary>
        /// <param name="storageConsistencyMode">Storage consistency mode</param>
        /// <param name="appHandle">App handle</param>
        /// <returns>Delete all app task</returns>
        public async Task DeleteAllApp(
            StorageConsistencyMode storageConsistencyMode,
            string appHandle)
        {
            CTStore store = await this.tableStoreManager.GetStore(ContainerIdentifier.AllApps);

            FeedTable table     = this.tableStoreManager.GetTable(ContainerIdentifier.AllApps, TableIdentifier.AllAppsFeed) as FeedTable;
            Operation operation = Operation.Delete(table, ContainerIdentifier.AllApps.ToString(), this.tableStoreManager.DefaultFeedKey, appHandle);
            await store.ExecuteOperationAsync(operation, storageConsistencyMode.ToConsistencyMode());
        }
Exemplo n.º 18
0
        /// <summary>
        /// Update validation configuration
        /// </summary>
        /// <param name="storageConsistencyMode">Storage consistency mode</param>
        /// <param name="appHandle">App handle</param>
        /// <param name="validationConfigurationEntity">Validation configuration entity</param>
        /// <returns>Update validation configuration task</returns>
        public async Task UpdateValidationConfiguration(
            StorageConsistencyMode storageConsistencyMode,
            string appHandle,
            IValidationConfigurationEntity validationConfigurationEntity)
        {
            CTStore store = await this.tableStoreManager.GetStore(ContainerIdentifier.Apps);

            ObjectTable table     = this.tableStoreManager.GetTable(ContainerIdentifier.Apps, TableIdentifier.AppValidationConfigurationsObject) as ObjectTable;
            Operation   operation = Operation.Replace(table, appHandle, appHandle, validationConfigurationEntity as ValidationConfigurationEntity);
            await store.ExecuteOperationAsync(operation, storageConsistencyMode.ToConsistencyMode());
        }
Exemplo n.º 19
0
        /// <summary>
        /// Delete client name from ClientNamesFeed in AppKey container
        /// </summary>
        /// <param name="storageConsistencyMode">Storage consistency mode</param>
        /// <param name="appKey">App key</param>
        /// <param name="clientName">Client name</param>
        /// <returns>Delete client name from its feed</returns>
        public async Task DeleteClientName(
            StorageConsistencyMode storageConsistencyMode,
            string appKey,
            string clientName)
        {
            CTStore store = await this.tableStoreManager.GetStore(ContainerIdentifier.AppKeys);

            FeedTable table     = this.tableStoreManager.GetTable(ContainerIdentifier.AppKeys, TableIdentifier.ClientNamesFeed) as FeedTable;
            Operation operation = Operation.Delete(table, appKey, this.tableStoreManager.DefaultFeedKey, clientName);
            await store.ExecuteOperationAsync(operation, storageConsistencyMode.ToConsistencyMode());
        }
Exemplo n.º 20
0
        /// <summary>
        /// Delete linked account
        /// </summary>
        /// <param name="storageConsistencyMode">Storage consistency mode</param>
        /// <param name="userHandle">User handle</param>
        /// <param name="identityProviderType">Identity provider type</param>
        /// <returns>Delete linked account task</returns>
        public async Task DeleteLinkedAccount(
            StorageConsistencyMode storageConsistencyMode,
            string userHandle,
            IdentityProviderType identityProviderType)
        {
            CTStore store = await this.tableStoreManager.GetStore(ContainerIdentifier.Users);

            FeedTable accountsTable = this.tableStoreManager.GetTable(ContainerIdentifier.Users, TableIdentifier.UserLinkedAccountsFeed) as FeedTable;
            Operation operation     = Operation.Delete(accountsTable, userHandle, this.tableStoreManager.DefaultFeedKey, identityProviderType.ToString());
            await store.ExecuteOperationAsync(operation, storageConsistencyMode.ToConsistencyMode());
        }
Exemplo n.º 21
0
        /// <summary>
        /// Update reply
        /// </summary>
        /// <param name="storageConsistencyMode">Storage consistency mode</param>
        /// <param name="replyHandle">Reply handle</param>
        /// <param name="replyEntity">Reply entity</param>
        /// <returns>Update reply task</returns>
        public async Task UpdateReply(
            StorageConsistencyMode storageConsistencyMode,
            string replyHandle,
            IReplyEntity replyEntity)
        {
            CTStore store = await this.tableStoreManager.GetStore(ContainerIdentifier.Replies);

            ObjectTable table     = this.tableStoreManager.GetTable(ContainerIdentifier.Replies, TableIdentifier.RepliesObject) as ObjectTable;
            Operation   operation = Operation.Replace(table, replyHandle, replyHandle, replyEntity as ReplyEntity);
            await store.ExecuteOperationAsync(operation, storageConsistencyMode.ToConsistencyMode());
        }
Exemplo n.º 22
0
        /// <summary>
        /// Updates image review status
        /// </summary>
        /// <param name="storageConsistencyMode">Storage consistency mode</param>
        /// <param name="appHandle">App handle</param>
        /// <param name="userHandle">User handle</param>
        /// <param name="blobHandle">Blob handle</param>
        /// <param name="reviewStatus">Review status</param>
        /// <param name="imageMetadataEntity">Image metadata entity</param>
        /// <returns>Update image review status task</returns>
        public async Task UpdateImageReviewStatus(StorageConsistencyMode storageConsistencyMode, string appHandle, string userHandle, string blobHandle, ReviewStatus reviewStatus, IImageMetadataEntity imageMetadataEntity)
        {
            CTStore store = await this.tableStoreManager.GetStore(ContainerIdentifier.Images);

            ObjectTable table        = this.tableStoreManager.GetTable(ContainerIdentifier.Images, TableIdentifier.ImagesMetadata) as ObjectTable;
            string      partitionKey = this.GetPartitionKey(appHandle, userHandle);

            imageMetadataEntity.ReviewStatus = reviewStatus;

            Operation operation = Operation.Replace(table, partitionKey, blobHandle, imageMetadataEntity as ImageMetadataEntity);
            await store.ExecuteOperationAsync(operation, storageConsistencyMode.ToConsistencyMode());
        }
Exemplo n.º 23
0
        /// <summary>
        /// Delete linked account index
        /// </summary>
        /// <param name="storageConsistencyMode">Storage consistency mode</param>
        /// <param name="identityProviderType">Identity provider type</param>
        /// <param name="accountId">Account id</param>
        /// <returns>Delete linked account index task</returns>
        public async Task DeleteLinkedAccountIndex(
            StorageConsistencyMode storageConsistencyMode,
            IdentityProviderType identityProviderType,
            string accountId)
        {
            CTStore store = await this.tableStoreManager.GetStore(ContainerIdentifier.LinkedAccounts);

            ObjectTable indexTable = this.tableStoreManager.GetTable(ContainerIdentifier.LinkedAccounts, TableIdentifier.LinkedAccountsIndex) as ObjectTable;
            string      key        = this.GetLinkedAccountKey(identityProviderType, accountId);
            Operation   operation  = Operation.Delete(indexTable, key, this.tableStoreManager.DefaultObjectKey);
            await store.ExecuteOperationAsync(operation, storageConsistencyMode.ToConsistencyMode());
        }
Exemplo n.º 24
0
        /// <summary>
        /// Update user
        /// </summary>
        /// <param name="storageConsistencyMode">Storage consistency mode</param>
        /// <param name="userHandle">User handle</param>
        /// <param name="appHandle">App handle</param>
        /// <param name="userProfileEntity">User profile entity</param>
        /// <returns>Update user task</returns>
        public async Task UpdateUserProfile(
            StorageConsistencyMode storageConsistencyMode,
            string userHandle,
            string appHandle,
            IUserProfileEntity userProfileEntity)
        {
            CTStore store = await this.tableStoreManager.GetStore(ContainerIdentifier.Users);

            ObjectTable profilesTable = this.tableStoreManager.GetTable(ContainerIdentifier.Users, TableIdentifier.UserProfilesObject) as ObjectTable;
            Operation   operation     = Operation.Replace(profilesTable, userHandle, appHandle, userProfileEntity as UserProfileEntity);
            await store.ExecuteOperationAsync(operation, storageConsistencyMode.ToConsistencyMode());
        }
        /// <summary>
        /// Delete push registrations
        /// </summary>
        /// <param name="storageConsistencyMode">Consistency mode</param>
        /// <param name="userHandle">User handle</param>
        /// <param name="appHandle">App handle</param>
        /// <param name="registrationId">OS registration id</param>
        /// <returns>Delete push registration task</returns>
        public async Task DeletePushRegistration(
            StorageConsistencyMode storageConsistencyMode,
            string userHandle,
            string appHandle,
            string registrationId)
        {
            CTStore store = await this.tableStoreManager.GetStore(ContainerIdentifier.PushRegistrations);

            FeedTable table     = this.tableStoreManager.GetTable(ContainerIdentifier.PushRegistrations, TableIdentifier.PushRegistrationsFeed) as FeedTable;
            Operation operation = Operation.Delete(table, userHandle, appHandle, registrationId);
            await store.ExecuteOperationAsync(operation, storageConsistencyMode.ToConsistencyMode());
        }
Exemplo n.º 26
0
        /// <summary>
        /// Update push notifications configuration
        /// </summary>
        /// <param name="storageConsistencyMode">Storage consistency mode</param>
        /// <param name="appHandle">App handle</param>
        /// <param name="platformType">Platform type</param>
        /// <param name="pushNotificationsConfigurationEntity">Push notifications configuration entity</param>
        /// <returns>Update push notifications configuration task</returns>
        public async Task UpdatePushNotificationsConfiguration(
            StorageConsistencyMode storageConsistencyMode,
            string appHandle,
            PlatformType platformType,
            IPushNotificationsConfigurationEntity pushNotificationsConfigurationEntity)
        {
            CTStore store = await this.tableStoreManager.GetStore(ContainerIdentifier.Apps);

            ObjectTable table     = this.tableStoreManager.GetTable(ContainerIdentifier.Apps, TableIdentifier.AppPushNotificationsConfigurationsObject) as ObjectTable;
            Operation   operation = Operation.Replace(table, appHandle, platformType.ToString(), pushNotificationsConfigurationEntity as PushNotificationsConfigurationEntity);
            await store.ExecuteOperationAsync(operation, storageConsistencyMode.ToConsistencyMode());
        }
Exemplo n.º 27
0
        /// <summary>
        /// Delete user from table of app administrators
        /// </summary>
        /// <param name="storageConsistencyMode">Storage consistency mode</param>
        /// <param name="appHandle">App handle</param>
        /// <param name="userHandle">User handle</param>
        /// <returns>Delete app administrator task</returns>
        public async Task DeleteAdminUser(
            StorageConsistencyMode storageConsistencyMode,
            string appHandle,
            string userHandle)
        {
            CTStore store = await this.tableStoreManager.GetStore(ContainerIdentifier.AppAdmins);

            ObjectTable table     = this.tableStoreManager.GetTable(ContainerIdentifier.AppAdmins, TableIdentifier.AppAdminsObject) as ObjectTable;
            var         objectKey = this.GetAppAdminObjectKey(appHandle, userHandle);
            Operation   operation = Operation.Delete(table, appHandle, objectKey);
            await store.ExecuteOperationAsync(operation, storageConsistencyMode.ToConsistencyMode());
        }
Exemplo n.º 28
0
        /// <summary>
        /// Delete client config
        /// </summary>
        /// <param name="storageConsistencyMode">Storage consistency mode</param>
        /// <param name="developerId">Developer id</param>
        /// <param name="clientName">Client name</param>
        /// <returns>Delete client config task</returns>
        public async Task DeleteClientConfig(
            StorageConsistencyMode storageConsistencyMode,
            string developerId,
            string clientName)
        {
            CTStore store = await this.tableStoreManager.GetStore(ContainerIdentifier.ClientConfigs);

            ObjectTable clientConfigsTable = this.tableStoreManager.GetTable(ContainerIdentifier.ClientConfigs, TableIdentifier.ClientConfigsObject) as ObjectTable;
            var         objectKey          = this.GetClientConfigsObjectKey(developerId, clientName);
            Operation   operation          = Operation.Delete(clientConfigsTable, objectKey, objectKey);
            await store.ExecuteOperationAsync(operation, storageConsistencyMode.ToConsistencyMode());
        }
Exemplo n.º 29
0
        /// <summary>
        /// Update identity provider credentials
        /// </summary>
        /// <param name="storageConsistencyMode">Storage consistency mode</param>
        /// <param name="appHandle">App handle</param>
        /// <param name="identityProviderType">Identity provider type</param>
        /// <param name="identityProviderCredentialsEntity">Identity provider credentials entity</param>
        /// <returns>Update identity provider credentials task</returns>
        public async Task UpdateIdentityProviderCredentials(
            StorageConsistencyMode storageConsistencyMode,
            string appHandle,
            IdentityProviderType identityProviderType,
            IIdentityProviderCredentialsEntity identityProviderCredentialsEntity)
        {
            CTStore store = await this.tableStoreManager.GetStore(ContainerIdentifier.Apps);

            ObjectTable table     = this.tableStoreManager.GetTable(ContainerIdentifier.Apps, TableIdentifier.AppIdentityProviderCredentialsObject) as ObjectTable;
            Operation   operation = Operation.Replace(table, appHandle, identityProviderType.ToString(), identityProviderCredentialsEntity as IdentityProviderCredentialsEntity);
            await store.ExecuteOperationAsync(operation, storageConsistencyMode.ToConsistencyMode());
        }
        /// <summary>
        /// Insert notification
        /// </summary>
        /// <param name="storageConsistencyMode">Storage consistency mode</param>
        /// <param name="userHandle">User handle</param>
        /// <param name="appHandle">App handle</param>
        /// <param name="activityHandle">Activity handle</param>
        /// <param name="activityType">Activity type</param>
        /// <param name="actorUserHandle">Actor user handle</param>
        /// <param name="actedOnUserHandle">Acted on user handle</param>
        /// <param name="actedOnContentType">Acted on content type</param>
        /// <param name="actedOnContentHandle">Acted on content handle</param>
        /// <param name="createdTime">Created time</param>
        /// <returns>Insert notification task</returns>
        public async Task InsertNotification(
            StorageConsistencyMode storageConsistencyMode,
            string userHandle,
            string appHandle,
            string activityHandle,
            ActivityType activityType,
            string actorUserHandle,
            string actedOnUserHandle,
            ContentType actedOnContentType,
            string actedOnContentHandle,
            DateTime createdTime)
        {
            ActivityFeedEntity activityFeedEntity = new ActivityFeedEntity()
            {
                ActivityHandle       = activityHandle,
                AppHandle            = appHandle,
                ActivityType         = activityType,
                ActorUserHandle      = actorUserHandle,
                ActedOnUserHandle    = actedOnUserHandle,
                ActedOnContentType   = actedOnContentType,
                ActedOnContentHandle = actedOnContentHandle,
                CreatedTime          = createdTime
            };

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

            FeedTable  feedTable  = this.tableStoreManager.GetTable(ContainerIdentifier.Notifications, TableIdentifier.NotificationsFeed) as FeedTable;
            CountTable countTable = this.tableStoreManager.GetTable(ContainerIdentifier.Notifications, TableIdentifier.NotificationsCount) as CountTable;

            // do an insert & increment in a transaction.
            // if a queue message for inserting a notification gets processed twice, then this transaction will generate
            // a storage exception on the second attempt (because the insert will fail with a conflict (409) http status)
            try
            {
                Transaction transaction = new Transaction();
                transaction.Add(Operation.Insert(feedTable, userHandle, appHandle, activityHandle, activityFeedEntity));
                transaction.Add(Operation.InsertOrIncrement(countTable, userHandle, appHandle));
                await store.ExecuteTransactionAsync(transaction, storageConsistencyMode.ToConsistencyMode());
            }
            catch (StorageException e)
            {
                // ignore this exception only if item exists (error code 409 conflict)
                if (e.RequestInformation.HttpStatusCode == (int)HttpStatusCode.Conflict)
                {
                    this.log.LogInformation("NotificationsStore.InsertNotification received a conflict on insert" + e.Message);
                }
                else
                {
                    throw e;
                }
            }
        }