Пример #1
0
        public void GetFile(int id)
        {
            var item = _dataContext.Photos
                       .Include(p => p.ParentFolder)
                       .FirstOrDefault(i => i.Id == id);

            var folder = item.ParentFolder;
            var path   = item.FileName;

            if (folder != null)
            {
                path = _galleryContext.GetFolderPath(folder.Id, item.FileName);
            }

            Response.Clear();
            Response.Headers.Add("Content-Disposition", "attachment;filename=" + item.FileName);

            try
            {
                using (var fileStream = _fileClient.GetFile(path))
                {
                    fileStream.CopyTo(Response.Body);
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "");
            }
        }
Пример #2
0
        private void LoadObservation()
        {
            if (_observation != null && _observation.ObservationAge < _settings.RefreshInterval)
            {
                return;
            }

            var downloaded = false;

            if (!_fileClient.FileExists("cache", "emhi.xml"))
            {
                downloaded = true;
                DownloadObservations();
            }

loadObservations:
            var xml = Encoding.UTF8.GetString(_fileClient.GetFile("cache", "emhi.xml"));
            var xRoot = new XmlRootAttribute {
                ElementName = "observations"
            };
            var serializer = new XmlSerializer(typeof(Observations), xRoot);

            using (var reader = new StringReader(xml))
            {
                _observation = (Observations)serializer.Deserialize(reader);
            }

            if (_observation.ObservationAge > _settings.RefreshInterval && !downloaded)
            {
                downloaded = true;
                DownloadObservations();
                goto loadObservations;
            }
        }
Пример #3
0
 public async Task <HotelData> GetAsync()
 {
     using (var fileStream = await _fileClient.GetFile("App_Data", "hotelrates.json"))
     {
         var rawJson = new StreamReader(fileStream).ReadToEnd();
         return(JsonSerializer.Deserialize <HotelData>(rawJson));
     }
 }
Пример #4
0
        //public GetFileWithEffectsCommand()
        //{

        //}

        public bool Execute(PicWithEffectModel model)
        {
            var item = _dataContext.Items
                       .Include(p => p.ParentFolder)
                       .FirstOrDefault(i => i.Id == model.Id);

            var fileItem = (Photo)item;
            var folder   = fileItem.ParentFolder;
            var path     = fileItem.FileName;

            if (folder != null)
            {
                path = _galleryContext.GetFolderPath(folder.Id, fileItem.FileName);
            }

            var fileName = fileItem.FileName;
            var effect   = model.Effect;

            try
            {
                IImageFormat format;
                using (var fileStream = _fileClient.GetFile(path))
                    using (var image = Image.Load(fileStream, out format))
                    {
                        Image <Rgba32> imageWithEffect;

                        if (effect == "BlackWhite")
                        {
                            imageWithEffect = image.Clone(ctx => ctx.BlackWhite());
                        }
                        else if (effect == "OilPaint")
                        {
                            imageWithEffect = image.Clone(ctx => ctx.OilPaint());
                        }
                        else if (effect == "Sepia")
                        {
                            imageWithEffect = image.Clone(ctx => ctx.Sepia());
                        }
                        else if (effect == "Blur")
                        {
                            imageWithEffect = image.Clone(ctx => ctx.GaussianBlur());
                        }
                        else if (effect == "Sharpen")
                        {
                            imageWithEffect = image.Clone(ctx => ctx.GaussianSharpen());
                        }
                        else if (effect == "Glow")
                        {
                            imageWithEffect = image.Clone(ctx => ctx.Glow());
                        }
                        else if (effect == "Invert")
                        {
                            imageWithEffect = image.Clone(ctx => ctx.Invert());
                        }
                        else
                        {
                            imageWithEffect = image;
                        }
                        imageWithEffect.Save(model.outStream, format);
                    }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "");
            }
            return(true);
        }