コード例 #1
0
        public Photo SavePhoto(CreatePhotoViewModel model, string userId)
        {
            string[] hashtags  = model.HashtagsString.Split(' ');
            Photo    photo     = Helpers.Helpers.GetPhotoFromCreatePhotoViewModel(model, userId);
            var      extension = model.OriginalImageExtension;


            if (model.DoConversion)
            {
                extension = model.ConversionExtension;
            }

            if (!Helpers.Helpers.GetAvailableFormats().Any(f => f == extension))
            {
                extension = "Jpeg";
            }


            //var uploads = Path.Combine(_hostingEnvironment.WebRootPath, "uploads");
            string uniqueFileName = Helpers.Helpers.GetUniqueFileName(extension);
            //var filePath = Path.Combine(uploads, uniqueFileName);
            long         imageSize = 0;
            MemoryStream ms        = new MemoryStream();

            using (Image <Rgba32> image = Image.Load <Rgba32>(model.PhotoFile.OpenReadStream()))
            {
                if (model.DoResize)
                {
                    image.Mutate(x => x
                                 .Resize(model.ResizeWidth, model.ResizeHeight)
                                 );
                }

                image.Save(ms, Helpers.Helpers.ResolveImageEncoder(extension));

                photo.Width  = image.Width;
                photo.Height = image.Height;
            }


            photo.Url = _storageStrategy.Store(ms, uniqueFileName, out imageSize);

            ms.Close();
            photo.Size = imageSize;

            _db.Photos.Add(photo);
            AddHashtagsToPhoto(hashtags, photo.Id);
            _db.SaveChanges();

            return(photo);
        }
コード例 #2
0
 /// <summary>Stores authorization token passed as an argument in the underlying storage strategy implementation.</summary>
 /// <param name="token">Token instance to be stored.</param>
 public void StoreToken(OAuthTokenDTO token)
 {
     _storageStrategy.Store(token);
 }
コード例 #3
0
 /// <summary>Stores authorization token passed as an argument in the underlying storage strategy implementation.</summary>
 /// <param name="token">Token instance to be stored.</param>
 public void StoreToken(OAuthTokenDTO token)
 {
     _storageStrategy.Store(token, GetEnvKey());
 }