private void queueableBeginQuery(Object asyncResult)
        {
            AsyncResult <IFeatureDataReader> typedAsyncResult = asyncResult as AsyncResult <IFeatureDataReader>;

            Assert.IsNotNull(typedAsyncResult);
            FeatureQueryExpression query = typedAsyncResult.AsyncState as FeatureQueryExpression;

            if (query == null)
            {
                SpatialBinaryExpression spatialBinaryExpression
                    = typedAsyncResult.AsyncState as SpatialBinaryExpression;

                if (spatialBinaryExpression != null)
                {
                    query = new FeatureQueryExpression(new AllAttributesExpression(),
                                                       spatialBinaryExpression, query.Sort);
                }
            }

            try
            {
                typedAsyncResult.SetComplete(InnerFeatureProvider.ExecuteFeatureQuery(query), false);
            }
            catch (Exception terminatingException)
            {
                typedAsyncResult.SetComplete(false, terminatingException);
            }
        }
        public void IFeatureProviderMethodsPassThroughAdapter()
        {
            MockRepository   mocks   = new MockRepository();
            IFeatureProvider adapted = mocks.CreateMock <IFeatureProvider>();
            IGeometryFactory iGeometryFactoryStub =
                MockRepository.GenerateStub <IGeometryFactory>();
            FeatureDataTable featureDataTableStub =
                MockRepository.GenerateStub <FeatureDataTable>(iGeometryFactoryStub);
            IFeatureDataReader iFeatureDataReaderStub =
                MockRepository.GenerateStub <IFeatureDataReader>();
            IExtents iExtentsStub =
                MockRepository.GenerateStub <IExtents>();
            FeatureQueryExpression featureQueryExpressionStub =
                MockRepository.GenerateStub <FeatureQueryExpression>(iExtentsStub, SpatialOperation.Intersects);
            FeatureQueryExecutionOptions featureQueryExecutionOptionsStub =
                new FeatureQueryExecutionOptions();
            DataTable dataTableStub =
                MockRepository.GenerateStub <DataTable>();
            CultureInfo cultureInfoStub =
                MockRepository.GenerateStub <CultureInfo>(1);

            using (mocks.Unordered())
            {
                Expect.Call(adapted.CreateNewTable())
                .Return(featureDataTableStub);
                Expect.Call(adapted.ExecuteFeatureQuery(featureQueryExpressionStub, featureQueryExecutionOptionsStub))
                .Return(iFeatureDataReaderStub);
                Expect.Call(adapted.ExecuteFeatureQuery(featureQueryExpressionStub))
                .Return(iFeatureDataReaderStub);
                adapted.GeometryFactory = iGeometryFactoryStub;
                Expect.Call(adapted.GeometryFactory)
                .Return(iGeometryFactoryStub);
                Expect.Call(adapted.GetFeatureCount())
                .Return(3);
                Expect.Call(adapted.GetSchemaTable())
                .Return(dataTableStub);
                Expect.Call(adapted.Locale)
                .Return(cultureInfoStub);
                adapted.SetTableSchema(featureDataTableStub);
            }
            mocks.ReplayAll();

            AsyncFeatureProviderAdapter adapter = new AsyncFeatureProviderAdapter(adapted);

            Assert.Same(featureDataTableStub, adapter.CreateNewTable());
            Assert.Same(iFeatureDataReaderStub,
                        adapter.ExecuteFeatureQuery(featureQueryExpressionStub, featureQueryExecutionOptionsStub));
            Assert.Same(iFeatureDataReaderStub,
                        adapter.ExecuteFeatureQuery(featureQueryExpressionStub));
            adapter.GeometryFactory = iGeometryFactoryStub;
            Assert.Same(iGeometryFactoryStub, adapter.GeometryFactory);
            Assert.Equal(3, adapter.GetFeatureCount());
            Assert.Same(dataTableStub, adapter.GetSchemaTable());
            Assert.Same(cultureInfoStub, adapter.Locale);
            adapter.SetTableSchema(featureDataTableStub);

            mocks.VerifyAll();
        }
        public void BeginExecuteQueryBlockUntilDone()
        {
            MockRepository   mocks        = new MockRepository();
            IFeatureProvider adapted      = mocks.CreateMock <IFeatureProvider>();
            IExtents         iExtentsStub =
                MockRepository.GenerateStub <IExtents>();
            FeatureQueryExpression featureQueryExpressionStub =
                MockRepository.GenerateStub <FeatureQueryExpression>(iExtentsStub, SpatialOperation.Intersects);

            _returnReaderStub = MockRepository.GenerateStub <IFeatureDataReader>();
            _sleepInterval    = 750;

            using (mocks.Unordered())
            {
                Expect.Call(adapted.ExecuteFeatureQuery(featureQueryExpressionStub))
                .Do(new ExecuteQueryDelegate(executeQueryMock));
            }
            mocks.ReplayAll();

            AsyncFeatureProviderAdapter adapter = new AsyncFeatureProviderAdapter(adapted);
            IAsyncResult ar = adapter.BeginExecuteQuery(featureQueryExpressionStub, null);

            Assert.NotNull(ar);

            Stopwatch timer = Stopwatch.StartNew();

            Assert.Same(_returnReaderStub, adapter.EndExecuteQuery(ar));
            timer.Stop();

            Assert.True(ar.IsCompleted);
            Assert.False(ar.CompletedSynchronously);
            Assert.True(timer.ElapsedMilliseconds > 500L);

            mocks.VerifyAll();
        }
        public void BeginExecuteQueryPollingNotification()
        {
            MockRepository   mocks        = new MockRepository();
            IFeatureProvider adapted      = mocks.CreateMock <IFeatureProvider>();
            IExtents         iExtentsStub =
                MockRepository.GenerateStub <IExtents>();
            FeatureQueryExpression featureQueryExpressionStub =
                MockRepository.GenerateStub <FeatureQueryExpression>(iExtentsStub, SpatialOperation.Intersects);

            _returnReaderStub = MockRepository.GenerateStub <IFeatureDataReader>();
            _sleepInterval    = 1000;

            using (mocks.Unordered())
            {
                Expect.Call(adapted.ExecuteFeatureQuery(featureQueryExpressionStub))
                .Do(new ExecuteQueryDelegate(executeQueryMock));
            }
            mocks.ReplayAll();

            AsyncFeatureProviderAdapter adapter = new AsyncFeatureProviderAdapter(adapted);
            IAsyncResult ar = adapter.BeginExecuteQuery(featureQueryExpressionStub, null);

            Assert.NotNull(ar);
            Assert.False(ar.IsCompleted);
            while (!ar.IsCompleted)
            {
                Thread.Sleep(350);
            }

            Assert.True(ar.IsCompleted);
            Assert.Same(_returnReaderStub, adapter.EndExecuteQuery(ar));

            mocks.VerifyAll();
        }
        public void RenderFeatureTest()
        {
            IFeatureProvider   provider       = DataSourceHelper.CreateGeometryDatasource(_factories.GeoFactory);
            TestVectorRenderer vectorRenderer = new TestVectorRenderer();
            BasicGeometryRenderer2D <RenderObject> geometryRenderer =
                new BasicGeometryRenderer2D <RenderObject>(vectorRenderer);

            FeatureDataTable       features = new FeatureDataTable(_factories.GeoFactory);
            IExtents               extents  = provider.GetExtents();
            FeatureQueryExpression query    = new FeatureQueryExpression(extents.ToGeometry(),
                                                                         SpatialOperation.Intersects,
                                                                         provider);

            features.Merge(provider.ExecuteFeatureQuery(query) as IEnumerable <IFeatureDataRecord>,
                           provider.GeometryFactory);

            foreach (FeatureDataRow feature in features)
            {
                IGeometry           g = feature.Geometry;
                List <RenderObject> renderedObjects = new List <RenderObject>(geometryRenderer.RenderFeature(feature));

                for (Int32 i = 0; i < renderedObjects.Count; i++)
                {
                    RenderObject ro = renderedObjects[i];
                }
            }
        }
        public void EndExecuteQueryThrowsTerminatingException()
        {
            MockRepository   mocks        = new MockRepository();
            IFeatureProvider adapted      = mocks.CreateMock <IFeatureProvider>();
            IExtents         iExtentsStub =
                MockRepository.GenerateStub <IExtents>();
            FeatureQueryExpression featureQueryExpressionStub =
                MockRepository.GenerateStub <FeatureQueryExpression>(iExtentsStub, SpatialOperation.Intersects);

            using (mocks.Unordered())
            {
                Expect.Call(adapted.ExecuteFeatureQuery(featureQueryExpressionStub))
                .Do(new ExecuteQueryDelegate(executeQueryExceptionMock));
            }
            mocks.ReplayAll();

            AsyncFeatureProviderAdapter adapter = new AsyncFeatureProviderAdapter(adapted);
            IAsyncResult ar = adapter.BeginExecuteQuery(featureQueryExpressionStub, null);

            Assert.NotNull(ar);

            Assert.Throws <InvalidOperationException>(delegate { adapter.EndExecuteQuery(ar); });
        }
예제 #7
0
        private void DoConversion(ProviderItem input, IEnumerable <ProcessorItem> processors, ProviderItem output)
        {
            using (IConfigureFeatureSource csource = (IConfigureFeatureSource)Activator.CreateInstance(input.Builder))
            {
                IFeatureProvider psource    = csource.ConstructSourceProvider(_geometryServices);
                Type             srcOidType = GetTypeParamsOfImplementedInterface(psource.GetType(), typeof(IFeatureProvider <>))[0];
                List <IProcessFeatureDataRecords> realProcessors = new List <IProcessFeatureDataRecords>();

                foreach (ProcessorItem pi in processors)
                {
                    realProcessors.Add((IProcessFeatureDataRecords)Activator.CreateInstance(pi.ProcessorType));
                }

                FeatureDataRecordProcessor processChain = null;

                foreach (IProcessFeatureDataRecords processor in realProcessors)
                {
                    processChain = Equals(processChain, null)
                                       ? processor.Processor
                                       : ((IEnumerable <IFeatureDataRecord> o, ref int i) =>
                                          processor.Processor(processChain(o, ref i), ref i));
                }

                processChain = processChain ??
                               new FeatureDataRecordProcessor((IEnumerable <IFeatureDataRecord> o, ref int i) => o);

                if (!psource.IsOpen)
                {
                    psource.Open();
                }

                FeatureQueryExpression exp         = csource.ConstructSourceQueryExpression();
                FeatureDataTable       sourceModel = psource.CreateNewTable();
                int index = sourceModel.Columns.IndexOf(sourceModel.PrimaryKey[0]);
                IEnumerable <IFeatureDataRecord> sourceRecords = processChain(psource.ExecuteFeatureQuery(exp), ref index);

                //jd: TODO: need to test what happens if the IFeatureDataRecord shape is changed by the processor chain

                IConvertData converter = null;

                /* Some Data Providers do not respect the oidType param passed in.
                 * For instance Shapefile will always be IWritableFeatureProvider<UInt32>
                 * so we need to make sure we can coerce OID values  */



                using (
                    IConfigureFeatureTarget ctarget =
                        (IConfigureFeatureTarget)Activator.CreateInstance(output.Builder))
                {
                    Type oidType = csource.OidType;



                    using (IWritableFeatureProvider ptarget =
                               ctarget.ConstructTargetProvider(oidType, sourceModel.GeometryFactory,
                                                               _geometryServices.CoordinateSystemFactory,
                                                               sourceModel))
                    {
                        if (!ptarget.IsOpen)
                        {
                            ptarget.Open();
                        }

                        converter = GetConverter(csource.OidType, ctarget.OidType, sourceModel.NewRow(), index, sourceModel.GeometryFactory);



                        Console.WriteLine("Beginning Import.");
                        List <FeatureDataRow> features = new List <FeatureDataRow>();
                        int count = 0;
                        foreach (IFeatureDataRecord fdr in sourceRecords)
                        {
                            try
                            {
                                features.Add(converter.ConvertRecord(fdr));
                                if (++count % 100 == 0)
                                {
                                    ptarget.Insert(features);
                                    features.Clear();
                                }
                            }
                            catch (GeometryInvalidException ex)
                            {
                                Console.WriteLine("An Error Occured : " + ex.Message);
                                continue;
                            }
                        }

                        if (features.Count > 0)
                        {
                            ptarget.Insert(features);
                        }

                        count += features.Count;

                        features = null;

                        ptarget.Close();
                        Console.WriteLine(string.Format("{0} records processed", count));

                        ctarget.PostImport();
                    }
                }
            }

            Console.WriteLine("Finished");
        }