/// <summary> /// Gets a User object from a user's name. /// </summary> /// <param name="userName">The name of the user.</param> /// <returns>A User object corresponding to the name</returns> private static RightsManagementUser GetUserFromUserName(string userName) { if (RightsTable.IsEveryone(userName)) { return(RightsManagementUser.AnyoneRightsManagementUser); } else { // XPS Viewer doesn't allow document authors to explicitly define the authentication type of the consumers. // So we are using WindowsPassport Authentication type as means of enabling both Passport and Windows // consumers return (RightsManagementUser.CreateUser( userName, AuthenticationType.WindowsPassport)); } }
//------------------------------------------------------ // 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); }