コード例 #1
0
        public override async Task <IEnumerable <WebHookSignature> > CreateWebHook(ExecutionContext context, [NotNull] CrawlJobData jobData, [NotNull] IWebhookDefinition webhookDefinition, [NotNull] IDictionary <string, object> config)
        {
            if (jobData == null)
            {
                throw new ArgumentNullException(nameof(jobData));
            }

            if (webhookDefinition == null)
            {
                throw new ArgumentNullException(nameof(webhookDefinition));
            }

            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            return(await Task.Run(() =>
            {
                var webhookSignatures = new List <WebHookSignature>();

                var webhookSignature = new WebHookSignature {
                    Signature = webhookDefinition.ProviderDefinitionId.ToString(), ExternalVersion = "v1", ExternalId = null, EventTypes = "Created,Uploaded,Commented,Downloaded,Previewed,Moved,Copied"
                };

                webhookSignatures.Add(webhookSignature);

                webhookDefinition.Uri = new Uri(appContext.System.Configuration.WebhookReturnUrl.Trim('/') + ConfigurationManager.AppSettings["Providers.Dropbox.WebhookEndpoint"]);

                var organizationProviderDataStore = context.Organization.DataStores.GetDataStore <ProviderDefinition>();
                if (organizationProviderDataStore != null)
                {
                    if (webhookDefinition.ProviderDefinitionId != null)
                    {
                        var webhookEnabled = organizationProviderDataStore.GetById(context, webhookDefinition.ProviderDefinitionId.Value);
                        if (webhookEnabled != null)
                        {
                            webhookEnabled.WebHooks = true;
                            organizationProviderDataStore.Update(context, webhookEnabled);
                        }
                    }
                }

                webhookDefinition.Verified = true;

                return webhookSignatures;
            }));
        }
コード例 #2
0
        public WebhookResponse DeleteWebhooks(WebHookSignature webhook)
        {
            var api = "https://api.adversus.dk/webhooks/" + webhook.ExternalId;

            using (HttpClient httpClient = new HttpClient())
            {
                var webhooks = new List <AdversusWebhook>();
                try
                {
                    var credentials = System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(_adversusCrawlJobData.Username + ":" + _adversusCrawlJobData.Password));
                    var auth        = string.Format("Basic {0}", credentials);
                    httpClient.DefaultRequestHeaders.Add("Authorization", auth);
                    var response        = httpClient.DeleteAsync(api).Result;
                    var responseContent = response.Content.ReadAsStringAsync().Result;
                    if (response.StatusCode == HttpStatusCode.Unauthorized)
                    {
                        log.LogError("401 Unauthorized. Check credentials");
                    }
                    else if (response.StatusCode == HttpStatusCode.InternalServerError)
                    {
                        log.LogError("500 Internal Server Error.");
                    }
                    else if (response.StatusCode != HttpStatusCode.OK)
                    {
                        log.LogError(response.StatusCode.ToString() + " Failed to get data");
                    }
                    var results = JsonConvert.DeserializeObject <WebhookResponse>(responseContent);
                    return(results);
                }
                catch (Exception exception)
                {
                    log.LogError("Call to Adversus API Failed", exception);
                }

                return(null);
            }
        }