Cloudinary upload call takes too longerlong
I can notcannot reply to any of the comments below as my reputation is under 50.
Cloudinary upload call takes too longer
I can not reply to any of comments below as my reputation is under 50.
Cloudinary upload call takes too long
I cannot reply to any of the comments below as my reputation is under 50.
Calls to Cloudinary for manipulation or image upload call takes too longer
I can not reply to any of comments below as my reputation is under 50.
Calls to Cloudinary for manipulation or image upload
Cloudinary upload call takes too longer
I can not reply to any of comments below as my reputation is under 50.
How I optimize the performance of this code? Calls to Cloudinary for manipulation or image upload
public async Task<ActionResult> most_loved_pix()
{
var access_token = HttpContext.Items["access_token"].ToString();
if (!string.IsNullOrEmpty(access_token))
{
Account account = new Account();
account.Cloud = ConfigurationManager.AppSettings["CloudName"];
account.ApiKey = ConfigurationManager.AppSettings["CloudinaryAPI"];
account.ApiSecret = ConfigurationManager.AppSettings["CloudinarySecret"];
Cloudinary cloudinary = new Cloudinary(account);
var access_token = HttpContext.Items["access_token"].ToString();
if (!string.IsNullOrEmpty(access_token))
var{
appsecret_proof Account account = access_token.GenerateAppSecretProofnew Account();
account.Cloud = ConfigurationManager.AppSettings["CloudName"];
account.ApiKey = ConfigurationManager.AppSettings["CloudinaryAPI"];
account.ApiSecret = ConfigurationManager.AppSettings["CloudinarySecret"];
varCloudinary fbcloudinary = new FacebookClientCloudinary(access_tokenaccount);
#region FacebookUser Name and Picture plus other Info
//Get current user's profile
dynamicvar myInfoappsecret_proof = await fb.GetTaskAsync("me?fields=id,first_name,last_name,link,locale,email,name,birthday,gender,location,age_range,about"access_token.GraphAPICallGenerateAppSecretProof(appsecret_proof));
dynamicvar myinfojsonfb = JsonConvert.DeserializeObject(myInfo.ToStringnew FacebookClient()access_token);
#region FacebookUser Name and stringPicture userNameplus =other myinfojson.name;Info
string//Get userIdcurrent =user's myinfojson.id;profile
stringdynamic firstNamemyInfo = myinfojsonawait fb.first_name;GetTaskAsync("me?fields=id,first_name,last_name,link,locale,email,name,birthday,gender,location,age_range,about".GraphAPICall(appsecret_proof));
//get current picture
dynamic profileImgResultmyinfojson = await fb.GetTaskAsync("{0}/picture?width=200&height=200&redirect=false"JsonConvert.GraphAPICall(DeserializeObject(string)myInfo.id, appsecret_proofToString());
string userName = myinfojson.name;
ViewBag.ProfilePictureURL = profileImgResult.data.url;
string userId = myinfojson.id;
string firstName = #endregionmyinfojson.first_name;
//get current picture
dynamic myAlbumsprofileImgResult = await fb.GetTaskAsync(
("me"{0}/albumspicture?fields = id,name")
width=200&height=200&redirect=false".GraphAPICall(appsecret_proof));
(string result = myAlbums)myInfo.ToString(id, appsecret_proof));
ViewBag.ProfilePictureURL = profileImgResult.data.url;
#endregion
vardynamic jsonResultmyAlbums = JsonConvertawait fb.DeserializeObject<AlbumsRootObject>GetTaskAsync(result);
if (jsonResult.data.Count"me/albums?fields <= 1id,name")
{
return RedirectToAction.GraphAPICall("Index", "Home"appsecret_proof));
string result = }myAlbums.ToString();
foreach (var AlbumItems in jsonResult.data.Where(i => i.name == "Profile Pictures"))
{
var jsonResult = JsonConvert.DeserializeObject<AlbumsRootObject>(result);
if string(jsonResult.data.Count albumIdstring< =1)
AlbumItems.id.ToString {
return RedirectToAction("Index", "Home");
}
foreach (var AlbumItems in jsonResult.data.Where(i => i.name == "Profile Pictures"))
string AlbumId = albumIdstring.Trim('"'); {
dynamic myProfilePictures = await fb.GetTaskAsync(
(string.Format("{0}/photos", AlbumId)
albumIdstring += "?fields=images,likes.summary(total_count),comments.summary(total_count),reactions.type(LOVE)AlbumItems.summary(true)&limit=10")
id.GraphAPICallToString(appsecret_proof));
string picturesAlbumId = myProfilePicturesalbumIdstring.ToStringTrim('"');
dynamic myProfilePictures = await fb.GetTaskAsync(
var picturesResult = JsonConvert (string.DeserializeObject<ProfilePicturesRootObject>Format(pictures"{0}/photos", AlbumId)
+ "?fields=images,likes.summary(total_count),comments.summary(total_count),reactions.type(LOVE).summary(true)&limit=10")
.GraphAPICall(appsecret_proof));
#region MostLiked
var likesSummary = new List<ProfilePicturesSummary>();
varstring likesImagespictures = new List<ProfilePicturesImage>myProfilePictures.ToString();
foreach (var LikesItems in picturesResult.data)
{
likesSummary.Add(LikesItems.likes.summary);
foreach (var imagesLiked in LikesItems.images)
{
likesImages.Add(imagesLiked);
break;
}
}
var maxLikeCount = likesSummaryJsonConvert.MaxDeserializeObject<ProfilePicturesRootObject>( l => l.total_countpictures);
#region MostLiked
var maxlikecountindexlikesSummary = likesSummary.FindIndexnew List<ProfilePicturesSummary>(a);
=> a.total_count == maxLikeCount var likesImages = new List<ProfilePicturesImage>();
foreach (var LikesItems in picturesResult.data)
{
likesSummary.Add(LikesItems.likes.summary);
foreach (var imageindeximagesLiked in LikesItems.images)
{
likesImages.Add(imagesLiked);
break;
}
}
var maxLikeCount = likesImages[maxlikecountindex];likesSummary.Max( l => l.total_count);
var maxlikecountindex = likesSummary.FindIndex(a string=> mostlikedImageSourceRawURLa.total_count === imageindex.source.ToString(maxLikeCount);
stringvar mostlikedImageSourceTrimedURLimageindex = mostlikedImageSourceRawURL.Trim('"');likesImages[maxlikecountindex];
if (!string.IsNullOrEmpty(mostlikedImageSourceRawURL))
{
var UsersMostLikedtextParams = new TextParams("دوست داشتنی")
{
PublicIdmostlikedImageSourceRawURL = stringimageindex.Format("MostLiked{0}", userId),
FontFamily = "Amiri",
//FontWeight = "regular",
FontSize = 40,
TextAlign = "center",
FontColor = "blue",
Background = "white",
Opacity = "60"
};
var textResult = cloudinarysource.TextToString(UsersMostLikedtextParams);
var usersMostLikedImage = new ImageUploadParams()
{
File = new FileDescription(mostlikedImageSourceTrimedURL),
PublicId = string.Format("MostLiked{0}", AlbumId),
Tags = "Most Liked Picture, Facebook",
Transformation = new Transformation().Border("1px_solid_blue")
.Width(233).Height(320).Crop("fill")
.Chain().Overlay("like.png").Flags("relative").Gravity("north_east").Width(65).Height(65)
.Chain().Overlay(string.Format("text:MostLiked{0}.png", userId)).Radius(20).Gravity("south").Y(20)
};
var userMostLikedImageResultmostlikedImageSourceTrimedURL = cloudinarymostlikedImageSourceRawURL.UploadTrim(usersMostLikedImage'"');
}
#endregion
if (!string.IsNullOrEmpty(mostlikedImageSourceRawURL))
#region MostLoved {
var UsersMostLikedtextParams = new TextParams("دوست داشتنی")
{
PublicId = string.Format("MostLiked{0}", userId),
FontFamily = "Amiri",
//FontWeight = "regular",
FontSize = 40,
TextAlign = "center",
FontColor = "blue",
Background = "white",
Opacity = "60"
};
var textResult = cloudinary.Text(UsersMostLikedtextParams);
var usersMostLikedImage = new varImageUploadParams()
mostCommentedImageCommentCount {
File = new List<ProfilePicturesSummary2>FileDescription(mostlikedImageSourceTrimedURL);,
varPublicId mostCommentedImageSource= string.Format("MostLiked{0}", AlbumId),
Tags = "Most Liked Picture, Facebook",
Transformation = new List<ProfilePicturesImage>Transformation().Border("1px_solid_blue")
.Width(233).Height(320).Crop("fill")
.Chain().Overlay("like.png").Flags("relative").Gravity("north_east").Width(65).Height(65)
.Chain().Overlay(string.Format("text:MostLiked{0}.png", userId)).Radius(20).Gravity("south").Y(20)
};
var userMostLikedImageResult = cloudinary.Upload(usersMostLikedImage);
}
#endregion
foreach (var CommentItems in picturesResult.data)
{
mostCommentedImageCommentCount.Add(CommentItems.comments.summary);
foreach (var imageCommented in CommentItems.images)
{
mostCommentedImageSource.Add(imageCommented);
break;
}
#region }MostLoved
var mostCommentedImageCommentCount = new List<ProfilePicturesSummary2>();
var mostCommentCountmostCommentedImageSource = mostCommentedImageCommentCount.Max(l =>new l.total_countList<ProfilePicturesImage>();
foreach (var CommentItems in picturesResult.data)
var mostCommentCountIndex = {
mostCommentedImageCommentCount.FindIndexAdd(aCommentItems.comments.summary);
=> a foreach (var imageCommented in CommentItems.total_countimages)
== mostCommentCount {
mostCommentedImageSource.Add(imageCommented);
varbreak;
commentImageIndex = mostCommentedImageSource[mostCommentCountIndex]; }
}
stringvar mostCommentedImageRawURLmostCommentCount = commentImageIndex.sourcemostCommentedImageCommentCount.ToStringMax();
string mostCommentedImageTrimmedURLl ==> mostCommentedImageRawURLl.Trim('"'total_count);
if (!string.IsNullOrEmpty(mostCommentedImageRawURL))
{
var UsersMostLovedtextParams = new TextParams("دلپذیر")
{
PublicIdmostCommentCountIndex = stringmostCommentedImageCommentCount.FormatFindIndex("MostLoved{0}", userId),
FontFamily = "Amiri",
//FontWeight = "regular",
FontSize = 40,
TextAlign = "center",
FontColor = "red",
Background = "white",
Opacity = "60"
};
a var=> UserMostLovedtextResulta.total_count === cloudinary.Text(UsersMostLovedtextParamsmostCommentCount);
var usersMostLovedImage = new ImageUploadParams()
{
File = new FileDescription(mostCommentedImageTrimmedURL),
PublicId = string.Format("MostLoved{0}", AlbumId),
Tags = "Most Commented, Facebook",
TransformationcommentImageIndex = new Transformation().Border("1px_solid_red")
.Width(233).Height(320).Crop("fill")
.Chain().Overlay("love.png").Flags("relative").Gravity("north_east").Width(65).Height(65)
.Chain().Overlay(string.Format("text:MostLoved{0}.png", userId)).Radius(20).Gravity("south").Y(20)
};mostCommentedImageSource[mostCommentCountIndex];
varstring usersMostLovedImageResultmostCommentedImageRawURL = cloudinarycommentImageIndex.Uploadsource.ToString(usersMostLovedImage);
}
string mostCommentedImageTrimmedURL = #endregionmostCommentedImageRawURL.Trim('"');
if (!string.IsNullOrEmpty(mostCommentedImageRawURL))
#region MostCommented
{
var mostLovedImageCommentCountUsersMostLovedtextParams = new List<ProfilePicturesSummary3>TextParams("دلپذیر")
{
PublicId = string.Format("MostLoved{0}", userId),
FontFamily = "Amiri",
//FontWeight = "regular",
FontSize = 40,
TextAlign = "center",
FontColor = "red",
Background = "white",
Opacity = "60"
};
var UserMostLovedtextResult = cloudinary.Text(UsersMostLovedtextParams);
var mostLovedImageSourceusersMostLovedImage = new List<ProfilePicturesImage>ImageUploadParams()
{
File = new FileDescription(mostCommentedImageTrimmedURL),
PublicId = string.Format("MostLoved{0}", AlbumId),
Tags = "Most Commented, Facebook",
Transformation = new Transformation().Border("1px_solid_red")
.Width(233).Height(320).Crop("fill")
.Chain().Overlay("love.png").Flags("relative").Gravity("north_east").Width(65).Height(65)
.Chain().Overlay(string.Format("text:MostLoved{0}.png", userId)).Radius(20).Gravity("south").Y(20)
};
foreach (var Loved in picturesResult.data)
{
mostLovedImageCommentCount.Add(Loved.reactions.summary);
foreach (var imageLoved in Loved.images)
{
usersMostLovedImageResult = mostLovedImageSourcecloudinary.AddUpload(imageLovedusersMostLovedImage);
break;}
}
}#endregion
#region MostCommented
var mostLovedCountmostLovedImageCommentCount = mostLovedImageCommentCount.Maxnew List<ProfilePicturesSummary3>(l);
=> l.total_count var mostLovedImageSource = new List<ProfilePicturesImage>();
foreach (var Loved in picturesResult.data)
var mostLovedCountIndex = {
mostLovedImageCommentCount.FindIndexAdd(aLoved.reactions.summary);
=> a foreach (var imageLoved in Loved.total_countimages)
== mostLovedCount {
mostLovedImageSource.Add(imageLoved);
break;
}
}
var lovedImageIndexmostLovedCount = mostLovedImageSource[mostLovedCountIndex];mostLovedImageCommentCount.Max(l => l.total_count);
var mostLovedCountIndex = mostLovedImageCommentCount.FindIndex(a string=> mostLovedImageRawURLa.total_count === lovedImageIndex.source.ToString(mostLovedCount);
stringvar mostLovedImageTrimmedURLlovedImageIndex = mostLovedImageRawURL.Trim('"');mostLovedImageSource[mostLovedCountIndex];
if (!string.IsNullOrEmpty(mostLovedImageRawURL))
{
var UsersMostCommentedtextParams = new TextParams("بیشترین اظهار نظرات")
{
PublicIdmostLovedImageRawURL = stringlovedImageIndex.Format("MostComment{0}", userId),
FontFamily = "Amiri",
//FontWeight = "regular",
FontSize = 30,
TextAlign = "center",
FontColor = "green",
Background = "white",
Opacity = "60"
};
var UserMostCommentedtextResult = cloudinarysource.TextToString(UsersMostCommentedtextParams);
var mostCommentImage = new ImageUploadParams()
{
File = new FileDescription(mostLovedImageTrimmedURL),
PublicId = string.Format("MostComment{0}", AlbumId),
Tags = "Most Comment, Facebook",
Transformation = new Transformation().Border("1px_solid_green")
.Width(233).Height(320).Crop("fill")
.Chain().Overlay("comment.png").Flags("relative").Gravity("north_east").Width(65).Height(65)
.Chain().Overlay(string.Format("text:MostComment{0}.png", userId)).Radius(20).Gravity("south").Y(20)
};
var mostCommentImageResult = cloudinary.Upload(mostCommentImage);
}
#endregion
#region BuildImageFinalURL
ViewBag.ImageURLmostLovedImageTrimmedURL = cloudinary.Api.UrlImgUp.Transform(new Transformation()
.Width(233).Height(320).Overlay(string.Format("MostLiked{0}.jpg", AlbumId)).Gravity("north_west").Y(50).X(0)
.Chain().Width(233).Height(320).Overlay(string.Format("MostLoved{0}.jpg", AlbumId)).Gravity("north").Y(50).X(0)
.Chain().Width(233).Height(320).Overlay(string.Format("MostComment{0}.jpg", AlbumId)).Gravity("north_east").Y(50).X(0))
.BuildUrl("top_threemostLovedImageRawURL.jpg");
return ViewTrim('"');
if (!string.IsNullOrEmpty(mostLovedImageRawURL))
#endregion {
var UsersMostCommentedtextParams = new TextParams("بیشترین اظهار نظرات")
{
PublicId = string.Format("MostComment{0}", userId),
FontFamily = "Amiri",
//FontWeight = "regular",
FontSize = 30,
TextAlign = "center",
FontColor = "green",
Background = "white",
Opacity = "60"
};
var UserMostCommentedtextResult = cloudinary.Text(UsersMostCommentedtextParams);
var mostCommentImage = new ImageUploadParams()
{
File = new FileDescription(mostLovedImageTrimmedURL),
PublicId = string.Format("MostComment{0}", AlbumId),
Tags = "Most Comment, Facebook",
Transformation = new Transformation().Border("1px_solid_green")
.Width(233).Height(320).Crop("fill")
.Chain().Overlay("comment.png").Flags("relative").Gravity("north_east").Width(65).Height(65)
.Chain().Overlay(string.Format("text:MostComment{0}.png", userId)).Radius(20).Gravity("south").Y(20)
};
var mostCommentImageResult = cloudinary.Upload(mostCommentImage);
}
#endregion
#region BuildImageFinalURL
ViewBag.ImageURL = cloudinary.Api.UrlImgUp.Transform(new Transformation()
.Width(233).Height(320).Overlay(string.Format("MostLiked{0}.jpg", AlbumId)).Gravity("north_west").Y(50).X(0)
.Chain().Width(233).Height(320).Overlay(string.Format("MostLoved{0}.jpg", AlbumId)).Gravity("north").Y(50).X(0)
.Chain().Width(233).Height(320).Overlay(string.Format("MostComment{0}.jpg", AlbumId)).Gravity("north_east").Y(50).X(0))
.BuildUrl("top_three.jpg");
return View();
#endregion
}
}
return View();
}
How I optimize the performance of this code?
public async Task<ActionResult> most_loved_pix()
{
var access_token = HttpContext.Items["access_token"].ToString();
if (!string.IsNullOrEmpty(access_token))
{
Account account = new Account();
account.Cloud = ConfigurationManager.AppSettings["CloudName"];
account.ApiKey = ConfigurationManager.AppSettings["CloudinaryAPI"];
account.ApiSecret = ConfigurationManager.AppSettings["CloudinarySecret"];
Cloudinary cloudinary = new Cloudinary(account);
var appsecret_proof = access_token.GenerateAppSecretProof();
var fb = new FacebookClient(access_token);
#region FacebookUser Name and Picture plus other Info
//Get current user's profile
dynamic myInfo = await fb.GetTaskAsync("me?fields=id,first_name,last_name,link,locale,email,name,birthday,gender,location,age_range,about".GraphAPICall(appsecret_proof));
dynamic myinfojson = JsonConvert.DeserializeObject(myInfo.ToString());
string userName = myinfojson.name;
string userId = myinfojson.id;
string firstName = myinfojson.first_name;
//get current picture
dynamic profileImgResult = await fb.GetTaskAsync("{0}/picture?width=200&height=200&redirect=false".GraphAPICall((string)myInfo.id, appsecret_proof));
ViewBag.ProfilePictureURL = profileImgResult.data.url;
#endregion
dynamic myAlbums = await fb.GetTaskAsync(
("me/albums?fields = id,name")
.GraphAPICall(appsecret_proof));
string result = myAlbums.ToString();
var jsonResult = JsonConvert.DeserializeObject<AlbumsRootObject>(result);
if (jsonResult.data.Count < 1)
{
return RedirectToAction("Index", "Home");
}
foreach (var AlbumItems in jsonResult.data.Where(i => i.name == "Profile Pictures"))
{
string albumIdstring = AlbumItems.id.ToString();
string AlbumId = albumIdstring.Trim('"');
dynamic myProfilePictures = await fb.GetTaskAsync(
(string.Format("{0}/photos", AlbumId)
+ "?fields=images,likes.summary(total_count),comments.summary(total_count),reactions.type(LOVE).summary(true)&limit=10")
.GraphAPICall(appsecret_proof));
string pictures = myProfilePictures.ToString();
var picturesResult = JsonConvert.DeserializeObject<ProfilePicturesRootObject>(pictures);
#region MostLiked
var likesSummary = new List<ProfilePicturesSummary>();
var likesImages = new List<ProfilePicturesImage>();
foreach (var LikesItems in picturesResult.data)
{
likesSummary.Add(LikesItems.likes.summary);
foreach (var imagesLiked in LikesItems.images)
{
likesImages.Add(imagesLiked);
break;
}
}
var maxLikeCount = likesSummary.Max( l => l.total_count);
var maxlikecountindex = likesSummary.FindIndex(a => a.total_count == maxLikeCount);
var imageindex = likesImages[maxlikecountindex];
string mostlikedImageSourceRawURL = imageindex.source.ToString();
string mostlikedImageSourceTrimedURL = mostlikedImageSourceRawURL.Trim('"');
if (!string.IsNullOrEmpty(mostlikedImageSourceRawURL))
{
var UsersMostLikedtextParams = new TextParams("دوست داشتنی")
{
PublicId = string.Format("MostLiked{0}", userId),
FontFamily = "Amiri",
//FontWeight = "regular",
FontSize = 40,
TextAlign = "center",
FontColor = "blue",
Background = "white",
Opacity = "60"
};
var textResult = cloudinary.Text(UsersMostLikedtextParams);
var usersMostLikedImage = new ImageUploadParams()
{
File = new FileDescription(mostlikedImageSourceTrimedURL),
PublicId = string.Format("MostLiked{0}", AlbumId),
Tags = "Most Liked Picture, Facebook",
Transformation = new Transformation().Border("1px_solid_blue")
.Width(233).Height(320).Crop("fill")
.Chain().Overlay("like.png").Flags("relative").Gravity("north_east").Width(65).Height(65)
.Chain().Overlay(string.Format("text:MostLiked{0}.png", userId)).Radius(20).Gravity("south").Y(20)
};
var userMostLikedImageResult = cloudinary.Upload(usersMostLikedImage);
}
#endregion
#region MostLoved
var mostCommentedImageCommentCount = new List<ProfilePicturesSummary2>();
var mostCommentedImageSource = new List<ProfilePicturesImage>();
foreach (var CommentItems in picturesResult.data)
{
mostCommentedImageCommentCount.Add(CommentItems.comments.summary);
foreach (var imageCommented in CommentItems.images)
{
mostCommentedImageSource.Add(imageCommented);
break;
}
}
var mostCommentCount = mostCommentedImageCommentCount.Max(l => l.total_count);
var mostCommentCountIndex = mostCommentedImageCommentCount.FindIndex(a => a.total_count == mostCommentCount);
var commentImageIndex = mostCommentedImageSource[mostCommentCountIndex];
string mostCommentedImageRawURL = commentImageIndex.source.ToString();
string mostCommentedImageTrimmedURL = mostCommentedImageRawURL.Trim('"');
if (!string.IsNullOrEmpty(mostCommentedImageRawURL))
{
var UsersMostLovedtextParams = new TextParams("دلپذیر")
{
PublicId = string.Format("MostLoved{0}", userId),
FontFamily = "Amiri",
//FontWeight = "regular",
FontSize = 40,
TextAlign = "center",
FontColor = "red",
Background = "white",
Opacity = "60"
};
var UserMostLovedtextResult = cloudinary.Text(UsersMostLovedtextParams);
var usersMostLovedImage = new ImageUploadParams()
{
File = new FileDescription(mostCommentedImageTrimmedURL),
PublicId = string.Format("MostLoved{0}", AlbumId),
Tags = "Most Commented, Facebook",
Transformation = new Transformation().Border("1px_solid_red")
.Width(233).Height(320).Crop("fill")
.Chain().Overlay("love.png").Flags("relative").Gravity("north_east").Width(65).Height(65)
.Chain().Overlay(string.Format("text:MostLoved{0}.png", userId)).Radius(20).Gravity("south").Y(20)
};
var usersMostLovedImageResult = cloudinary.Upload(usersMostLovedImage);
}
#endregion
#region MostCommented
var mostLovedImageCommentCount = new List<ProfilePicturesSummary3>();
var mostLovedImageSource = new List<ProfilePicturesImage>();
foreach (var Loved in picturesResult.data)
{
mostLovedImageCommentCount.Add(Loved.reactions.summary);
foreach (var imageLoved in Loved.images)
{
mostLovedImageSource.Add(imageLoved);
break;
}
}
var mostLovedCount = mostLovedImageCommentCount.Max(l => l.total_count);
var mostLovedCountIndex = mostLovedImageCommentCount.FindIndex(a => a.total_count == mostLovedCount);
var lovedImageIndex = mostLovedImageSource[mostLovedCountIndex];
string mostLovedImageRawURL = lovedImageIndex.source.ToString();
string mostLovedImageTrimmedURL = mostLovedImageRawURL.Trim('"');
if (!string.IsNullOrEmpty(mostLovedImageRawURL))
{
var UsersMostCommentedtextParams = new TextParams("بیشترین اظهار نظرات")
{
PublicId = string.Format("MostComment{0}", userId),
FontFamily = "Amiri",
//FontWeight = "regular",
FontSize = 30,
TextAlign = "center",
FontColor = "green",
Background = "white",
Opacity = "60"
};
var UserMostCommentedtextResult = cloudinary.Text(UsersMostCommentedtextParams);
var mostCommentImage = new ImageUploadParams()
{
File = new FileDescription(mostLovedImageTrimmedURL),
PublicId = string.Format("MostComment{0}", AlbumId),
Tags = "Most Comment, Facebook",
Transformation = new Transformation().Border("1px_solid_green")
.Width(233).Height(320).Crop("fill")
.Chain().Overlay("comment.png").Flags("relative").Gravity("north_east").Width(65).Height(65)
.Chain().Overlay(string.Format("text:MostComment{0}.png", userId)).Radius(20).Gravity("south").Y(20)
};
var mostCommentImageResult = cloudinary.Upload(mostCommentImage);
}
#endregion
#region BuildImageFinalURL
ViewBag.ImageURL = cloudinary.Api.UrlImgUp.Transform(new Transformation()
.Width(233).Height(320).Overlay(string.Format("MostLiked{0}.jpg", AlbumId)).Gravity("north_west").Y(50).X(0)
.Chain().Width(233).Height(320).Overlay(string.Format("MostLoved{0}.jpg", AlbumId)).Gravity("north").Y(50).X(0)
.Chain().Width(233).Height(320).Overlay(string.Format("MostComment{0}.jpg", AlbumId)).Gravity("north_east").Y(50).X(0))
.BuildUrl("top_three.jpg");
return View();
#endregion
}
}
return View();
Calls to Cloudinary for manipulation or image upload
public async Task<ActionResult> most_loved_pix()
{
var access_token = HttpContext.Items["access_token"].ToString();
if (!string.IsNullOrEmpty(access_token))
{
Account account = new Account();
account.Cloud = ConfigurationManager.AppSettings["CloudName"];
account.ApiKey = ConfigurationManager.AppSettings["CloudinaryAPI"];
account.ApiSecret = ConfigurationManager.AppSettings["CloudinarySecret"];
Cloudinary cloudinary = new Cloudinary(account);
var appsecret_proof = access_token.GenerateAppSecretProof();
var fb = new FacebookClient(access_token);
#region FacebookUser Name and Picture plus other Info
//Get current user's profile
dynamic myInfo = await fb.GetTaskAsync("me?fields=id,first_name,last_name,link,locale,email,name,birthday,gender,location,age_range,about".GraphAPICall(appsecret_proof));
dynamic myinfojson = JsonConvert.DeserializeObject(myInfo.ToString());
string userName = myinfojson.name;
string userId = myinfojson.id;
string firstName = myinfojson.first_name;
//get current picture
dynamic profileImgResult = await fb.GetTaskAsync("{0}/picture?width=200&height=200&redirect=false".GraphAPICall((string)myInfo.id, appsecret_proof));
ViewBag.ProfilePictureURL = profileImgResult.data.url;
#endregion
dynamic myAlbums = await fb.GetTaskAsync(
("me/albums?fields = id,name")
.GraphAPICall(appsecret_proof));
string result = myAlbums.ToString();
var jsonResult = JsonConvert.DeserializeObject<AlbumsRootObject>(result);
if (jsonResult.data.Count < 1)
{
return RedirectToAction("Index", "Home");
}
foreach (var AlbumItems in jsonResult.data.Where(i => i.name == "Profile Pictures"))
{
string albumIdstring = AlbumItems.id.ToString();
string AlbumId = albumIdstring.Trim('"');
dynamic myProfilePictures = await fb.GetTaskAsync(
(string.Format("{0}/photos", AlbumId)
+ "?fields=images,likes.summary(total_count),comments.summary(total_count),reactions.type(LOVE).summary(true)&limit=10")
.GraphAPICall(appsecret_proof));
string pictures = myProfilePictures.ToString();
var picturesResult = JsonConvert.DeserializeObject<ProfilePicturesRootObject>(pictures);
#region MostLiked
var likesSummary = new List<ProfilePicturesSummary>();
var likesImages = new List<ProfilePicturesImage>();
foreach (var LikesItems in picturesResult.data)
{
likesSummary.Add(LikesItems.likes.summary);
foreach (var imagesLiked in LikesItems.images)
{
likesImages.Add(imagesLiked);
break;
}
}
var maxLikeCount = likesSummary.Max( l => l.total_count);
var maxlikecountindex = likesSummary.FindIndex(a => a.total_count == maxLikeCount);
var imageindex = likesImages[maxlikecountindex];
string mostlikedImageSourceRawURL = imageindex.source.ToString();
string mostlikedImageSourceTrimedURL = mostlikedImageSourceRawURL.Trim('"');
if (!string.IsNullOrEmpty(mostlikedImageSourceRawURL))
{
var UsersMostLikedtextParams = new TextParams("دوست داشتنی")
{
PublicId = string.Format("MostLiked{0}", userId),
FontFamily = "Amiri",
//FontWeight = "regular",
FontSize = 40,
TextAlign = "center",
FontColor = "blue",
Background = "white",
Opacity = "60"
};
var textResult = cloudinary.Text(UsersMostLikedtextParams);
var usersMostLikedImage = new ImageUploadParams()
{
File = new FileDescription(mostlikedImageSourceTrimedURL),
PublicId = string.Format("MostLiked{0}", AlbumId),
Tags = "Most Liked Picture, Facebook",
Transformation = new Transformation().Border("1px_solid_blue")
.Width(233).Height(320).Crop("fill")
.Chain().Overlay("like.png").Flags("relative").Gravity("north_east").Width(65).Height(65)
.Chain().Overlay(string.Format("text:MostLiked{0}.png", userId)).Radius(20).Gravity("south").Y(20)
};
var userMostLikedImageResult = cloudinary.Upload(usersMostLikedImage);
}
#endregion
#region MostLoved
var mostCommentedImageCommentCount = new List<ProfilePicturesSummary2>();
var mostCommentedImageSource = new List<ProfilePicturesImage>();
foreach (var CommentItems in picturesResult.data)
{
mostCommentedImageCommentCount.Add(CommentItems.comments.summary);
foreach (var imageCommented in CommentItems.images)
{
mostCommentedImageSource.Add(imageCommented);
break;
}
}
var mostCommentCount = mostCommentedImageCommentCount.Max(l => l.total_count);
var mostCommentCountIndex = mostCommentedImageCommentCount.FindIndex(a => a.total_count == mostCommentCount);
var commentImageIndex = mostCommentedImageSource[mostCommentCountIndex];
string mostCommentedImageRawURL = commentImageIndex.source.ToString();
string mostCommentedImageTrimmedURL = mostCommentedImageRawURL.Trim('"');
if (!string.IsNullOrEmpty(mostCommentedImageRawURL))
{
var UsersMostLovedtextParams = new TextParams("دلپذیر")
{
PublicId = string.Format("MostLoved{0}", userId),
FontFamily = "Amiri",
//FontWeight = "regular",
FontSize = 40,
TextAlign = "center",
FontColor = "red",
Background = "white",
Opacity = "60"
};
var UserMostLovedtextResult = cloudinary.Text(UsersMostLovedtextParams);
var usersMostLovedImage = new ImageUploadParams()
{
File = new FileDescription(mostCommentedImageTrimmedURL),
PublicId = string.Format("MostLoved{0}", AlbumId),
Tags = "Most Commented, Facebook",
Transformation = new Transformation().Border("1px_solid_red")
.Width(233).Height(320).Crop("fill")
.Chain().Overlay("love.png").Flags("relative").Gravity("north_east").Width(65).Height(65)
.Chain().Overlay(string.Format("text:MostLoved{0}.png", userId)).Radius(20).Gravity("south").Y(20)
};
var usersMostLovedImageResult = cloudinary.Upload(usersMostLovedImage);
}
#endregion
#region MostCommented
var mostLovedImageCommentCount = new List<ProfilePicturesSummary3>();
var mostLovedImageSource = new List<ProfilePicturesImage>();
foreach (var Loved in picturesResult.data)
{
mostLovedImageCommentCount.Add(Loved.reactions.summary);
foreach (var imageLoved in Loved.images)
{
mostLovedImageSource.Add(imageLoved);
break;
}
}
var mostLovedCount = mostLovedImageCommentCount.Max(l => l.total_count);
var mostLovedCountIndex = mostLovedImageCommentCount.FindIndex(a => a.total_count == mostLovedCount);
var lovedImageIndex = mostLovedImageSource[mostLovedCountIndex];
string mostLovedImageRawURL = lovedImageIndex.source.ToString();
string mostLovedImageTrimmedURL = mostLovedImageRawURL.Trim('"');
if (!string.IsNullOrEmpty(mostLovedImageRawURL))
{
var UsersMostCommentedtextParams = new TextParams("بیشترین اظهار نظرات")
{
PublicId = string.Format("MostComment{0}", userId),
FontFamily = "Amiri",
//FontWeight = "regular",
FontSize = 30,
TextAlign = "center",
FontColor = "green",
Background = "white",
Opacity = "60"
};
var UserMostCommentedtextResult = cloudinary.Text(UsersMostCommentedtextParams);
var mostCommentImage = new ImageUploadParams()
{
File = new FileDescription(mostLovedImageTrimmedURL),
PublicId = string.Format("MostComment{0}", AlbumId),
Tags = "Most Comment, Facebook",
Transformation = new Transformation().Border("1px_solid_green")
.Width(233).Height(320).Crop("fill")
.Chain().Overlay("comment.png").Flags("relative").Gravity("north_east").Width(65).Height(65)
.Chain().Overlay(string.Format("text:MostComment{0}.png", userId)).Radius(20).Gravity("south").Y(20)
};
var mostCommentImageResult = cloudinary.Upload(mostCommentImage);
}
#endregion
#region BuildImageFinalURL
ViewBag.ImageURL = cloudinary.Api.UrlImgUp.Transform(new Transformation()
.Width(233).Height(320).Overlay(string.Format("MostLiked{0}.jpg", AlbumId)).Gravity("north_west").Y(50).X(0)
.Chain().Width(233).Height(320).Overlay(string.Format("MostLoved{0}.jpg", AlbumId)).Gravity("north").Y(50).X(0)
.Chain().Width(233).Height(320).Overlay(string.Format("MostComment{0}.jpg", AlbumId)).Gravity("north_east").Y(50).X(0))
.BuildUrl("top_three.jpg");
return View();
#endregion
}
}
return View();
}
lang-cs