示例#1
0
        /// <summary>
        /// Starts a batch scan for a list of 'proceChecked' scans
        /// </summary>
        /// <param name="model">A model with the list of scan id's to start and error handeling defenition in case one or more scans have a starting error.
        /// The Model also contains an include list of completed scans that will be compared against</param>
        /// <returns>A task that represents the asynchronous operation.
        /// The task result contains a list of successfully started scans and a list of scans that have failed starting </returns>
        public async Task <StartResponse> StartBatchAsync(StartBatchRequest model, string token)
        {
            if (string.IsNullOrEmpty(token))
            {
                throw new ArgumentException("Token is mandatory", nameof(token));
            }

            if (model.Trigger == null)
            {
                throw new ArgumentException("Trigger is mandatory.", nameof(model.Trigger));
            }

            var    method     = new HttpMethod("PATCH");
            string requestUri = $"{this.CopyleaksApiServer}{this.ApiVersion}/scans/batch/start";
            var    msg        = new HttpRequestMessage(method, requestUri);

            msg.SetupHeaders(token);
            msg.Content = new StringContent(JsonConvert.SerializeObject(model), Encoding.UTF8, "application/json");

            using (var stream = new MemoryStream())
                using (var streamContent = new StreamContent(stream))
                    using (var response = await Client.SendAsync(await msg.CloneAsync(stream, streamContent).ConfigureAwait(false)).ConfigureAwait(false))
                    {
                        if (!response.IsSuccessStatusCode)
                        {
                            throw new CopyleaksHttpException(response);
                        }
                        return(await response.ExtractJsonResultsAsync <StartResponse>().ConfigureAwait(false));
                    }
        }
示例#2
0
        public async void Post([FromBody] StartBatchRequest request)
        {
            Log.Info($"Processing send batch request for batch id {request.BatchId} with {request.BatchData.Count} items.");
            var batchDataFilePath = Path.GetTempFileName();

            File.AppendAllLines(batchDataFilePath, request.BatchData);

            await MessageSession.Send(new StartBatch
            {
                BatchId       = request.BatchId,
                BatchDataPath = batchDataFilePath
            });
        }
        public Task Submit(string batchId, List <string> batchData)
        {
            var request = new StartBatchRequest()
            {
                BatchId   = batchId,
                BatchData = batchData
            };

            var json = JsonConvert.SerializeObject(request);

            Console.WriteLine($"Submitting request for batch id {batchId} with {batchData.Count} items to {client.BaseAddress}/api/Batch");

            return(client.PostAsync("/api/Batch", new StringContent(json, Encoding.UTF8, "application/json")));
        }