/// <summary> /// Gets and bulk updates media libraries. Called when the "Get and bulk update libraries" button is pressed. /// Expects the CreateMediaLibrary method to be run first. /// </summary> private bool GetAndBulkUpdateMediaLibraries() { // Prepare the parameters string where = "LibraryName LIKE 'MyNew%'"; // Get the data DataSet libraries = MediaLibraryInfoProvider.GetMediaLibraries(where, null); if (!DataHelper.DataSourceIsEmpty(libraries)) { // Loop through the individual items foreach (DataRow libraryDr in libraries.Tables[0].Rows) { // Create object from DataRow MediaLibraryInfo modifyLibrary = new MediaLibraryInfo(libraryDr); // Update the property modifyLibrary.LibraryDisplayName = modifyLibrary.LibraryDisplayName.ToUpper(); // Update the media library MediaLibraryInfoProvider.SetMediaLibraryInfo(modifyLibrary); } return(true); } return(false); }
public void RaisePostBackEvent(string eventArgument) { // Check 'Modify' permission if (!MediaLibraryInfoProvider.IsUserAuthorizedPerLibrary(LibraryInfo, "manage")) { return; } string[] args = eventArgument.Split('|'); if (args.Length == 2) { // Get info on currently selected item int permission = Convert.ToInt32(args[0]); int access = Convert.ToInt32(args[1]); if (LibraryInfo != null) { // Update library permission access information switch (permission) { case 0: LibraryInfo.FileCreate = ((SecurityAccessEnum)access); break; case 2: LibraryInfo.FileDelete = (SecurityAccessEnum)access; break; case 4: LibraryInfo.FileModify = ((SecurityAccessEnum)access); break; case 1: LibraryInfo.FolderCreate = (SecurityAccessEnum)access; break; case 3: LibraryInfo.FolderDelete = (SecurityAccessEnum)access; break; case 5: LibraryInfo.FolderModify = (SecurityAccessEnum)access; break; case 6: LibraryInfo.Access = (SecurityAccessEnum)access; break; default: break; } // Save changes to the library MediaLibraryInfoProvider.SetMediaLibraryInfo(LibraryInfo); } } }
protected void ucMetaFile_OnAfterUpload(object sender, EventArgs e) { if (MediaLibraryID > 0) { MediaLibraryInfo info = LibraryInfo; if (info != null) { UpdateImagePath(info); MediaLibraryInfoProvider.SetMediaLibraryInfo(info); } } }
protected void ucMetaFile_OnAfterDelete(object sender, EventArgs e) { if (MediaLibraryID > 0) { MediaLibraryInfo info = LibraryInfo; if (info != null) { //info.LibraryTeaserPath = String.Empty; //info.LibraryTeaserGuid = Guid.Empty; UpdateImagePath(info); MediaLibraryInfoProvider.SetMediaLibraryInfo(info); } } }
/// <summary> /// Creates department media library. /// </summary> /// <param name="departmentNode">Department node</param> private void CreateDepartmentMediaLibrary(TreeNode departmentNode) { // Set general values string departmentName = departmentNode.GetDocumentName(); string codeName = "Department_" + departmentNode.NodeGUID; string suffix = ""; // Check if library with same name already exists MediaLibraryInfo mlInfo = MediaLibraryInfoProvider.GetMediaLibraryInfo(codeName, CMSContext.CurrentSiteName); if (mlInfo != null) { return; } // Create new object (record) if needed mlInfo = new MediaLibraryInfo(); suffix = " media library"; mlInfo.LibraryDisplayName = TextHelper.LimitLength(departmentName, 200 - suffix.Length, "") + suffix; mlInfo.LibraryFolder = departmentNode.NodeAlias; mlInfo.LibraryDescription = "Media library for " + departmentName + " department."; mlInfo.LibraryName = codeName; mlInfo.LibrarySiteID = CMSContext.CurrentSiteID; // Set security mlInfo.FileCreate = SecurityAccessEnum.AuthorizedRoles; mlInfo.FileDelete = SecurityAccessEnum.AuthorizedRoles; mlInfo.FileModify = SecurityAccessEnum.AuthorizedRoles; mlInfo.FolderCreate = SecurityAccessEnum.AuthorizedRoles; mlInfo.FolderDelete = SecurityAccessEnum.AuthorizedRoles; mlInfo.FolderModify = SecurityAccessEnum.AuthorizedRoles; mlInfo.Access = SecurityAccessEnum.AuthorizedRoles; try { MediaLibraryInfoProvider.SetMediaLibraryInfo(mlInfo); } catch { return; } // Create additional folders //MediaLibraryInfoProvider.CreateMediaLibraryFolder(CMSContext.CurrentSiteName, mlInfo.LibraryID, "Videos", false); //MediaLibraryInfoProvider.CreateMediaLibraryFolder(CMSContext.CurrentSiteName, mlInfo.LibraryID, "Other", false); //MediaLibraryInfoProvider.CreateMediaLibraryFolder(CMSContext.CurrentSiteName, mlInfo.LibraryID, "Photos & Images", false); }
/// <summary> /// Creates group media library. /// </summary> /// <param name="group">Particular group info object</param> private void CreateGroupMediaLibrary(GroupInfo group) { // Set general values string codeName = "Library_group_" + group.GroupGUID; // Check if library with same name already exists MediaLibraryInfo mlInfo = MediaLibraryInfoProvider.GetMediaLibraryInfo(codeName, CMSContext.CurrentSiteName); if (mlInfo != null) { return; } else { // Create new object (record) if needed mlInfo = new MediaLibraryInfo(); string suffix = " media"; mlInfo.LibraryDisplayName = TextHelper.LimitLength(group.GroupDisplayName, 200 - suffix.Length, "") + suffix; mlInfo.LibraryFolder = group.GroupName; mlInfo.LibraryName = codeName; mlInfo.LibraryDescription = ""; mlInfo.LibraryGroupID = group.GroupID; mlInfo.LibrarySiteID = CMSContext.CurrentSiteID; // Set security mlInfo.FileCreate = SecurityAccessEnum.GroupMembers; mlInfo.FileDelete = SecurityAccessEnum.GroupMembers; mlInfo.FileModify = SecurityAccessEnum.GroupMembers; mlInfo.FolderCreate = SecurityAccessEnum.GroupMembers; mlInfo.FolderDelete = SecurityAccessEnum.GroupMembers; mlInfo.FolderModify = SecurityAccessEnum.GroupMembers; mlInfo.Access = SecurityAccessEnum.GroupMembers; try { MediaLibraryInfoProvider.SetMediaLibraryInfo(mlInfo); } catch { return; } // Create additional folders //MediaLibraryInfoProvider.CreateMediaLibraryFolder(CMSContext.CurrentSiteName, mlInfo.LibraryID, "Videos", false); //MediaLibraryInfoProvider.CreateMediaLibraryFolder(CMSContext.CurrentSiteName, mlInfo.LibraryID, "Other", false); //MediaLibraryInfoProvider.CreateMediaLibraryFolder(CMSContext.CurrentSiteName, mlInfo.LibraryID, "Photos & Images", false); } }
/// <summary> /// Create new Meadia Library /// </summary> public static void CreateMeadiaLiabrary(string folderName) { try { MediaLibraryInfo newLibrary = new MediaLibraryInfo(); newLibrary.LibraryDisplayName = !string.IsNullOrEmpty(folderName) ? folderName : "Campaign Products"; newLibrary.LibraryName = !string.IsNullOrEmpty(folderName) ? folderName.Replace(" ", "") : "CampaignProducts"; newLibrary.LibraryFolder = !string.IsNullOrEmpty(folderName) ? folderName.Replace(" ", "") : "CampaignProducts"; newLibrary.LibrarySiteID = SiteContext.CurrentSiteID; MediaLibraryInfoProvider.SetMediaLibraryInfo(newLibrary); } catch (Exception ex) { EventLogProvider.LogException("UploadImage", "CreateMeadiaLiabrary", ex, SiteContext.CurrentSite.SiteID, ex.Message); } }
private void ucMetaFile_OnAfterDelete(object sender, EventArgs e) { MediaLibraryInfo mli = null; if (this.MediaLibraryID > 0) { mli = this.LibraryInfo; } if (mli != null) { // Delete teaser path mli.LibraryTeaserPath = null; MediaLibraryInfoProvider.SetMediaLibraryInfo(mli); } }
/// <inheritdoc/> public void SetMediaLibrarySecurityOption(IMediaLibrary library, SecurityPropertyEnum option, SecurityAccessEnum securityAccess) { // Gets the media library var existingLibrary = GetMediaLibrary(library); if (existingLibrary != null) { // Get security property name from enum string propName = Enum.GetName(typeof(SecurityPropertyEnum), option); // Set security property value using reflection existingLibrary.GetType().GetProperty(propName).SetValue(existingLibrary, securityAccess); // Saves the updated media library to the database MediaLibraryInfoProvider.SetMediaLibraryInfo(existingLibrary); } }
/// <summary> /// Gets and updates media library. Called when the "Get and update library" button is pressed. /// Expects the CreateMediaLibrary method to be run first. /// </summary> private bool GetAndUpdateMediaLibrary() { // Get the media library MediaLibraryInfo updateLibrary = MediaLibraryInfoProvider.GetMediaLibraryInfo("MyNewLibrary", SiteContext.CurrentSiteName); if (updateLibrary != null) { // Update the property updateLibrary.LibraryDisplayName = updateLibrary.LibraryDisplayName.ToLower(); // Update the media library MediaLibraryInfoProvider.SetMediaLibraryInfo(updateLibrary); return(true); } return(false); }
/// <inheritdoc/> public IMediaLibrary CreateMediaLibrary(IMediaLibrary library) { // Creates a new media library object MediaLibraryInfo newLibrary = new MediaLibraryInfo { // Sets the library properties LibraryDisplayName = library.LibraryDisplayName, LibraryName = library.LibraryName, LibraryDescription = library.LibraryDescription, LibraryFolder = library.LibraryFolder, LibrarySiteID = library.LibrarySiteID, }; // Saves the new media library to the database MediaLibraryInfoProvider.SetMediaLibraryInfo(newLibrary); return(newLibrary.ActLike <IMediaLibrary>()); }
/// <summary> /// Creates media library. Called when the "Create library" button is pressed. /// </summary> private bool CreateMediaLibrary() { // Create new media library object MediaLibraryInfo newLibrary = new MediaLibraryInfo(); // Set the properties newLibrary.LibraryDisplayName = "My new library"; newLibrary.LibraryName = "MyNewLibrary"; newLibrary.LibraryDescription = "My new library description"; newLibrary.LibraryFolder = "MyNewLibrary"; newLibrary.LibrarySiteID = SiteContext.CurrentSiteID; newLibrary.LibraryGUID = Guid.NewGuid(); newLibrary.LibraryLastModified = DateTime.Now; // Create the media library MediaLibraryInfoProvider.SetMediaLibraryInfo(newLibrary); return(true); }
private void EnsureLibrary() { var siteName = SiteInfoProvider.GetSiteInfo(SiteId).SiteName; _mediaLibrary = MediaLibraryInfoProvider.GetMediaLibraryInfo(LibraryName, siteName); if (_mediaLibrary == null) { _mediaLibrary = new MediaLibraryInfo() { LibraryDisplayName = LibraryName, LibraryName = LibraryName, LibraryDescription = LibraryDescription, LibraryFolder = LibraryFolder, LibrarySiteID = SiteId, Access = CMS.Helpers.SecurityAccessEnum.AuthenticatedUsers }; MediaLibraryInfoProvider.SetMediaLibraryInfo(_mediaLibrary); } }
/// <inheritdoc/> public IMediaLibrary UpdateMediaLibrary(IMediaLibrary library, bool isReplace = true) { var updateLibrary = GetMediaLibrary(library); if (updateLibrary != null) { if (isReplace) { updateLibrary = library.UndoActLike(); } else { // Updates the library properties updateLibrary.LibraryDisplayName = library.LibraryDisplayName ?? updateLibrary.LibraryDisplayName; updateLibrary.LibraryDescription = library.LibraryDescription ?? updateLibrary.LibraryDescription; updateLibrary.LibraryFolder = library.LibraryFolder ?? updateLibrary.LibraryFolder; } // Saves the updated library to the database MediaLibraryInfoProvider.SetMediaLibraryInfo(updateLibrary); } return(updateLibrary.ActLike <IMediaLibrary>()); }
protected void btnOK_Click(object sender, EventArgs e) { // Check whether the current user is authorized to manage the edited media library if (!CheckPermissions()) { ShowError(MediaLibraryHelper.GetAccessDeniedMessage("Manage")); return; } // Get the code name of the edited media library string codeName = txtCodeName.Text; if (DisplayMode == ControlDisplayModeEnum.Simple) { if (MediaLibraryID == 0) { codeName = ValidationHelper.GetCodeName(txtDisplayName.Text, null, "_group_" + Guid.NewGuid()); } else { codeName = LibraryInfo.LibraryName; } } codeName = codeName.Trim(); // Validate user input if (!ValidateForm(codeName)) { return; } // Create new object (record) if needed MediaLibraryInfo mli = (MediaLibraryID > 0) ? LibraryInfo : new MediaLibraryInfo(); mli.LibraryDisplayName = txtDisplayName.Text; if (txtFolder.Enabled) { mli.LibraryFolder = txtFolder.Text; } mli.LibraryDescription = txtDescription.Text; mli.LibraryName = codeName; // If the library is group related if (MediaLibraryGroupID > 0) { mli.LibraryGroupID = MediaLibraryGroupID; // If creating new group library setup default security if (MediaLibraryID == 0) { // Set default group media library security mli.FileCreate = SecurityAccessEnum.GroupMembers; mli.FileDelete = SecurityAccessEnum.Nobody; mli.FileModify = SecurityAccessEnum.Nobody; mli.FolderCreate = SecurityAccessEnum.Nobody; mli.FolderDelete = SecurityAccessEnum.Nobody; mli.FolderModify = SecurityAccessEnum.Nobody; mli.Access = SecurityAccessEnum.GroupMembers; } } mli.LibrarySiteID = CMSContext.CurrentSiteID; try { MediaLibraryInfoProvider.SetMediaLibraryInfo(mli); } catch (Exception ex) { ShowError(GetString("general.errorsaving"), ex.Message, null); return; } if ((mli != null) && (mli.LibraryID != 0)) { // Add teaser image to media library ucMetaFile.ObjectID = mli.LibraryID; ucMetaFile.SiteID = mli.LibrarySiteID; ucMetaFile.UploadFile(); UpdateImagePath(mli); try { MediaLibraryInfoProvider.SetMediaLibraryInfo(mli); } catch (Exception ex) { ShowError(GetString("general.errorsaving"), ex.Message, null); return; } // Update current media library id MediaLibraryID = mli.LibraryID; ShowChangesSaved(); FillForm(mli); RaiseOnSaved(); } // Reload header if changes were saved ScriptHelper.RefreshTabHeader(Page, GetString("general.general")); }
protected void btnOK_Click(object sender, EventArgs e) { bool isAuthorized = false; // Check 'Manage' permission for user if (this.LibraryInfo != null) { isAuthorized = MediaLibraryInfoProvider.IsUserAuthorizedPerLibrary(this.LibraryInfo, "Manage"); } else { if (CMSContext.CurrentUser.IsAuthorizedPerResource("CMS.MediaLibrary", "Manage")) { isAuthorized = true; } else { if ((this.MediaLibraryGroupID > 0) && (CMSContext.CurrentUser.IsGroupAdministrator(this.MediaLibraryGroupID))) { isAuthorized = true; } } } // If user isn't authorized let her now if (!isAuthorized) { lblError.Text = MediaLibraryHelper.GetAccessDeniedMessage("Manage"); lblError.Visible = true; return; } string codeName = txtCodeName.Text; if (DisplayMode == ControlDisplayModeEnum.Simple) { if (this.MediaLibraryID == 0) { codeName = ValidationHelper.GetCodeName(txtDisplayName.Text, null, "_group_" + Guid.NewGuid()); } else { codeName = this.LibraryInfo.LibraryName; } } codeName = codeName.Trim(); // Validate input boxes if (!ValidateForm(codeName)) { return; } // Create new object (record) if needed MediaLibraryInfo mli = null; if (this.MediaLibraryID > 0) { mli = this.LibraryInfo; } else { mli = new MediaLibraryInfo(); } mli.LibraryDisplayName = txtDisplayName.Text; if (txtFolder.Enabled) { mli.LibraryFolder = txtFolder.Text; } mli.LibraryDescription = txtDescription.Text; mli.LibraryName = codeName; // If the library is group related if (this.MediaLibraryGroupID > 0) { mli.LibraryGroupID = this.MediaLibraryGroupID; // If creating new group library setup default security if (this.MediaLibraryID == 0) { // Set default group media library security mli.FileCreate = SecurityAccessEnum.GroupMembers; mli.FileDelete = SecurityAccessEnum.Nobody; mli.FileModify = SecurityAccessEnum.Nobody; mli.FolderCreate = SecurityAccessEnum.Nobody; mli.FolderDelete = SecurityAccessEnum.Nobody; mli.FolderModify = SecurityAccessEnum.Nobody; mli.Access = SecurityAccessEnum.GroupMembers; } } mli.LibrarySiteID = CMSContext.CurrentSiteID; try { MediaLibraryInfoProvider.SetMediaLibraryInfo(mli); } catch { lblError.Text = GetString("general.errorsaving"); lblError.Visible = true; return; } if ((mli != null) && (mli.LibraryID != 0)) { // Add teaser image to media library ucMetaFile.ObjectID = mli.LibraryID; ucMetaFile.UploadFile(); UpdateImagePath(mli); try { MediaLibraryInfoProvider.SetMediaLibraryInfo(mli); } catch (Exception ex) { lblError.Text = ex.Message; lblError.Visible = true; return; } // Update current media library id this.MediaLibraryID = mli.LibraryID; lblInfo.Visible = true; lblInfo.Text = GetString("general.changessaved"); FillForm(mli); this.RaiseOnSaved(); } // Reload header if changes were saved ScriptHelper.RefreshTabHeader(Page, GetString("general.general")); }