Exemplo n.º 1
0
        private void bgGridLoader_DoWork(object sender, DoWorkEventArgs e)
        {
            var reader = (MgReader)e.Argument;
            var wktRw  = new MgWktReaderWriter();
            var agfRw  = new MgAgfReaderWriter();

            var cls     = _layer.GetClassDefinition();
            var idProps = cls.GetIdentityProperties();
            var idNames = new List <string>();

            for (int i = 0; i < idProps.Count; i++)
            {
                var prop = idProps.GetItem(i);
                idNames.Add(prop.Name);
            }
            _identityProps = idNames.ToArray();

            var propNames = new List <string>();
            int propCount = reader.GetPropertyCount();
            //.net 2.0 compatibility hack for set-like behaviour
            var skipProps = new Dictionary <int, int>();

            for (int i = 0; i < propCount; i++)
            {
                var pt = reader.GetPropertyType(i);
                if (pt == MgPropertyType.Blob ||
                    pt == MgPropertyType.Clob ||
                    pt == MgPropertyType.Feature ||
                    pt == MgPropertyType.Null ||
                    pt == MgPropertyType.Raster)
                {
                    skipProps[i] = i;
                }
                else
                {
                    var name = reader.GetPropertyName(i);
                    _propMap.Add(name, pt);
                    propNames.Add(name);
                }
            }
            try
            {
                bgGridLoader.ReportProgress(-1, new InitGridAction()
                {
                    ColumnNames = propNames.ToArray()
                });
                int read = 0;
                while (reader.ReadNext())
                {
                    object[] values = new object[propCount];
                    for (int i = 0; i < propCount; i++)
                    {
                        if (skipProps.ContainsKey(i))
                        {
                            continue;
                        }

                        if (reader.IsNull(i))
                        {
                            values[i] = null;
                        }
                        else
                        {
                            switch (reader.GetPropertyType(i))
                            {
                            case MgPropertyType.Boolean:
                                values[i] = reader.GetBoolean(i);
                                break;

                            case MgPropertyType.Byte:
                                values[i] = reader.GetByte(i);
                                break;

                            case MgPropertyType.DateTime:
                                values[i] = ToClrDateTime(reader.GetDateTime(i));
                                break;

                            case MgPropertyType.Decimal:
                            case MgPropertyType.Double:
                                values[i] = reader.GetDouble(i);
                                break;

                            case MgPropertyType.Geometry:
                            {
                                try
                                {
                                    var agf   = reader.GetGeometry(i);
                                    var geom  = agfRw.Read(agf);
                                    var env   = geom.Envelope();
                                    var envLL = env.LowerLeftCoordinate;
                                    var envUR = env.UpperRightCoordinate;
                                    var wkt   = wktRw.Write(geom);

                                    values[i] = new BoxedGeometry()
                                    {
                                        Text       = wkt,
                                        GeomBounds = new Bounds()
                                        {
                                            LowerX = envLL.X,
                                            LowerY = envLL.Y,
                                            UpperX = envUR.X,
                                            UpperY = envUR.Y
                                        }
                                    };
                                }
                                catch
                                {
                                    values[i] = null;
                                }
                            }
                            break;

                            case MgPropertyType.Int16:
                                values[i] = reader.GetInt16(i);
                                break;

                            case MgPropertyType.Int32:
                                values[i] = reader.GetInt32(i);
                                break;

                            case MgPropertyType.Int64:
                                values[i] = reader.GetInt64(i);
                                break;

                            case MgPropertyType.Single:
                                values[i] = reader.GetSingle(i);
                                break;

                            case MgPropertyType.String:
                                values[i] = reader.GetString(i);
                                break;
                            }
                        }
                    }
                    bgGridLoader.ReportProgress(-1, new AddRow()
                    {
                        Values = values
                    });
                    read++;
                    if ((_limit > 0 && read >= _limit))
                    {
                        break;
                    }
                }
            }
            finally
            {
                reader.Close();
                wktRw.Dispose();
                agfRw.Dispose();
                wktRw = null;
                agfRw = null;
            }
        }
Exemplo n.º 2
0
        private void bgGridLoader_DoWork(object sender, DoWorkEventArgs e)
        {
            var reader = (MgReader)e.Argument;
            var wktRw = new MgWktReaderWriter();
            var agfRw = new MgAgfReaderWriter();

            var cls = _layer.GetClassDefinition();
            var idProps = cls.GetIdentityProperties();
            var idNames = new List<string>();
            for (int i = 0; i < idProps.Count; i++)
            {
                var prop = idProps.GetItem(i);
                idNames.Add(prop.Name);
            }
            _identityProps = idNames.ToArray();

            var propNames = new List<string>();
            int propCount = reader.GetPropertyCount();
            //.net 2.0 compatibility hack for set-like behaviour
            var skipProps = new Dictionary<int, int>();
            for (int i = 0; i < propCount; i++)
            {
                var pt = reader.GetPropertyType(i);
                if (pt == MgPropertyType.Blob ||
                    pt == MgPropertyType.Clob ||
                    pt == MgPropertyType.Feature ||
                    pt == MgPropertyType.Null ||
                    pt == MgPropertyType.Raster)
                {
                    skipProps[i] = i;
                }
                else
                {
                    var name = reader.GetPropertyName(i);
                    _propMap.Add(name, pt);
                    propNames.Add(name);
                }
            }
            try
            {
                bgGridLoader.ReportProgress(-1, new InitGridAction() { ColumnNames = propNames.ToArray() });
                int read = 0;
                while (reader.ReadNext())
                {
                    object[] values = new object[propCount];
                    for (int i = 0; i < propCount; i++)
                    {
                        if (skipProps.ContainsKey(i))
                            continue;

                        if (reader.IsNull(i))
                        {
                            values[i] = null;
                        }
                        else
                        {
                            switch (reader.GetPropertyType(i))
                            {
                                case MgPropertyType.Boolean:
                                    values[i] = reader.GetBoolean(i);
                                    break;
                                case MgPropertyType.Byte:
                                    values[i] = reader.GetByte(i);
                                    break;
                                case MgPropertyType.DateTime:
                                    values[i] = ToClrDateTime(reader.GetDateTime(i));
                                    break;
                                case MgPropertyType.Decimal:
                                case MgPropertyType.Double:
                                    values[i] = reader.GetDouble(i);
                                    break;
                                case MgPropertyType.Geometry:
                                    {
                                        try
                                        {
                                            var agf = reader.GetGeometry(i);
                                            var geom = agfRw.Read(agf);
                                            var env = geom.Envelope();
                                            var envLL = env.LowerLeftCoordinate;
                                            var envUR = env.UpperRightCoordinate;
                                            var wkt = wktRw.Write(geom);

                                            values[i] = new BoxedGeometry()
                                            {
                                                Text = wkt,
                                                GeomBounds = new Bounds()
                                                {
                                                    LowerX = envLL.X,
                                                    LowerY = envLL.Y,
                                                    UpperX = envUR.X,
                                                    UpperY = envUR.Y
                                                }
                                            };
                                        }
                                        catch
                                        {
                                            values[i] = null;
                                        }
                                    }
                                    break;
                                case MgPropertyType.Int16:
                                    values[i] = reader.GetInt16(i);
                                    break;
                                case MgPropertyType.Int32:
                                    values[i] = reader.GetInt32(i);
                                    break;
                                case MgPropertyType.Int64:
                                    values[i] = reader.GetInt64(i);
                                    break;
                                case MgPropertyType.Single:
                                    values[i] = reader.GetSingle(i);
                                    break;
                                case MgPropertyType.String :
                                    values[i] = reader.GetString(i);
                                    break;
                            }
                        }
                    }
                    bgGridLoader.ReportProgress(-1, new AddRow() { Values = values });
                    read++;
                    if ((_limit > 0 && read >= _limit))
                        break;
                }
            }
            finally
            {
                reader.Close();
                wktRw.Dispose();
                agfRw.Dispose();
                wktRw = null;
                agfRw = null;
            }
        }