コード例 #1
0
        /// <summary>
        ///
        /// </summary>
        public void ManagerFile()
        {
            var pagedResult = _operations.GetPaged(1, 100);
            var files       = pagedResult.Results.ToList();

            byte[] buffer = new byte[4096];

            int len;

            files.ForEach(file =>
            {
                Parallel.Invoke(() =>
                {
                    file.Status      = Infrastructure.Enums.FileStatus.InProcess;
                    file.ProcessDate = DateTime.Now;
                    file.InitialDate = DateTime.Now;

                    _operations.Update(file.Key.ToString(), _mapper.Map <FileDataContract>(file));
                });

                try
                {
                    using (var originStream = new FileStream($"{file.OriginPath}{file.Name}", FileMode.OpenOrCreate))
                    {
                        using (var destinyStream = new FileStream($"{file.DestinyPath}{file.Name}", FileMode.CreateNew))
                        {
                            while ((len = originStream.Read(buffer, 0, buffer.Length)) > 0)
                            {
                                destinyStream.Write(buffer, 0, len);
                            }
                        }
                    }

                    Parallel.Invoke(() =>
                    {
                        file.FinishProcessDate = DateTime.Now;

                        if (VerifyCheckSumBetweenFiles($"{file.OriginPath}{file.Name}", $"{file.DestinyPath}{file.Name}", out string result))
                        {
                            file.Checksum = result;
                            file.Status   = Infrastructure.Enums.FileStatus.Moved;
                        }
                        else
                        {
                            file.Checksum = result;
                            file.Status   = Infrastructure.Enums.FileStatus.Error;
                        }

                        _operations.Update(file.Key.ToString(), _mapper.Map <FileDataContract>(file));
                    }
                                    );
                }
                catch (SystemException ex)
                {
                    throw new Exception(ex.Message);
                }
            });
        }
コード例 #2
0
ファイル: FilesController.cs プロジェクト: DAREAS/FileManager
        public ActionResult Put(string idFile, [FromBody] FileDataContract file, [FromServices] IFileOperations operations)
        {
            try
            {
                var result = operations.Update(idFile, file);

                if (result == null)
                {
                    return(OkWithSuccess(result, System.Net.HttpStatusCode.NotFound));
                }

                if (result.Error.Any())
                {
                    return(BadRequest(result.Error));
                }


                return(OkWithSuccess(result));
            }
            catch (Exception ex)
            {
                return(BadRequest(new { Code = HttpContext.Response.StatusCode, Message = ex.Message }));
            }
        }