コード例 #1
0
        //------------------------------------------------------
        // 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);
        }
コード例 #2
0
ファイル: RMPermissions.cs プロジェクト: zheng1748/wpf
        /// <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);
        }