Beispiel #1
0
        public async Task Get(char letter, string color)
        {
            if (string.IsNullOrEmpty(color))
            {
                throw new ArgumentNullException(nameof(color));
            }

            var fileName = $"{letter}-{color}.png";
            var r        = Response;

            r.Clear();

            var existingFileBytes = await _fileStore.GetFileBytesAsync(_fileStore.Combine(
                                                                           _sitesFolder.RootPath,
                                                                           _pathToImages,
                                                                           fileName));

            if (existingFileBytes != null)
            {
                r.ContentType = "image/png";
                r.Headers.Add("content-disposition", $"filename=\"{fileName}\"");
                r.Headers.Add("content-length", Convert.ToString((int)existingFileBytes.Length));
                r.Body.Write(existingFileBytes, 0, existingFileBytes.Length);
            }
            else
            {
                // Validate supplied input as this input is used by the letter renderer
                var isCorrectChars  = color.IsValidHex();
                var isCorrectLength = color.Length <= 6;
                if (!isCorrectChars | !isCorrectLength)
                {
                    throw new Exception("The supplied color is not a valid hexadecimal value.");
                }

                // For the first request to the image generate the image,
                // save the image to disk & serve the response. Subsequent requests
                // for the same image will be served from disk to avoid creating
                // the image upon every request and to reduce global locks due
                // to System.Drawing and internal calls to GDI+ on Windows
                using (var renderer = _letterRenderer)
                {
                    var fileBytes = renderer.GetLetter(new LetterOptions()
                    {
                        Letter    = letter.ToString().ToUpper(),
                        BackColor = color
                    }).StreamToByteArray();

                    using (var stream = new MemoryStream(fileBytes))
                    {
                        await _sitesFolder.SaveFileAsync(stream, fileName, _pathToImages);
                    }

                    r.ContentType = "image/png";
                    r.Headers.Add("content-disposition", $"filename=\"{fileName}\"");
                    r.Headers.Add("content-length", Convert.ToString((int)fileBytes.Length));
                    r.Body.Write(fileBytes, 0, fileBytes.Length);
                }
            }
        }
Beispiel #2
0
        public LetterController(
            IInMemoryLetterRenderer letterRenderer,
            IFileStore fileStore,
            IShellSettings shellSettings,
            ISitesFolder sitesFolder,
            IHostingEnvironment hostEnvironment)
        {
            _letterRenderer  = letterRenderer;
            _fileStore       = fileStore;
            _sitesFolder     = sitesFolder;
            _hostEnvironment = hostEnvironment;

            _pathToImages = fileStore.Combine(hostEnvironment.ContentRootPath, shellSettings.Location, "images");
            _urlToImages  = $"/sites/{shellSettings.Location.ToLower()}/images/";
        }
Beispiel #3
0
        public LetterController(
            IInMemoryLetterRenderer letterRenderer,
            IHostingEnvironment hostEnvironment,
            IShellSettings shellSettings,
            ISitesFolder sitesFolder,
            IFileStore fileStore)
        {
            _letterRenderer = letterRenderer;
            _sitesFolder    = sitesFolder;
            _fileStore      = fileStore;

            _pathToImages = fileStore.Combine(
                hostEnvironment.ContentRootPath,
                shellSettings.Location,
                "images");
        }
Beispiel #4
0
        public MediaController(
            IMediaStore <Models.Media> mediaStore,
            IHostingEnvironment hostEnvironment,
            IFileStore fileStore)
        {
            _mediaStore = mediaStore;
            _fileStore  = fileStore;

            if (_pathToEmptyImage == null)
            {
                _pathToEmptyImage = _fileStore.Combine(hostEnvironment.ContentRootPath,
                                                       "wwwroot",
                                                       "images",
                                                       "photo.png");
            }
        }
        public EditProfileViewProvider(
            IUserPhotoStore <UserPhoto> userPhotoStore,
            IPlatoUserStore <User> platoUserStore,
            IHostingEnvironment hostEnvironment,
            IShellSettings shellSettings,
            UserManager <User> userManager,
            ISitesFolder sitesFolder,
            IFileStore fileStore)
        {
            _platoUserStore = platoUserStore;
            _userPhotoStore = userPhotoStore;
            _sitesFolder    = sitesFolder;
            _userManager    = userManager;

            // paths
            _pathToImages = fileStore.Combine(hostEnvironment.ContentRootPath, shellSettings.Location, "images");
            _urlToImages  = $"/sites/{shellSettings.Location.ToLower()}/images/";
        }
Beispiel #6
0
        public AdminViewProvider(
            IShellSettings shellSettings,
            UserManager <User> userManager,
            IStringLocalizer <AdminViewProvider> stringLocalizer,
            IUserPhotoStore <UserPhoto> userPhotoStore,
            IUserRepository <User> userRepository,
            IHostEnvironment hostEnvironment,
            IPlatoUserStore <User> userStore,
            ISitesFolder sitesFolder,
            IFileStore fileStore)
        {
            _userPhotoStore = userPhotoStore;
            _userRepository = userRepository;
            _userManager    = userManager;
            _sitesFolder    = sitesFolder;
            _userStore      = userStore;

            T = stringLocalizer;

            // paths
            _pathToImages = fileStore.Combine(hostEnvironment.ContentRootPath, shellSettings.Location, "images");
            _urlToImages  = $"/sites/{shellSettings.Location.ToLower()}/images/";
        }
Beispiel #7
0
 public string Combine(params string[] paths)
 {
     return(_fileStore.Combine(paths));
 }