public async Task <bool> Update([FromUri] string jobId) { PageJobMappingTable = azureTableProvider.GetAzureTableReference(Settings.PageJobMappingTableName); Expression <Func <PageJobEntity, bool> > filter = (e => e.RowKey == jobId); List <PageJobEntity> pageJobEntityList = await azureTableProvider.QueryEntitiesAsync <PageJobEntity>(PageJobMappingTable, filter); PageJobEntity page = pageJobEntityList[0]; string sourceInfo = await sourceProvider.GetAuthTokenForResource(page.PartitionKey, jobId); PageJobEntity pageJobEntity = new PageJobEntity(page.PartitionKey, jobId); pageJobEntity.SourceInfo = sourceInfo; await azureTableProvider.InsertOrReplaceEntityAsync(PageJobMappingTable, pageJobEntity); Trace.TraceInformation("Job update complete page successfully saved for jobId: {0}", jobId); try { Trace.TraceInformation("Job with JobId: {0} subscribing to webhook", jobId); 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 <bool> SavePage([FromBody] ConnectorEntity page, [FromUri] string jobId) { string sourceInfo = await sourceProvider.GetAuthTokenForResource(page.Id, jobId); PageJobMappingTable = azureTableProvider.GetAzureTableReference(Settings.PageJobMappingTableName); PageJobEntity pageJobEntity = new PageJobEntity(page.Id, jobId); pageJobEntity.SourceInfo = sourceInfo; await azureTableProvider.InsertEntityAsync(PageJobMappingTable, pageJobEntity); Trace.TraceInformation("Job Setup complete page succesfully saved for jobId: {0}", jobId); try { Trace.TraceInformation("Job with JobId: {0} subscribing to webhook", jobId); 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); }
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 <HttpResponseMessage> ScheduleTask([FromBody] ScheduleTaskRequest request) { Trace.TraceInformation($"Request came to Web for JobId: {request.JobId} and TaskId: {request.TaskId}"); if (string.IsNullOrEmpty(Settings.AAdAppId) || string.IsNullOrEmpty(Settings.AAdAppSecret)) { Trace.TraceError($"AAD Settings missing. Request failed for JobId: {request.JobId} and TaskId: {request.TaskId}."); return(new HttpResponseMessage(HttpStatusCode.ExpectationFailed) { Content = new StringContent("Connector is not configured. AAD Settings missing.") }); } PageJobEntity entity = await GetJobIdFromTable(request.JobId); if (entity == null) { Trace.TraceError($"Failed to find job in the table. Request failed for JobId: {request.JobId} and TaskId: {request.TaskId}."); return(new HttpResponseMessage(HttpStatusCode.NotFound) { Content = new StringContent("Failed to find job in the table") }); } 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)); } }
/// <summary> /// convert facebook data to table object /// </summary> /// <param name="data">the data comng from server</param> /// <returns>Table object</returns> private async Task SendDataAsync(WebhookFeedFB data) { string jobId; foreach (Entry entry in data.Entry) { if (PageJobMapping.ContainsKey(entry.Id)) { jobId = PageJobMapping[entry.Id].RowKey; } else { Trace.TraceInformation($"Page Id: {entry.Id}"); Expression <Func <PageJobEntity, bool> > filter = (entity => entity.PartitionKey == entry.Id); PageJobMappingTable = azureTableProvider.GetAzureTableReference(Settings.PageJobMappingTableName); List <PageJobEntity> pageJobEntityList = await azureTableProvider.QueryEntitiesAsync <PageJobEntity>(PageJobMappingTable, filter); Trace.TraceInformation($"Fetched entries from Table: {pageJobEntityList.Count}"); PageJobEntity pageJobEntity = pageJobEntityList?[0]; PageJobMapping.Add(pageJobEntity?.PartitionKey, pageJobEntity); jobId = pageJobEntity?.RowKey; } foreach (Change change in entry.Changes) { if (change.Value != null && change.Value.PostId != null) { await eventApiClient.OnWebhookEvent(Settings.TenantId, jobId, $"{change.Value?.CreatedTime}", $"{change.Value?.PostId}", "update"); } else { Trace.TraceWarning("No post id"); } } } }