コード例 #1
0
 public DocumentsController(IDocumentService documentService, ICalculationService calculationService, IUserService userService, IDocumentTypeRepository documentTypeRepository, IDocumentRepository documentRepository, IUserRepository userRepository, ICheckedRepository checkRepository, IDocumentLogRepository documentLogRepository, ICalculationRepository calculationRepository)
 {
     _documentService        = documentService;
     _calculationService     = calculationService;
     _userService            = userService;
     _documentTypeRepository = documentTypeRepository;
     _documentRepository     = documentRepository;
     _userRepository         = userRepository;
     _checkRepository        = checkRepository;
     _docLogRepository       = documentLogRepository;
     _calcRepository         = calculationRepository;
 }
コード例 #2
0
 public DocumentLogController(IDocumentLogRepository documentLogRepository)
 {
     _documentLogRepository = documentLogRepository;
 }
コード例 #3
0
        private bool UpdateEntitiesOnUpload(Client currentClient, Document entity, String pathFile, Boolean isImage, IDocumentLogRepository repoLog)
        {
            FileInfo f = new FileInfo(pathFile);

            repoLog.includes.Add("ResourceConfig");
            DocumentLog logEntity = repoLog.GetDocumentLogById(currentClient.Id);

            entity.SizeDocument        = f.Length;
            entity.Url                 = pathFile.Replace(WebApiApplication.UPLOAD_FOLDER_ROOT, string.Empty);
            entity.DateUpload          = DateTime.Now;
            logEntity.CurrentSize     += DocumentUtils.GetAllDocumentsSize(f.Length, pathFile, isImage);
            logEntity.DateModification = DateTime.Now;
            if (!((DocumentValidation)validation).CheckSizeUpload(validationDictionnary, logEntity))
            {
                return(false);
            }
            repo.Update(entity);
            repo.Save();
            repoLog.Update(logEntity);
            repoLog.Save();
            return(true);
        }
コード例 #4
0
        /*
        **
        ** Upload
        **
        */

        public virtual HttpResponseMessage UploadFile(Client currentClient, Document entity, HttpRequestMessage Request, IHomeRepository homeRepo, IDocumentLogRepository logRepo)
        {
            MyMultipartFileStreamProvider provider;
            Boolean isImage = false;

            ValidateNull(entity);
            if (entity != null && ((IDocumentRepository)repo).GetDocumentById(entity.Id, currentClient.Id) == null)
            {
                validationDictionnary.AddModelError(TypeOfName.GetNameFromType <Document>(), GenericError.FORBIDDEN_RESOURCE_OR_DOES_NO_EXIST);
            }
            if (!((DocumentValidation)validation).UploadValidationBeforeProvider(validationDictionnary, currentClient, entity, Request))
            {
                throw new ManahostValidationException(validationDictionnary);
            }
            provider = new MyMultipartFileStreamProvider(ManahostUploadFileSystem.GetUploadFolderPath(WebApiApplication.UPLOAD_FOLDER_ROOT, currentClient.Id, (Boolean)entity.IsPrivate));
            try
            {
                IEnumerable <HttpContent> parts = null;
                Task.Factory.StartNew(() => parts = Request.Content.ReadAsMultipartAsync(provider).Result.Contents,
                                      CancellationToken.None,
                                      TaskCreationOptions.LongRunning, // guarantees separate thread
                                      TaskScheduler.Default).Wait();
                MultipartFileData file = provider.FileData.First();

                if (!((DocumentValidation)validation).UploadValidationAfterProvider(validationDictionnary, currentClient, file))
                {
                    throw new ManahostValidationException(validationDictionnary);
                }
                if (isImage = ManahostUploadFileSystem.imageExtension.Any(s => entity.Title.EndsWith(s, StringComparison.OrdinalIgnoreCase)))
                {
                    ImageCompressAndThumbnail(file.LocalFileName);
                }
                if ((Boolean)entity.IsPrivate && currentClient != null)
                {
                    EncryptFileOnUpload(file.LocalFileName, DocumentUtils.GetEncryptionPassword(homeRepo, currentClient), isImage);
                }
                if (!UpdateEntitiesOnUpload(currentClient, entity, file.LocalFileName, isImage, logRepo))
                {
                    throw new ManahostValidationException(validationDictionnary);
                }
            }
            catch (Exception e)
            {
                if (validationDictionnary.IsValid)
                {
                    validationDictionnary.AddModelError(String.Format(GenericNames.MODEL_STATE_FORMAT, TypeOfName.GetNameFromType <Document>(), "Upload"), GenericError.INVALID_GIVEN_PARAMETER);
                }
                if (entity.Url != null)
                {
                    DocumentUtils.DeleteAllFile(entity.Url, isImage);
                }
                repo.Delete(entity);
                repo.Save();
                throw new ManahostValidationException(validationDictionnary, e.StackTrace);
            }
            return(BuildStringContent.BuildFromRequestOK(Request));
        }