/// <summary> /// Displayt the given Exception in the ErrorDialog /// </summary> /// <param name="ex">Exception to display</param> public static void ShowError(Exception ex) { if (ex == null || String.IsNullOrEmpty(ex.Message)) { // This shouldn't ever happen DebugLog.WriteVerbose("ex is NULL?!?!"); return; } ErrorDialog dialog = new ErrorDialog(); dialog.Text = ErrorTitle; dialog.ErrorIcon.Image = EWSEditor.Forms.FormsUtil.ConvertIconToImage(SystemIcons.Error); // Set the header text of the dialog with the exception message // and calling method. //ex.InnerException. dialog.FromWhere.Text = EwsMethodFromStackTrace(ex); if (ex is Microsoft.Exchange.WebServices.Data.ServiceObjectPropertyException) { Microsoft.Exchange.WebServices.Data.ServiceObjectPropertyException x = (Microsoft.Exchange.WebServices.Data.ServiceObjectPropertyException)ex; dialog.ExceptionMessage.Text = ex.Message + "\r\nPropertyName: " + x.Name; } else { dialog.ExceptionMessage.Text = ex.Message; } dialog.txtHResult.Text = ex.HResult.ToString(); dialog.txtHResultHex.Text = String.Format("{0:X}", ex.HResult); // Add verbose exception details dialog.ExceptionDetailBox.Text = BuildExceptionDetail(ex); Form parent = Form.ActiveForm; if (parent == null) { foreach (Form openForm in Application.OpenForms) { DebugLog.WriteVerbose(String.Format("Type: {0} Focused: {0} Visible: {0} Modal: {0}", openForm.GetType().FullName, openForm.Focused.ToString(), openForm.Visible.ToString(), openForm.Modal.ToString())); if (openForm.Visible) { parent = openForm; } if (openForm.Modal && openForm.Visible) { parent = openForm; } } } dialog.BringToFront(); dialog.ShowDialog(parent); }
/// <summary> /// Gets the property value. /// </summary> /// <param name="propertyDefinition">The property definition.</param> /// <param name="exception">Exception that would be raised if there's an error retrieving the property.</param> /// <returns>Propert value. May be null.</returns> private object GetPropertyValueOrException(PropertyDefinition propertyDefinition, out ServiceLocalException exception) { object propertyValue = null; exception = null; if (propertyDefinition.Version > this.Owner.Service.RequestedServerVersion) { exception = new ServiceVersionException( string.Format( Strings.PropertyIncompatibleWithRequestVersion, propertyDefinition.Name, propertyDefinition.Version)); return(null); } if (this.TryGetValue(propertyDefinition, out propertyValue)) { // If the requested property is in the bag, return it. return(propertyValue); } else { if (propertyDefinition.HasFlag(PropertyDefinitionFlags.AutoInstantiateOnRead)) { // The requested property is an auto-instantiate-on-read property ComplexPropertyDefinitionBase complexPropertyDefinition = propertyDefinition as ComplexPropertyDefinitionBase; EwsUtilities.Assert( complexPropertyDefinition != null, "PropertyBag.get_this[]", "propertyDefinition is marked with AutoInstantiateOnRead but is not a descendant of ComplexPropertyDefinitionBase"); propertyValue = complexPropertyDefinition.CreatePropertyInstance(this.Owner); if (propertyValue != null) { this.InitComplexProperty(propertyValue as ComplexProperty); this.properties[propertyDefinition] = propertyValue; } } else { // If the property is not the Id (we need to let developers read the Id when it's null) and if has // not been loaded, we throw. if (propertyDefinition != this.Owner.GetIdPropertyDefinition()) { if (!this.IsPropertyLoaded(propertyDefinition)) { exception = new ServiceObjectPropertyException(Strings.MustLoadOrAssignPropertyBeforeAccess, propertyDefinition); return(null); } // Non-nullable properties (int, bool, etc.) must be assigned or loaded; cannot return null value. if (!propertyDefinition.IsNullable) { string errorMessage = this.IsRequestedProperty(propertyDefinition) ? Strings.ValuePropertyNotLoaded : Strings.ValuePropertyNotAssigned; exception = new ServiceObjectPropertyException(errorMessage, propertyDefinition); } } } return(propertyValue); } }