示例#1
0
        public Task ExecuteBatchAsync(FileBatch batch)
        {
            foreach (var file in batch.FilesToCreate)
            {
                CopyFile(file);
            }

            return(Task.FromResult(42));
        }
示例#2
0
 public async Task ExecuteBatchAsync(FileBatch batch)
 {
     try
     {
         await _files.ExecuteBatchAsync(batch);
     }
     catch (Exception e)
     {
         throw new RemoteNodeException(_machine, e);
     }
 }
示例#3
0
        public List <File> Patch(FileBatch request)
        {
            if (true != request?.Any())
            {
                throw new HttpError(HttpStatusCode.NotFound, "Request cannot be empty.");
            }

            var ret      = new List <File>();
            var errors   = new List <ResponseError>();
            var errorMap = new Dictionary <string, string>();
            var i        = 0;

            request.ForEach(dto =>
            {
                try
                {
                    var obj = Patch(dto) as File;
                    ret.Add(obj);
                    errorMap[$"{i}"] = $"true";
                }
                catch (Exception ex)
                {
                    errorMap[$"{i}"] = $"false";
                    errors.Add(new ResponseError()
                    {
                        Message   = $"{ex.Message}{Environment.NewLine}{ex.InnerException?.Message}",
                        ErrorCode = $"{i}"
                    });
                }
                i += 1;
            });
            base.Response.AddHeader("X-AutoBatch-Completed", $"{ret.Count} succeeded");
            if (errors.Any())
            {
                throw new HttpError(HttpStatusCode.BadRequest, $"{errors.Count} failed in batch")
                      {
                          Response = new ErrorResponse()
                          {
                              ResponseStatus = new ResponseStatus
                              {
                                  ErrorCode = nameof(HttpError),
                                  Meta      = errorMap,
                                  Message   = "Incomplete request",
                                  Errors    = errors
                              }
                          }
                      };
            }
            return(ret);
        }
示例#4
0
        private void CopyFileBatch(IReadOnlyList <string> sourceFilePaths, IReadOnlyList <string> destinationFilePaths)
        {
            var tasks = new TaskList(maxPending: MaxParallelBatchTasks);

            var  batch  = new FileBatch();
            long length = 0;

            for (int i = 0; i < sourceFilePaths.Count; ++i)
            {
                var sourceFilePath      = sourceFilePaths[i];
                var destinationFilePath = destinationFilePaths[i];

                Log.InfoFormat("Copying '{0}' to '{1}'...", sourceFilePath, destinationFilePath);

                var instruction = new CreateFile
                {
                    FilePath = destinationFilePath,
                    Content  = File.ReadAllBytes(sourceFilePath)
                };
                batch.FilesToCreate.Add(instruction);
                length += instruction.Content.Length;

                if (length >= FilePacketBufferSize)
                {
                    tasks.Add(_files.ExecuteBatchAsync(batch));
                    batch  = new FileBatch();
                    length = 0;
                }
            }

            if (batch.Any())
            {
                tasks.Add(_files.ExecuteBatchAsync(batch));
            }

            tasks.WaitAll();
        }
示例#5
0
 public List <File> Put(FileBatch request)
 {
     return(Patch(request));
 }