Beispiel #1
0
        public void RecordPackageDependency(Package package, string feed, PackageConsumer consumer, string apiKey)
        {
            var request = WebRequest.CreateHttp(this.BaseUrl + "/api/dependencies/dependents");

            request.Method      = "POST";
            request.ContentType = "application/json";
            if (!string.IsNullOrWhiteSpace(apiKey))
            {
                request.Headers.Add("X-ApiKey", apiKey);
            }

            using (var requestStream = request.GetRequestStream())
            {
#if NETCOREAPP3_1
                using (var writer = new Utf8JsonWriter(requestStream))
                {
                    JsonSerializer.Serialize(writer, new DependentPackage(package, feed, consumer));
                }
#else
                using (var writer = new StreamWriter(requestStream, Encoding.UTF8))
                {
                    new JsonSerializer().Serialize(writer, new DependentPackage(package, feed, consumer));
                }
#endif
            }

            try
            {
                using (var response = request.GetResponse())
                {
                }
            }
            catch (WebException ex) when(ex.Response is HttpWebResponse response)
            {
                using (var reader = new StreamReader(response.GetResponseStream()))
                {
                    var message = new char[8192];
                    int length  = reader.ReadBlock(message, 0, message.Length);
                    if (length > 0)
                    {
                        throw new PgScanException($"Server responded with {(int)response.StatusCode} {response.StatusDescription}: {new string(message, 0, length)}");
                    }
                    else
                    {
                        throw new PgScanException($"Server responded with {(int)response.StatusCode} {response.StatusDescription}");
                    }
                }
            }
        }
Beispiel #2
0
 public DependentPackage(Package p, string feed, PackageConsumer consumer)
 {
     this.p        = p;
     this.c        = consumer;
     this.FeedName = feed;
 }