コード例 #1
0
        /// <summary>
        /// GetCredentialManagementResources.
        /// </summary>
        /// <param name="user">The user object from which to get resources</param>
        internal static string GetCredentialManagementResources(RightsManagementUser user)
        {
            string accountName = null;

            if (user == null)
            {
                throw new ArgumentNullException("user");
            }

            switch (user.AuthenticationType)
            {
            case (AuthenticationType.Windows):
                accountName = String.Format(
                    CultureInfo.CurrentCulture,
                    SR.Get(SRID.RMCredManagementWindowsAccount),
                    user.Name);
                break;

            case (AuthenticationType.Passport):
                accountName = String.Format(
                    CultureInfo.CurrentCulture,
                    SR.Get(SRID.RMCredManagementPassportAccount),
                    user.Name);
                break;

            default:
                accountName = String.Format(
                    CultureInfo.CurrentCulture,
                    SR.Get(SRID.RMCredManagementUnknownAccount),
                    user.Name);
                break;
            }

            return(accountName);
        }
コード例 #2
0
 /// <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));
     }
 }
コード例 #3
0
        //------------------------------------------------------
        // Constructors
        //------------------------------------------------------
        #region Constructors
        /// <summary>
        /// Creates a new Publishing dialog for the given user with the given list of
        /// already granted rights.
        /// </summary>
        /// <param name="grantDictionary">A dictionary of rights already granted on the
        /// document.  This should be null if the document is not protected, and an
        /// empty dictionary if it is but no grants exist.</param>
        internal RMPublishingDialog(
            RightsManagementUser user,
            IDictionary <RightsManagementUser, RightsManagementLicense> grantDictionary)
        {
            checkBoxValidUntil.Checked   = false;
            datePickerValidUntil.Enabled = false;

            // The DateTimePicker displays validity dates in the local time
            // zone, so the date displayed is not necessarily the value that is
            // returned by the ValidUntil property.
            datePickerValidUntil.MinDate = DateTime.Today.AddDays(1);
            datePickerValidUntil.Value   = DateTime.Today.AddDays(1);

            textBoxPermissionsContact.Enabled = true;

            checkBoxPermissionsContact.Checked = true;
            textBoxPermissionsContact.Text     = user.Name;

            // Check if referral info is already specified in a license
            if (grantDictionary != null && grantDictionary.Count != 0)
            {
                IEnumerator <RightsManagementLicense> licenseEnumerator =
                    grantDictionary.Values.GetEnumerator();

                licenseEnumerator.MoveNext();

                Uri referralUri = licenseEnumerator.Current.ReferralInfoUri;

                string address =
                    AddressUtility.GetEmailAddressFromMailtoUri(referralUri);

                // If there was an address previously specified, use it
                if (!string.IsNullOrEmpty(address))
                {
                    textBoxPermissionsContact.Text = address;
                }
                // Otherwise disable the checkbox
                else
                {
                    checkBoxPermissionsContact.Checked = false;
                }
            }

            if (grantDictionary != null)
            {
                _isAlreadyProtected            = true;
                radioButtonPermissions.Checked = true;

                _rmLicenses = new List <RightsManagementLicense>(grantDictionary.Values);

                DateTime validUntil = DateTime.MaxValue;

                foreach (RightsManagementLicense license in grantDictionary.Values)
                {
                    if (license.ValidUntil > DateTime.UtcNow &&
                        license.ValidUntil < validUntil)
                    {
                        validUntil = license.ValidUntil;
                    }
                }

                DateTime localValidUntil = DateTimePicker.MaximumDateTime;

                // Convert the UTC time to local time if necessary
                if (validUntil < DateTime.MaxValue)
                {
                    localValidUntil = validUntil.ToLocalTime();
                }

                if (localValidUntil < DateTimePicker.MaximumDateTime)
                {
                    checkBoxValidUntil.Checked   = true;
                    datePickerValidUntil.Enabled = true;
                    datePickerValidUntil.Value   = localValidUntil;
                }
            }


            rightsTable.InitializeRightsTable(user.Name, grantDictionary);
            UpdateAnyoneEnabled();

            // Determine the list of available templates.
            InitializeTemplates();
            // Add templates to the UI (ComboBox).
            PopulateTemplateUI();

            // Attach our event handlers for the Save/SaveAs buttons here.
            // We do this here so that the event handlers can be Critical (and not TAS) to prevent
            // them from being invoked in other ways...
            buttonSave.Click   += new System.EventHandler(this.buttonSave_Click);
            buttonSaveAs.Click += new System.EventHandler(this.buttonSaveAs_Click);

            // Update the radiobuttons to their initial state, which will also toggle the
            // Save buttons appropriately.
            UpdateRadioButtonState();

            // check if we can save the document with the current filename
            _canSave = false;

            DocumentManager documentManager = DocumentManager.CreateDefault();

            if (documentManager != null)
            {
                _canSave = documentManager.CanSave;
            }

            buttonSave.Enabled = _canSave;
        }