internal void ClassChanged(JoinSourceType type) { if (type == JoinSourceType.Target) { return; } _view.ClearJoins(); FdoConnection conn = GetConnection(type); if (conn != null) { using (FdoFeatureService service = conn.CreateFeatureService()) { switch (type) { case JoinSourceType.Left: { string schema = _view.SelectedLeftSchema; string className = _view.SelectedLeftClass; ClassDefinition cd = service.GetClassByName(schema, className); if (cd != null) { List <string> properties = new List <string>(); foreach (PropertyDefinition pd in cd.Properties) { properties.Add(pd.Name); } _view.LeftProperties = properties; } } break; case JoinSourceType.Right: { string schema = _view.SelectedRightSchema; string className = _view.SelectedRightClass; ClassDefinition cd = service.GetClassByName(schema, className); if (cd != null) { List <string> properties = new List <string>(); foreach (PropertyDefinition pd in cd.Properties) { properties.Add(pd.Name); } _view.RightProperties = properties; } } break; } } } SetTargetGeometries(); }
/// <summary> /// Validates this instance. /// </summary> public void Validate() { foreach (FdoClassCopyOptions copt in this.ClassCopyOptions) { FdoConnection src = GetConnection(copt.SourceConnectionName); FdoConnection dst = GetConnection(copt.TargetConnectionName); if (src == null) { throw new TaskValidationException("The specified source connection name does not exist"); } if (dst == null) { throw new TaskValidationException("The specified target connection name does not exist"); } using (FdoFeatureService srcSvc = src.CreateFeatureService()) using (FdoFeatureService dstSvc = dst.CreateFeatureService()) { ClassDefinition srcCls = srcSvc.GetClassByName(copt.SourceSchema, copt.SourceClassName); ClassDefinition dstCls = dstSvc.GetClassByName(copt.TargetSchema, copt.TargetClassName); if (srcCls == null) { throw new TaskValidationException("The specified source feature class does not exist"); } if (dstCls == null) { throw new TaskValidationException("The specified target feature class does not exist"); } } } }
public void Init() { _view.InitializeGrid(); _view.UseTransactionEnabled = (_conn.Capability.GetBooleanCapability(CapabilityType.FdoCapabilityType_SupportsTransactions)); using (FdoFeatureService service = _conn.CreateFeatureService()) { ClassDefinition cd = service.GetClassByName(_className); if (cd != null) { _view.ClassName = cd.Name; foreach (PropertyDefinition pd in cd.Properties) { switch (pd.PropertyType) { case PropertyType.PropertyType_DataProperty: _view.AddDataProperty((DataPropertyDefinition)pd); break; case PropertyType.PropertyType_GeometricProperty: _view.AddGeometricProperty((GeometricPropertyDefinition)pd); break; } } } } }
public override int Execute() { IConnection conn = null; try { conn = CreateConnection(_provider, _connstr); conn.Open(); } catch (OSGeo.FDO.Common.Exception ex) { WriteException(ex); return (int)CommandStatus.E_FAIL_CONNECT; } using (FdoFeatureService service = new FdoFeatureService(conn)) { ClassDefinition cd = service.GetClassByName(_schema, _class); if (cd == null) { Console.Error.WriteLine("Class {0} not found in schema {1}", _class, _schema); return (int)CommandStatus.E_FAIL_CLASS_NOT_FOUND; } else { using (cd) { foreach (PropertyDefinition propDef in cd.Properties) { bool isIdentity = (propDef.PropertyType == PropertyType.PropertyType_DataProperty && cd.IdentityProperties.Contains((DataPropertyDefinition)propDef)); Console.WriteLine("\nName: {0} ({1}) {2}\n", propDef.Name, propDef.PropertyType, isIdentity ? "(IDENTITY)" : ""); Console.WriteLine("\tQualified Name: {0}\n\tIs System: {1}", propDef.QualifiedName, propDef.IsSystem); switch (propDef.PropertyType) { case PropertyType.PropertyType_DataProperty: WriteDataProperty(propDef as DataPropertyDefinition); break; case PropertyType.PropertyType_GeometricProperty: WriteGeometricProperty(propDef as GeometricPropertyDefinition); break; case PropertyType.PropertyType_AssociationProperty: WriteAssociationProperty(propDef as AssociationPropertyDefinition); break; case PropertyType.PropertyType_ObjectProperty: WriteObjectProperty(propDef as ObjectPropertyDefinition); break; case PropertyType.PropertyType_RasterProperty: WriteRasterProperty(propDef as RasterPropertyDefinition); break; } } } } } conn.Close(); return (int)CommandStatus.E_OK; }
public void Init(string initSchema, string initClass) { List <QueryMode> modes = new List <QueryMode>(); if (!string.IsNullOrEmpty(initSchema) && !string.IsNullOrEmpty(initClass)) { if (_service.SupportsCommand(OSGeo.FDO.Commands.CommandType.CommandType_Select)) { using (FdoFeatureService service = _connection.CreateFeatureService()) { ClassDefinition classDef = service.GetClassByName(initSchema, initClass); if (!ExpressUtility.HasRaster(classDef)) { modes.Add(QueryMode.Standard); _queryViews.Add(QueryMode.Standard, new FdoStandardQueryCtl(_connection, initSchema, initClass)); } } } if (_service.SupportsCommand(OSGeo.FDO.Commands.CommandType.CommandType_SelectAggregates)) { modes.Add(QueryMode.Aggregate); _queryViews.Add(QueryMode.Aggregate, new FdoAggregateQueryCtl(_connection, initSchema, initClass)); } } else { if (_service.SupportsCommand(OSGeo.FDO.Commands.CommandType.CommandType_Select)) { modes.Add(QueryMode.Standard); _queryViews.Add(QueryMode.Standard, new FdoStandardQueryCtl(_connection)); } if (_service.SupportsCommand(OSGeo.FDO.Commands.CommandType.CommandType_SelectAggregates)) { modes.Add(QueryMode.Aggregate); _queryViews.Add(QueryMode.Aggregate, new FdoAggregateQueryCtl(_connection)); } } if (_service.SupportsCommand(OSGeo.FDO.Commands.CommandType.CommandType_SQLCommand)) { modes.Add(QueryMode.SQL); _queryViews.Add(QueryMode.SQL, new FdoSqlQueryCtl()); } foreach (IQuerySubView qv in _queryViews.Values) { qv.MapPreviewStateChanged += new MapPreviewStateEventHandler(OnMapPreviewStateChanged); qv.SetRestrictions(_connection.Capability); } _view.QueryModes = modes; _view.InsertEnabled = (_view.SelectedQueryMode != QueryMode.SQL) && insertSupported; }
internal CopyTaskNodeDecorator(TreeNode root, string srcConnName, string srcSchema, string srcClass, string dstConnName, string dstSchema, string dstClass, string taskName, bool createIfNotExists) { _node = new TreeNode(); root.Nodes.Add(_node); _node.Nodes.Add(new TreeNode("Description")); _node.Nodes.Add(new TreeNode("Options")); _node.Nodes.Add(new TreeNode("Property Mappings")); _node.Nodes.Add(new TreeNode("Expression Mappings (Right click to add)")); this.Name = taskName; this.Description = "Copies features from " + srcClass + " to " + dstClass; InitDescription(srcConnName, srcSchema, srcClass, dstConnName, dstSchema, dstClass, createIfNotExists); _connMgr = ServiceManager.Instance.GetService <FdoConnectionManager>(); _srcConnName = srcConnName; _dstConnName = dstConnName; this.CreateIfNotExists = createIfNotExists; using (FdoFeatureService srcSvc = GetSourceConnection().CreateFeatureService()) using (FdoFeatureService dstSvc = GetTargetConnection().CreateFeatureService()) { ClassDefinition sourceClass = srcSvc.GetClassByName(srcSchema, srcClass); Debug.Assert(sourceClass != null); ClassDefinition targetClass = dstSvc.GetClassByName(dstSchema, dstClass); if (targetClass == null && !this.CreateIfNotExists) { throw new InvalidOperationException("Target class " + dstClass + " does not exist. If you want this class created make sure you checked \"Create class of the name name\" when creating a new copy task"); } _srcClass = sourceClass; _dstClass = targetClass; } _options = new OptionsNodeDecorator(this, _node.Nodes[1]); _propMappings = new PropertyMappingsNodeDecorator(this, _node.Nodes[2]); _exprMappings = new ExpressionMappingsNodeDecorator(this, _node.Nodes[3]); _node.ExpandAll(); }
private void SetTargetGeometries() { if (!_init) { return; } _view.LeftGeometryName = string.Empty; _view.RightGeometryName = string.Empty; _view.LeftGeometryEnabled = false; _view.RightGeometryEnabled = false; _view.LeftGeometryChecked = false; _view.RightGeometryChecked = false; using (FdoFeatureService leftService = GetConnection(JoinSourceType.Left).CreateFeatureService()) using (FdoFeatureService rightService = GetConnection(JoinSourceType.Right).CreateFeatureService()) { ClassDefinition leftClass = leftService.GetClassByName(_view.SelectedLeftSchema, _view.SelectedLeftClass); ClassDefinition rightClass = rightService.GetClassByName(_view.SelectedRightSchema, _view.SelectedRightClass); if (leftClass.ClassType == ClassType.ClassType_FeatureClass) { string geomName = ((FeatureClass)leftClass).GeometryProperty.Name; //targetGeoms.Add(geomName + " (Left)", geomName); //_view.LeftGeometryEnabled = true; _view.LeftGeometryName = geomName; _view.LeftGeometryChecked = true; } if (rightClass.ClassType == ClassType.ClassType_FeatureClass) { string geomName = ((FeatureClass)rightClass).GeometryProperty.Name; //targetGeoms.Add(geomName + " (Right)", geomName); //_view.RightGeometryEnabled = true; _view.RightGeometryName = geomName; if (!_view.LeftGeometryChecked) { _view.RightGeometryChecked = true; } } } }
/// <summary> /// Executes the operation /// </summary> /// <param name="rows"></param> /// <returns></returns> public override IEnumerable <FdoRow> Execute(IEnumerable <FdoRow> rows) { //We fetch the class def here instead of the ctor as the class in question //may have to be created by a pre-copy operation _clsDef = _service.GetClassByName(this.ClassName); IInsert insert = null; using (FdoFeatureService service = _conn.CreateFeatureService()) { insert = service.CreateCommand <IInsert>(CommandType.CommandType_Insert); } this.Info("Set feature class to: {0}", this.ClassName); insert.SetFeatureClassName(this.ClassName); PropertyValueCollection propVals = insert.PropertyValues; Prepare(propVals); foreach (FdoRow row in rows) { Bind(row); insert.Prepare(); try { using (IFeatureReader reader = insert.Execute()) { reader.Close(); } } catch (OSGeo.FDO.Common.Exception ex) { ex.Data["Class/Table"] = this.ClassName; RaiseFailedFeatureProcessed(row, ex); RePrepare(propVals); } yield return(row); } insert.Dispose(); //yield break; }
private void txtUpdateFilter_Click(object sender, EventArgs e) { if (_classDef == null) { using (FdoFeatureService service = _conn.CreateFeatureService()) { _classDef = service.GetClassByName(this.ClassName); } } if (!string.IsNullOrEmpty(this.Filter)) { string filter = ExpressionEditor.EditExpression(_conn, _classDef, null, this.Filter, ExpressionMode.Filter); if (filter != null) { this.Filter = filter; } } else { this.Filter = ExpressionEditor.NewExpression(_conn, _classDef, null, ExpressionMode.Filter); } }
/// <summary> /// Initializes this instance /// </summary> /// <param name="pipelineExecuter"></param> public override void PrepareForExecution(IPipelineExecuter pipelineExecuter) { //Omit read-only properties using (FdoFeatureService service = _conn.CreateFeatureService()) { ClassDefinition c = service.GetClassByName(this.ClassName); foreach (PropertyDefinition p in c.Properties) { string name = p.Name; if (p.PropertyType != PropertyType.PropertyType_DataProperty && p.PropertyType != PropertyType.PropertyType_GeometricProperty) { _unWritableProperties.Add(name); } else { if (p.PropertyType == PropertyType.PropertyType_GeometricProperty) { GeometricPropertyDefinition g = p as GeometricPropertyDefinition; if (g.ReadOnly) { _unWritableProperties.Add(name); } } else { DataPropertyDefinition d = p as DataPropertyDefinition; if (d.ReadOnly) //|| d.IsAutoGenerated) { _unWritableProperties.Add(name); } } } } c.Dispose(); } base.PrepareForExecution(pipelineExecuter); }
public void Init() { _view.InitializeGrid(); _view.UseTransactionEnabled = (_conn.Capability.GetBooleanCapability(CapabilityType.FdoCapabilityType_SupportsTransactions)); using (FdoFeatureService service = _conn.CreateFeatureService()) { ClassDefinition cd = service.GetClassByName(_className); if (cd != null) { _view.ClassName = cd.Name; foreach (PropertyDefinition pd in cd.Properties) { switch (pd.PropertyType) { case PropertyType.PropertyType_DataProperty: _view.AddDataProperty((DataPropertyDefinition)pd, _feature[pd.Name]); break; case PropertyType.PropertyType_GeometricProperty: if (null != (_feature[pd.Name] as FdoGeometry)) // else throws exeption with the ".Text" null reference { _view.AddGeometricProperty((GeometricPropertyDefinition)pd, (_feature[pd.Name] as FdoGeometry).Text); } break; case PropertyType.PropertyType_AssociationProperty: AssociationPropertyDefinition pdAssoc = (AssociationPropertyDefinition)pd; ClassDefinition cdAssoc = service.GetClassByName(pdAssoc.AssociatedClass.Name); foreach (PropertyDefinition pdThis in cdAssoc.Properties) { String szPropertyName = pd.Name + "." + pdThis.Name; // TODO: iterate associations and objects switch (pdThis.PropertyType) { case PropertyType.PropertyType_DataProperty: // TODO: fix this issue of reverse association // at the moment can get geom from parent to child - but throws error from child to parent try { _view.AddDataProperty((DataPropertyDefinition)pdThis, _feature[szPropertyName], pd.Name); } catch (Exception exThis) { // System.Windows.Forms.MessageBox.Show("Cannot Edit Association Property\n\n" + exThis.Message); } break; case PropertyType.PropertyType_GeometricProperty: // TODO: fix this issue of reverse association // at the moment can get geom from parent to child - but throws error from child to parent try { if (null != (_feature[szPropertyName] as FdoGeometry)) // else throws exeption with the ".Text" null reference { _view.AddGeometricProperty((GeometricPropertyDefinition)pdThis, (_feature[szPropertyName] as FdoGeometry).Text, pd.Name); } } catch (Exception exThis) { System.Windows.Forms.MessageBox.Show("Cannot Edit Association Geometry\n\n" + exThis.Message); } break; } } break; case PropertyType.PropertyType_ObjectProperty: ObjectPropertyDefinition pdObject = (ObjectPropertyDefinition)pd; ClassDefinition cdObject = service.GetClassByName(pdObject.Class.Name); foreach (PropertyDefinition pdThis in cdObject.Properties) { String szPropertyName = pd.Name + "." + pdThis.Name; // TODO: iterate associations and objects switch (pdThis.PropertyType) { case PropertyType.PropertyType_DataProperty: _view.AddDataProperty((DataPropertyDefinition)pdThis, _feature[szPropertyName], pd.Name); break; case PropertyType.PropertyType_GeometricProperty: if (null != (_feature[szPropertyName] as FdoGeometry)) // else throws exeption with the ".Text" null reference { _view.AddGeometricProperty((GeometricPropertyDefinition)pdThis, (_feature[szPropertyName] as FdoGeometry).Text, pd.Name); } break; } } break; } } } } }
public override int Execute() { IConnection conn = null; try { conn = CreateConnection(_provider, _connstr); conn.Open(); } catch (OSGeo.FDO.Common.Exception ex) { WriteException(ex); return((int)CommandStatus.E_FAIL_CONNECT); } using (FdoFeatureService service = new FdoFeatureService(conn)) { ClassDefinition cd = service.GetClassByName(_schema, _class); if (cd == null) { Console.Error.WriteLine("Class {0} not found in schema {1}", _class, _schema); return((int)CommandStatus.E_FAIL_CLASS_NOT_FOUND); } else { using (cd) { foreach (PropertyDefinition propDef in cd.Properties) { bool isIdentity = (propDef.PropertyType == PropertyType.PropertyType_DataProperty && cd.IdentityProperties.Contains((DataPropertyDefinition)propDef)); Console.WriteLine("\nName: {0} ({1}) {2}\n", propDef.Name, propDef.PropertyType, isIdentity ? "(IDENTITY)" : ""); Console.WriteLine("\tQualified Name: {0}\n\tIs System: {1}", propDef.QualifiedName, propDef.IsSystem); switch (propDef.PropertyType) { case PropertyType.PropertyType_DataProperty: WriteDataProperty(propDef as DataPropertyDefinition); break; case PropertyType.PropertyType_GeometricProperty: WriteGeometricProperty(propDef as GeometricPropertyDefinition); break; case PropertyType.PropertyType_AssociationProperty: WriteAssociationProperty(propDef as AssociationPropertyDefinition); break; case PropertyType.PropertyType_ObjectProperty: WriteObjectProperty(propDef as ObjectPropertyDefinition); break; case PropertyType.PropertyType_RasterProperty: WriteRasterProperty(propDef as RasterPropertyDefinition); break; } } } } } conn.Close(); return((int)CommandStatus.E_OK); }
private void Prepare(PropertyValueCollection propVals) { propVals.Clear(); currentValues.Clear(); // I do not trust the long-term stability of the PropertyValueCollection // // So what we do is load it up once with LiteralValue references and manipulate these // outside of the collection (via a cached dictionary). We cache everything from the wrapper API // that can be cached in the managed world so that we only have minimal contact with it // Omit read-only properties using (FdoFeatureService service = _conn.CreateFeatureService()) { ClassDefinition c = service.GetClassByName(this.ClassName); foreach (PropertyDefinition p in c.Properties) { string name = p.Name; PropertyValue pv = new PropertyValue(name, null); if (p.PropertyType == PropertyType.PropertyType_DataProperty) { DataPropertyDefinition d = p as DataPropertyDefinition; if (!d.ReadOnly && !d.IsAutoGenerated) { DataValue dv = null; switch (d.DataType) { case DataType.DataType_BLOB: dv = new BLOBValue(); break; case DataType.DataType_Boolean: dv = new BooleanValue(); break; case DataType.DataType_Byte: dv = new ByteValue(); break; case DataType.DataType_CLOB: dv = new CLOBValue(); break; case DataType.DataType_DateTime: dv = new DateTimeValue(); break; case DataType.DataType_Decimal: dv = new DecimalValue(); break; case DataType.DataType_Double: dv = new DoubleValue(); break; case DataType.DataType_Int16: dv = new Int16Value(); break; case DataType.DataType_Int32: dv = new Int32Value(); break; case DataType.DataType_Int64: dv = new Int64Value(); break; case DataType.DataType_Single: dv = new SingleValue(); break; case DataType.DataType_String: dv = new StringValue(); break; } if (dv != null) { pv.Value = dv; propVals.Add(pv); } } } else if (p.PropertyType == PropertyType.PropertyType_GeometricProperty) { GeometricPropertyDefinition g = p as GeometricPropertyDefinition; if (!g.ReadOnly) { GeometryValue gv = new GeometryValue(); pv.Value = gv; propVals.Add(pv); } } } c.Dispose(); } //Load property values into temp dictionary foreach (PropertyValue p in propVals) { currentValues[p.Name.Name] = p.Value as LiteralValue; } if (propertySnapshot == null) { propertySnapshot = new List <string>(); foreach (PropertyValue p in propVals) { propertySnapshot.Add(p.Name.Name); } } }
void DoWork(object sender, DoWorkEventArgs e) { IFdoReader reader = null; using (FdoFeatureService service = _connection.CreateFeatureService()) { try { if (e.Argument is FeatureAggregateOptions) { reader = service.SelectAggregates((FeatureAggregateOptions)e.Argument); } else if (e.Argument is StandardQuery) { var stdArg = (e.Argument as StandardQuery); reader = service.SelectFeatures(stdArg.query, stdArg.Limit, stdArg.UseExtendedSelect); } else if (e.Argument is string) { reader = service.ExecuteSQLQuery(e.Argument.ToString()); } //Init the data grid view FdoFeatureTable table = new FdoFeatureTable(); table.RequestSpatialContext += delegate(object o, string name) { SpatialContextInfo c = service.GetSpatialContext(name); if (c != null) { table.AddSpatialContext(c); } }; ClassDefinition clsDef = null; bool hasJoins = false; if (e.Argument is StandardQuery) { var qry = ((StandardQuery)e.Argument).query; clsDef = service.GetClassByName(qry.ClassName); //TODO: Should really qualify this, but our input parameters do not specify a schema hasJoins = qry.JoinCriteria.Count > 0; } table.InitTable(reader, clsDef, hasJoins); // need to store object class defn outside loop ClassDefinition classDefObject = null; ClassDefinition classDefAssoc = null; while (reader.ReadNext() && !_queryWorker.CancellationPending) { //Pass processed feature to data grid view FdoFeature feat = table.NewRow(); for (int i = 0; i < reader.FieldCount; i++) { string name = reader.GetName(i); if (!reader.IsNull(name)) { FdoPropertyType pt = reader.GetFdoPropertyType(name); switch (pt) { case FdoPropertyType.Association: // TODO: how to handle for non-StandardQuery if (e.Argument is StandardQuery) { // because the original code used an iterator over the reader.FieldCount // it is a bit of a hack to get another definition of the class and check // we are at the right property with a name comparison // TODO: code review to see if this can be implemented better FdoFeatureReader readerFeature = (FdoFeatureReader)reader; ClassDefinition classDef = readerFeature.GetClassDefinition(); foreach (PropertyDefinition propertyDef in classDef.Properties) { // only looking for the right association if ((PropertyType.PropertyType_AssociationProperty == propertyDef.PropertyType) && (propertyDef.Name.Equals(name))) { AssociationPropertyDefinition assocProp = (AssociationPropertyDefinition)propertyDef; ClassDefinition classAssoc = assocProp.AssociatedClass; // get a reader from the association - nice! IFeatureReader readerAssoc = readerFeature.GetFeatureObject(name); if ((null != readerAssoc) && (readerAssoc.ReadNext())) { // TODO: this should be an iterative function // the simple reassignment on each instance fails // (classDefObject.Properties is always zero after first record) // so have set classDefObject higher-up and re-use/ // - problem will occur if more than one association // ClassDefinition classDefObject = readerObject.GetClassDefinition(); if (null == classDefAssoc) { classDefAssoc = readerAssoc.GetClassDefinition(); } foreach (PropertyDefinition propertyDefAssoc in classDefAssoc.Properties) { String nameAssoc = propertyDefAssoc.Name; // TODO: only "data" type handled at present if (PropertyType.PropertyType_DataProperty == propertyDefAssoc.PropertyType) { DataPropertyDefinition datapropertyDefAssoc = (DataPropertyDefinition)propertyDefAssoc; String szFullName = name + "." + nameAssoc; DataType ptAssoc = datapropertyDefAssoc.DataType; // TODO: handle all types switch (ptAssoc) { case DataType.DataType_String: feat[szFullName] = readerAssoc.GetString(nameAssoc); break; case DataType.DataType_Int16: feat[szFullName] = readerAssoc.GetInt16(nameAssoc); break; case DataType.DataType_Int32: feat[szFullName] = readerAssoc.GetInt32(nameAssoc); break; case DataType.DataType_Int64: feat[szFullName] = readerAssoc.GetInt64(nameAssoc); break; } } } readerAssoc.Close(); } } } } break; case FdoPropertyType.BLOB: feat[name] = reader.GetLOB(name).Data; break; case FdoPropertyType.Boolean: feat[name] = reader.GetBoolean(name); break; case FdoPropertyType.Byte: feat[name] = reader.GetByte(name); break; case FdoPropertyType.CLOB: feat[name] = reader.GetLOB(name).Data; break; case FdoPropertyType.DateTime: { try { feat[name] = reader.GetDateTime(name); } catch //Unrepresentable dates { feat[name] = DBNull.Value; } } break; case FdoPropertyType.Decimal: //We should probably remove this as FDO coerces decimals to doubles (otherwise why is there not a GetDecimal() method in FdoIReader?) { double val = reader.GetDouble(name); if (Double.IsNaN(val)) { feat[name] = DBNull.Value; } else { feat[name] = Convert.ToDecimal(val); } } break; case FdoPropertyType.Double: feat[name] = reader.GetDouble(name); break; case FdoPropertyType.Geometry: { try { byte[] fgf = reader.GetGeometry(name); OSGeo.FDO.Geometry.IGeometry geom = service.GeometryFactory.CreateGeometryFromFgf(fgf); var fg = new FdoGeometry(geom); //OGR geometry trap using (var env = fg.Envelope) { } feat[name] = fg; } catch { feat[name] = DBNull.Value; } } break; case FdoPropertyType.Int16: feat[name] = reader.GetInt16(name); break; case FdoPropertyType.Int32: feat[name] = reader.GetInt32(name); break; case FdoPropertyType.Int64: feat[name] = reader.GetInt64(name); break; case FdoPropertyType.Object: // TODO: how to handle for non-StandardQuery if (e.Argument is StandardQuery) { // because the original code used an iterator over the reader.FieldCount // it is a bit of a hack to get another definition of the class and check // we are at the right property with a name comparison // TODO: code review to see if this can be implemented better FdoFeatureReader readerFeature = (FdoFeatureReader)reader; ClassDefinition classDef = readerFeature.GetClassDefinition(); foreach (PropertyDefinition propertyDef in classDef.Properties) { // only looking for the right object if ((PropertyType.PropertyType_ObjectProperty == propertyDef.PropertyType) && (propertyDef.Name.Equals(name))) { ObjectPropertyDefinition assocProp = (ObjectPropertyDefinition)propertyDef; ClassDefinition classAssoc = assocProp.Class; // get a reader from the object - nice! IFeatureReader readerObject = readerFeature.GetFeatureObject(name); if ((null != readerObject) && (readerObject.ReadNext())) { // TODO: this should be an iterative function // the simple reassignment on each instance fails // (classDefObject.Properties is always zero after first record) // so have set classDefObject higher-up and re-use/ // - problem will occur if more than one association // ClassDefinition classDefObject = readerObject.GetClassDefinition(); if (null == classDefObject) { classDefObject = readerObject.GetClassDefinition(); } foreach (PropertyDefinition propertyDefObject in classDefObject.Properties) { String nameObject = propertyDefObject.Name; // TODO: only "data" type handled at present if (PropertyType.PropertyType_DataProperty == propertyDefObject.PropertyType) { DataPropertyDefinition datapropertyDefObject = (DataPropertyDefinition)propertyDefObject; String szFullName = name + "." + nameObject; DataType ptAssoc = datapropertyDefObject.DataType; // TODO: handle all types switch (ptAssoc) { case DataType.DataType_String: feat[szFullName] = readerObject.GetString(nameObject); break; case DataType.DataType_Int16: feat[szFullName] = readerObject.GetInt16(nameObject); break; case DataType.DataType_Int32: feat[szFullName] = readerObject.GetInt32(nameObject); break; case DataType.DataType_Int64: feat[szFullName] = readerObject.GetInt64(nameObject); break; } } } readerObject.Close(); readerObject = null; } } } } break; //case FdoPropertyType.Raster: case FdoPropertyType.Single: feat[name] = reader.GetSingle(name); break; case FdoPropertyType.String: feat[name] = reader.GetString(name); break; } } else { feat[name] = DBNull.Value; } } table.AddRow(feat); if (table.Rows.Count % 50 == 0) { System.Threading.Thread.Sleep(50); } } if (_queryWorker.CancellationPending) { e.Cancel = true; _cancelResult = table; } else { e.Result = table; } } finally { if (reader != null) { reader.Close(); } } } }
void OnAfterNodeExpansion(object sender, TreeViewEventArgs e) { if (e.Action == TreeViewAction.Expand) { TreeNode node = e.Node; TreeNode root = _explorer.GetRootNode(RootNodeName); //Is a FDO data source node if (IsChild(root.Nodes, node, NODE_LEVEL_CLASS)) { //Find the connection node TreeNode connNode = node; while (connNode.Level > 1) { connNode = connNode.Parent; } string connName = connNode.Name; using (new TempCursor(Cursors.WaitCursor)) { switch (node.Level) { case NODE_LEVEL_CONNECTION: //Connection node { if (!(bool)node.Tag) //Not loaded, load it now { //Clear out dummy node node.Nodes.Clear(); CreateSchemaNodes(node); node.Tag = true; //Schema is loaded } } break; case NODE_LEVEL_SCHEMA: //Schema Node { bool isPartial = Convert.ToBoolean(node.Tag); if (isPartial) { Debug.Assert(node.Nodes.Count == 1); //Has a dummy node string schemaName = node.Name; FdoConnection conn = _connMgr.GetConnection(connName); using (FdoFeatureService svc = conn.CreateFeatureService()) { Debug.Assert(svc.SupportsPartialSchemaDiscovery()); List <string> classNames = svc.GetClassNames(schemaName); GetClassNodesPartial(classNames, node); node.Tag = false; //This node is no longer partial node.Expand(); } } } break; case NODE_LEVEL_CLASS: //Class Node { bool isPartial = Convert.ToBoolean(node.Tag); if (isPartial) { Debug.Assert(node.Nodes.Count == 1); //Has a dummy node string schemaName = node.Parent.Name; FdoConnection conn = _connMgr.GetConnection(connName); using (FdoFeatureService svc = conn.CreateFeatureService()) { Debug.Assert(svc.SupportsPartialSchemaDiscovery()); ClassDefinition cd = svc.GetClassByName(schemaName, node.Name); if (cd != null) { UpdateClassNode(node, cd); } } } } break; } } } } }