internal static UserActivity ComposeActivityByPhotos(Album album) { UserActivity ua = new UserActivity(); ua.ContentID = GetAlbumContentID(album); ua.TenantID = CurrentTenantID; ua.Date = ASC.Core.Tenants.TenantUtil.DateTimeNow(); ua.ModuleID = PhotoConst.ModuleID; ua.ProductID = ASC.Web.Community.Product.CommunityProduct.ID; ua.Title = album.Event.Name; ua.URL = String.Format("{0}?item={1}", PhotoConst.ViewAlbumPageUrl, album.Id); return ua; }
private void GetRequestParams() { var selectedID = Request.QueryString[PhotoConst.PARAM_ALBUM]; long id; if (!string.IsNullOrEmpty(selectedID) && long.TryParse(selectedID, out id)) { var storage = StorageFactory.GetStorage(); selectedAlbum = storage.GetAlbum(id); editable = false; } if (selectedAlbum == null) if (!Int64.TryParse(Request[PhotoConst.PARAM_EVENT], out requestedEvent)) requestedEvent = -1; }
public static void AddPhoto(Album album, Guid authorID, IList<AlbumItem> images) { var ua = ApplyCustomeActivityParams( ComposeActivityByPhotos(album), Resources.PhotoManagerResource.UserActivity_AddPhoto, authorID, UserActivityConstants.ContentActionType, PhotoConst.AddPhotoBusinessValue ); var builder = new StringBuilder(); IDataStore store = ASC.Data.Storage.StorageFactory.GetStorage(CoreContext.TenantManager.GetCurrentTenant().TenantId.ToString(), "photo"); foreach (var albumItem in images) { builder.AppendFormat("<img style=\"margin:10px;\" src=\"{0}\"/>", ImageHTMLHelper.GetImageUrl(albumItem.ExpandedStoreThumb, store)); } ua.HtmlPreview = builder.ToString(); PublishInternal(ua); }
public void SaveAlbum(Album album, IEnumerable<AlbumItem> newItems) { if (album == null) throw new ArgumentNullException("album"); if (album.Event == null) throw new ArgumentNullException("album.Event can not be null."); if (album.Id != 0) { DbManager .ExecuteList(Query("photo_album").Select("ImagesCount", "ViewsCount", "CommentsCount").Where("Id", album.Id)) .ForEach(r => { album.ImagesCount = (int)Convert.ToInt64(r[0]); album.ViewsCount = (int)Convert.ToInt64(r[1]); album.CommentsCount = (int)Convert.ToInt64(r[2]); }); } album.Id = DbManager.ExecuteScalar<long>( Insert("photo_album") .InColumns(Mappers.AlbumColumns) .Values(album.Id, album.Caption, album.UserID, album.Event.Id, album.FaceItem != null ? album.FaceItem.Id : 0, DateTime.UtcNow, album.ImagesCount, album.ViewsCount, album.CommentsCount) .Identity(1, 0L, true) ); if (newItems != null && newItems.Count() > 0) { NotifyAlbumSave(album, newItems); } }
public void SaveAlbum(Album album) { SaveAlbum(album, null); }
private void LoadThumbnails(Album AlbumItem) { var storage = StorageFactory.GetStorage(); var store = Data.Storage.StorageFactory.GetStorage(TenantProvider.CurrentTenantID.ToString(), "photo"); var items = storage.GetAlbumItems(AlbumItem); var thumbnails = new List<Dictionary<String, String>>(); for (int i = 0, n = items.Count; i < n; i++) { var thumbnail = new Dictionary<String, String>(); thumbnail.Add("Id", items[i].Id.ToString()); thumbnail.Add("Name", (items[i].Name ?? string.Empty).HtmlEncode()); thumbnail.Add("Src", ImageHTMLHelper.GetImageUrl(items[i].ExpandedStoreThumb, store)); thumbnails.Add(thumbnail); } PhotoThumbnails.DataSource = thumbnails; PhotoThumbnails.DataBind(); }
public override FileUploadResult ProcessUpload(HttpContext context) { if (!ASC.Core.SecurityContext.AuthenticateMe(CookiesManager.GetCookies(CookiesType.AuthKey))) { return new FileUploadResult { Success = false, Message = "Permission denied" }; } var result = ""; try { if (ProgressFileUploader.HasFilesToUpload(context)) { var postedFile = new ProgressFileUploader.FileToUpload(context); var fileName = postedFile.FileName; var inputStream = postedFile.InputStream; var store = Data.Storage.StorageFactory.GetStorage(TenantProvider.CurrentTenantID.ToString(), "photo"); var storage = StorageFactory.GetStorage(); var uid = context.Request["uid"]; var eventID = context.Request["eventID"]; var albums = storage.GetAlbums(Convert.ToInt64(eventID), uid); var currentAlbum = 0 < albums.Count ? albums[0] : null; if (currentAlbum == null) { var Event = storage.GetEvent(Convert.ToInt64(eventID)); currentAlbum = new Album { Event = Event, UserID = uid }; storage.SaveAlbum(currentAlbum); } if (context.Session["photo_albumid"] != null) { context.Session["photo_albumid"] = currentAlbum.Id; } var fileNamePath = PhotoConst.ImagesPath + uid + "/" + currentAlbum.Id + "/"; var currentImageInfo = new ImageInfo(); var listFiles = store.ListFilesRelative("", fileNamePath, "*.*", false); context.Session["photo_listFiles"] = listFiles; var fileExtension = FileUtility.GetFileExtension(fileName); var fileNameWithOutExtension = GetFileName(fileName); var addSuffix = string.Empty; //if file already exists var i = 1; while (CheckFile(listFiles, fileNameWithOutExtension + addSuffix + PhotoConst.THUMB_SUFFIX + fileExtension)) { addSuffix = "(" + i.ToString() + ")"; i++; } var fileNameThumb = fileNamePath + fileNameWithOutExtension + addSuffix + PhotoConst.THUMB_SUFFIX + "." + PhotoConst.jpeg_extension; var fileNamePreview = fileNamePath + fileNameWithOutExtension + addSuffix + PhotoConst.PREVIEW_SUFFIX + "." + PhotoConst.jpeg_extension; currentImageInfo.Name = fileNameWithOutExtension; currentImageInfo.PreviewPath = fileNamePreview; currentImageInfo.ThumbnailPath = fileNameThumb; var fs = inputStream; try { var reader = new EXIFReader(fs); currentImageInfo.ActionDate = (string) reader[PropertyTagId.DateTime]; } catch { } ImageHelper.GenerateThumbnail(fs, fileNameThumb, ref currentImageInfo, store); ImageHelper.GeneratePreview(fs, fileNamePreview, ref currentImageInfo, store); fs.Dispose(); var image = new AlbumItem(currentAlbum) { Name = currentImageInfo.Name, Timestamp = ASC.Core.Tenants.TenantUtil.DateTimeNow(), UserID = uid, Location = currentImageInfo.Name, PreviewSize = new Size(currentImageInfo.PreviewWidth, currentImageInfo.PreviewHeight), ThumbnailSize = new Size(currentImageInfo.ThumbnailWidth, currentImageInfo.ThumbnailHeight) }; storage.SaveAlbumItem(image); currentAlbum.FaceItem = image; storage.SaveAlbum(currentAlbum); var response = image.Id.ToString(); var byteArray = System.Text.Encoding.UTF8.GetBytes(response); result = Convert.ToBase64String(byteArray); } } catch (Exception ex) { return new FileUploadResult { Success = false, Message = ex.Message, }; } return new FileUploadResult { Success = true, Data = "", Message = result }; }
public PhotoAlbumWrapper(Album album) { Id=album.Id; Title=album.Caption; Image = new PhotoAlbumItemWrapper(album.FaceItem); }
public AlbumItem GetAlbumItem(Album album, int index) { if (album == null) return null; var images = DbManager .ExecuteList( Query("photo_image") .Select(Mappers.ImageColumns) .Where("Album", album.Id) .OrderBy("Name", true) .OrderBy("Id", true) .SetMaxResults(1).SetFirstResult(index)) .ConvertAll(r => Mappers.ToImage(r)); if (images.Count == 0) return null; var image = images[0]; image.Album = album; if (album != null && album.FaceImageId == image.Id) album.FaceItem = image; return image; }
private List<string> CreateImagesInfoBySimple() { var info = new List<string>(); var store = Data.Storage.StorageFactory.GetStorage(TenantProvider.CurrentTenantID.ToString(), "photo"); var storage = StorageFactory.GetStorage(); var uid = SecurityContext.CurrentAccount.ID.ToString(); var eventID = Request["events_selector"]; var albums = storage.GetAlbums(Convert.ToInt64(eventID), uid); var currentAlbum = 0 < albums.Count ? albums[0] : null; if (currentAlbum == null) { var Event = storage.GetEvent(Convert.ToInt64(eventID)); currentAlbum = new Album {Event = Event, UserID = uid}; storage.SaveAlbum(currentAlbum); } var fileNamePath = PhotoConst.ImagesPath + uid + "/" + currentAlbum.Id + "/"; var listFiles = store.ListFilesRelative("", fileNamePath, "*.*", false); for (var j = 0; j < Request.Files.Count; j++) { var file = Request.Files[j]; if (file.ContentLength > SetupInfo.MaxUploadSize) continue; if (string.IsNullOrEmpty(file.FileName)) continue; var currentImageInfo = new ImageInfo(); var fileExtension = FileUtility.GetFileExtension(file.FileName); var fileNameWithOutExtension = FileUtility.GetFileName(file.FileName); var addSuffix = string.Empty; var i = 1; while (CheckFile(listFiles, fileNameWithOutExtension + addSuffix + PhotoConst.THUMB_SUFFIX + fileExtension)) { addSuffix = "(" + i.ToString() + ")"; i++; } var fileNameThumb = fileNamePath + fileNameWithOutExtension + addSuffix + PhotoConst.THUMB_SUFFIX + "." + PhotoConst.jpeg_extension; var fileNamePreview = fileNamePath + fileNameWithOutExtension + addSuffix + PhotoConst.PREVIEW_SUFFIX + "." + PhotoConst.jpeg_extension; currentImageInfo.Name = fileNameWithOutExtension; currentImageInfo.PreviewPath = fileNamePreview; currentImageInfo.ThumbnailPath = fileNameThumb; var fs = file.InputStream; try { var reader = new EXIFReader(fs); currentImageInfo.ActionDate = (string) reader[PropertyTagId.DateTime]; } catch { } ImageHelper.GenerateThumbnail(fs, fileNameThumb, ref currentImageInfo, store); ImageHelper.GeneratePreview(fs, fileNamePreview, ref currentImageInfo, store); fs.Dispose(); var image = new AlbumItem(currentAlbum) { Name = currentImageInfo.Name, Timestamp = ASC.Core.Tenants.TenantUtil.DateTimeNow(), UserID = uid, Location = currentImageInfo.Name, PreviewSize = new Size(currentImageInfo.PreviewWidth, currentImageInfo.PreviewHeight), ThumbnailSize = new Size(currentImageInfo.ThumbnailWidth, currentImageInfo.ThumbnailHeight) }; storage.SaveAlbumItem(image); currentAlbum.FaceItem = image; storage.SaveAlbum(currentAlbum); info.Add(image.Id.ToString()); } return info; }
protected void Page_Load(object sender, EventArgs e) { try { // Get the data HttpPostedFile jpeg_image_upload = Request.Files["Filedata"]; IDataStore store = StorageFactory.GetStorage(TenantProvider.CurrentTenantID.ToString(), "photo"); var storage = ASC.PhotoManager.Model.StorageFactory.GetStorage(); string uid = Request["uid"]; string eventID = Request["eventID"]; bool clearSession = false; Album currentAlbum = null; var albums = storage.GetAlbums(Convert.ToInt64(eventID), uid); clearSession = true; currentAlbum = 0 < albums.Count ? albums[0] : null; if (currentAlbum == null) { Event Event = storage.GetEvent(Convert.ToInt64(eventID)); currentAlbum = new Album(); currentAlbum.Event = Event; currentAlbum.UserID = uid; storage.SaveAlbum(currentAlbum); } if (Session["photo_albumid"] != null) { if (currentAlbum.Id != (long)Session["photo_albumid"]) clearSession = true; Session["photo_albumid"] = currentAlbum.Id; } else clearSession = true; string fileNamePath = Resources.PhotoManagerResource.ImagesPath + uid + "/" + currentAlbum.Id + "/"; ImageInfo currentImageInfo = new ImageInfo(); string[] listFiles; if (Session["photo_listFiles"] != null && !clearSession) listFiles = (string[])Session["photo_listFiles"]; else { listFiles = store.ListFilesRelative("", fileNamePath, "*.*", false); Session["photo_listFiles"] = listFiles; } string fileExtension = GetFileExtension(jpeg_image_upload.FileName); string fileNameWithOutExtension = GetFileName(jpeg_image_upload.FileName); string addSuffix = string.Empty; //if file already exists int i = 1; while (CheckFile(listFiles, fileNameWithOutExtension + addSuffix + Constants.THUMB_SUFFIX + fileExtension)) { addSuffix = "(" + i.ToString() + ")"; i++; } string fileNameThumb = fileNamePath + fileNameWithOutExtension + addSuffix + Constants.THUMB_SUFFIX + "." + Constants.jpeg_extension; string fileNamePreview = fileNamePath + fileNameWithOutExtension + addSuffix + Constants.PREVIEW_SUFFIX + "." + Constants.jpeg_extension; currentImageInfo.Name = fileNameWithOutExtension; currentImageInfo.PreviewPath = fileNamePreview; currentImageInfo.ThumbnailPath = fileNameThumb; Stream fs = jpeg_image_upload.InputStream; try { EXIFReader reader = new EXIFReader(fs); currentImageInfo.ActionDate = (string)reader[PropertyTagId.DateTime]; } catch { } ImageHelper.GenerateThumbnail(fs, fileNameThumb, ref currentImageInfo, store); ImageHelper.GeneratePreview(fs, fileNamePreview, ref currentImageInfo, store); fs.Dispose(); AlbumItem image = new AlbumItem(currentAlbum); image.Name = currentImageInfo.Name; image.Timestamp = ASC.Core.Tenants.TenantUtil.DateTimeNow(); image.UserID = uid; image.Location = currentImageInfo.Name; image.PreviewSize = new Size(currentImageInfo.PreviewWidth, currentImageInfo.PreviewHeight); image.ThumbnailSize = new Size(currentImageInfo.ThumbnailWidth, currentImageInfo.ThumbnailHeight); storage.SaveAlbumItem(image); currentAlbum.FaceItem = image; storage.SaveAlbum(currentAlbum); string response = image.Id.ToString(); byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(response); string encodingResponse = Convert.ToBase64String(byteArray); Response.StatusCode = 200; Response.Write(encodingResponse); } catch { // If any kind of error occurs return a 500 Internal Server error Response.StatusCode = 500; Response.Write("An error occured"); Response.End(); } finally { Response.End(); } }
public static void EditPhoto(Album album, Guid authorID) { var ua = ApplyCustomeActivityParams( ComposeActivityByPhotos(album), Resources.PhotoManagerResource.UserActivity_EditPhoto, authorID, UserActivityConstants.ActivityActionType, PhotoConst.EditPhotoBusinessValue); PublishInternal(ua); }
internal static string GetAlbumContentID(Album album) { return String.Format("album#{0}", album.Id); }
public AlbumItem(Album album) : this() { if (album == null) throw new ArgumentNullException("album"); Album = album; }
private void NotifyAlbumSave(Album currentAlbum, IEnumerable<AlbumItem> newItems) { var initiatorInterceptor = new InitiatorInterceptor(new DirectRecipient(SecurityContext.CurrentAccount.ID.ToString(), "")); try { NotifyClient.AddInterceptor(initiatorInterceptor); NotifyClient.BeginSingleRecipientEvent("photo uploaded"); var albumUrl = UrlHelper.GetAbsoluteAlbumUrl(currentAlbum.Id); var eventUrl = UrlHelper.GetAbsoluteEventUrl(currentAlbum.Event.Id); var userName = DisplayUserSettings.GetFullUserName(SecurityContext.CurrentAccount.ID); var userUrl = CommonLinkUtility.GetFullAbsolutePath(CommonLinkUtility.GetUserProfile(SecurityContext.CurrentAccount.ID, ASC.Web.Community.Product.CommunityProduct.ID)); NotifyClient.SendNoticeAsync( PhotoConst.NewPhotoUploaded, null, null, new[]{ new TagValue(PhotoConst.TagEventName, currentAlbum.Event.Name), new TagValue(PhotoConst.TagUserName, userName), new TagValue(PhotoConst.TagUserURL, userUrl), new TagValue(PhotoConst.TagPhotoCount, newItems.Count()), new TagValue(PhotoConst.TagDate, string.Format("{0:d} {0:t}", TenantUtil.DateTimeNow())), new TagValue(PhotoConst.TagURL, albumUrl), new TagValue(PhotoConst.TagEventUrl, eventUrl), new TagValue("PHOTO_UPLOAD", true)}); } finally { NotifyClient.EndSingleRecipientEvent("photo uploaded"); NotifyClient.RemoveInterceptor(initiatorInterceptor.Name); } PhotoUserActivityPublisher.AddPhoto(currentAlbum, SecurityContext.CurrentAccount.ID, newItems.ToList()); }
private void SavePhotoItem(int i) { var storage = StorageFactory.GetStorage(); var image = storage.GetAlbumItem(Convert.ToInt64(Request.Form["image_id_" + i])); if (selectedAlbum == null) selectedAlbum = image.Album; image.Name = GetLimitedText(Request.Form[PhotoConst.PARAM_EDIT_NAME + i]); storage.SaveAlbumItem(image); }
public List<AlbumItem> GetAlbumItems(Album album) { if (album == null) return new List<AlbumItem>(); var images = DbManager .ExecuteList(Query("photo_image").Select(Mappers.ImageColumns).Where("Album", album.Id).OrderBy("Name", true).OrderBy("Id", true)) .ConvertAll(r => Mappers.ToImage(r)); images.ForEach(i => { i.Album = album; if (i.Id == album.FaceImageId) album.FaceItem = i; }); return images; }
protected void btnUpload_Click(object sender, EventArgs e) { var photoCount = 0; var simpleUploader = false; var sb = new StringBuilder(); IList<AlbumItem> images = new List<AlbumItem>(); var storage = StorageFactory.GetStorage(); try { var eventID = Convert.ToInt64(Request.Form["events_selector"]); var authorID = SecurityContext.CurrentAccount.ID.ToString(); Album currentAlbum = null; if (selectedAlbum != null) { currentAlbum = selectedAlbum; } else if (string.IsNullOrEmpty(authorID)) return; else if (authorID != "0") { var albums = storage.GetAlbums(eventID, authorID); currentAlbum = 0 < albums.Count ? albums[0] : null; } if (currentAlbum == null) { var Event = storage.GetEvent(eventID); currentAlbum = new Album(); currentAlbum.Event = Event; currentAlbum.UserID = SecurityContext.CurrentAccount.ID.ToString(); storage.SaveAlbum(currentAlbum); } var imagesInfo = !simpleUploader ? CreateImagesInfo(Request.Form["phtm_imagesInfo"]) : CreateImagesInfoBySimple(); if (imagesInfo != null) { var i = 0; var store = Data.Storage.StorageFactory.GetStorage(TenantProvider.CurrentTenantID.ToString(), "photo"); foreach (var info in imagesInfo) { var item = storage.GetAlbumItem(Convert.ToInt64(info)); images.Add(item); if (photoCount != 0 && photoCount%3 == 0) sb.Append("</div>"); if (photoCount%3 == 0) sb.Append("<div class=\"borderLight tintMediumLight clearFix\" style=\"padding:20px; border-left:none;border-right:none;margin-bottom:8px;\">"); sb.Append("<div style='float:left;margin-bottom:5px;" + (photoCount%3 == 0 ? "" : "margin-left:22px; ") + "'>"); sb.Append(AddPreviewImage(ImageHTMLHelper.GetImageUrl(item.ExpandedStorePreview, store), item.Name, item.Id, i == 0, i, item.PreviewSize.Width, item.PreviewSize.Height)); sb.Append("</div>"); i++; photoCount++; } } sb.Append("</div>"); ltrUploadedImages.Text = sb.ToString(); pnlImageForm.Visible = false; pnlSave.Visible = true; storage.SaveAlbum(currentAlbum, images); } catch (Exception) { } }
private void UpdateImage(int index) { var storage = StorageFactory.GetStorage(); AlbumItem image = storage.GetAlbumItem(Convert.ToInt64(Request.Form[ASC.PhotoManager.PhotoConst.PARAM_EDIT_ITEMID + index])); image.Name = GetLimitedText(Request.Form[ASC.PhotoManager.PhotoConst.PARAM_EDIT_NAME + index]); if (albumForPublisher == null) albumForPublisher = image.Album; storage.SaveAlbumItem(image); }
private string GetAlbumInfo(Album item) { var sb = new StringBuilder(); var face = item.FaceItem; var date = item.LastUpdate; var store = Data.Storage.StorageFactory.GetStorage("~/Products/Community/Modules/PhotoManager/web.config", TenantProvider.CurrentTenantID.ToString(), "photo", HttpContext.Current); var albumURL = VirtualPathUtility.ToAbsolute(PhotoConst.AddonPath + PhotoConst.PAGE_PHOTO) + "?" + PhotoConst.PARAM_ALBUM + "=" + item.Id; sb.Append("<div style=\"margin-bottom:10px;\">"); sb.Append("<table cellpadding='0' cellspacing='0' border='0'><tr valign=\"top\"><td style=\"width:60px;\">"); sb.Append(GetHTMLSmallThumb(face, 54, albumURL, store)); sb.Append("</td><td>"); sb.Append("<div style='padding-left:10px;'>"); sb.Append("<div style=\"margin-top:2px;\">"); sb.Append("<a class='linkHeaderLightMedium' href='" + VirtualPathUtility.ToAbsolute(PhotoConst.AddonPath + PhotoConst.PAGE_DEFAULT) + "?" + PhotoConst.PARAM_EVENT + "=" + item.Event.Id + "'>" + HttpUtility.HtmlEncode(item.Event.Name) + "</a>"); sb.Append("</div>"); sb.Append("<div style=\"margin-top: 6px;\">"); sb.Append("<a class='linkHeaderSmall' href='" + albumURL + "'>" + (face != null ? DisplayUserSettings.GetFullUserName(new Guid(face.UserID)) : "") + "</a>"); sb.Append("</div>"); sb.Append("<div style=\"margin-top: 5px;\">"); sb.Append("<a href='" + albumURL + "'>" + Grammatical.PhotosCount("{0} {1}", item.ImagesCount) + "</a>"); sb.Append("<span class='textMediumDescribe' style='margin-left:10px;'>" + date.ToShortDateString() + "</span>"); sb.Append("</div>"); sb.Append("</div>"); sb.Append("</td></tr></table>"); sb.Append("</div>"); return sb.ToString(); }