示例#1
0
        private async Task GetConfigurationSettingFomStorge()
        {
            CloudTable settingsTable = azureTableProvider.GetAzureTableReference(Settings.ConfigurationSettingsTableName);

            Settings.AAdAppId     = (await azureTableProvider.GetEntityAsync <ConfigurationSettingsEntity>(settingsTable, "ConfigurationSetting", "AAdAppId")).settingValue;
            Settings.AAdAppSecret = (await azureTableProvider.GetEntityAsync <ConfigurationSettingsEntity>(settingsTable, "ConfigurationSetting", "AAdAppSecret")).settingValue;
        }
示例#2
0
        public async Task <bool> Configure([FromBody] Dictionary <string, string> configSettings)
        {
            SettingsTable = azureTableProvider.GetAzureTableReference(Settings.ConfigurationSettingsTableName);

            if (!string.IsNullOrEmpty(configSettings["FBAppIdValue"]))
            {
                SettingsFB.FacebookAppId = configSettings["FBAppIdValue"];
                await azureTableProvider.InsertOrReplaceEntityAsync(SettingsTable, new ConfigurationSettingsEntity("FacebookAppId", configSettings["FBAppIdValue"]));
            }

            if (!string.IsNullOrEmpty(configSettings["FBAppSecretValue"]))
            {
                SettingsFB.FacebookAppSecret = configSettings["FBAppSecretValue"];
                await azureTableProvider.InsertOrReplaceEntityAsync(SettingsTable, new ConfigurationSettingsEntity("FacebookAppSecret", configSettings["FBAppSecretValue"]));
            }

            if (!string.IsNullOrEmpty(configSettings["FBVerifyTokenValue"]))
            {
                SettingsFB.FacebookVerifyToken = configSettings["FBVerifyTokenValue"];
                await azureTableProvider.InsertOrReplaceEntityAsync(SettingsTable, new ConfigurationSettingsEntity("FacebookVerifyToken", configSettings["FBVerifyTokenValue"]));
            }

            if (!string.IsNullOrEmpty(configSettings["AADAppIdValue"]))
            {
                Settings.AAdAppId = configSettings["AADAppIdValue"];
                await azureTableProvider.InsertOrReplaceEntityAsync(SettingsTable, new ConfigurationSettingsEntity("AAdAppId", configSettings["AADAppIdValue"]));
            }

            if (!string.IsNullOrEmpty(configSettings["AADAppSecretValue"]))
            {
                Settings.AAdAppSecret = configSettings["AADAppSecretValue"];
                await azureTableProvider.InsertOrReplaceEntityAsync(SettingsTable, new ConfigurationSettingsEntity("AAdAppSecret", configSettings["AADAppSecretValue"]));
            }
            return(true);
        }
        private async Task <PageJobEntity> GetJobIdFromTable(string jobId)
        {
            Expression <Func <PageJobEntity, bool> > filter = (entity => entity.RowKey == jobId);

            pageJobMappingTable = azureTableProvider.GetAzureTableReference(Settings.PageJobMappingTableName);
            List <PageJobEntity> pageJobEntityList = await azureTableProvider.QueryEntitiesAsync <PageJobEntity>(pageJobMappingTable, filter);

            if (pageJobEntityList == null || pageJobEntityList.Count == 0)
            {
                return(null);
            }
            return(pageJobEntityList?[0]);
        }
        public async Task <IEnumerable <ConnectorEntity> > Get([FromUri] string jobType, [FromUri] string jobId)
        {
            CloudTable jobMappingTable = azureTableProvider.GetAzureTableReference(Settings.PageJobMappingTableName);

            Trace.TraceInformation("Getting connector Entities for JobType {0}", jobType.ToString());

            IEnumerable <ConnectorEntity> entities = await sourceProvider.GetEntities(jobId);

            Trace.TraceInformation("Entities retrieved: {0}", entities?.Count());

            if (entities != null)
            {
                foreach (ConnectorEntity entity in entities)
                {
                    Expression <Func <PageJobEntity, bool> > filter = (e => e.PartitionKey == entity.Id);
                    List <PageJobEntity> pageJobEntityList          = await azureTableProvider.QueryEntitiesAsync <PageJobEntity>(jobMappingTable, filter);

                    entity.AlreadyUsed = pageJobEntityList.Any();
                }
            }

            return(entities);
        }
        public async Task <bool> Configure([FromBody] Dictionary <string, string> configSettings)
        {
            SettingsTable = azureTableProvider.GetAzureTableReference(Settings.ConfigurationSettingsTableName);

            if (!string.IsNullOrEmpty(configSettings["FBAppIdValue"]))
            {
                SettingsFB.FacebookAppId = configSettings["FBAppIdValue"];
                await azureTableProvider.InsertOrReplaceEntityAsync(SettingsTable, new ConfigurationSettingsEntity("FacebookAppId", configSettings["FBAppIdValue"]));
            }

            if (!string.IsNullOrEmpty(configSettings["FBAppSecretValue"]))
            {
                SettingsFB.FacebookAppSecret = configSettings["FBAppSecretValue"];
                await azureTableProvider.InsertOrReplaceEntityAsync(SettingsTable, new ConfigurationSettingsEntity("FacebookAppSecret", configSettings["FBAppSecretValue"]));
            }

            if (!string.IsNullOrEmpty(configSettings["FBVerifyTokenValue"]))
            {
                SettingsFB.FacebookVerifyToken = configSettings["FBVerifyTokenValue"];
                await azureTableProvider.InsertOrReplaceEntityAsync(SettingsTable, new ConfigurationSettingsEntity("FacebookVerifyToken", configSettings["FBVerifyTokenValue"]));
            }

            if (!string.IsNullOrEmpty(configSettings["AADAppIdValue"]))
            {
                Settings.AAdAppId = configSettings["AADAppIdValue"];
                await azureTableProvider.InsertOrReplaceEntityAsync(SettingsTable, new ConfigurationSettingsEntity("AAdAppId", configSettings["AADAppIdValue"]));
            }

            if (!string.IsNullOrEmpty(configSettings["AADAppSecretValue"]))
            {
                Settings.AAdAppSecret = configSettings["AADAppSecretValue"];
                await azureTableProvider.InsertOrReplaceEntityAsync(SettingsTable, new ConfigurationSettingsEntity("AAdAppSecret", configSettings["AADAppSecretValue"]));
            }

            if (!string.IsNullOrEmpty(configSettings["AADAppUriValue"]))
            {
                Settings.AADAppUri = configSettings["AADAppUriValue"];
                await azureTableProvider.InsertOrReplaceEntityAsync(SettingsTable, new ConfigurationSettingsEntity("AADAppUri", configSettings["AADAppUriValue"]));
            }

            if (!string.IsNullOrEmpty(configSettings["InstrumentationKeyValue"]))
            {
                Settings.APPINSIGHTS_INSTRUMENTATIONKEY = configSettings["InstrumentationKeyValue"];
                await azureTableProvider.InsertOrReplaceEntityAsync(SettingsTable, new ConfigurationSettingsEntity("APPINSIGHTS_INSTRUMENTATIONKEY", configSettings["InstrumentationKeyValue"]));

                TelemetryConfiguration.Active.InstrumentationKey = configSettings["InstrumentationKeyValue"];
            }
            return(true);
        }
        /// <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");
                    }
                }
            }
        }
 public Utility()
 {
     azureTableProvider = new AzureTableProvider(Settings.StorageAccountConnectionString);
     settingsTable      = azureTableProvider.GetAzureTableReference(Settings.ConfigurationSettingsTableName);
 }