Exemplo n.º 1
0
        public JsonNetResult DeleteGalleryImageForObject(string objectType, string objectId, string groupNameKey, string formatNameKey, int imageIndex)
        {
            var response = new ApplicationImagesService.DataAccessResponseType();

            #region Delete Image

            var user = AuthenticationCookieManager.GetAuthenticationCookie();

            try
            {
                var applicationImagesServicesClient = new ApplicationImagesServiceClient();
                response = applicationImagesServicesClient.DeleteGalleryImage(user.AccountID.ToString(), objectType, objectId, groupNameKey, formatNameKey, imageIndex, user.Id, ApplicationImagesService.RequesterType.AccountUser, Common.SharedClientKey);
            }
            catch (Exception e)
            {
                response.isSuccess    = false;
                response.ErrorMessage = e.Message;
            }

            #endregion

            #region Handle Caching Expiration on Account image type

            if (objectType == "account")
            {
                //Expire accountimages cache
                RedisCacheKeys.AccountImages.Expire(user.AccountNameKey);
            }

            #endregion

            #region Handle Results

            JsonNetResult jsonNetResult = new JsonNetResult();
            jsonNetResult.Formatting = Newtonsoft.Json.Formatting.Indented;
            jsonNetResult.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Local; //<-- Convert UTC times to LocalTime
            jsonNetResult.Data = response;

            return(jsonNetResult);

            #endregion
        }
Exemplo n.º 2
0
        public JsonNetResult ProcessImage(string imageId, string objectType, string objectId, string imageGroupNameKey, string imageFormatNameKey, string containerName, string imageFormat, string type, int quality, float top, float left, float right, float bottom, string title, string description, string tags, int brightness, int contrast, int saturation, int sharpness, bool sepia, bool polaroid, bool greyscale)
        {
            var response = new ApplicationImagesService.DataAccessResponseType();


            #region Generate Job Models

            var imageProcessingManifest = new ImageProcessingManifestModel
            {
                SourceContainerName = containerName,
                FileName            = imageId + "." + imageFormat,

                GroupTypeNameKey = objectType,
                ObjectId         = objectId,

                Type    = type,
                Quality = quality,

                GroupNameKey  = imageGroupNameKey,
                FormatNameKey = imageFormatNameKey,

                ImageId     = imageId,
                Title       = title,
                Description = description
            };


            var imageCropCoordinates = new ImageCropCoordinates
            {
                Top    = top,
                Left   = left,
                Right  = right,
                Bottom = bottom
            };

            var imageEnhancementInstructions = new ImageEnhancementInstructions();

            if (brightness != 0 || contrast != 0 || saturation != 0 || saturation != 0 || sharpness != 0 || sepia == true || polaroid == true || greyscale == true)
            {
                imageEnhancementInstructions.Brightness = brightness;
                imageEnhancementInstructions.Contrast   = contrast;
                imageEnhancementInstructions.Saturation = saturation;
                imageEnhancementInstructions.Sharpen    = sharpness;
                imageEnhancementInstructions.Sepia      = sepia;
                imageEnhancementInstructions.Greyscale  = greyscale;
                imageEnhancementInstructions.Polaroid   = polaroid;
            }
            else
            {
                imageEnhancementInstructions = null;
            }



            #endregion

            #region Submit Job

            var user    = AuthenticationCookieManager.GetAuthenticationCookie();
            var account = Common.GetAccountObject(user.AccountNameKey);

            try
            {
                var applicationImagesServicesClient = new ApplicationImagesServiceClient();
                response = applicationImagesServicesClient.ProcessImage(user.AccountID.ToString(), imageProcessingManifest, imageCropCoordinates, user.Id, ApplicationImagesService.RequesterType.AccountUser, imageEnhancementInstructions, Common.SharedClientKey);
            }
            catch (Exception e)
            {
                response.isSuccess    = false;
                response.ErrorMessage = e.Message;
            }

            #endregion

            #region Handle Caching Expiration on Account image type

            if (objectType == "account")
            {
                //Expire accountimages cache
                RedisCacheKeys.AccountImages.Expire(user.AccountNameKey);
            }

            #endregion

            //Append account CDN url to Success message (newImageUrlPath)
            var storagePartition = CoreServices.PlatformSettings.StorageParitions.FirstOrDefault(partition => partition.Name == account.StoragePartition);
            response.SuccessMessage = "https://" + storagePartition.CDN + "/" + response.SuccessMessage;

            #region Handle Results

            JsonNetResult jsonNetResult = new JsonNetResult();
            jsonNetResult.Formatting = Newtonsoft.Json.Formatting.Indented;
            jsonNetResult.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Local; //<-- Convert UTC times to LocalTime
            jsonNetResult.Data = response;

            return(jsonNetResult);

            #endregion
        }