Esempio n. 1
0
        public bool ValidateBusinessRules(FlowChunk chunk, out List<string> errorMessages)
        {
            errorMessages = new List<string>();
            if (MaxFileSize.HasValue && chunk.TotalSize > MaxFileSize.Value)
                errorMessages.Add(MaxFileSizeMessage ?? "size");

            if (AcceptedExtensions.Count > 0 && AcceptedExtensions.SingleOrDefault(x => x == chunk.FileName.Split('.').Last()) == null)
                errorMessages.Add(AcceptedExtensionsMessage ?? "type");

            return errorMessages.Count == 0;
        }
Esempio n. 2
0
        public FlowJsPostChunkResponse PostChunk(FlowChunk chunk, IFlowValidationRules validationRules)
        {
            var errResponse = new FlowJsPostChunkResponse();
            errResponse.Status = PostChunkStatus.Error;
            errResponse.ErrorMessages.Add("damaged");

            List<string> errorMessages = null;
            var file = chunk.Files[0];

            var response = new FlowJsPostChunkResponse { FileName = chunk.FileName, Size = chunk.TotalSize };

            var chunkIsValid = true;
            if (validationRules != null)
                chunkIsValid = validationRules.ValidateBusinessRules(chunk, out errorMessages);

            if (!chunkIsValid)
            {
                response.Status = PostChunkStatus.Error;
                response.ErrorMessages = errorMessages;
                return response;
            }

            var chunkFullPathName = GetChunkFilename(chunk.Number, chunk.Identifier);
            try
            {
                file.SaveAs(chunkFullPathName);
            }
            catch (Exception)
            {
                throw;
            }

            lock(lockObj)
            {
                for (int i = 1, l = chunk.TotalChunks; i <= l; i++)
                {
                    var chunkNameToTest = GetChunkFilename(i, chunk.Identifier);
                    var exists = File.Exists(chunkNameToTest);
                    if (!exists)
                    {
                        response.Status = PostChunkStatus.PartlyDone;
                        return response;
                    }
                }

                var fileAry = new List<string>();
                for (int i = 1, l = chunk.TotalChunks; i <= l; i++)
                {
                    fileAry.Add("flow-" + chunk.Identifier + "." + i);
                }

                response.FilePath = MergeChunks(fileAry, chunk.FileName);

                for (int i = 0, l = fileAry.Count; i < l; i++)
                {
                    try
                    {
                        File.Delete(Path.Combine(filesPath.GetFlowJsTempDirectory(), fileAry[i]));
                    }
                    catch (Exception)
                    {
                    }
                }
            }
            response.Status = PostChunkStatus.Done;
            return response;
        }
Esempio n. 3
0
 public FlowJsPostChunkResponse PostChunk(FlowChunk chunk)
 {
     return PostChunk(chunk, null);
 }