/// <summary> /// Has the reporting user already complained about this user? /// </summary> /// <param name="appHandle">uniquely identifies the app that the users are in</param> /// <param name="reportedUserHandle">uniquely identifies the user who is being reported</param> /// <param name="reportingUserHandle">uniquely identifies the user doing the reporting</param> /// <returns>true if this user has previously complained about this user</returns> public async Task <bool> HasReportingUserReportedUserBefore(string appHandle, string reportedUserHandle, string reportingUserHandle) { // check the inputs if (string.IsNullOrWhiteSpace(appHandle)) { throw new ArgumentNullException("appHandle"); } else if (string.IsNullOrWhiteSpace(reportedUserHandle)) { throw new ArgumentNullException("reportedUserHandle"); } else if (string.IsNullOrWhiteSpace(reportingUserHandle)) { throw new ArgumentNullException("reportingUserHandle"); } // get the table interface CTStore store = await this.tableStoreManager.GetStore(ContainerIdentifier.UserReports); ObjectTable lookupUniquenessTable = this.tableStoreManager.GetTable(ContainerIdentifier.UserReports, TableIdentifier.UserReportsLookupUniquenessByReportingUser) as ObjectTable; // check if the reporting user has previously reported this user string uniquenessKey = UniquenessObjectKey(reportedUserHandle, reportingUserHandle); ObjectEntity uniquenessObject = await store.QueryObjectAsync <ObjectEntity>(lookupUniquenessTable, appHandle, uniquenessKey); if (uniquenessObject == null) { return(false); } return(true); }
/// <summary> /// Upgrade the store version number in persistent redis /// </summary> /// <param name="ctStoreMananger">ctstore manager</param> /// <param name="persistentCacheConnectionString">connection string for persistent cache</param> /// <returns>true if upgrade is successful</returns> private static async Task <bool> UpgradeStoreVersionRedis(CTStoreManager ctStoreMananger, string persistentCacheConnectionString) { RedisCache redisCachePersistent = new RedisCache(persistentCacheConnectionString); CTStore persistentCacheStore = new CTStore(null, redisCachePersistent); ObjectTable versionTable = Table.GetObjectTable( ContainerIdentifier.ServiceConfig.ToString(), ctStoreMananger.ServiceConfigContainerInitials, ctStoreMananger.StoreVersionTableName, ctStoreMananger.StoreVersionTableInitials, StorageMode.CacheOnly); var persistentCacheVersion = await persistentCacheStore.QueryObjectAsync <StoreVersionEntity>(versionTable, ctStoreMananger.StoreVersionKey, ctStoreMananger.StoreVersionKey); // if version in store does not match oldVersion, then refuse to upgrade if (persistentCacheVersion.Version != oldVersion) { Console.WriteLine("Version mismatch in persistent Redis: original version in store is {0}", persistentCacheVersion.Version); return(false); } persistentCacheVersion.Version = newVersion; var operation = Operation.Replace(versionTable, ctStoreMananger.StoreVersionKey, ctStoreMananger.StoreVersionKey, persistentCacheVersion); // perform the insert operation on persistent redis await persistentCacheStore.ExecuteOperationAsync(operation, ConsistencyMode.Strong); return(true); }
/// <summary> /// Query app key index /// </summary> /// <param name="appKey">App key</param> /// <returns>App lookup entity</returns> public async Task <IAppLookupEntity> QueryAppKeyIndex(string appKey) { CTStore store = await this.tableStoreManager.GetStore(ContainerIdentifier.AppKeys); ObjectTable table = this.tableStoreManager.GetTable(ContainerIdentifier.AppKeys, TableIdentifier.AppKeysIndex) as ObjectTable; return(await store.QueryObjectAsync <AppLookupEntity>(table, appKey, appKey)); }
/// <summary> /// Query pin /// </summary> /// <param name="userHandle">User handle</param> /// <param name="topicHandle">Topic handle</param> /// <returns>Pin lookup entity</returns> public async Task <IPinLookupEntity> QueryPin(string userHandle, string topicHandle) { CTStore store = await this.tableStoreManager.GetStore(ContainerIdentifier.Pins); ObjectTable lookupTable = this.tableStoreManager.GetTable(ContainerIdentifier.Pins, TableIdentifier.PinsLookup) as ObjectTable; return(await store.QueryObjectAsync <PinLookupEntity>(lookupTable, userHandle, topicHandle)); }
/// <summary> /// Query like /// </summary> /// <param name="contentHandle">Content handle</param> /// <param name="userHandle">User handle</param> /// <returns>Like lookup entity</returns> public async Task <ILikeLookupEntity> QueryLike(string contentHandle, string userHandle) { CTStore store = await this.tableStoreManager.GetStore(ContainerIdentifier.Likes); ObjectTable lookupTable = this.tableStoreManager.GetTable(ContainerIdentifier.Likes, TableIdentifier.LikesLookup) as ObjectTable; return(await store.QueryObjectAsync <LikeLookupEntity>(lookupTable, contentHandle, userHandle)); }
/// <summary> /// Query client config /// </summary> /// <param name="developerId">Developer id</param> /// <param name="clientName">Client name</param> /// <returns>Client config entity</returns> public async Task <IClientConfigEntity> QueryClientConfig(string developerId, string clientName) { CTStore store = await this.tableStoreManager.GetStore(ContainerIdentifier.ClientConfigs); ObjectTable clientNameTable = this.tableStoreManager.GetTable(ContainerIdentifier.ClientConfigs, TableIdentifier.ClientConfigsObject) as ObjectTable; var objectKey = this.GetClientConfigsObjectKey(developerId, clientName); return(await store.QueryObjectAsync <ClientConfigEntity>(clientNameTable, objectKey, objectKey)); }
/// <summary> /// Query validation configuration /// </summary> /// <param name="appHandle">App handle</param> /// <returns>Validation configuration entity</returns> public async Task <IValidationConfigurationEntity> QueryValidationConfiguration(string appHandle) { CTStore store = await this.tableStoreManager.GetStore(ContainerIdentifier.Apps); ObjectTable table = this.tableStoreManager.GetTable(ContainerIdentifier.Apps, TableIdentifier.AppValidationConfigurationsObject) as ObjectTable; ValidationConfigurationEntity validationConfigurationEntity = await store.QueryObjectAsync <ValidationConfigurationEntity>(table, appHandle, appHandle); return(validationConfigurationEntity); }
/// <summary> /// Query to determine if a user is an app administrator /// </summary> /// <param name="appHandle">App handle</param> /// <param name="userHandle">User handle</param> /// <returns>App administrator entity</returns> public async Task <IAppAdminEntity> QueryAdminUser(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); return(await store.QueryObjectAsync <AppAdminEntity>(table, appHandle, objectKey)); }
/// <summary> /// Query app profile /// </summary> /// <param name="appHandle">App handle</param> /// <returns>App profile entity</returns> public async Task <IAppProfileEntity> QueryAppProfile(string appHandle) { CTStore store = await this.tableStoreManager.GetStore(ContainerIdentifier.Apps); ObjectTable table = this.tableStoreManager.GetTable(ContainerIdentifier.Apps, TableIdentifier.AppProfilesObject) as ObjectTable; AppProfileEntity appProfileEntity = await store.QueryObjectAsync <AppProfileEntity>(table, appHandle, appHandle); return(appProfileEntity); }
/// <summary> /// Query notifications status /// </summary> /// <param name="userHandle">User handle</param> /// <param name="appHandle">App handle</param> /// <returns>Notifications status entity</returns> public async Task <INotificationsStatusEntity> QueryNotificationsStatus(string userHandle, string appHandle) { CTStore store = await this.tableStoreManager.GetStore(ContainerIdentifier.Notifications); ObjectTable table = this.tableStoreManager.GetTable(ContainerIdentifier.Notifications, TableIdentifier.NotificationsStatus) as ObjectTable; NotificationsStatusEntity notificationsStatusEntity = await store.QueryObjectAsync <NotificationsStatusEntity>(table, userHandle, appHandle); return(notificationsStatusEntity); }
/// <summary> /// Query topic /// </summary> /// <param name="topicHandle">Topic handle</param> /// <returns>Topic entity</returns> public async Task <ITopicEntity> QueryTopic(string topicHandle) { CTStore store = await this.tableStoreManager.GetStore(ContainerIdentifier.Topics); ObjectTable table = this.tableStoreManager.GetTable(ContainerIdentifier.Topics, TableIdentifier.TopicsObject) as ObjectTable; TopicEntity topicEntity = await store.QueryObjectAsync <TopicEntity>(table, topicHandle, topicHandle); return(topicEntity); }
/// <summary> /// Query user /// </summary> /// <param name="userHandle">User handle</param> /// <param name="appHandle">App handle</param> /// <returns>User profile entity</returns> public async Task <IUserProfileEntity> QueryUserProfile(string userHandle, string appHandle) { CTStore store = await this.tableStoreManager.GetStore(ContainerIdentifier.Users); ObjectTable profilesTable = this.tableStoreManager.GetTable(ContainerIdentifier.Users, TableIdentifier.UserProfilesObject) as ObjectTable; UserProfileEntity userProfileEntity = await store.QueryObjectAsync <UserProfileEntity>(profilesTable, userHandle, appHandle); return(userProfileEntity); }
/// <summary> /// Query reply /// </summary> /// <param name="replyHandle">Reply handle</param> /// <returns>Reply entity</returns> public async Task <IReplyEntity> QueryReply(string replyHandle) { CTStore store = await this.tableStoreManager.GetStore(ContainerIdentifier.Replies); ObjectTable table = this.tableStoreManager.GetTable(ContainerIdentifier.Replies, TableIdentifier.RepliesObject) as ObjectTable; ReplyEntity replyEntity = await store.QueryObjectAsync <ReplyEntity>(table, replyHandle, replyHandle); return(replyEntity); }
/// <summary> /// Query comment /// </summary> /// <param name="commentHandle">Comment handle</param> /// <returns>Comment entity</returns> public async Task <ICommentEntity> QueryComment(string commentHandle) { CTStore store = await this.tableStoreManager.GetStore(ContainerIdentifier.Comments); ObjectTable table = this.tableStoreManager.GetTable(ContainerIdentifier.Comments, TableIdentifier.CommentsObject) as ObjectTable; CommentEntity commentEntity = await store.QueryObjectAsync <CommentEntity>(table, commentHandle, commentHandle); return(commentEntity); }
/// <summary> /// Query topic name /// </summary> /// <param name="appHandle">App handle</param> /// <param name="topicName">Topic name</param> /// <returns>Query topic name task</returns> public async Task <ITopicNameEntity> QueryTopicName(string appHandle, string topicName) { CTStore store = await this.tableStoreManager.GetStore(ContainerIdentifier.TopicNames); ObjectTable table = this.tableStoreManager.GetTable(ContainerIdentifier.TopicNames, TableIdentifier.TopicNamesObject) as ObjectTable; string objectKey = this.GetTopicNameObjectKey(appHandle, topicName); TopicNameEntity topicNameEntity = await store.QueryObjectAsync <TopicNameEntity>(table, objectKey, objectKey); return(topicNameEntity); }
/// <summary> /// Look up a particular user report /// </summary> /// <param name="appHandle">uniquely identifies the app that the user is in</param> /// <param name="reportHandle">uniquely identifies the report</param> /// <returns>a task that returns the user report</returns> public async Task <IUserReportEntity> QueryUserReport(string appHandle, string reportHandle) { // get the table interface CTStore store = await this.tableStoreManager.GetStore(ContainerIdentifier.UserReports); ObjectTable lookupTable = this.tableStoreManager.GetTable(ContainerIdentifier.UserReports, TableIdentifier.UserReportsLookup) as ObjectTable; // do the lookup & return it return(await store.QueryObjectAsync <UserReportEntity>(lookupTable, appHandle, reportHandle)); }
/// <summary> /// Query blob metadata /// </summary> /// <param name="appHandle">App handle</param> /// <param name="userHandle">User handle</param> /// <param name="blobHandle">Blob handle</param> /// <returns>Blob metadata entity</returns> public async Task <IBlobMetadataEntity> QueryBlobMetadata(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); BlobMetadataEntity blobMetadataEntity = await store.QueryObjectAsync <BlobMetadataEntity>(table, partitionKey, blobHandle); return(blobMetadataEntity); }
/// <summary> /// Query linked account index /// </summary> /// <param name="identityProviderType">Identity provider type</param> /// <param name="accountId">Account id</param> /// <returns>User lookup entity</returns> public async Task <IUserLookupEntity> QueryLinkedAccountIndex( 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); return(await store.QueryObjectAsync <UserLookupEntity>(indexTable, key, this.tableStoreManager.DefaultObjectKey)); }
/// <summary> /// Query topic follower relationship /// Follower user : someone who follows the topic. /// </summary> /// <param name="topicHandle">Topic handle</param> /// <param name="relationshipUserHandle">Relationship user handle</param> /// <param name="appHandle">App handle</param> /// <returns>User relationship lookup entity</returns> public async Task <ITopicRelationshipLookupEntity> QueryTopicFollowerRelationship( string topicHandle, string relationshipUserHandle, string appHandle) { CTStore store = await this.tableStoreManager.GetStore(ContainerIdentifier.TopicFollowers); ObjectTable lookupTable = this.tableStoreManager.GetTable(ContainerIdentifier.TopicFollowers, TableIdentifier.TopicFollowersLookup) as ObjectTable; string objectKey = this.GetObjectKey(appHandle, relationshipUserHandle); return(await store.QueryObjectAsync <TopicRelationshipLookupEntity>(lookupTable, topicHandle, objectKey)); }
/// <summary> /// Query following relationship. /// Following user : someone who i am following. /// </summary> /// <param name="userHandle">User handle</param> /// <param name="relationshipUserHandle">Relationship handle</param> /// <param name="appHandle">App handle</param> /// <returns>User relationship lookup entity</returns> public async Task <IUserRelationshipLookupEntity> QueryFollowingRelationship( string userHandle, string relationshipUserHandle, string appHandle) { CTStore store = await this.tableStoreManager.GetStore(ContainerIdentifier.UserFollowing); ObjectTable lookupTable = this.tableStoreManager.GetTable(ContainerIdentifier.UserFollowing, TableIdentifier.FollowingLookup) as ObjectTable; string objectKey = this.GetObjectKey(appHandle, relationshipUserHandle); return(await store.QueryObjectAsync <UserRelationshipLookupEntity>(lookupTable, userHandle, objectKey)); }
/// <summary> /// Look up a particular AVERT transaction /// </summary> /// <param name="reportHandle">uniquely identifies this report</param> /// <returns>a task that returns the AVERT transaction</returns> public async Task <IAVERTTransactionEntity> QueryTransaction(string reportHandle) { // 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; // do the lookup & return it return(await store.QueryObjectAsync <AVERTTransactionEntity>(lookupTable, reportHandle, reportHandle)); }
/// <summary> /// Initialization routine performs a version check for each storage component: the table store, persistent redis, and volatile redis. /// Fails if the version numbers don't match for any of the stores. /// </summary> /// <returns>true if the version checks pass</returns> public async Task <bool> Initialize() { string azureStorageConnectionString = await this.connectionStringProvider.GetTablesAzureStorageConnectionString(AzureStorageInstanceType.Default); AzureTableStorage azureTableStorage = new AzureTableStorage(azureStorageConnectionString); string redisConnectionStringPersistent = await this.connectionStringProvider.GetRedisConnectionString(RedisInstanceType.Persistent); RedisCache redisCachePersistent = new RedisCache(redisConnectionStringPersistent); CTStore tableStore = new CTStore(azureTableStorage, null); CTStore persistentCacheStore = new CTStore(null, redisCachePersistent); ObjectTable versionTable = Table.GetObjectTable( ContainerIdentifier.ServiceConfig.ToString(), this.ServiceConfigContainerInitials, this.StoreVersionTableName, this.StoreVersionTableInitials, StorageMode.PersistentOnly); var tableVersion = await tableStore.QueryObjectAsync <StoreVersionEntity>(versionTable, this.StoreVersionKey, this.StoreVersionKey); // if version table was not found or the version number is not current, return false indicating checks don't pass if (tableVersion == null || tableVersion.Version != this.StoreVersionString) { return(false); } versionTable = Table.GetObjectTable( ContainerIdentifier.ServiceConfig.ToString(), this.ServiceConfigContainerInitials, this.StoreVersionTableName, this.StoreVersionTableInitials, StorageMode.CacheOnly); var persistentCacheVersion = await persistentCacheStore.QueryObjectAsync <StoreVersionEntity>(versionTable, this.StoreVersionKey, this.StoreVersionKey); // check version for persistent redis cache if (persistentCacheVersion.Version != this.StoreVersionString) { return(false); } this.initialized = true; return(true); }
/// <summary> /// Look up a particular moderation entity /// </summary> /// <param name="appHandle">uniquely identifies the app that the content came from</param> /// <param name="moderationHandle">uniquely identifies this moderation request</param> /// <returns>a task that returns the content report</returns> public async Task <IModerationEntity> QueryModeration(string appHandle, string moderationHandle) { if (string.IsNullOrWhiteSpace(appHandle)) { throw new ArgumentNullException("appHandle"); } if (string.IsNullOrWhiteSpace(moderationHandle)) { throw new ArgumentNullException("moderationHandle"); } // get content moderation table CTStore store = await this.tableStoreManager.GetStore(ContainerIdentifier.Moderation); ObjectTable lookupTable = this.tableStoreManager.GetTable( ContainerIdentifier.Moderation, TableIdentifier.ModerationObject) as ObjectTable; // do the lookup & return it return(await store.QueryObjectAsync <ModerationEntity>(lookupTable, appHandle, moderationHandle)); }
/// <summary> /// Query push notifications configuration /// </summary> /// <param name="appHandle">App handle</param> /// <param name="platformType">Platform type</param> /// <returns>Validation configuration entity</returns> public async Task <IPushNotificationsConfigurationEntity> QueryPushNotificationsConfiguration(string appHandle, PlatformType platformType) { CTStore store = await this.tableStoreManager.GetStore(ContainerIdentifier.Apps); ObjectTable table = this.tableStoreManager.GetTable(ContainerIdentifier.Apps, TableIdentifier.AppPushNotificationsConfigurationsObject) as ObjectTable; PushNotificationsConfigurationEntity pushNotificationsConfigurationEntity = await store.QueryObjectAsync <PushNotificationsConfigurationEntity>(table, appHandle, platformType.ToString()); return(pushNotificationsConfigurationEntity); }
/// <summary> /// Query identity provider credentials for an app /// </summary> /// <param name="appHandle">App handle</param> /// <param name="identityProviderType">Identity provider type</param> /// <returns>Identity provider credentials entity</returns> public async Task <IIdentityProviderCredentialsEntity> QueryIdentityProviderCredentials( string appHandle, IdentityProviderType identityProviderType) { CTStore store = await this.tableStoreManager.GetStore(ContainerIdentifier.Apps); ObjectTable table = this.tableStoreManager.GetTable(ContainerIdentifier.Apps, TableIdentifier.AppIdentityProviderCredentialsObject) as ObjectTable; IdentityProviderCredentialsEntity identityProviderCredentialsEntity = await store.QueryObjectAsync <IdentityProviderCredentialsEntity>(table, appHandle, identityProviderType.ToString()); return(identityProviderCredentialsEntity); }