Example #1
0
        public override void Dispose()
        {
            base.Dispose();
            if (_queryInfo != null)
            {
                _queryInfo.Dispose();
                _queryInfo = null;
            }

            if (_stream != null)
            {
                _stream.Free();
                _stream = null;
            }

            if (_connection != null)
            {
                try
                {
                    _connection.Close();
                }
                catch { }
                _connection = null;
            }
        }
Example #2
0
        public SdeFeatureCursor(SdeDataset dataset, ITableClass tc, IQueryFilter filter)
            : base((tc is IFeatureClass) && ((IFeatureClass)tc).SpatialReference != null ?
                   ((IFeatureClass)tc).SpatialReference : filter.ContextLayerDefaultSpatialReference,
                   (filter != null) ? filter.FeatureSpatialReference : null)
        {
            try
            {
                if (filter != null && !filter.SubFields.Contains("*"))
                {
                    filter.AddField(tc.IDFieldName, false);
                }
                filter.fieldPrefix  = tc.Name + ".";
                filter.fieldPostfix = "";

                if (filter is ISpatialFilter &&
                    (((ISpatialFilter)filter).SpatialRelation != spatialRelation.SpatialRelationMapEnvelopeIntersects))
                {
                    if (tc is IFeatureClass)
                    {
                        filter.AddField(((IFeatureClass)tc).ShapeFieldName);
                    }
                    _spatialFilter = (ISpatialFilter)filter;
                }

                Int32 err_no = 0;

                _dataset = dataset;
                if (_dataset == null)
                {
                    return;
                }

                //_connection = _dataset.AllocConnection();
                _connection = new ArcSdeConnection(dataset.ConnectionString);
                if (!_connection.Open(this._dataset))
                {
                    return;
                }

                _queryInfo = new SdeQueryInfo(_connection, tc, filter);
                if (_queryInfo.ErrorMessage != "")
                {
                    Dispose();
                    return;
                }

                //if (Wrapper10.SE_stream_create(_connection.SeConnection, ref _stream) != 0)
                //{
                //    Dispose();
                //    return;
                //}

                //_connection.ResetStream();

                _stream = _connection.CreateStream();

                // SE_stream_set_state sollte auch aufgerufen werden (siehe mapsde.c von UMN)
                if (Wrapper10.SE_stream_set_state(
                        _stream.SeStream,
                        CONST.SE_DEFAULT_STATE_ID,
                        CONST.SE_DEFAULT_STATE_ID,
                        CONST.SE_STATE_DIFF_NOCHECK) != 0)
                {
                    Dispose();
                    return;
                }

                if ((err_no = Wrapper10.SE_stream_query_with_info(_stream.SeStream, _queryInfo.SeQueryInfo)) != 0)
                {
                    Dispose();
                    return;
                }

                if (_queryInfo.IsSpatial)
                {
                    SE_FILTER se_filter = _queryInfo.Filter_Shape;
                    if ((err_no = Wrapper10.SE_stream_set_spatial_constraints(_stream.SeStream, CONST.SE_SPATIAL_FIRST, false, 1, ref se_filter)) != 0)
                    {
                        _errMsg = Wrapper10.GetErrorMsg(_connection.SeConnection, err_no);
                        Dispose();
                        return;
                    }
                }
                else
                {
                    /*
                     * SE_FILTER se_filter = _queryInfo.Filter_Id;
                     * if (Wrapper10.SE_stream_set_spatial_constraints(_stream, CONST.SE_SPATIAL_FIRST, false, 1, ref se_filter) != 0)
                     * {
                     *  Release();
                     *  return;
                     * }
                     * */
                }

                if (Wrapper10.SE_stream_execute(_stream.SeStream) != 0)
                {
                    Dispose();
                    return;
                }

                _queryFields = _queryInfo.QueryFields;
                _queryInfo.Dispose();
                _queryInfo = null;
            }
            catch (Exception ex)
            {
                _errMsg = ex.Message + "\n" + ex.StackTrace;
                Dispose();
            }
        }