//-------------------------------------------------------------------------- // Constructors //-------------------------------------------------------------------------- #region Constructors /// <summary> /// Constructor to use for non-owners /// </summary> /// <param name="userLicense">The use license of the current user</param> internal RMPermissionsDialog(RightsManagementLicense userLicense) { // Set up labels authenticatedAsLabel.Text = userLicense.LicensedUser.Name; expiresOnLabel.Text = GetUtcDateAsString(userLicense.ValidUntil); InitializeReferralInformation(userLicense); // Set up list of rights AddPermissions(GetRightsFromPermissions(userLicense)); }
//------------------------------------------------------ // Private Methods //------------------------------------------------------ #region Private Methods /// <summary> /// Generates RightsManagementLicense objects for each grant specified by /// the user. /// </summary> /// <returns>A list of RightsManagementLicense objects</returns> private IList <RightsManagementLicense> CreateRightsManagementLicenses() { List <RightsManagementLicense> licenseList = new List <RightsManagementLicense>(); // Enumerate through all the rows that correspond with users foreach (DataGridViewRow row in rightsTable.Rows) { if (row != null) { RightsManagementLicense rmLicense = new RightsManagementLicense(); string userName = RightsTable.GetUsernameFromRow(row); rmLicense.LicensedUser = GetUserFromUserName(userName); rmLicense.LicensePermissions = RightsTable.GetPermissionsFromRow(row); rmLicense.ValidFrom = DateTime.MinValue; rmLicense.ValidUntil = DateTime.MaxValue; if (ReferralUri != null) { rmLicense.ReferralInfoName = textBoxPermissionsContact.Text; rmLicense.ReferralInfoUri = ReferralUri; } // If the user for the current license has not been given // owner rights, and the dialog contains an expiration // date, set the ValidFrom and ValidUntil dates in the // license from the dialog if (!rmLicense.HasPermission(RightsManagementPermissions.AllowOwner) && ValidUntil.HasValue) { rmLicense.ValidFrom = DateTime.UtcNow; rmLicense.ValidUntil = ValidUntil.Value; } licenseList.Add(rmLicense); } } return(licenseList); }
/// <summary> /// Generates a string for each individual right granted to a user as represented /// in a RightsManagementLicense object. /// </summary> /// <param name="license">The license to convert</param> /// <returns>An array of strings representing all rights granted</returns> private static string[] GetRightsFromPermissions(RightsManagementLicense license) { IList <string> rightsStrings = new List <string>(); if (license.HasPermission(RightsManagementPermissions.AllowOwner)) { rightsStrings.Add(SR.Get(SRID.RMPermissionsOwnerPermission)); } else { if (license.HasPermission(RightsManagementPermissions.AllowView)) { rightsStrings.Add(SR.Get(SRID.RMPermissionsViewPermission)); } if (license.HasPermission(RightsManagementPermissions.AllowPrint)) { rightsStrings.Add(SR.Get(SRID.RMPermissionsPrintPermission)); } if (license.HasPermission(RightsManagementPermissions.AllowCopy)) { rightsStrings.Add(SR.Get(SRID.RMPermissionsCopyPermission)); } if (license.HasPermission(RightsManagementPermissions.AllowSign)) { rightsStrings.Add(SR.Get(SRID.RMPermissionsSignPermission)); } if (license.HasPermission(RightsManagementPermissions.AllowAnnotate)) { rightsStrings.Add(SR.Get(SRID.RMPermissionsAnnotatePermission)); } } string[] stringArray = new string[rightsStrings.Count]; rightsStrings.CopyTo(stringArray, 0); return(stringArray); }
//-------------------------------------------------------------------------- // Private Methods //-------------------------------------------------------------------------- #region Private Methods /// <summary> /// Initialize the referral information (the name and the URI) to /// display in the UI. /// </summary> /// <param name="userLicense">The license from which to retrieve the /// information to display</param> private void InitializeReferralInformation(RightsManagementLicense userLicense) { string referralName = userLicense.ReferralInfoName; Uri referralUri = userLicense.ReferralInfoUri; // The referral information displayed is: // - the referral URI. If that is not available, // - the referral name. If that is not available, // - the default text "Unknown" if (referralUri != null) { requestFromLabel.Text = referralUri.ToString(); } else if (!string.IsNullOrEmpty(referralName)) { requestFromLabel.Text = referralName; } // If the referral URI is a mailto URI, make the LinkLabel clickable if (referralUri != null && AddressUtility.IsMailtoUri(referralUri)) { // LinkLabels have one Link in the Links list by default requestFromLabel.Links[0].Description = referralName; // Set up the click handler; it uses _referralUri _referralUri = referralUri; requestFromLabel.LinkClicked += new LinkLabelLinkClickedEventHandler(requestFromLabel_LinkClicked); } else { // If there is no referral URI or it is not a mailto: link, the // label should not appear clickable. requestFromLabel.Links.Clear(); } }