/// <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); } }
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; } }