private static void AddToEnumerable(Type objectType, FeatureLayerInfo layerInfo, Graphic graphic, IEnumerable itemsSource) { var listType = typeof(ObservableCollection <>).MakeGenericType(new[] { objectType }); var row = AttributeListToObject(objectType, layerInfo, graphic, graphic.Attributes.Keys, null); listType.GetMethod("Add").Invoke((itemsSource as ICollectionView).SourceCollection, new[] { row }); }
/// <summary> /// Returns CodedValueSources that make up the display text of each value of the TypeIDField. /// </summary> /// <param name="field">TypeIDField</param> /// <param name="layerInfo">FeatureLayerInof used to construct the CodedValueSources from the FeatureTypes.</param> /// <returns>CodedValueSoruces that contain code an value matches to all possible TypeIDField values.</returns> internal static CodedValueSources BuildTypeIDCodedValueSource(Field field, FeatureLayerInfo layerInfo) { CodedValueSources codedValueSources = null; foreach (KeyValuePair <object, FeatureType> kvp in layerInfo.FeatureTypes) { if (kvp.Key == null) { continue; } string name = (kvp.Value != null && kvp.Value.Name != null) ? kvp.Value.Name : ""; CodedValueSource codedValueSource = new CodedValueSource() { Code = kvp.Key, DisplayName = name }; if (codedValueSources == null) { codedValueSources = new CodedValueSources(); if (field.Nullable) { CodedValueSource nullableSource = new CodedValueSource() { Code = null, DisplayName = " " }; codedValueSources.Add(nullableSource); } } codedValueSources.Add(codedValueSource); } return(codedValueSources); }
private void MapLayer_Initialized(object sender, EventArgs e) { bool mapIsLoaded = true; foreach (Layer layer in myMap.Layers) { if (!layer.IsInitialized) { mapIsLoaded = false; break; } if (layer is FeatureLayer) { FeatureLayer fLayer = layer as FeatureLayer; FeatureLayerInfo lyrInfo = fLayer.LayerInfo; if (lyrInfo != null) { fLayer.MapTip = new MapTipPopup(lyrInfo.Fields, fLayer.OutFields, lyrInfo.DisplayField, lyrInfo.Name) { ShowArrow = false, ShowCloseButton = false, Background = this.myTaskbarWidget.Background }; } } } if (mapIsLoaded) { InitializeMapUnits(); InitializeMapExtent(); EventCenter.DispatchMapLoadCompleteEvent(this.myMap, new RoutedEventArgs()); } }
/// <summary> /// Populates associated GraphicsLayer's PropertyChanged event handler (if it's not a FeatureLayer) to update /// contents of the FeatureDataGrid when its Graphics collection changes. Also, checks whether the layer is a /// FeatureLayer and populates the internal LayerInfo and EndSaveEdits event handlers for editing purposes. /// At the end sets the ItemsSource of FeatureDataGrid and resets its internal variables states and values, and /// if it's called as a result of the Initialized event handler of GraphicsLayer unregisters the handler. /// </summary> /// <param name="graphicsLayer">The GraphicsLayer.</param> /// <param name="handler">The Initialized event handler to be unregistered.</param> private void PopulateItemsSource(GraphicsLayer graphicsLayer, EventHandler <EventArgs> handler) { featureLayer = graphicsLayer as FeatureLayer; if (featureLayer != null) { featureLayerInfo = featureLayer.LayerInfo; } GraphicsLayer.PropertyChanged += GraphicsLayer_PropertyChanged; UnregisterGraphicCollectionEventHandlers(); currentGraphicCollection = graphicsLayer.Graphics; RegisterGraphicCollectionEventHandlers(); SetItemsSource((GraphicsLayer != null && GraphicsLayer.Graphics != null) ? (IList <Graphic>)GraphicsLayer.Graphics : new List <Graphic>()); ResetLayout(); // Restoring previously selected graphics (if any): if (GraphicsLayer != null) { RestorePreviousSelection(GraphicsLayer.SelectedGraphics); } if (handler != null) { graphicsLayer.Initialized -= handler; } }
internal static void AddToDataSource(this IEnumerable itemsSource, FeatureLayerInfo layerInfo, Graphic graphic, Type objectType) { if (objectType != null) { AddToEnumerable(objectType, layerInfo, graphic, itemsSource); } }
/// <summary> /// Sets the field information in the feature layer. /// </summary> /// <param name="featureLayerInfo">The feature layer info.</param> /// <param name="fieldProps">The properties associated with the field.</param> /// <returns>Dictionary of field types keyed by their actual names. Also, populates range domain information and field properties if any.</returns> internal static Dictionary<string, Type> SetFieldInfo(FeatureLayerInfo featureLayerInfo, out Dictionary<string, Field> fieldProps) { Dictionary<string, Type> fieldInfo = null; fieldProps = new Dictionary<string, Field>(); if (featureLayerInfo != null) { fieldInfo = new Dictionary<string, Type>(); foreach (Field field in featureLayerInfo.Fields) { if (fieldInfo.ContainsKey(field.Name)) continue; Type fieldType = typeof(object); switch (field.Type) { case Field.FieldType.Date: fieldType = typeof(DateTime?); break; case Field.FieldType.Double: fieldType = typeof(double?); break; case Field.FieldType.Integer: fieldType = typeof(int?); break; case Field.FieldType.OID: fieldType = typeof(int); break; case Field.FieldType.Geometry: case Field.FieldType.Blob: case Field.FieldType.Raster: case Field.FieldType.Unknown: fieldType = typeof(object); break; case Field.FieldType.Single: fieldType = typeof(float?); break; case Field.FieldType.SmallInteger: fieldType = typeof(short?); break; ; case Field.FieldType.GlobalID: case Field.FieldType.String: case Field.FieldType.XML: fieldType = typeof(string); break; case Field.FieldType.GUID: fieldType = typeof(Guid); break; default: throw new NotSupportedException(string.Format(Properties.Resources.FieldDomain_FieldTypeNotSupported, fieldType.GetType())); } fieldInfo.Add(field.Name, fieldType); fieldProps.Add(field.Name, field); } } return fieldInfo; }
private static IEnumerable GenerateEnumerable(Type objectType, FeatureLayerInfo layerInfo, IEnumerable <Graphic> graphics, string[] types, IEnumerable <Graphic> filter) { IEnumerable graphicsAfterFilter = filter != null?graphics.Intersect <Graphic>(filter) : graphics; var listType = typeof(ObservableCollection <>).MakeGenericType(new[] { objectType }); var listOfCustom = Activator.CreateInstance(listType); foreach (Graphic g in graphicsAfterFilter) { var row = AttributeListToObject(objectType, layerInfo, g, null, types); listType.GetMethod("Add").Invoke(listOfCustom, new[] { row }); } return(listOfCustom as IEnumerable); }
/// <summary> /// Sets the <see cref="FeatureDataGrid"/>'s ItemsSource after converting the source parameter to /// the proper format. /// </summary> /// <param name="graphics">The graphics.</param> private void SetItemsSource(IEnumerable <Graphic> graphics) { Dictionary <string, Field> fieldProps = null; string uniqueID = null; if (featureLayer == null) { featureLayer = GraphicsLayer as FeatureLayer; } if (featureLayer != null) { featureLayerInfo = featureLayer.LayerInfo; SetSubmitButtonVisibility(); if (featureLayer.LayerInfo != null) { fieldInfo = FieldDomainUtils.SetFieldInfo(featureLayerInfo, out rangeDomainInfo, out fieldProps); uniqueID = featureLayerInfo.ObjectIdField; } } else { fieldInfo = null; rangeDomainInfo = null; } // Indicate that the ItemsSource is about to be created by setting the isCreatingItemsSource flag. // We have to do this for both Silverlight and WPF as PagedCollectionView and CollectionViewSource // always add the first object to their selection: isCreatingItemsSource = true; var enumerableGraphics = graphics.ToDataSource(fieldInfo, rangeDomainInfo, fieldProps, uniqueID, FilterSource, out objectType) as IEnumerable <object>; if (enumerableGraphics.Count <object>() == 0) { // use this when collection is empty, because it shows the column headers. // PagedCollectionView does not create the headers for the collection it contains // when the collection is empty. ItemsSource = enumerableGraphics; } else { ItemsSource = new PagedCollectionView(enumerableGraphics); (ItemsSource as PagedCollectionView).CollectionChanged += PagedCollectionView_CollectionChanged; } if (GraphicsLayer != null) { RestorePreviousSelection(GraphicsLayer.SelectedGraphics); } ShowNumberOfRecords(); }
/// <summary> /// Checks Fields and determines if Field is Dynamic Coded Value Domain (aka Sub Domain) /// </summary> /// <param name="field">The field that needs to be checked.</param> /// <param name="layerInfo"> /// The FeatureLayerInfo that has the information to determine if the field /// is a dynamic coded value domain (aka Sub Domain). /// </param> /// <returns>Boolean value indicating if the field is a DynamicCodedValueDomain (aka Sub Domain)</returns> internal static bool IsDynamicDomain(Field field, FeatureLayerInfo layerInfo) { bool result = false; if (field != null && layerInfo != null && layerInfo.FeatureTypes != null && layerInfo.FeatureTypes.Count > 0) { foreach (object key in layerInfo.FeatureTypes.Keys) { FeatureType featureType = layerInfo.FeatureTypes[key]; if (featureType.Domains.ContainsKey(field.Name)) { result = true; break; } } } return(result); }
/// <summary> /// Initializes a new instance of the <see cref="FeatureDataField<T>"/> class. /// </summary> /// <param name="featureDataForm">The feature data form.</param> /// <param name="layerInfo">The feature layer info.</param> /// <param name="field">The field.</param> /// <param name="propertyType">Type of the property.</param> /// <param name="propertyValue">The property value.</param> internal FeatureDataField(FeatureDataForm featureDataForm, FeatureLayerInfo layerInfo, Field field, Type propertyType, T propertyValue) { this._featureDataForm = featureDataForm; this._field = field; this._layerInfo = layerInfo; this._codedValueDomain = null; Domain domain = field.Domain; if (domain != null && !Toolkit.Utilities.FieldDomainUtils.IsDynamicDomain(_field, _layerInfo)) { this._codedValueDomain = domain as CodedValueDomain; if (propertyType == typeof(DateTime) || propertyType == typeof(DateTime?)) { this._dateRangeDomain = domain as RangeDomain <DateTime>; } else if (propertyType == typeof(double) || propertyType == typeof(double?)) { this._doubleRangeDomain = domain as RangeDomain <double>; } else if (propertyType == typeof(float) || propertyType == typeof(float?)) { this._floatRangeDomain = domain as RangeDomain <float>; } else if (propertyType == typeof(int) || propertyType == typeof(int?)) { this._intRangeDomain = domain as RangeDomain <int>; } else if (propertyType == typeof(short) || propertyType == typeof(short?)) { this._shortRangeDomain = domain as RangeDomain <short>; } else if (propertyType == typeof(long) || propertyType == typeof(long?)) { this._longRangeDomain = domain as RangeDomain <long>; } else if (propertyType == typeof(byte) || propertyType == typeof(byte?)) { this._byteRangeDomain = domain as RangeDomain <byte>; } } this._propertyType = propertyType; this._propertyValue = propertyValue; }
/// <summary> /// Checks Fields and determines if Field is Dynamic Coded Value Domain (aka Sub Domain) /// </summary> /// <param name="field">The field that needs to be checked.</param> /// <param name="layerInfo"> /// The FeatureLayerInfo that has the information to determine if the field /// is a dynamic coded value domain (aka Sub Domain). /// </param> /// <returns>Boolean value indicating if the field is a DynamicCodedValueDomain (aka Sub Domain)</returns> internal static bool IsDynamicDomain(Field field, FeatureLayerInfo layerInfo) { bool result = false; if (field.Domain == null && layerInfo != null && layerInfo.FeatureTypes != null && layerInfo.FeatureTypes.Count > 0) { foreach (object key in layerInfo.FeatureTypes.Keys) { FeatureType featureType = layerInfo.FeatureTypes[key]; if (featureType.Domains.ContainsKey(field.Name)) { result = true; break; } } } return result; }
/// <summary> /// Builds a DynamicCodedValueSource object used to lookup display value. /// </summary> /// <param name="field">The field to build DynamicCodedValueSource for</param> /// <param name="layerInfo">The FeatureLayerInfo used to lookup all the coded value domains </param> /// <returns>DynamicCodedValueSource which is a collection of coded value domain values for a field.</returns> internal static DynamicCodedValueSource BuildDynamicCodedValueSource(Field field, FeatureLayerInfo layerInfo) { DynamicCodedValueSource dynamicCodedValueSource = null; foreach (object key in layerInfo.FeatureTypes.Keys) { FeatureType featureType = layerInfo.FeatureTypes[key]; if (featureType.Domains.ContainsKey(field.Name)) { if (dynamicCodedValueSource == null) dynamicCodedValueSource = new DynamicCodedValueSource(); CodedValueDomain codedValueDomain = featureType.Domains[field.Name] as CodedValueDomain; if (codedValueDomain != null) { CodedValueSources codedValueSources = null; foreach (KeyValuePair<object, string> kvp in codedValueDomain.CodedValues) { if (codedValueSources == null) { codedValueSources = new CodedValueSources(); if (field.Nullable) { CodedValueSource nullableSource = new CodedValueSource() { Code = null, DisplayName = " " }; codedValueSources.Add(nullableSource); } } codedValueSources.Add(new CodedValueSource() { Code = kvp.Key, DisplayName = kvp.Value }); } if (codedValueSources != null) { if (dynamicCodedValueSource == null) dynamicCodedValueSource = new DynamicCodedValueSource(); dynamicCodedValueSource.Add(featureType.Id, codedValueSources); } } } } return dynamicCodedValueSource; }
public static DomainSubtypeLookup GetDomainSubTypeLookup(FeatureLayerInfo featureLayerInfo, Client.Field field) { DomainSubtypeLookup lookup = DomainSubtypeLookup.None; if (featureLayerInfo != null) { Client.Field f = GetField(field.Name, featureLayerInfo.Fields); //Field has domain if (f != null && f.Domain is CodedValueDomain) { lookup = DomainSubtypeLookup.FieldDomain; } //field is type id field else if (featureLayerInfo.TypeIdField == field.Name) { lookup = DomainSubtypeLookup.TypeIdField; } //feature type defines domain for field else if (featureLayerInfo.FeatureTypes != null) { foreach (KeyValuePair <object, FeatureType> fTypePair in featureLayerInfo.FeatureTypes) { if (fTypePair.Value != null && fTypePair.Value.Domains != null) { foreach (KeyValuePair <string, Domain> pair in fTypePair.Value.Domains) { if (pair.Key.Equals(field.Name) && pair.Value is CodedValueDomain) { lookup = DomainSubtypeLookup.FeatureTypeDomain; break; } } } } } } return(lookup); }
// FeatureLayerInfo internal static Dictionary <string, object> ToDictionary(this FeatureLayerInfo layerInfo) { try { Dictionary <string, object> dictionary = new Dictionary <string, object>(); #region Common Info dictionary.Add("id", layerInfo.Id); if (!string.IsNullOrEmpty(layerInfo.Name)) { dictionary.Add("name", layerInfo.Name); } if (!string.IsNullOrEmpty(layerInfo.Type)) { dictionary.Add("type", layerInfo.Type); } if (!string.IsNullOrEmpty(layerInfo.Description)) { dictionary.Add("description", layerInfo.Description); } if (!string.IsNullOrEmpty(layerInfo.DefinitionExpression)) { dictionary.Add("definitionExpression", layerInfo.DefinitionExpression); } #endregion // new to 10.1 Feature Service dictionary.Add("isDataVersioned", layerInfo.IsDataVersioned); #region Field Info if (!string.IsNullOrEmpty(layerInfo.ObjectIdField)) { dictionary.Add("objectIdField", layerInfo.ObjectIdField); } if (!string.IsNullOrEmpty(layerInfo.GlobalIdField)) { dictionary.Add("globalIdField", layerInfo.GlobalIdField); } if (!string.IsNullOrEmpty(layerInfo.TypeIdField)) { dictionary.Add("typeIdField", layerInfo.TypeIdField); } if (!string.IsNullOrEmpty(layerInfo.DisplayField)) { dictionary.Add("displayField", layerInfo.DisplayField); } List <object> fields = new List <object>(); layerInfo.Fields.ForEach(f => fields.Add(f.ToDictionary())); dictionary.Add("fields", fields); #endregion #region Layer-Specific Info string geometryType = null; switch (layerInfo.GeometryType) { case Client.Tasks.GeometryType.Point: geometryType = "esriGeometryPoint"; break; case Client.Tasks.GeometryType.MultiPoint: geometryType = "esriGeometryMultipoint"; break; case Client.Tasks.GeometryType.Polyline: geometryType = "esriGeometryPolyline"; break; case Client.Tasks.GeometryType.Polygon: geometryType = "esriGeometryPolygon"; break; case Client.Tasks.GeometryType.Envelope: geometryType = "esriGeometryEnvelope"; break; } if (geometryType != null) { dictionary.Add("geometryType", geometryType); } dictionary.Add("minScale", layerInfo.MinimumScale); dictionary.Add("maxScale", layerInfo.MaximumScale); if (!string.IsNullOrEmpty(layerInfo.CopyrightText)) { dictionary.Add("copyrightText", layerInfo.CopyrightText); } if (layerInfo.Extent != null) { dictionary.Add("extent", layerInfo.Extent); } if (layerInfo.DefaultSpatialReference != null) { dictionary.Add("spatialReference", layerInfo.DefaultSpatialReference); } dictionary.Add("hasAttachments", layerInfo.HasAttachments); if (layerInfo.Renderer != null) { dictionary.Add("drawingInfo", layerInfo.Renderer.ToDictionary()); } // TODO: SUPPORT TIME INFO - TimeInfo property is not accessible //if (dictionary.ContainsKey("timeInfo")) // this.TimeInfo = TimeInfo.FromDictionary(dictionary["timeInfo"] as Dictionary<string, object>); if (layerInfo.Relationships != null) { List <Dictionary <string, object> > relationships = new List <Dictionary <string, object> >(); foreach (Relationship relationship in layerInfo.Relationships) { relationships.Add(relationship.ToDictionary()); } dictionary.Add("relationships", relationships); } if (layerInfo.Capabilities != null) { dictionary.Add("capabilities", string.Join(",", layerInfo.Capabilities.ToArray())); } dictionary.Add("maxRecordCount", layerInfo.MaxRecordCount); dictionary.Add("supportsAdvancedQueries", layerInfo.SupportsAdvancedQueries); dictionary.Add("supportsStatistics", layerInfo.SupportsStatistics); dictionary.Add("canModifyLayer", layerInfo.CanModifyLayer); dictionary.Add("canScaleSymbols", layerInfo.CanScaleSymbols); dictionary.Add("hasLabels", layerInfo.HasLabels); #endregion #region FeatureTypes if (layerInfo.FeatureTypes != null) { List <Dictionary <string, object> > types = new List <Dictionary <string, object> >(); foreach (KeyValuePair <object, FeatureType> type in layerInfo.FeatureTypes) { types.Add(type.Value.ToDictionary()); } dictionary.Add("types", types); } #endregion #region FeatureTemplates if (layerInfo.Templates != null) { List <Dictionary <string, object> > templates = new List <Dictionary <string, object> >(); foreach (KeyValuePair <string, FeatureTemplate> template in layerInfo.Templates) { templates.Add(template.Value.ToDictionary()); } dictionary.Add("templates", templates); } #endregion #region Editor Tracking if (layerInfo.EditFieldsInfo != null) { dictionary.Add("editFieldsInfo", layerInfo.EditFieldsInfo.ToDictionary()); } #endregion #region OwnershipBasedAccess if (layerInfo.OwnershipBasedAccessControl != null) { dictionary.Add("ownershipBasedAccessControlForFeatures", layerInfo.OwnershipBasedAccessControl.ToDictionary()); } #endregion #region Z & M data dictionary.Add("hasZ", layerInfo.HasZ); dictionary.Add("hasM", layerInfo.HasM); dictionary.Add("zDefault", layerInfo.ZDefault); dictionary.Add("enableZDefaults", layerInfo.EnableZDefaults); dictionary.Add("allowGeometryUpdates", layerInfo.AllowGeometryUpdates); #endregion return(dictionary); } catch { return(null); } }
/// <summary> /// Sets the <see cref="FeatureDataGrid"/>'s ItemsSource after converting the source parameter to /// the proper format. /// </summary> /// <param name="graphics">The graphics.</param> private void SetItemsSource(IEnumerable<Graphic> graphics) { Dictionary<string, Field> fieldProps = null; string uniqueID = null; if (featureLayer == null) featureLayer = GraphicsLayer as FeatureLayer; if (featureLayer != null) { featureLayerInfo = featureLayer.LayerInfo; SetSubmitButtonVisibility(); if (featureLayer.LayerInfo != null) { fieldInfo = FieldDomainUtils.SetFieldInfo(featureLayerInfo, out fieldProps); uniqueID = featureLayerInfo.ObjectIdField; } } else { fieldInfo = null; } // Indicate that the ItemsSource is about to be created by setting the isCreatingItemsSource flag. // We have to do this for both Silverlight and WPF as PagedCollectionView and CollectionViewSource // always add the first object to their selection: isCreatingItemsSource = true; var enumerableGraphics = graphics.ToDataSource(featureLayerInfo, fieldInfo, fieldProps, uniqueID, FilterSource, out objectType) as IEnumerable<object>; if (enumerableGraphics.Count<object>() == 0) { // use this when collection is empty, because it shows the column headers. // PagedCollectionView does not create the headers for the collection it contains // when the collection is empty. ItemsSource = enumerableGraphics; } else { ItemsSource = new PagedCollectionView(enumerableGraphics); (ItemsSource as PagedCollectionView).CollectionChanged += PagedCollectionView_CollectionChanged; } if(GraphicsLayer != null) RestorePreviousSelection(GraphicsLayer.SelectedGraphics); ShowNumberOfRecords(); }
/// <summary> /// Populates associated GraphicsLayer's PropertyChanged event handler (if it's not a FeatureLayer) to update /// contents of the FeatureDataGrid when its Graphics collection changes. Also, checks whether the layer is a /// FeatureLayer and populates the internal LayerInfo and EndSaveEdits event handlers for editing purposes. /// At the end sets the ItemsSource of FeatureDataGrid and resets its internal variables states and values, and /// if it's called as a result of the Initialized event handler of GraphicsLayer unregisters the handler. /// </summary> /// <param name="graphicsLayer">The GraphicsLayer.</param> /// <param name="handler">The Initialized event handler to be unregistered.</param> private void PopulateItemsSource(GraphicsLayer graphicsLayer, EventHandler<EventArgs> handler) { featureLayer = graphicsLayer as FeatureLayer; if (featureLayer != null) { featureLayerInfo = featureLayer.LayerInfo; } GraphicsLayer.PropertyChanged += GraphicsLayer_PropertyChanged; UnregisterGraphicCollectionEventHandlers(); currentGraphicCollection = graphicsLayer.Graphics; RegisterGraphicCollectionEventHandlers(); SetItemsSource((GraphicsLayer != null && GraphicsLayer.Graphics != null) ? (IList<Graphic>)GraphicsLayer.Graphics : new List<Graphic>()); ResetLayout(); // Restoring previously selected graphics (if any): if (GraphicsLayer != null) RestorePreviousSelection(GraphicsLayer.SelectedGraphics); if (handler != null) graphicsLayer.Initialized -= handler; }
/// <summary> /// Sets the field information in the feature layer. /// </summary> /// <param name="featureLayerInfo">The feature layer info.</param> /// <param name="fieldProps">The properties associated with the field.</param> /// <returns>Dictionary of field types keyed by their actual names. Also, populates range domain information and field properties if any.</returns> internal static Dictionary <string, Type> SetFieldInfo(FeatureLayerInfo featureLayerInfo, out Dictionary <string, Field> fieldProps) { Dictionary <string, Type> fieldInfo = null; fieldProps = new Dictionary <string, Field>(); if (featureLayerInfo != null) { fieldInfo = new Dictionary <string, Type>(); foreach (Field field in featureLayerInfo.Fields) { if (fieldInfo.ContainsKey(field.Name)) { continue; } Type fieldType = typeof(object); switch (field.Type) { case Field.FieldType.Date: fieldType = typeof(DateTime?); break; case Field.FieldType.Double: fieldType = typeof(double?); break; case Field.FieldType.Integer: fieldType = typeof(int?); break; case Field.FieldType.OID: fieldType = typeof(int); break; case Field.FieldType.Geometry: case Field.FieldType.Blob: case Field.FieldType.Raster: case Field.FieldType.Unknown: fieldType = typeof(object); break; case Field.FieldType.Single: fieldType = typeof(float?); break; case Field.FieldType.SmallInteger: fieldType = typeof(short?); break;; case Field.FieldType.GlobalID: case Field.FieldType.String: case Field.FieldType.XML: fieldType = typeof(string); break; case Field.FieldType.GUID: fieldType = typeof(Guid); break; default: throw new NotSupportedException(string.Format(Properties.Resources.FieldDomain_FieldTypeNotSupported, fieldType.GetType())); } fieldInfo.Add(field.Name, fieldType); fieldProps.Add(field.Name, field); } } return(fieldInfo); }
public static DomainSubtypeLookup GetDomainSubTypeLookup(FeatureLayerInfo featureLayerInfo, Client.Field field) { DomainSubtypeLookup lookup = DomainSubtypeLookup.None; if (featureLayerInfo != null) { Client.Field f = GetField(field.Name, featureLayerInfo.Fields); //Field has domain if (f != null && f.Domain is CodedValueDomain) { lookup = DomainSubtypeLookup.FieldDomain; } //field is type id field else if (featureLayerInfo.TypeIdField == field.Name) { lookup = DomainSubtypeLookup.TypeIdField; } //feature type defines domain for field else if (featureLayerInfo.FeatureTypes != null) { foreach (KeyValuePair<object, FeatureType> fTypePair in featureLayerInfo.FeatureTypes) { if (fTypePair.Value != null && fTypePair.Value.Domains != null) { foreach (KeyValuePair<string, Domain> pair in fTypePair.Value.Domains) { if (pair.Key.Equals(field.Name) && pair.Value is CodedValueDomain) { lookup = DomainSubtypeLookup.FeatureTypeDomain; break; } } } } } } return lookup; }
private static string errorMessage = Properties.Resources.Validation_InvalidRangeDomain; // Error message shown after validation fails /// <summary> /// Validates subtype fields that have range domain defined. /// </summary> /// <param name="layerInfo">FeatureLayerInfo that contains the subtype information.</param> /// <param name="field">The field to validate.</param> /// <param name="typeIdValue">The current TypeIDField value to uses as lookup value for SubType</param> /// <param name="value">The current value to validate.</param> internal static void ValidateRange(FeatureLayerInfo layerInfo, Field field, object typeIdValue, object value) { if (layerInfo == null || field == null || typeIdValue == null || value == null) return; switch (field.Type) { case Field.FieldType.Date: if (value is DateTime) { var dynamicRangeDomains = FieldDomainUtils.BuildDynamicRangeDomain<DateTime>(field, layerInfo); if (dynamicRangeDomains != null && typeIdValue != null) { var domains = dynamicRangeDomains.Where(kvp => kvp.Key.Equals(typeIdValue)); if (domains != null && domains.Any()) { var domain = domains.First().Value; if (((DateTime)value) < domain.MinimumValue || ((DateTime)value) > domain.MaximumValue) throw new ArgumentException(string.Format(errorMessage, domain.MinimumValue, domain.MaximumValue)); } } } break; case Field.FieldType.Double: if (value is Double) { var dynamicRangeDomains = FieldDomainUtils.BuildDynamicRangeDomain<Double>(field, layerInfo); if (dynamicRangeDomains != null && typeIdValue != null) { var domains = dynamicRangeDomains.Where(kvp => kvp.Key.Equals(typeIdValue)); if (domains != null && domains.Any()) { var domain = domains.First().Value; if (((Double)value) < domain.MinimumValue || ((Double)value) > domain.MaximumValue) throw new ArgumentException(string.Format(errorMessage, domain.MinimumValue, domain.MaximumValue)); } } } break; case Field.FieldType.Integer: if (value is Int32) { var dynamicRangeDomains = FieldDomainUtils.BuildDynamicRangeDomain<Int32>(field, layerInfo); if (dynamicRangeDomains != null && typeIdValue != null) { var domains = dynamicRangeDomains.Where(kvp => kvp.Key.Equals(typeIdValue)); if (domains != null && domains.Any()) { var domain = domains.First().Value; if (((Int32)value) < domain.MinimumValue || ((Int32)value) > domain.MaximumValue) throw new ArgumentException(string.Format(errorMessage, domain.MinimumValue, domain.MaximumValue)); } } } break; case Field.FieldType.Single: if (value is Single) { var dynamicRangeDomains = FieldDomainUtils.BuildDynamicRangeDomain<Single>(field, layerInfo); if (dynamicRangeDomains != null && typeIdValue != null) { var domains = dynamicRangeDomains.Where(kvp => kvp.Key.Equals(typeIdValue)); if (domains != null && domains.Any()) { var domain = domains.First().Value; if (((Single)value) < domain.MinimumValue || ((Single)value) > domain.MaximumValue) throw new ArgumentException(string.Format(errorMessage, domain.MinimumValue, domain.MaximumValue)); } } } break; case Field.FieldType.SmallInteger: if (value is Int16) { var dynamicRangeDomains = FieldDomainUtils.BuildDynamicRangeDomain<Int16>(field, layerInfo); if (dynamicRangeDomains != null && typeIdValue != null) { var domains = dynamicRangeDomains.Where(kvp => kvp.Key.Equals(typeIdValue)); if (domains != null && domains.Any()) { var domain = domains.First().Value; if (((Int16)value) < domain.MinimumValue || ((Int16)value) > domain.MaximumValue) throw new ArgumentException(string.Format(errorMessage, domain.MinimumValue, domain.MaximumValue)); } } } break; } }
private static object AttributeListToObject(Type objectType, FeatureLayerInfo layerInfo, Graphic graphic,IEnumerable<string> attributeKeys, IEnumerable<string> propertyNames) { string typeIdFieldName = null; if(layerInfo != null && string.IsNullOrEmpty(layerInfo.TypeIdField) == false) { if (_fieldMapping != null && _fieldMapping.ContainsKey(layerInfo.TypeIdField)) typeIdFieldName = _fieldMapping.KeyOfValue(layerInfo.TypeIdField); } Action<object, string, object> myDynamicRangeValidationMethod = (instance, fieldName, value) => { if (layerInfo == null || layerInfo.Fields == null || layerInfo.Fields.Count == 0) return; var field = layerInfo.Fields.FirstOrDefault(f => string.Equals(f.FieldName, fieldName)); if(field != null) { if(FieldDomainUtils.IsDynamicDomain(field, layerInfo)) { var fieldInfo = instance.GetType().GetProperty(typeIdFieldName); var typeIDValue = fieldInfo.GetValue(instance, null); RangeDomainValidator.ValidateRange(layerInfo, field, typeIDValue, value); } else if(field.Domain != null && !(field.Domain is CodedValueDomain)) { RangeDomainValidator.ValidateRange(field, value); } } }; var row = Activator.CreateInstance(objectType, new object[] { graphic, myDynamicRangeValidationMethod }); foreach (string type in propertyNames ?? attributeKeys) { IDictionary<string, object> currentDict = graphic.Attributes; string propertyName = type; string attributeKey = type; if (propertyNames == null) { if (_fieldMapping.ContainsKey(attributeKey)) propertyName = _fieldMapping[attributeKey]; } else attributeKey = _fieldMapping.KeyOfValue(propertyName); if (propertyName != null && currentDict != null) { if (currentDict.ContainsKey(attributeKey)) SetProperty(currentDict[attributeKey], row, objectType.GetProperty(propertyName)); } } return row; }
internal static IEnumerable ToDataSource(this IEnumerable<Graphic> graphics, FeatureLayerInfo layerInfo, Dictionary<string, Type> fieldInfo, Dictionary<string, Field> fieldProps, string uniqueID, IEnumerable<Graphic> filterGraphics, out Type objectType) { objectType = null; IDictionary firstDict = null; IEnumerable<IDictionary<string, object>> list = GetGraphicsEnumerable(graphics); Dictionary<string, Type> properties = new Dictionary<string, Type>(); _fieldMapping = new Dictionary<string, string>(); if (fieldInfo == null) { if (list != null) { IEnumerator enumList = list.GetEnumerator(); if (enumList != null && enumList.MoveNext()) { firstDict = enumList.Current as IDictionary; if (firstDict != null) { foreach (DictionaryEntry pair in firstDict) { string keyToUse = CreateMappedKey(pair.Key.ToString()); Type t = GetValueType(keyToUse, pair.Value, fieldInfo); properties.Add(keyToUse, t); } while (enumList.MoveNext()) { IDictionary nextDict = enumList.Current as IDictionary; IDictionaryEnumerator enumEntries = nextDict.GetEnumerator(); while (enumEntries != null && enumEntries.MoveNext()) { DictionaryEntry pair = (DictionaryEntry)enumEntries.Current; Type t = GetValueType(pair.Key as string, pair.Value, fieldInfo); if (!firstDict.Contains(pair.Key)) // Attribute doesn't exist => add it { object defaultValue = t.IsValueType ? Activator.CreateInstance(t) : null; firstDict.Add(pair.Key, defaultValue); } else // Attribute exists => check for data type compatibility { Type typeInFirstDict = GetValueType(pair.Key as string, firstDict[pair.Key], fieldInfo); if (typeInFirstDict is Object && firstDict[pair.Key] == null) { string keyToUse = GetMappedKey(pair.Key.ToString()); if (t == typeof(string) || IsNumericType(t)) properties[keyToUse] = t; continue; } if (pair.Value != null && // null values in nextDict match the nullable data type associated with the attribute in firstDict !t.IsOfType(typeInFirstDict)) // attribute data types don't match { if (typeInFirstDict == typeof(string)) continue; if(IsNumericType(typeInFirstDict) && IsNumericType(t)) { int rank1 = NumericRank(typeInFirstDict); int rank2 = NumericRank(t); string keyToUse = GetMappedKey(pair.Key.ToString()); if (rank1 < rank2) properties[keyToUse] = t; else if (rank1 == rank2 && IsUnsigned(typeInFirstDict) != IsUnsigned(t)) properties[keyToUse] = UpgradeRankType(t); continue; } throw new InvalidCastException(string.Format(Properties.Resources.FeatureDataGrid_MixedAttributeTypesNotAllowed,firstDict[pair.Key].GetType(), pair.Key)); } } } } } } } } if(firstDict == null && fieldInfo == null) return new object[] { }; if (fieldInfo != null) // FeatureLayer { foreach (string key in fieldInfo.Keys) { string keyToUse = CreateMappedKey(key); Type t = fieldInfo[key]; properties.Add(keyToUse, t); } } string typeSignature = GetTypeSignature(properties); objectType = GetTypeByTypeSignature(typeSignature); if (objectType == null) { TypeBuilder tb = GetTypeBuilder(typeSignature); FieldBuilder DynamicTypeRangeDomainValidationFieldBuilder = tb.DefineField("DynamicTypeRangeDomainValidationMethod", typeof(Action<object, string, object>), FieldAttributes.Private); FieldBuilder fieldBuilder = tb.DefineField("_graphicSibling", typeof(Graphic), FieldAttributes.Private); ConstructorBuilder constructorBuilder = tb.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, new Type[] { typeof(Graphic), typeof(Action<object, string, object>)}); ILGenerator cbIL = constructorBuilder.GetILGenerator(); cbIL.Emit(OpCodes.Ldarg_0); cbIL.Emit(OpCodes.Call, typeof(object).GetConstructor(Type.EmptyTypes)); cbIL.Emit(OpCodes.Ldarg_0); cbIL.Emit(OpCodes.Ldarg_1); cbIL.Emit(OpCodes.Stfld, fieldBuilder); cbIL.Emit(OpCodes.Ldarg_0); cbIL.Emit(OpCodes.Ldarg_2); cbIL.Emit(OpCodes.Stfld, DynamicTypeRangeDomainValidationFieldBuilder); cbIL.Emit(OpCodes.Ret); MethodBuilder methodBuilder = tb.DefineMethod("GetGraphicSibling", MethodAttributes.Public, typeof(Graphic), Type.EmptyTypes); ILGenerator mbIL = methodBuilder.GetILGenerator(); mbIL.Emit(OpCodes.Ldarg_0); mbIL.Emit(OpCodes.Ldfld, fieldBuilder); mbIL.Emit(OpCodes.Ret); int order = 0; foreach (string key in properties.Keys) { if (fieldProps != null) // FeatureLayer { if (_fieldMapping.KeyOfValue(key) != null) { string mappedKey = _fieldMapping.KeyOfValue(key); if (fieldProps.ContainsKey(mappedKey)) // Only create the property if the key is contained in field properties { Field fld = fieldProps[mappedKey]; if (IsViewableAttribute(fld)) CreateProperty(tb, DynamicTypeRangeDomainValidationFieldBuilder, key, properties[key], layerInfo, fld, order++, uniqueID == key); } } } else // GraphicsLayer CreateProperty(tb, null, key, properties[key], null, null, order++, uniqueID == key); } objectType = tb.CreateType(); _typeBySignature.Add(typeSignature, objectType); } return GenerateEnumerable(objectType, layerInfo, graphics, properties.Keys.ToArray(), filterGraphics); }
public GraphicComparer(string Field, FeatureLayerInfo LayerInfo) { this.Field = Field; this.LayerInfo = LayerInfo; }
private static string errorMessage = Properties.Resources.Validation_InvalidRangeDomain; // Error message shown after validation fails /// <summary> /// Validates subtype fields that have range domain defined. /// </summary> /// <param name="layerInfo">FeatureLayerInfo that contains the subtype information.</param> /// <param name="field">The field to validate.</param> /// <param name="typeIdValue">The current TypeIDField value to uses as lookup value for SubType</param> /// <param name="value">The current value to validate.</param> internal static void ValidateRange(FeatureLayerInfo layerInfo, Field field, object typeIdValue, object value) { if (layerInfo == null || field == null || typeIdValue == null || value == null) { return; } switch (field.Type) { case Field.FieldType.Date: if (value is DateTime) { var dynamicRangeDomains = FieldDomainUtils.BuildDynamicRangeDomain <DateTime>(field, layerInfo); if (dynamicRangeDomains != null && typeIdValue != null) { var domains = dynamicRangeDomains.Where(kvp => kvp.Key.Equals(typeIdValue)); if (domains != null && domains.Any()) { var domain = domains.First().Value; if (((DateTime)value) < domain.MinimumValue || ((DateTime)value) > domain.MaximumValue) { throw new ArgumentException(string.Format(errorMessage, domain.MinimumValue, domain.MaximumValue)); } } } } break; case Field.FieldType.Double: if (value is Double) { var dynamicRangeDomains = FieldDomainUtils.BuildDynamicRangeDomain <Double>(field, layerInfo); if (dynamicRangeDomains != null && typeIdValue != null) { var domains = dynamicRangeDomains.Where(kvp => kvp.Key.Equals(typeIdValue)); if (domains != null && domains.Any()) { var domain = domains.First().Value; if (((Double)value) < domain.MinimumValue || ((Double)value) > domain.MaximumValue) { throw new ArgumentException(string.Format(errorMessage, domain.MinimumValue, domain.MaximumValue)); } } } } break; case Field.FieldType.Integer: if (value is Int32) { var dynamicRangeDomains = FieldDomainUtils.BuildDynamicRangeDomain <Int32>(field, layerInfo); if (dynamicRangeDomains != null && typeIdValue != null) { var domains = dynamicRangeDomains.Where(kvp => kvp.Key.Equals(typeIdValue)); if (domains != null && domains.Any()) { var domain = domains.First().Value; if (((Int32)value) < domain.MinimumValue || ((Int32)value) > domain.MaximumValue) { throw new ArgumentException(string.Format(errorMessage, domain.MinimumValue, domain.MaximumValue)); } } } } break; case Field.FieldType.Single: if (value is Single) { var dynamicRangeDomains = FieldDomainUtils.BuildDynamicRangeDomain <Single>(field, layerInfo); if (dynamicRangeDomains != null && typeIdValue != null) { var domains = dynamicRangeDomains.Where(kvp => kvp.Key.Equals(typeIdValue)); if (domains != null && domains.Any()) { var domain = domains.First().Value; if (((Single)value) < domain.MinimumValue || ((Single)value) > domain.MaximumValue) { throw new ArgumentException(string.Format(errorMessage, domain.MinimumValue, domain.MaximumValue)); } } } } break; case Field.FieldType.SmallInteger: if (value is Int16) { var dynamicRangeDomains = FieldDomainUtils.BuildDynamicRangeDomain <Int16>(field, layerInfo); if (dynamicRangeDomains != null && typeIdValue != null) { var domains = dynamicRangeDomains.Where(kvp => kvp.Key.Equals(typeIdValue)); if (domains != null && domains.Any()) { var domain = domains.First().Value; if (((Int16)value) < domain.MinimumValue || ((Int16)value) > domain.MaximumValue) { throw new ArgumentException(string.Format(errorMessage, domain.MinimumValue, domain.MaximumValue)); } } } } break; } }
private static void CreateProperty(TypeBuilder tb, FieldBuilder dynamicRangeDomainValidation, string propertyName, Type propertyType, FeatureLayerInfo layerInfo, Field field, int order, bool isKey) { // Create the private data backed property i.e. (private int _myProperty) FieldBuilder fieldBuilder = tb.DefineField("_" + propertyName, propertyType, FieldAttributes.Private); // Create the public property i.e. (public int MyProperty { get { return _myProperty; } set{ _myPropety = value; } }) PropertyBuilder propertyBuilder = tb.DefineProperty(propertyName, PropertyAttributes.HasDefault, propertyType, null); string displayName = null; if (field != null) { displayName = field.Alias; } if (string.IsNullOrEmpty(displayName)) { displayName = _fieldMapping.KeyOfValue(propertyName); } if (!string.IsNullOrEmpty(displayName)) { // Add DisplayAttribute to property [DisplayAttribute(Name = displayName)] Type displayAttribute = typeof(DisplayAttribute); PropertyInfo info = displayAttribute.GetProperty("Name"); PropertyInfo info2 = displayAttribute.GetProperty("AutoGenerateField"); PropertyInfo info3 = displayAttribute.GetProperty("Order"); CustomAttributeBuilder cabuilder = new CustomAttributeBuilder( displayAttribute.GetConstructor(new Type[] { }), new object[] { }, new PropertyInfo[] { info, info2, info3 }, new object[] { displayName, !isKey, order }); propertyBuilder.SetCustomAttribute(cabuilder); } if (isKey) { // Add KeyAttribute to property [KeyAttribute] CustomAttributeBuilder cabuilder = new CustomAttributeBuilder( typeof(KeyAttribute).GetConstructor(new Type[] { }), new object[] { }); propertyBuilder.SetCustomAttribute(cabuilder); } if (field != null) { if (!field.Nullable && field.Type != Field.FieldType.GlobalID) { // Add Required to property using standard validation error [Required()] CustomAttributeBuilder requiredCABuilder = new CustomAttributeBuilder( typeof(System.ComponentModel.DataAnnotations.RequiredAttribute).GetConstructor(new Type[] { }), new object[] { }); propertyBuilder.SetCustomAttribute(requiredCABuilder); } // Add AllowEdit to property and allow an initial value PropertyInfo allowEditInfo = typeof(EditableAttribute).GetProperty("AllowEdit"); PropertyInfo allowInitialValueInfo = typeof(EditableAttribute).GetProperty("AllowInitialValue"); CustomAttributeBuilder allowEditCABuilder = new CustomAttributeBuilder( typeof(EditableAttribute).GetConstructor(new Type[] { typeof(bool) }), new object[] { field.Editable }, new PropertyInfo[] { allowEditInfo, allowInitialValueInfo }, new object[] { field.Editable, true }); propertyBuilder.SetCustomAttribute(allowEditCABuilder); // Add MaximumLength to property if (field.Type == Field.FieldType.String && field.Length > 0) { PropertyInfo maximumLengthInfo = typeof(StringLengthAttribute).GetProperty("MaximumLength"); CustomAttributeBuilder cabuilder = new CustomAttributeBuilder( typeof(StringLengthAttribute).GetConstructor(new Type[] { typeof(int) }), new object[] { field.Length }, new PropertyInfo[] { maximumLengthInfo }, new object[] { field.Length }); propertyBuilder.SetCustomAttribute(cabuilder); } } if (propertyType == typeof(DateTime) || propertyType == typeof(DateTime?)) { // Add DisplayAttribute to property [DisplayFormatAttribute(DataFormatString = "m/dd/YYYY")] PropertyInfo info = typeof(DisplayFormatAttribute).GetProperty("DataFormatString"); CustomAttributeBuilder cabuilder = new CustomAttributeBuilder( typeof(DisplayFormatAttribute).GetConstructor(new Type[] { }), new object[] { }, new PropertyInfo[] { info }, new object[] { System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern }); propertyBuilder.SetCustomAttribute(cabuilder); } MethodBuilder getPropMthdBldr = tb.DefineMethod("get_" + propertyName, MethodAttributes.Public | MethodAttributes.SpecialName | MethodAttributes.HideBySig, propertyType, Type.EmptyTypes); ILGenerator getIL = getPropMthdBldr.GetILGenerator(); getIL.Emit(OpCodes.Ldarg_0); getIL.Emit(OpCodes.Ldfld, fieldBuilder); getIL.Emit(OpCodes.Ret); MethodBuilder setPropMthdBldr = tb.DefineMethod("set_" + propertyName, MethodAttributes.Public | MethodAttributes.SpecialName | MethodAttributes.HideBySig, null, new Type[] { propertyType }); ILGenerator setIL = setPropMthdBldr.GetILGenerator(); // for feature layer range domain validation is added to the setter call. if (dynamicRangeDomainValidation != null) { // Labels are used to jump ahead to a specific line of code. // for example if an if statement returns false then you will want to jump // over the code that would execute if the condition was true because you don't // want that code to get executed. // An un-named temp variable that the compiler needs // in order to store the resulting boolean from the if statement. setIL.DeclareLocal(typeof(bool)); // Stloc_0 System.Reflection.Emit.Label endIfLabel = setIL.DefineLabel(); setIL.Emit(OpCodes.Ldarg_0); // load this instance setIL.Emit(OpCodes.Ldfld, dynamicRangeDomainValidation); // load this field setIL.Emit(OpCodes.Ldnull); // load a null value setIL.Emit(OpCodes.Ceq); // compare equality setIL.Emit(OpCodes.Stloc_0); // store the result of the equality check. note: setIL.DeclareLocal(typeof(bool)) must be declared. setIL.Emit(OpCodes.Ldloc_0); // load the result of the equality check setIL.Emit(OpCodes.Brtrue_S, endIfLabel); // if true execute the next argument. if false jump to the else if statement label. setIL.Emit(OpCodes.Ldarg_0); setIL.Emit(OpCodes.Ldfld, dynamicRangeDomainValidation); setIL.Emit(OpCodes.Ldarg_0); setIL.Emit(OpCodes.Ldstr, field != null ? field.FieldName : ""); setIL.Emit(OpCodes.Ldarg_1); setIL.Emit(OpCodes.Box, propertyType); setIL.Emit(OpCodes.Callvirt, typeof(Action <object, string, object>).GetMethod("Invoke", new Type[] { typeof(object), typeof(string), typeof(object) })); setIL.MarkLabel(endIfLabel); } setIL.Emit(OpCodes.Ldarg_0); setIL.Emit(OpCodes.Ldarg_1); setIL.Emit(OpCodes.Stfld, fieldBuilder); setIL.Emit(OpCodes.Ret); propertyBuilder.SetGetMethod(getPropMthdBldr); propertyBuilder.SetSetMethod(setPropMthdBldr); }
/// <summary> /// Sets the <see cref="FeatureDataGrid"/>'s ItemsSource after converting the source parameter to /// the proper format. /// </summary> /// <param name="graphics">The graphics.</param> private void SetItemsSource(IEnumerable<Graphic> graphics) { Dictionary<string, Field> fieldProps = null; string uniqueID = null; if (featureLayer == null) featureLayer = GraphicsLayer as FeatureLayer; if (featureLayer != null) { featureLayerInfo = featureLayer.LayerInfo; SetSubmitButtonVisibility(); if (featureLayer.LayerInfo != null) { fieldInfo = FieldDomainUtils.SetFieldInfo(featureLayerInfo, out rangeDomainInfo, out fieldProps); uniqueID = featureLayerInfo.ObjectIdField; } } else { fieldInfo = null; rangeDomainInfo = null; } // Indicate that the ItemsSource is about to be created by setting the isCreatingItemsSource flag. // We have to do this for both Silverlight and WPF as PagedCollectionView and CollectionViewSource // always add the first object to their selection: isCreatingItemsSource = true; ItemsSource = new PagedCollectionView(graphics.ToDataSource(fieldInfo, rangeDomainInfo, fieldProps, uniqueID, out objectType)); (ItemsSource as PagedCollectionView).CollectionChanged += PagedCollectionView_CollectionChanged; ShowNumberOfRecords(); }
/// <summary> /// Returns CodedValueSources that make up the display text of each value of the TypeIDField. /// </summary> /// <param name="field">TypeIDField</param> /// <param name="layerInfo">FeatureLayerInof used to construct the CodedValueSources from the FeatureTypes.</param> /// <returns>CodedValueSoruces that contain code an value matches to all possible TypeIDField values.</returns> internal static CodedValueSources BuildTypeIDCodedValueSource(Field field, FeatureLayerInfo layerInfo) { CodedValueSources codedValueSources = null; foreach (KeyValuePair<object, FeatureType> kvp in layerInfo.FeatureTypes) { if (kvp.Key == null) continue; string name = (kvp.Value != null && kvp.Value.Name != null) ? kvp.Value.Name : ""; CodedValueSource codedValueSource = new CodedValueSource() { Code = kvp.Key, DisplayName = name }; if (codedValueSources == null) { codedValueSources = new CodedValueSources(); if (field.Nullable) { CodedValueSource nullableSource = new CodedValueSource() { Code = null, DisplayName = " " }; codedValueSources.Add(nullableSource); } } codedValueSources.Add(codedValueSource); } return codedValueSources; }
private static void CreateProperty(TypeBuilder tb, FieldBuilder dynamicRangeDomainValidation, string propertyName, Type propertyType, FeatureLayerInfo layerInfo, Field field, int order, bool isKey) { // Create the private data backed property i.e. (private int _myProperty) FieldBuilder fieldBuilder = tb.DefineField("_" + propertyName, propertyType, FieldAttributes.Private); // Create the public property i.e. (public int MyProperty { get { return _myProperty; } set{ _myPropety = value; } }) PropertyBuilder propertyBuilder = tb.DefineProperty(propertyName, PropertyAttributes.HasDefault, propertyType, null); string displayName = null; if (field != null) displayName = field.Alias; if (string.IsNullOrEmpty(displayName)) displayName = _fieldMapping.KeyOfValue(propertyName); if (!string.IsNullOrEmpty(displayName)) { // Add DisplayAttribute to property [DisplayAttribute(Name = displayName)] Type displayAttribute = typeof(DisplayAttribute); PropertyInfo info = displayAttribute.GetProperty("Name"); PropertyInfo info2 = displayAttribute.GetProperty("AutoGenerateField"); PropertyInfo info3 = displayAttribute.GetProperty("Order"); CustomAttributeBuilder cabuilder = new CustomAttributeBuilder( displayAttribute.GetConstructor(new Type[] { }), new object[] { }, new PropertyInfo[] { info, info2, info3 }, new object[] { displayName, !isKey, order }); propertyBuilder.SetCustomAttribute(cabuilder); } if (isKey) { // Add KeyAttribute to property [KeyAttribute] CustomAttributeBuilder cabuilder = new CustomAttributeBuilder( typeof(KeyAttribute).GetConstructor(new Type[] { }), new object[] { }); propertyBuilder.SetCustomAttribute(cabuilder); } if (field != null) { if (!field.Nullable && field.Type != Field.FieldType.GlobalID) { // Add Required to property using standard validation error [Required()] CustomAttributeBuilder requiredCABuilder = new CustomAttributeBuilder( typeof(System.ComponentModel.DataAnnotations.RequiredAttribute).GetConstructor(new Type[] { }), new object[] { }); propertyBuilder.SetCustomAttribute(requiredCABuilder); } // Add AllowEdit to property and allow an initial value PropertyInfo allowEditInfo = typeof(EditableAttribute).GetProperty("AllowEdit"); PropertyInfo allowInitialValueInfo = typeof(EditableAttribute).GetProperty("AllowInitialValue"); CustomAttributeBuilder allowEditCABuilder = new CustomAttributeBuilder( typeof(EditableAttribute).GetConstructor(new Type[] { typeof(bool) }), new object[] { field.Editable }, new PropertyInfo[] { allowEditInfo, allowInitialValueInfo }, new object[] { field.Editable, true }); propertyBuilder.SetCustomAttribute(allowEditCABuilder); // Add MaximumLength to property if (field.Type == Field.FieldType.String && field.Length > 0) { PropertyInfo maximumLengthInfo = typeof(StringLengthAttribute).GetProperty("MaximumLength"); CustomAttributeBuilder cabuilder = new CustomAttributeBuilder( typeof(StringLengthAttribute).GetConstructor(new Type[] { typeof(int) }), new object[] { field.Length }, new PropertyInfo[] { maximumLengthInfo }, new object[] { field.Length }); propertyBuilder.SetCustomAttribute(cabuilder); } } if (propertyType == typeof(DateTime) || propertyType == typeof(DateTime?)) { // Add DisplayAttribute to property [DisplayFormatAttribute(DataFormatString = "m/dd/YYYY")] PropertyInfo info = typeof(DisplayFormatAttribute).GetProperty("DataFormatString"); CustomAttributeBuilder cabuilder = new CustomAttributeBuilder( typeof(DisplayFormatAttribute).GetConstructor(new Type[] { }), new object[] { }, new PropertyInfo[] { info }, new object[] { System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern }); propertyBuilder.SetCustomAttribute(cabuilder); } MethodBuilder getPropMthdBldr = tb.DefineMethod("get_" + propertyName, MethodAttributes.Public | MethodAttributes.SpecialName | MethodAttributes.HideBySig, propertyType, Type.EmptyTypes); ILGenerator getIL = getPropMthdBldr.GetILGenerator(); getIL.Emit(OpCodes.Ldarg_0); getIL.Emit(OpCodes.Ldfld, fieldBuilder); getIL.Emit(OpCodes.Ret); MethodBuilder setPropMthdBldr = tb.DefineMethod("set_" + propertyName, MethodAttributes.Public | MethodAttributes.SpecialName | MethodAttributes.HideBySig, null, new Type[] { propertyType }); ILGenerator setIL = setPropMthdBldr.GetILGenerator(); // for feature layer range domain validation is added to the setter call. if (dynamicRangeDomainValidation != null) { // Labels are used to jump ahead to a specific line of code. // for example if an if statement returns false then you will want to jump // over the code that would execute if the condition was true because you don't // want that code to get executed. // An un-named temp variable that the compiler needs // in order to store the resulting boolean from the if statement. setIL.DeclareLocal(typeof(bool)); // Stloc_0 System.Reflection.Emit.Label endIfLabel = setIL.DefineLabel(); setIL.Emit(OpCodes.Ldarg_0); // load this instance setIL.Emit(OpCodes.Ldfld, dynamicRangeDomainValidation); // load this field setIL.Emit(OpCodes.Ldnull); // load a null value setIL.Emit(OpCodes.Ceq); // compare equality setIL.Emit(OpCodes.Stloc_0); // store the result of the equality check. note: setIL.DeclareLocal(typeof(bool)) must be declared. setIL.Emit(OpCodes.Ldloc_0); // load the result of the equality check setIL.Emit(OpCodes.Brtrue_S, endIfLabel); // if true execute the next argument. if false jump to the else if statement label. setIL.Emit(OpCodes.Ldarg_0); setIL.Emit(OpCodes.Ldfld, dynamicRangeDomainValidation); setIL.Emit(OpCodes.Ldarg_0); setIL.Emit(OpCodes.Ldstr, field != null ? field.FieldName : ""); setIL.Emit(OpCodes.Ldarg_1); setIL.Emit(OpCodes.Box, propertyType); setIL.Emit(OpCodes.Callvirt, typeof(Action<object, string, object>).GetMethod("Invoke", new Type[] { typeof(object), typeof(string), typeof(object) })); setIL.MarkLabel(endIfLabel); } setIL.Emit(OpCodes.Ldarg_0); setIL.Emit(OpCodes.Ldarg_1); setIL.Emit(OpCodes.Stfld, fieldBuilder); setIL.Emit(OpCodes.Ret); propertyBuilder.SetGetMethod(getPropMthdBldr); propertyBuilder.SetSetMethod(setPropMthdBldr); }
/// <summary> /// Builds a DynamicCodedValueSource object used to lookup display value. /// </summary> /// <param name="field">The field to build DynamicCodedValueSource for</param> /// <param name="layerInfo">The FeatureLayerInfo used to lookup all the coded value domains </param> /// <returns>DynamicCodedValueSource which is a collection of coded value domain values for a field.</returns> internal static DynamicCodedValueSource BuildDynamicCodedValueSource(Field field, FeatureLayerInfo layerInfo) { DynamicCodedValueSource dynamicCodedValueSource = null; foreach (object key in layerInfo.FeatureTypes.Keys) { FeatureType featureType = layerInfo.FeatureTypes[key]; if (featureType.Domains.ContainsKey(field.Name)) { if (dynamicCodedValueSource == null) { dynamicCodedValueSource = new DynamicCodedValueSource(); } CodedValueDomain codedValueDomain = featureType.Domains[field.Name] as CodedValueDomain; if (codedValueDomain != null) { CodedValueSources codedValueSources = null; foreach (KeyValuePair <object, string> kvp in codedValueDomain.CodedValues) { if (codedValueSources == null) { codedValueSources = new CodedValueSources(); if (field.Nullable) { CodedValueSource nullableSource = new CodedValueSource() { Code = null, DisplayName = " " }; codedValueSources.Add(nullableSource); } } codedValueSources.Add(new CodedValueSource() { Code = kvp.Key, DisplayName = kvp.Value }); } if (codedValueSources != null) { if (dynamicCodedValueSource == null) { dynamicCodedValueSource = new DynamicCodedValueSource(); } dynamicCodedValueSource.Add(featureType.Id, codedValueSources); } } } } return(dynamicCodedValueSource); }
internal static IEnumerable <KeyValuePair <object, RangeDomain <T> > > BuildDynamicRangeDomain <T>(Field field, FeatureLayerInfo layerInfo) where T : System.IComparable { List <KeyValuePair <object, RangeDomain <T> > > dynamicRangeDomains = null; foreach (object key in layerInfo.FeatureTypes.Keys) { FeatureType featureType = layerInfo.FeatureTypes[key]; if (featureType.Domains.ContainsKey(field.Name)) { if (dynamicRangeDomains == null) { dynamicRangeDomains = new List <KeyValuePair <object, RangeDomain <T> > >(); } RangeDomain <T> rangeDomain = featureType.Domains[field.Name] as RangeDomain <T>; if (rangeDomain != null) { dynamicRangeDomains.Add(new KeyValuePair <object, RangeDomain <T> >(featureType.Id, rangeDomain)); } } } return(dynamicRangeDomains); }
private static object AttributeListToObject(Type objectType, FeatureLayerInfo layerInfo, Graphic graphic, IEnumerable <string> attributeKeys, IEnumerable <string> propertyNames) { string typeIdFieldName = null; if (layerInfo != null && string.IsNullOrEmpty(layerInfo.TypeIdField) == false) { if (_fieldMapping != null && _fieldMapping.ContainsKey(layerInfo.TypeIdField)) { typeIdFieldName = _fieldMapping.KeyOfValue(layerInfo.TypeIdField); } } Action <object, string, object> myDynamicRangeValidationMethod = (instance, fieldName, value) => { if (layerInfo == null || layerInfo.Fields == null || layerInfo.Fields.Count == 0) { return; } var field = layerInfo.Fields.FirstOrDefault(f => string.Equals(f.FieldName, fieldName)); if (field != null) { if (FieldDomainUtils.IsDynamicDomain(field, layerInfo)) { var fieldInfo = instance.GetType().GetProperty(typeIdFieldName); var typeIDValue = fieldInfo.GetValue(instance, null); RangeDomainValidator.ValidateRange(layerInfo, field, typeIDValue, value); } else if (field.Domain != null && !(field.Domain is CodedValueDomain)) { RangeDomainValidator.ValidateRange(field, value); } } }; var row = Activator.CreateInstance(objectType, new object[] { graphic, myDynamicRangeValidationMethod }); foreach (string type in propertyNames ?? attributeKeys) { IDictionary <string, object> currentDict = graphic.Attributes; string propertyName = type; string attributeKey = type; if (propertyNames == null) { if (_fieldMapping.ContainsKey(attributeKey)) { propertyName = _fieldMapping[attributeKey]; } } else { attributeKey = _fieldMapping.KeyOfValue(propertyName); } if (propertyName != null && currentDict != null) { if (currentDict.ContainsKey(attributeKey)) { SetProperty(currentDict[attributeKey], row, objectType.GetProperty(propertyName)); } } } return(row); }
/// <summary> /// Sets the field information in the feature layer. /// </summary> /// <param name="featureLayerInfo">The feature layer info.</param> /// <param name="rangeDomainInfo">The range domain info.</param> /// <param name="fieldProps">The properties associated with the field.</param> /// <returns>Dictionary of field types keyed by their actual names. Also, populates range domain information and field properties if any.</returns> internal static Dictionary<string, Type> SetFieldInfo(FeatureLayerInfo featureLayerInfo, out Dictionary<string, object[]> rangeDomainInfo, out Dictionary<string, Field> fieldProps) { Dictionary<string, Type> fieldInfo = null; rangeDomainInfo = null; fieldProps = new Dictionary<string, Field>(); if (featureLayerInfo != null) { fieldInfo = new Dictionary<string, Type>(); foreach (Field field in featureLayerInfo.Fields) { Type fieldType = typeof(object); switch (field.Type) { case Field.FieldType.Date: fieldType = typeof(DateTime?); break; case Field.FieldType.Double: fieldType = typeof(double?); break; case Field.FieldType.Integer: fieldType = typeof(int?); break; case Field.FieldType.OID: fieldType = typeof(int); break; case Field.FieldType.Geometry: case Field.FieldType.GUID: case Field.FieldType.Blob: case Field.FieldType.Raster: case Field.FieldType.Unknown: fieldType = typeof(object); break; case Field.FieldType.Single: fieldType = typeof(float?); break; case Field.FieldType.SmallInteger: fieldType = typeof(short?); break; ; case Field.FieldType.GlobalID: case Field.FieldType.String: case Field.FieldType.XML: fieldType = typeof(string); break; default: throw new NotSupportedException(string.Format(Properties.Resources.FieldDomain_FieldTypeNotSupported, fieldType.GetType())); } fieldInfo.Add(field.Name, fieldType); fieldProps.Add(field.Name, field); // Populating the range domain info if any: if (field.Domain != null) { switch (field.Type) { case Field.FieldType.Date: RangeDomain<DateTime> dateTimeRangeDomain = field.Domain as RangeDomain<DateTime>; if (dateTimeRangeDomain != null) { if (rangeDomainInfo == null) rangeDomainInfo = new Dictionary<string, object[]>(); rangeDomainInfo.Add(field.Name, new object[] { dateTimeRangeDomain.MinimumValue, dateTimeRangeDomain.MaximumValue }); } break; case Field.FieldType.Double: RangeDomain<double> doubleRangeDomain = field.Domain as RangeDomain<double>; if (doubleRangeDomain != null) { if (rangeDomainInfo == null) rangeDomainInfo = new Dictionary<string, object[]>(); rangeDomainInfo.Add(field.Name, new object[] { doubleRangeDomain.MinimumValue, doubleRangeDomain.MaximumValue }); } break; case Field.FieldType.Integer: RangeDomain<int> intRangeDomain = field.Domain as RangeDomain<int>; if (intRangeDomain != null) { if (rangeDomainInfo == null) rangeDomainInfo = new Dictionary<string, object[]>(); rangeDomainInfo.Add(field.Name, new object[] { intRangeDomain.MinimumValue, intRangeDomain.MaximumValue }); } break; case Field.FieldType.Single: RangeDomain<Single> singleRangeDomain = field.Domain as RangeDomain<Single>; if (singleRangeDomain != null) { if (rangeDomainInfo == null) rangeDomainInfo = new Dictionary<string, object[]>(); rangeDomainInfo.Add(field.Name, new object[] { singleRangeDomain.MinimumValue, singleRangeDomain.MaximumValue }); } break; case Field.FieldType.SmallInteger: RangeDomain<short> shortRangeDomain = field.Domain as RangeDomain<short>; if (shortRangeDomain != null) { if (rangeDomainInfo == null) rangeDomainInfo = new Dictionary<string, object[]>(); rangeDomainInfo.Add(field.Name, new object[] { shortRangeDomain.MinimumValue, shortRangeDomain.MaximumValue }); } break; } } } } return fieldInfo; }
internal static void RefreshRow(this Graphic graphic, IEnumerable itemsSource, int itemIndex, Type objectType, FeatureLayerInfo layerInfo) { if (objectType != null) itemsSource.AsList()[itemIndex] = AttributeListToObject(objectType, layerInfo, graphic, graphic.Attributes.Keys, null); }
internal static IEnumerable ToDataSource(this IEnumerable <Graphic> graphics, FeatureLayerInfo layerInfo, Dictionary <string, Type> fieldInfo, Dictionary <string, Field> fieldProps, string uniqueID, IEnumerable <Graphic> filterGraphics, out Type objectType) { objectType = null; IDictionary firstDict = null; IEnumerable <IDictionary <string, object> > list = GetGraphicsEnumerable(graphics); Dictionary <string, Type> properties = new Dictionary <string, Type>(); _fieldMapping = new Dictionary <string, string>(); if (fieldInfo == null) { if (list != null) { IEnumerator enumList = list.GetEnumerator(); if (enumList != null && enumList.MoveNext()) { firstDict = enumList.Current as IDictionary; if (firstDict != null) { foreach (DictionaryEntry pair in firstDict) { string keyToUse = CreateMappedKey(pair.Key.ToString()); Type t = GetValueType(keyToUse, pair.Value, fieldInfo); properties.Add(keyToUse, t); } while (enumList.MoveNext()) { IDictionary nextDict = enumList.Current as IDictionary; IDictionaryEnumerator enumEntries = nextDict.GetEnumerator(); while (enumEntries != null && enumEntries.MoveNext()) { DictionaryEntry pair = (DictionaryEntry)enumEntries.Current; Type t = GetValueType(pair.Key as string, pair.Value, fieldInfo); if (!firstDict.Contains(pair.Key)) // Attribute doesn't exist => add it { object defaultValue = t.IsValueType ? Activator.CreateInstance(t) : null; firstDict.Add(pair.Key, defaultValue); } else // Attribute exists => check for data type compatibility { Type typeInFirstDict = GetValueType(pair.Key as string, firstDict[pair.Key], fieldInfo); if (typeInFirstDict is Object && firstDict[pair.Key] == null) { string keyToUse = GetMappedKey(pair.Key.ToString()); if (t == typeof(string) || IsNumericType(t)) { properties[keyToUse] = t; } continue; } if (pair.Value != null && // null values in nextDict match the nullable data type associated with the attribute in firstDict !t.IsOfType(typeInFirstDict)) // attribute data types don't match { if (typeInFirstDict == typeof(string)) { continue; } if (IsNumericType(typeInFirstDict) && IsNumericType(t)) { int rank1 = NumericRank(typeInFirstDict); int rank2 = NumericRank(t); string keyToUse = GetMappedKey(pair.Key.ToString()); if (rank1 < rank2) { properties[keyToUse] = t; } else if (rank1 == rank2 && IsUnsigned(typeInFirstDict) != IsUnsigned(t)) { properties[keyToUse] = UpgradeRankType(t); } continue; } throw new InvalidCastException(string.Format(Properties.Resources.FeatureDataGrid_MixedAttributeTypesNotAllowed, firstDict[pair.Key].GetType(), pair.Key)); } } } } } } } } if (firstDict == null && fieldInfo == null) { return new object[] { } } ; if (fieldInfo != null) // FeatureLayer { foreach (string key in fieldInfo.Keys) { string keyToUse = CreateMappedKey(key); Type t = fieldInfo[key]; properties.Add(keyToUse, t); } } string typeSignature = GetTypeSignature(properties); objectType = GetTypeByTypeSignature(typeSignature); if (objectType == null) { TypeBuilder tb = GetTypeBuilder(typeSignature); FieldBuilder DynamicTypeRangeDomainValidationFieldBuilder = tb.DefineField("DynamicTypeRangeDomainValidationMethod", typeof(Action <object, string, object>), FieldAttributes.Private); FieldBuilder fieldBuilder = tb.DefineField("_graphicSibling", typeof(Graphic), FieldAttributes.Private); ConstructorBuilder constructorBuilder = tb.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, new Type[] { typeof(Graphic), typeof(Action <object, string, object>) }); ILGenerator cbIL = constructorBuilder.GetILGenerator(); cbIL.Emit(OpCodes.Ldarg_0); cbIL.Emit(OpCodes.Call, typeof(object).GetConstructor(Type.EmptyTypes)); cbIL.Emit(OpCodes.Ldarg_0); cbIL.Emit(OpCodes.Ldarg_1); cbIL.Emit(OpCodes.Stfld, fieldBuilder); cbIL.Emit(OpCodes.Ldarg_0); cbIL.Emit(OpCodes.Ldarg_2); cbIL.Emit(OpCodes.Stfld, DynamicTypeRangeDomainValidationFieldBuilder); cbIL.Emit(OpCodes.Ret); MethodBuilder methodBuilder = tb.DefineMethod("GetGraphicSibling", MethodAttributes.Public, typeof(Graphic), Type.EmptyTypes); ILGenerator mbIL = methodBuilder.GetILGenerator(); mbIL.Emit(OpCodes.Ldarg_0); mbIL.Emit(OpCodes.Ldfld, fieldBuilder); mbIL.Emit(OpCodes.Ret); int order = 0; foreach (string key in properties.Keys) { if (fieldProps != null) // FeatureLayer { if (_fieldMapping.KeyOfValue(key) != null) { string mappedKey = _fieldMapping.KeyOfValue(key); if (fieldProps.ContainsKey(mappedKey)) // Only create the property if the key is contained in field properties { Field fld = fieldProps[mappedKey]; if (IsViewableAttribute(fld)) { CreateProperty(tb, DynamicTypeRangeDomainValidationFieldBuilder, key, properties[key], layerInfo, fld, order++, uniqueID == key); } } } } else // GraphicsLayer { CreateProperty(tb, null, key, properties[key], null, null, order++, uniqueID == key); } } objectType = tb.CreateType(); _typeBySignature.Add(typeSignature, objectType); } return(GenerateEnumerable(objectType, layerInfo, graphics, properties.Keys.ToArray(), filterGraphics)); }
private static void AddToEnumerable(Type objectType, FeatureLayerInfo layerInfo, Graphic graphic, IEnumerable itemsSource) { var listType = typeof(ObservableCollection<>).MakeGenericType(new[] { objectType }); var row = AttributeListToObject(objectType, layerInfo, graphic, graphic.Attributes.Keys, null); listType.GetMethod("Add").Invoke((itemsSource as ICollectionView).SourceCollection, new[] { row }); }
internal static void RefreshRow(this Graphic graphic, IEnumerable itemsSource, int itemIndex, Type objectType, FeatureLayerInfo layerInfo) { if (objectType != null) { itemsSource.AsList()[itemIndex] = AttributeListToObject(objectType, layerInfo, graphic, graphic.Attributes.Keys, null); } }
internal static void AddToDataSource(this IEnumerable itemsSource, FeatureLayerInfo layerInfo, Graphic graphic, Type objectType) { if (objectType != null) AddToEnumerable(objectType, layerInfo, graphic, itemsSource); }
private void processLayerInfoResult(ArcGISWebClient.DownloadStringCompletedEventArgs e) { #region Parse layer info from json if (e.Cancelled) { return; } if (e.Error != null) { singleLayerRequestCompleted(null, e); return; } string json = null; try { json = e.Result; } catch (Exception exception) { if (exception != null) { singleLayerRequestCompleted(null, e); return; } } Exception ex = ESRI.ArcGIS.Mapping.DataSources.Utils.CheckJsonForException(json); if (ex != null) { singleLayerRequestCompleted(null, e); return; } json = "{\"layerDefinition\":" + json + "}"; FeatureLayer featureLayer = FeatureLayer.FromJson(json); FeatureLayerInfo featurelayerinfo = featureLayer.LayerInfo; if (featurelayerinfo == null) { singleLayerRequestCompleted(null, e); return; } LayerInformation info = new LayerInformation() { ID = featurelayerinfo.Id, DisplayField = featurelayerinfo.DisplayField, Name = featurelayerinfo.Name, PopUpsEnabled = false, LayerJson = json, FeatureLayer = featureLayer }; Collection <ESRI.ArcGIS.Mapping.Core.FieldInfo> fieldInfos = new Collection <ESRI.ArcGIS.Mapping.Core.FieldInfo>(); if (featurelayerinfo.Fields != null) { foreach (ESRI.ArcGIS.Client.Field field in featurelayerinfo.Fields) { if (FieldHelper.IsFieldFilteredOut(field.Type)) { continue; } ESRI.ArcGIS.Mapping.Core.FieldInfo fieldInfo = ESRI.ArcGIS.Mapping.Core.FieldInfo.FieldInfoFromField(featureLayer, field); fieldInfos.Add(fieldInfo); } } info.Fields = fieldInfos; if (fieldInfos.Count > 0) { singleLayerRequestCompleted(info, e); } else { singleLayerRequestCompleted(null, e); } #endregion }
private static IEnumerable GenerateEnumerable(Type objectType, FeatureLayerInfo layerInfo, IEnumerable<Graphic> graphics, string[] types, IEnumerable<Graphic> filter) { IEnumerable graphicsAfterFilter = filter != null ? graphics.Intersect<Graphic>(filter) : graphics; var listType = typeof(ObservableCollection<>).MakeGenericType(new[] { objectType }); var listOfCustom = Activator.CreateInstance(listType); foreach (Graphic g in graphicsAfterFilter) { var row = AttributeListToObject(objectType, layerInfo, g, null, types); listType.GetMethod("Add").Invoke(listOfCustom, new[] { row }); } return listOfCustom as IEnumerable; }
/// <summary> /// Sets the field information in the feature layer. /// </summary> /// <param name="featureLayerInfo">The feature layer info.</param> /// <param name="rangeDomainInfo">The range domain info.</param> /// <param name="fieldProps">The properties associated with the field.</param> /// <returns>Dictionary of field types keyed by their actual names. Also, populates range domain information and field properties if any.</returns> internal static Dictionary <string, Type> SetFieldInfo(FeatureLayerInfo featureLayerInfo, out Dictionary <string, object[]> rangeDomainInfo, out Dictionary <string, Field> fieldProps) { Dictionary <string, Type> fieldInfo = null; rangeDomainInfo = null; fieldProps = new Dictionary <string, Field>(); if (featureLayerInfo != null) { fieldInfo = new Dictionary <string, Type>(); foreach (Field field in featureLayerInfo.Fields) { Type fieldType = typeof(object); switch (field.Type) { case Field.FieldType.Date: fieldType = typeof(DateTime?); break; case Field.FieldType.Double: fieldType = typeof(double?); break; case Field.FieldType.Integer: fieldType = typeof(int?); break; case Field.FieldType.OID: fieldType = typeof(int); break; case Field.FieldType.Geometry: case Field.FieldType.GUID: case Field.FieldType.Blob: case Field.FieldType.Raster: case Field.FieldType.Unknown: fieldType = typeof(object); break; case Field.FieldType.Single: fieldType = typeof(float?); break; case Field.FieldType.SmallInteger: fieldType = typeof(short?); break;; case Field.FieldType.GlobalID: case Field.FieldType.String: case Field.FieldType.XML: fieldType = typeof(string); break; default: throw new NotSupportedException(string.Format(Properties.Resources.FieldDomain_FieldTypeNotSupported, fieldType.GetType())); } fieldInfo.Add(field.Name, fieldType); fieldProps.Add(field.Name, field); // Populating the range domain info if any: if (field.Domain != null) { switch (field.Type) { case Field.FieldType.Date: RangeDomain <DateTime> dateTimeRangeDomain = field.Domain as RangeDomain <DateTime>; if (dateTimeRangeDomain != null) { if (rangeDomainInfo == null) { rangeDomainInfo = new Dictionary <string, object[]>(); } rangeDomainInfo.Add(field.Name, new object[] { dateTimeRangeDomain.MinimumValue, dateTimeRangeDomain.MaximumValue }); } break; case Field.FieldType.Double: RangeDomain <double> doubleRangeDomain = field.Domain as RangeDomain <double>; if (doubleRangeDomain != null) { if (rangeDomainInfo == null) { rangeDomainInfo = new Dictionary <string, object[]>(); } rangeDomainInfo.Add(field.Name, new object[] { doubleRangeDomain.MinimumValue, doubleRangeDomain.MaximumValue }); } break; case Field.FieldType.Integer: RangeDomain <int> intRangeDomain = field.Domain as RangeDomain <int>; if (intRangeDomain != null) { if (rangeDomainInfo == null) { rangeDomainInfo = new Dictionary <string, object[]>(); } rangeDomainInfo.Add(field.Name, new object[] { intRangeDomain.MinimumValue, intRangeDomain.MaximumValue }); } break; case Field.FieldType.Single: RangeDomain <Single> singleRangeDomain = field.Domain as RangeDomain <Single>; if (singleRangeDomain != null) { if (rangeDomainInfo == null) { rangeDomainInfo = new Dictionary <string, object[]>(); } rangeDomainInfo.Add(field.Name, new object[] { singleRangeDomain.MinimumValue, singleRangeDomain.MaximumValue }); } break; case Field.FieldType.SmallInteger: RangeDomain <short> shortRangeDomain = field.Domain as RangeDomain <short>; if (shortRangeDomain != null) { if (rangeDomainInfo == null) { rangeDomainInfo = new Dictionary <string, object[]>(); } rangeDomainInfo.Add(field.Name, new object[] { shortRangeDomain.MinimumValue, shortRangeDomain.MaximumValue }); } break; } } } } return(fieldInfo); }