private static void AppendServiceResponse(ServiceResponse response, StringBuilder details) { if (response != null) { details.AppendLine(String.Concat("ErrorCode: ", response.ErrorCode.ToString())); if (response.ErrorDetails.Count > 0) { details.AppendLine("ErrorDetails:"); foreach (string key in response.ErrorDetails.Keys) { details.AppendLine(String.Concat(key, ": ", response.ErrorDetails[key])); } } details.AppendLine(String.Concat("ErrorMessage: ", response.ErrorMessage)); if (response.ErrorProperties.Count > 0) { details.AppendLine("ErrorProperties:"); foreach (PropertyDefinitionBase prop in response.ErrorProperties) { details.AppendLine(PropertyInterpretation.GetPropertyName(prop)); } } } }
protected override void LoadContents() { // Add each Appointment to the ContentsGrid with no data binding foreach (Appointment appt in this.currentAppointments) { int row = this.ContentsGrid.Rows.Add(); this.ContentsGrid.Rows[row].Cells[ColNameStartTime].Value = appt.Start.ToString(); this.ContentsGrid.Rows[row].Cells[ColNameEndTime].Value = appt.End.ToString(); this.ContentsGrid.Rows[row].Cells[ColNameSubject].Value = appt.Subject; this.ContentsGrid.Rows[row].Cells[ColNameOrganizer].Value = PropertyInterpretation.GetPropertyValue(appt.Organizer); this.ContentsGrid.Rows[row].Cells[ColNameReqAttendees].Value = PropertyInterpretation.GetPropertyValue(appt.RequiredAttendees); this.ContentsGrid.Rows[row].Cells[ColNameOptAttendees].Value = PropertyInterpretation.GetPropertyValue(appt.OptionalAttendees); this.ContentsGrid.Rows[row].Cells[ColNameResources].Value = PropertyInterpretation.GetPropertyValue(appt.Resources); //this.ContentsGrid.Rows[row].Cells[ColNameItemId].Value = appt.Id.UniqueId; //this.ContentsGrid.Rows[row].Cells[ColPidLidClientIntent].Value = PropertyInterpretation.GetPropertyValue(appt.Resources); //this.ContentsGrid.Rows[row].Cells[ColClientInfoString].Value = PropertyInterpretation.GetPropertyValue(appt.Resources); //this.ContentsGrid.Rows[row].Cells[ColPidLidCleanGlobalObjectId].Value = PropertyInterpretation.GetPropertyValue(appt.Resources); } base.LoadContents(); }
private void DisplayAttendeeResults(AttendeeDataContainer attendeeData) { // Clear existing availability information this.AttendeeAvailabilityList.Items.Clear(); this.CalEventsList.Items.Clear(); // Display the given AttendeeAvailability in the ListView AttendeeAvailability availability = attendeeData.Availability; if (availability != null && availability.Result == ServiceResult.Success) { // Change the label text to indicate the selected attendee //this.AttendeeAvailabilityGroup.Text = string.Format(SelectedAttendeeLabelText, attendeeData.Info.SmtpAddress); ListViewItem availRow = this.AttendeeAvailabilityList.Items.Add(PropertyInterpretation.GetPropertyValue(availability.ViewType)); availRow.SubItems.Add(PropertyInterpretation.GetPropertyValue(availability.WorkingHours)); if (availability.MergedFreeBusyStatus.Count > 0) { availRow.SubItems.Add(PropertyInterpretation.GetPropertyValue(availability.MergedFreeBusyStatus)); } foreach (CalendarEvent calEvent in availability.CalendarEvents) { ListViewItem calRow = this.CalEventsList.Items.Add(PropertyInterpretation.GetPropertyValue(calEvent.FreeBusyStatus)); calRow.SubItems.Add(PropertyInterpretation.GetPropertyValue(calEvent.StartTime)); calRow.SubItems.Add(PropertyInterpretation.GetPropertyValue(calEvent.EndTime)); if (calEvent.Details != null) { calRow.SubItems.Add(calEvent.Details.Subject); calRow.SubItems.Add(calEvent.Details.Location); calRow.SubItems.Add(calEvent.Details.IsException.ToString()); calRow.SubItems.Add(calEvent.Details.IsMeeting.ToString()); calRow.SubItems.Add(calEvent.Details.IsPrivate.ToString()); calRow.SubItems.Add(calEvent.Details.IsRecurring.ToString()); calRow.SubItems.Add(calEvent.Details.IsReminderSet.ToString()); calRow.SubItems.Add(calEvent.Details.StoreId); } } } else if (availability != null && availability.Result == ServiceResult.Error) { ErrorDialog.ShowServiceResponseMsgBox( availability, String.Format("Availability request returned an error for attendee, {0}.", attendeeData.Info.SmtpAddress), string.Empty, MessageBoxIcon.Warning); } else if (availability != null) { throw new NotImplementedException( string.Format( "Unexpected ServiceResult, {0}, for AttendeeAvailability", availability.Result.ToString())); } }
/// <summary> /// Save the current profile and its items to the given file path. /// </summary> /// <param name="profilePath">File to save the profile information.</param> internal void SaveProfile(string profilePath) { ServicesProfile.ServiceBindingDataTable data = new ServicesProfile.ServiceBindingDataTable(); foreach (ServiceProfileItem item in this.profileItems) { ServicesProfile.ServiceBindingRow row = data.NewServiceBindingRow(); row.Name = PropertyInterpretation.GetPropertyValue(item.Service); //row.AutoDiscoverEmail = this.AutodiscoverEmailUsed; row.ServicesURL = item.Service.Url.OriginalString; row.RequestedServerVersion = item.Service.RequestedServerVersion.ToString(); if (item.Service.ImpersonatedUserId != null) { row.ImpersonationId = item.Service.ImpersonatedUserId.Id; row.ImpersonationType = item.Service.ImpersonatedUserId.IdType.ToString(); } row.UsesDefaultCredentials = item.Service.UseDefaultCredentials; //row.UserName = item.Service.GetNetworkCredential().UserName; //TODO: The saving and loading of profiles needs to be reworked. //row.Domain = item.Service.GetNetworkCredential().Domain; // Add root folders to the data table. StringBuilder sb = new StringBuilder(); foreach (FolderId id in item.RootFolderIds) { // If this is not the first FolderId add a separator if (sb.Length > 0) { sb.Append("|"); } if (id.FolderName.HasValue && id.Mailbox != null) { sb.Append(string.Format(System.Globalization.CultureInfo.CurrentCulture, "Name:{0},Mbx:{1}", id.FolderName.ToString(), id.Mailbox.Address)); } else if (id.FolderName.HasValue) { sb.Append(string.Format(System.Globalization.CultureInfo.CurrentCulture, "Name:{0}", id.FolderName.ToString())); } else { sb.Append(string.Format(System.Globalization.CultureInfo.CurrentCulture, "Id:{0}", id.UniqueId)); } } row.RootFolderIds = sb.ToString(); data.AddServiceBindingRow(row); } data.WriteXml(profilePath); }
private void btnFolderId_Click(object sender, EventArgs e) { FolderIdDialog oForm = new FolderIdDialog(_CurrentService); oForm.ShowDialog(); if (oForm.ChoseOK == true) { lblFolderId.Text = PropertyInterpretation.GetPropertyValue(oForm.ChosenFolderId); } //if (FolderIdDialog.ShowDialog(ref this._SelectedFolder) == DialogResult.OK) //{ // lblFolderId.Text = PropertyInterpretation.GetPropertyValue(this._SelectedFolder); //} }
/// <summary> /// Display the property name, type, and value /// </summary> private void PropertyEditorDialog_Load(object sender, EventArgs e) { if (this.CurrentServiceObejct == null || this.CurrentProperty == null) { return; } PropertyInterpretation propInter = new PropertyInterpretation( this.CurrentServiceObejct, this.CurrentProperty); txtName.Text = propInter.Name; txtType.Text = propInter.TypeName; txtSmartView.Text = propInter.SmartView; txtComments.Text = propInter.Comments; txtKnownNames.Text = propInter.AlternateNames; AddPropertyValueControls(propInter.Value, propInter.TypeName); }
/// <summary> /// Dump the properties from the given Item to an XML file in the given /// destination folder. /// </summary> /// <param name="item">Loaded Item whose properties are to be dumped</param> /// <param name="destinationFolderPath">Folder to save messages to</param> public static void DumpXML( Item item, string destinationFolderPath) { DebugLog.WriteVerbose("Writing item to file."); // Create a file path to save the item properties to string fileName = null; fileName = string.Format( System.Globalization.CultureInfo.CurrentCulture, "{0}\\{1}.xml", destinationFolderPath, FileHelper.SanitizeFileName(item.Subject)); XmlDocument xmlDoc = new XmlDocument(); XmlNode xmlMessage = xmlDoc.CreateNode(XmlNodeType.Element, "Message", string.Empty); xmlDoc.AppendChild(xmlMessage); XmlNode xmlProperties = xmlDoc.CreateNode(XmlNodeType.Element, "Properties", string.Empty); xmlMessage.AppendChild(xmlProperties); foreach (PropertyDefinitionBase baseProp in item.GetLoadedPropertyDefinitions()) { if (baseProp != ItemSchema.ExtendedProperties) { PropertyInterpretation propInter = new PropertyInterpretation(item, baseProp); xmlProperties.AppendChild(propInter.ToXML(xmlDoc)); } } // Write XML content to file System.IO.File.WriteAllText( FileHelper.EnsureUniqueFileName(fileName), xmlDoc.OuterXml); DebugLog.WriteVerbose(String.Concat("Wrote item to file, {0}", fileName)); }
/// <summary> /// Add the given property to the display table. The grid is /// customized as to how it sorts and displays property /// information. /// </summary> /// <param name="prop">Property to be added to the table.</param> private void AddPropertyToDisplayTable(PropertyDefinitionBase prop) { // If there is no property then bail out if (prop == null) { return; } DataRow row = this.propertyDisplayTable.NewRow(); row["PropertyName"] = PropertyInterpretation.GetPropertyName(prop); row["PropertyType"] = PropertyInterpretation.GetPropertyType(prop); row["WellKnownName"] = PropertyInterpretation.GetAlternateNames(prop); row["PropertyDefinitionBase"] = prop; // Don't add the row if it already exists if (!this.propertyDisplayTable.Rows.Contains(row["PropertyName"])) { this.propertyDisplayTable.Rows.Add(row); } }
/// <summary> /// Dump an error response as XML /// </summary> /// <param name="response">Response to get data from</param> /// <param name="destinationFolderPath">Folder to save messages to</param> private static void DumpErrorResponseXML( GetItemResponse response, string destinationFolderPath) { DebugLog.WriteVerbose("Writing error to file."); XmlDocument xmlDoc = new XmlDocument(); XmlNode xmlMessage = xmlDoc.CreateNode(XmlNodeType.Element, "Message", string.Empty); xmlDoc.AppendChild(xmlMessage); XmlNode xmlProperties = xmlDoc.CreateNode(XmlNodeType.Element, "Properties", string.Empty); xmlMessage.AppendChild(xmlProperties); // Create a file path to save the error message to string fileName = string.Format(System.Globalization.CultureInfo.CurrentCulture, "{0}\\_ERROR.txt", destinationFolderPath); // Get error message contents XmlNode xmlError = xmlDoc.CreateNode(XmlNodeType.Element, "Error", string.Empty); XmlNode xmlErrorCode = xmlDoc.CreateNode(XmlNodeType.Element, "ErrorCode", string.Empty); xmlErrorCode.InnerText = response.ErrorCode.ToString(); xmlError.AppendChild(xmlErrorCode); XmlNode xmlErrorMessage = xmlDoc.CreateNode(XmlNodeType.Element, "ErrorMessage", string.Empty); xmlErrorMessage.InnerText = response.ErrorMessage; xmlError.AppendChild(xmlErrorMessage); if (response.ErrorDetails != null && response.ErrorDetails.Count > 0) { XmlNode xmlErrorDetails = xmlDoc.CreateNode(XmlNodeType.Element, "ErrorDetails", string.Empty); StringBuilder detailsText = new StringBuilder(); foreach (KeyValuePair<string, string> detail in response.ErrorDetails) { XmlNode xmlErrorDetail = xmlDoc.CreateNode(XmlNodeType.Element, "ErrorDetail", string.Empty); XmlNode xmlKeyAttr = xmlDoc.CreateNode(XmlNodeType.Attribute, "Key", string.Empty); xmlKeyAttr.Value = detail.Key; xmlErrorDetail.AppendChild(xmlKeyAttr); xmlErrorDetail.InnerText = detail.Value; xmlErrorDetails.AppendChild(xmlErrorDetail); } xmlError.AppendChild(xmlErrorDetails); } if (response.ErrorProperties != null && response.ErrorProperties.Count > 0) { XmlNode xmlErrorProps = xmlDoc.CreateNode(XmlNodeType.Element, "ErrorProperties", string.Empty); StringBuilder propsText = new StringBuilder(); foreach (PropertyDefinitionBase baseProp in response.ErrorProperties) { PropertyInterpretation prop = new PropertyInterpretation(response.Item, baseProp); xmlErrorProps.AppendChild(prop.ToXML(xmlDoc)); } xmlError.AppendChild(xmlErrorProps); } xmlProperties.AppendChild(xmlError); // Write MIME content to file System.IO.File.WriteAllText( FileHelper.EnsureUniqueFileName(fileName), xmlDoc.OuterXml); DebugLog.WriteVerbose(String.Format("Wrote error to file, {0}.", fileName)); }
/// <summary> /// Dump an error response as XML /// </summary> /// <param name="response">Response to get data from</param> /// <param name="destinationFolderPath">Folder to save messages to</param> private static void DumpErrorResponseXML( GetItemResponse response, string destinationFolderPath) { DebugLog.WriteVerbose("Writing error to file."); XmlDocument xmlDoc = new XmlDocument(); XmlNode xmlMessage = xmlDoc.CreateNode(XmlNodeType.Element, "Message", string.Empty); xmlDoc.AppendChild(xmlMessage); XmlNode xmlProperties = xmlDoc.CreateNode(XmlNodeType.Element, "Properties", string.Empty); xmlMessage.AppendChild(xmlProperties); // Create a file path to save the error message to string fileName = string.Format(System.Globalization.CultureInfo.CurrentCulture, "{0}\\_ERROR.txt", destinationFolderPath); // Get error message contents XmlNode xmlError = xmlDoc.CreateNode(XmlNodeType.Element, "Error", string.Empty); XmlNode xmlErrorCode = xmlDoc.CreateNode(XmlNodeType.Element, "ErrorCode", string.Empty); xmlErrorCode.InnerText = response.ErrorCode.ToString(); xmlError.AppendChild(xmlErrorCode); XmlNode xmlErrorMessage = xmlDoc.CreateNode(XmlNodeType.Element, "ErrorMessage", string.Empty); xmlErrorMessage.InnerText = response.ErrorMessage; xmlError.AppendChild(xmlErrorMessage); if (response.ErrorDetails != null && response.ErrorDetails.Count > 0) { XmlNode xmlErrorDetails = xmlDoc.CreateNode(XmlNodeType.Element, "ErrorDetails", string.Empty); StringBuilder detailsText = new StringBuilder(); foreach (KeyValuePair <string, string> detail in response.ErrorDetails) { XmlNode xmlErrorDetail = xmlDoc.CreateNode(XmlNodeType.Element, "ErrorDetail", string.Empty); XmlNode xmlKeyAttr = xmlDoc.CreateNode(XmlNodeType.Attribute, "Key", string.Empty); xmlKeyAttr.Value = detail.Key; xmlErrorDetail.AppendChild(xmlKeyAttr); xmlErrorDetail.InnerText = detail.Value; xmlErrorDetails.AppendChild(xmlErrorDetail); } xmlError.AppendChild(xmlErrorDetails); } if (response.ErrorProperties != null && response.ErrorProperties.Count > 0) { XmlNode xmlErrorProps = xmlDoc.CreateNode(XmlNodeType.Element, "ErrorProperties", string.Empty); StringBuilder propsText = new StringBuilder(); foreach (PropertyDefinitionBase baseProp in response.ErrorProperties) { PropertyInterpretation prop = new PropertyInterpretation(response.Item, baseProp); xmlErrorProps.AppendChild(prop.ToXML(xmlDoc)); } xmlError.AppendChild(xmlErrorProps); } xmlProperties.AppendChild(xmlError); // Write MIME content to file System.IO.File.WriteAllText( FileHelper.EnsureUniqueFileName(fileName), xmlDoc.OuterXml); DebugLog.WriteVerbose(String.Format("Wrote error to file, {0}.", fileName)); }
/// <summary> /// Convert a given object into a PropertyListDataTable. /// </summary> /// <param name="obj">Object to convert</param> /// <returns>DataTable filled out for each property of the given item</returns> private static GridDataTables.PropertyListDataTable GetPropertyList(object obj) { if (obj == null) { throw new ApplicationException("Cannot load null object in PropertyList"); } GridDataTables.PropertyListDataTable propList = new GridDataTables.PropertyListDataTable(); ServiceObject so = obj as ServiceObject; if (so != null) { foreach (PropertyDefinitionBase baseProp in so.GetLoadedPropertyDefinitions()) { if (baseProp != ItemSchema.ExtendedProperties) { GridDataTables.PropertyListRow row = propList.NewPropertyListRow(); PropertyInterpretation propInter = new PropertyInterpretation(so, baseProp); if (propInter.Name != null) { row.Name = propInter.Name; } else { row.Name = ""; } row.Value = propInter.Value; row.SmartView = propInter.SmartView; row.Type = propInter.TypeName; row.KnownNames = propInter.AlternateNames; row.PropertyObject = baseProp; // SortName is simply the property name with a prefix to ensure // that first class properties and extended properties stay grouped // together. if (baseProp is PropertyDefinition) { row.Icon = global::EWSEditor.Properties.Resources.FirstProp; row.SortName = string.Concat("a", row.Name); } else if (baseProp is ExtendedPropertyDefinition) { row.Icon = global::EWSEditor.Properties.Resources.ExtProp; row.SortName = string.Concat("b", row.Name); } // Add the row to the table propList.AddPropertyListRow(row); } } } else { Type objType = obj.GetType(); foreach (PropertyInfo propInfo in objType.GetProperties()) { GridDataTables.PropertyListRow row = propList.NewPropertyListRow(); PropertyInterpretation propInter = new PropertyInterpretation(obj, propInfo); row.Name = propInter.Name; row.Value = propInter.Value.Substring( 0, propInter.Value.Length > MAX_VALUE_LENGTH ? MAX_VALUE_LENGTH : propInter.Value.Length); row.Type = propInter.TypeName; row.PropertyObject = propInfo; row.Icon = global::EWSEditor.Properties.Resources.FirstProp; row.SortName = string.Concat("a", row.Name); // Add the row to the table propList.AddPropertyListRow(row); } } return(propList); }
public void LoadItem(ExchangeService service, ItemId itemId, PropertySet propertySet) { Item item = null; Dictionary <PropertyDefinitionBase, Exception> errorProperties = new Dictionary <PropertyDefinitionBase, Exception>(); bool retry = false; do { try { service.ClientRequestId = Guid.NewGuid().ToString(); // Set a new GUID item = Item.Bind(service, itemId, propertySet); retry = false; this.CurrentObject = item; } catch (ServiceResponseException srex) { DebugLog.WriteVerbose("Handled exception when retrieving property", srex); // Remove the bad properties from the PropertySet and try again. foreach (PropertyDefinitionBase propDef in srex.Response.ErrorProperties) { errorProperties.Add(propDef, srex); propertySet.Remove(propDef); retry = true; } } } while (retry); GridDataTables.PropertyListDataTable propList = GetPropertyList(item); // Add properties which had errors to the list foreach (PropertyDefinitionBase errProp in errorProperties.Keys) { GridDataTables.PropertyListRow errRow = propList.NewPropertyListRow(); errRow.Name = PropertyInterpretation.GetPropertyName(errProp); errRow.KnownNames = PropertyInterpretation.GetAlternateNames(errProp); errRow.Value = errorProperties[errProp].Message; //errRow.SmartView = PropertyInterpretation.GetSmartView(errorProperties[errProp]); errRow.Type = errorProperties[errProp].GetType().ToString(); errRow.PropertyObject = errProp; // SortName is simply the property name with a prefix to ensure // that first class properties and extended properties stay grouped // together. if (errProp is PropertyDefinition) { errRow.Icon = global::EWSEditor.Properties.Resources.FirstProp; errRow.SortName = string.Concat("a", errRow.Name); } else if (errProp is ExtendedPropertyDefinition) { errRow.Icon = global::EWSEditor.Properties.Resources.ExtProp; errRow.SortName = string.Concat("b", errRow.Name); } // Add the row to the table propList.AddPropertyListRow(errRow); } // Add properties to the list who were not found on the item bool isFound = false; foreach (ExtendedPropertyDefinition propDef in propertySet) { foreach (ExtendedProperty extProp in item.ExtendedProperties) { if (propDef == extProp.PropertyDefinition) { isFound = true; break; } } if (isFound == false) { GridDataTables.PropertyListRow missRow = propList.NewPropertyListRow(); missRow.Name = PropertyInterpretation.GetPropertyName(propDef); missRow.KnownNames = PropertyInterpretation.GetAlternateNames(propDef); missRow.Type = PropertyInterpretation.GetPropertyType(propDef); propList.AddPropertyListRow(missRow); } } this.PropertyListDataGridView.DataSource = GetPropertyList(this.CurrentObject); this.PropertyListDataGridView.Sort(this.NameColumn, ListSortDirection.Ascending); // If the width of the control minus all other column widths is greater // than the default width of the ValueColumn, extend the width of the // ValueColumn to display as much data as possible. int availableWidth = this.PropertyListDataGridView.Width - (this.NameColumn.Width + this.KnownNamesColumn.Width + this.TypeColumn.Width + this.SmartViewColumn.Width); if (availableWidth > this.ValueColumn.Width) { this.ValueColumn.Width = availableWidth; } }