/// <summary> /// Validates the Referral address entered into the dialog and prompts /// the user if the address is invalid. If the address is valid, /// _referralUri is updated. /// </summary> /// <param name="isSaveAs"></param> /// <returns>A bool reflecting the validity of the address.</returns> private bool ValidateReferralAddress() { bool ok = true; _referralUri = null; // If the permissions contact check box is checked, parse the // referral information to make a mailto URI. if (checkBoxPermissionsContact.Checked) { string permissionsAddress = textBoxPermissionsContact.Text.Trim(); if (!string.IsNullOrEmpty(permissionsAddress)) { _referralUri = AddressUtility.GenerateMailtoUri(permissionsAddress); ok = true; } // If no e-mail address was entered, we should show an // error dialog box and not let the form be closed else { System.Windows.MessageBox.Show( string.Format( CultureInfo.CurrentCulture, SR.Get(SRID.RightsManagementWarnErrorNoReferralAddress), textBoxPermissionsContact.Text), SR.Get(SRID.RightsManagementWarnErrorTitle), MessageBoxButton.OK, MessageBoxImage.Exclamation); textBoxPermissionsContact.Focus(); textBoxPermissionsContact.SelectAll(); ok = false; } } return(ok); }
//-------------------------------------------------------------------------- // 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(); } }
//------------------------------------------------------ // 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; }