public async Task <bool> SavePage([FromBody] ConnectorEntity page, [FromUri] string jobId, [FromUri] string tenantId) { Expression <Func <PageJobEntity, bool> > filter = (entity => entity.RowKey == $"{jobId}"); PageJobMappingTable = azureTableProviderInstance.GetAzureTableReference(Settings.PageJobMappingTableName); List <PageJobEntity> pageJobEntityList = await azureTableProviderInstance.QueryEntitiesAsync <PageJobEntity>(PageJobMappingTable, filter); PageJobEntity pageJobEntity = pageJobEntityList?[0]; Trace.TraceInformation("Job Setup complete page succesfully saved for jobId: {0}", jobId); try { Trace.TraceInformation("Job with JobId: {0} subscribing to webhook", jobId); bool subscribed = await sourceProvider.Subscribe(pageJobEntity.SourceInfo); Trace.TraceInformation("Job with JobId: {0} successfully subscribed to webhook", jobId); } catch (Exception e) { Trace.TraceInformation("Job with JobId: {0} subscribed to webhook failed with error: {1}", jobId, e.Message); return(false); } return(true); }
public async Task <HttpStatusCode> DeleteJob([FromUri] string jobId) { CloudTable jobMappingTable = azureTableProvider.GetAzureTableReference(Settings.PageJobMappingTableName); Expression <Func <PageJobEntity, bool> > filter = (entity => entity.RowKey == jobId); List <PageJobEntity> pageJobEntityList = await azureTableProvider.QueryEntitiesAsync <PageJobEntity>(jobMappingTable, filter); if (!pageJobEntityList.Any()) { return(HttpStatusCode.NotFound); } PageJobEntity pageJobEntity = pageJobEntityList?[0]; bool unsubscribed = await connectorSourceProvider.Unsubscribe(pageJobEntity.SourceInfo); Trace.TraceInformation("Job with JobId: {0} successfully unsubscribed to webhook", jobId); if (unsubscribed == false) { return(HttpStatusCode.InternalServerError); } await azureTableProvider.DeleteEntityAsync <PageJobEntity>(jobMappingTable, pageJobEntity); Trace.TraceInformation("Job with JobId: {0} successfully deleted", jobId); return(HttpStatusCode.OK); }
public async Task <HttpResponseMessage> ScheduleTask([FromBody] ScheduleTaskRequest request) { Trace.TraceInformation($"Request came to Web for JobId: {request.JobId} and TaskId: {request.TaskId}"); PageJobEntity entity = await GetJobIdFromTable(request.JobId); if (entity == null) { return(new HttpResponseMessage(HttpStatusCode.NotFound)); } else { await queueProvider.InsertMessageAsync(JsonConvert.SerializeObject(new ConnectorTask { TenantId = Settings.TenantId, JobId = request.JobId, TaskId = request.TaskId, StartTime = request.StartTime, EndTime = request.EndTime, DirtyEntities = request.DirtyEntities, BlobSasUri = request.BlobSasUri })); return(new HttpResponseMessage(HttpStatusCode.OK)); } }
private async Task SavePageJobEntity(string jobId, string accessToken) { string page_id = string.Empty; SourceInfoTwitter sourceInfo = new SourceInfoTwitter(); sourceInfo.SinceId = "0"; foreach (var pair in accessToken.Split('&')) { var keys = pair.Split('='); if (keys[0].Equals("oauth_token")) { sourceInfo.ClientToken = keys[1]; } if (keys[0].Equals("oauth_token_secret")) { sourceInfo.ClientSecret = keys[1]; } if (keys[0].Equals("user_id")) { page_id = keys[1]; } } var PageJobMappingTable = azureTableProvider.GetAzureTableReference(Settings.PageJobMappingTableName); var pageJobEntity = new PageJobEntity(page_id, jobId) { SourceInfo = JsonConvert.SerializeObject(sourceInfo) }; await azureTableProvider.InsertOrReplaceEntityAsync(PageJobMappingTable, pageJobEntity); }
private async Task <string> GetSourceInfoFromTable(ConnectorTask taskInfo) { Expression <Func <PageJobEntity, bool> > filter = (entity => entity.RowKey == taskInfo.JobId); List <PageJobEntity> pageJobEntityList = await azureTableProvider.QueryEntitiesAsync <PageJobEntity>(PageJobMappingTable, filter); PageJobEntity pageJobEntity = pageJobEntityList?[0]; return(pageJobEntity.SourceInfo); }
public async Task UpdateSourceInfo(ConnectorTask taskInfo, SourceInfoTwitter twitterSourceInfo) { PageJobMappingTable = azureTableProviderInstance.GetAzureTableReference(Settings.PageJobMappingTableName); Expression <Func <PageJobEntity, bool> > filter = (entity => entity.RowKey == taskInfo.JobId); CloudTable pageJobMappingTable = azureTableProviderInstance.GetAzureTableReference(Settings.PageJobMappingTableName); List <PageJobEntity> pageJobEntityList = await azureTableProviderInstance.QueryEntitiesAsync <PageJobEntity>(pageJobMappingTable, filter); PageJobEntity pageJobEntity = pageJobEntityList[0]; pageJobEntity.SourceInfo = JsonConvert.SerializeObject(twitterSourceInfo); await azureTableProviderInstance.InsertOrReplaceEntityAsync(PageJobMappingTable, pageJobEntity); }
public string GetUserTokenForjobId(PageJobEntity pageJobEntity) { var queryParams = new Dictionary <string, string>(); queryParams.Add("format", "json"); queryParams.Add("include_email", "true"); queryParams.Add("include_entities", "false"); SourceInfoTwitter SourceInfoTwitter = JsonConvert.DeserializeObject <SourceInfoTwitter>(pageJobEntity.SourceInfo); string clientToken = SourceInfoTwitter.ClientToken; string clientSecret = SourceInfoTwitter.ClientSecret; string userToken = GetToken(SettingsTwitter.TwitterEndPoint + "/1.1/account/verify_credentials.json", HttpMethod.Get.ToString().ToUpperInvariant(), clientToken, clientSecret, queryParams); return(userToken); }
public async Task <bool> ConnectorOAuth([FromUri] string jobId) { CloudTable jobMappingTable = azureTableProvider.GetAzureTableReference(Settings.PageJobMappingTableName); Expression <Func <PageJobEntity, bool> > filter = (entity => entity.RowKey == jobId); List <PageJobEntity> pageJobEntityList = await azureTableProvider.QueryEntitiesAsync <PageJobEntity>(jobMappingTable, filter); if (!pageJobEntityList.Any()) { return(false); } Trace.TraceInformation("Job with JobId: {0} successfully set up", jobId); PageJobEntity pageJobEntity = pageJobEntityList?[0]; return(true); }
private async Task SavePageJobEntity(string jobId, string accessToken) { string page_id = string.Empty; SourceInfoTwitter sourceInfo = new SourceInfoTwitter(); var pageJobMappingTable = azureTableProvider.GetAzureTableReference(Settings.PageJobMappingTableName); Expression <Func <PageJobEntity, bool> > filter = (entity => entity.RowKey == $"{jobId}"); List <PageJobEntity> pageJobEntityList = await azureTableProvider.QueryEntitiesAsync <PageJobEntity>(pageJobMappingTable, filter); PageJobEntity pageJobEntity; if (pageJobEntityList.Count != 0) { pageJobEntity = pageJobEntityList[0]; SourceInfoTwitter SourceInfoTwitter = JsonConvert.DeserializeObject <SourceInfoTwitter>(pageJobEntity.SourceInfo); sourceInfo.SinceId = SourceInfoTwitter.SinceId; } else { sourceInfo.SinceId = "0"; } foreach (var pair in accessToken.Split('&')) { var keys = pair.Split('='); if (keys[0].Equals("oauth_token")) { sourceInfo.ClientToken = keys[1]; } if (keys[0].Equals("oauth_token_secret")) { sourceInfo.ClientSecret = keys[1]; } if (keys[0].Equals("user_id")) { page_id = keys[1]; } } pageJobEntity = new PageJobEntity(page_id, jobId) { SourceInfo = JsonConvert.SerializeObject(sourceInfo) }; await azureTableProvider.InsertOrReplaceEntityAsync(pageJobMappingTable, pageJobEntity); }
public void GetUserTokenForjobIdTest() { SourceInfoTwitter sourceinfo = new SourceInfoTwitter(); sourceinfo.ClientSecret = "CLIENT_SECRET"; sourceinfo.ClientToken = "CLIENT_TOKEN"; PageJobEntity pageJobEntity = new PageJobEntity() { PartitionKey = "123", RowKey = "abc", SourceInfo = JsonConvert.SerializeObject(sourceinfo), }; var twitterAuthProvider = new TwitterAuthProvider(restApiRepositoryMock.Object, azureTableProvider); var token = twitterAuthProvider.GetUserTokenForjobId(pageJobEntity); Assert.IsTrue(token.Contains("CLIENT_TOKEN")); }
public override async Task <IEnumerable <ConnectorEntity> > GetEntities(string jobId) { List <ConnectorEntity> entities = new List <ConnectorEntity>(); var PageJobMappingTable = azureTableProvider.GetAzureTableReference(Settings.PageJobMappingTableName); Expression <Func <PageJobEntity, bool> > filter = (entity => entity.RowKey == $"{jobId}"); List <PageJobEntity> pageJobEntityList = await azureTableProvider.QueryEntitiesAsync <PageJobEntity>(PageJobMappingTable, filter); PageJobEntity pageJobEntity = pageJobEntityList?[0]; string userToken = twitterAuthProvider.GetUserTokenForjobId(pageJobEntity); AccountTwitter AccountTwitter = await twitterAuthProvider.GetAuthorizedAccount(userToken); entities.Add(new ConnectorEntity { Id = AccountTwitter.Id, Name = AccountTwitter.Name }); return(entities); }
public async Task <HttpResponseMessage> ConnectorOAuth([FromUri] string jobId) { HttpRequestMessage request = new HttpRequestMessage(); var configuration = new HttpConfiguration(); request.SetConfiguration(configuration); CloudTable jobMappingTable = azureTableProvider.GetAzureTableReference(Settings.PageJobMappingTableName); Expression <Func <PageJobEntity, bool> > filter = (entity => entity.RowKey == jobId); List <PageJobEntity> pageJobEntityList = await azureTableProvider.QueryEntitiesAsync <PageJobEntity>(jobMappingTable, filter); if (!pageJobEntityList.Any()) { return(request.CreateResponse <JobCreationResponse>(HttpStatusCode.OK, new JobCreationResponse(false, null))); } Trace.TraceInformation("Job with JobId: {0} successfully set up", jobId); PageJobEntity pageJobEntity = pageJobEntityList?[0]; return(request.CreateResponse <JobCreationResponse>(HttpStatusCode.OK, new JobCreationResponse(true, null))); }