Пример #1
0
        public static FileConverter GetConverter(ENUMConverterType converterType)
        {
            switch (converterType)
            {
            case (ENUMConverterType.JPGToPNG):
                return(new JPGToPNGConverter());

            case (ENUMConverterType.PNGToJPG):
                return(new PNGToJPGConverter());

            default:
                return(null);
            }
        }
Пример #2
0
        public TreeEntity ConvertFile(ENUMConverterType type, TreeEntity file)
        {
            if (file.File == null)
            {
                throw new InvalidParametersException();
            }

            FileConverter converter = ConverterFactory.GetConverter(type);

            if (converter == null)
            {
                throw new InvalidParametersException();
            }

            file.File = converter.Convert(file);
            file.Name = converter.getNewFileName(file.Name);

            this.unitOfWork.TreeRepository.Update(file);
            this.unitOfWork.Save();

            return(file);
        }
Пример #3
0
        public async Task <ActionResult <Response <TreeEntity> > > ConvertFile(int entityId, ENUMConverterType type)
        {
            try
            {
                TreeEntity entity = this.treeBl.GetTreeEntity(entityId);
                var        authorizationResult = await authorizationService.AuthorizeAsync(User, entity, new ViewRequirement());

                if (authorizationResult.Succeeded)
                {
                    TreeEntity newTreeEntity = this.conversionBl.ConvertFile(type, entity);
                    return(new Response <TreeEntity>(newTreeEntity));
                }
                else
                {
                    return(new ForbidResult());
                }
            }
            catch (Exception ex)
            {
                return(new Response <TreeEntity>(ex));
            }
        }
Пример #4
0
 public FileConverter(ENUMConverterType type, string extension)
 {
     this.type      = type;
     this.extension = extension;
 }