Beispiel #1
0
        void ExportGeometry(IGeometry g)
        {
            // c.f. FdoToolbox bulk copy? - FdoBatchedOutputOperation
            using (IInsert cmd = m_Connection.CreateCommand(CommandType.CommandType_Insert) as IInsert)
            {
                cmd.SetFeatureClassName("FC");

                PropertyValueCollection pvc = cmd.PropertyValues;

                //PropertyValue pvId = new PropertyValue();
                //pvId.SetName("ID");
                //pvId.Value = new Int32Value(id);
                //pvc.Add(pvId);

                GeometryValue gv     = new GeometryValue(m_Factory.GetFgf(g));
                PropertyValue pvGeom = new PropertyValue();
                pvGeom.SetName("Geometry");
                pvGeom.Value = gv;
                pvc.Add(pvGeom);

                try
                {
                    IFeatureReader reader = cmd.Execute();
                    reader.Dispose();
                    m_NumOk++;
                }

                catch
                {
                    m_NumFail++;
                }
            }
        }
Beispiel #2
0
        public void TestCase_GeometryValue()
        {
            var mockGeom = new Mock <IGeometry>();

            mockGeom.Setup(g => g.AsText()).Returns("POINT (0 0)");

            var value = new GeometryValue();

            Assert.AreEqual(PropertyDefinitionType.Geometry, value.PropertyDefType);
            Assert.AreEqual(PropertyValueType.Geometry, value.Type);
            Assert.True(value.IsNull);
            Assert.Throws <Exception>(() => { var v = value.Value; });
            Assert.Throws <Exception>(() => { var v = value.ValueAsString(); });
            value.Value = mockGeom.Object;
            Assert.NotNull(value.Value);
            Assert.AreEqual("POINT (0 0)", value.ValueAsString());
            Assert.False(value.IsNull);

            value = new GeometryValue(mockGeom.Object);
            Assert.False(value.IsNull);
            Assert.NotNull(value.Value);
            Assert.AreEqual("POINT (0 0)", value.ValueAsString());

            value.SetNull();
            Assert.True(value.IsNull);
            Assert.Throws <Exception>(() => { var v = value.Value; });
        }
        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);
                }
            }
        }
        /// <summary>
        /// Gets the values.
        /// </summary>
        /// <returns></returns>
        public Dictionary<string, ValueExpression> GetValues()
        {
            Dictionary<string, ValueExpression> values = new Dictionary<string, ValueExpression>();
            foreach (DataGridViewRow row in grdProperties.Rows)
            {
                string name = row.Cells[0].Value.ToString();
                PropertyDefinition propDef = row.Cells[0].Tag as PropertyDefinition;
                if (row.Cells[1].Value != null)
                {
                    string str = row.Cells[1].Value.ToString();
                    if (!string.IsNullOrEmpty(str))
                    {
                        ValueExpression expr = null;
                        if (propDef.PropertyType == PropertyType.PropertyType_DataProperty)
                        {
                            DataPropertyDefinition dp = propDef as DataPropertyDefinition;
                            switch (dp.DataType)
                            {
                                case DataType.DataType_Boolean:
                                    expr = new BooleanValue(Convert.ToBoolean(str));
                                    break;
                                case DataType.DataType_Byte:
                                    expr = new ByteValue(Convert.ToByte(str));
                                    break;
                                case DataType.DataType_DateTime:
                                    expr = new DateTimeValue(Convert.ToDateTime(str));
                                    break;
                                case DataType.DataType_Decimal:
                                    expr = new DecimalValue(Convert.ToDouble(str));
                                    break;
                                case DataType.DataType_Double:
                                    expr = new DoubleValue(Convert.ToDouble(str));
                                    break;
                                case DataType.DataType_Int16:
                                    expr = new Int16Value(Convert.ToInt16(str));
                                    break;
                                case DataType.DataType_Int32:
                                    expr = new Int32Value(Convert.ToInt32(str));
                                    break;
                                case DataType.DataType_Int64:
                                    expr = new Int64Value(Convert.ToInt64(str));
                                    break;
                                case DataType.DataType_Single:
                                    expr = new SingleValue(Convert.ToSingle(str));
                                    break;
                                case DataType.DataType_String:
                                    expr = new StringValue(str);
                                    break;
                                default:
                                    throw new NotSupportedException("Unsupported data type: " + dp.DataType);
                            }
                        }
                        else if (propDef.PropertyType == PropertyType.PropertyType_GeometricProperty)
                        {
                            FdoGeometryFactory fact = FdoGeometryFactory.Instance;
                            OSGeo.FDO.Geometry.IGeometry geom = fact.CreateGeometry(str);
                            byte[] fgf = fact.GetFgf(geom);
                            expr = new GeometryValue(fgf);
                            geom.Dispose();
                        }

                        if (expr != null)
                            values.Add(name, expr);
                    }
                }
            }
            return values;
        }
        public LocalNativeRecord(MgReader reader, FixedWKTReader mgReader, MgAgfReaderWriter agfRw, MgWktReaderWriter wktRw)
        {
            for (int i = 0; i < reader.GetPropertyCount(); i++)
            {
                string name = reader.GetPropertyName(i);

                _ordinalMap[i] = name;

                var pt = (PropertyValueType)reader.GetPropertyType(name);
                switch (pt)
                {
                    case PropertyValueType.Blob:
                        _values[name] = new BlobValue();
                        break;

                    case PropertyValueType.Boolean:
                        _values[name] = new BooleanValue();
                        break;

                    case PropertyValueType.Byte:
                        _values[name] = new ByteValue();
                        break;

                    case PropertyValueType.Clob:
                        _values[name] = new ClobValue();
                        break;

                    case PropertyValueType.DateTime:
                        _values[name] = new DateTimeValue();
                        break;

                    case PropertyValueType.Double:
                        _values[name] = new DoubleValue();
                        break;

                    case PropertyValueType.Feature:
                        _values[name] = new FeatureValue();
                        break;

                    case PropertyValueType.Geometry:
                        _values[name] = new GeometryValue();
                        break;

                    case PropertyValueType.Int16:
                        _values[name] = new Int16Value();
                        break;

                    case PropertyValueType.Int32:
                        _values[name] = new Int32Value();
                        break;

                    case PropertyValueType.Int64:
                        _values[name] = new Int64Value();
                        break;

                    case PropertyValueType.Raster:
                        _values[name] = new RasterValue();
                        break;

                    case PropertyValueType.Single:
                        _values[name] = new SingleValue();
                        break;

                    case PropertyValueType.String:
                        _values[name] = new StringValue();
                        break;
                }
            }

            for (int i = 0; i < reader.GetPropertyCount(); i++)
            {
                string name = _ordinalMap[i];
                GetByteReaderMethod getblob = () => { return reader.GetBLOB(name); };
                GetByteReaderMethod getclob = () => { return reader.GetCLOB(name); };
                GetByteReaderMethod getgeom = () => { return reader.GetGeometry(name); };
                if (!reader.IsNull(name))
                {
                    var pt = (PropertyValueType)reader.GetPropertyType(name);
                    switch (pt)
                    {
                        case PropertyValueType.Blob:
                            ((BlobValue)_values[name]).Value = Utility.StreamAsArray(new MgReadOnlyStream(getblob));
                            break;

                        case PropertyValueType.Boolean:
                            ((BooleanValue)_values[name]).Value = reader.GetBoolean(name);
                            break;

                        case PropertyValueType.Byte:
                            ((ByteValue)_values[name]).Value = reader.GetByte(name);
                            break;

                        case PropertyValueType.Clob:
                            byte[] b = Utility.StreamAsArray(new MgReadOnlyStream(getclob));
                            ((ClobValue)_values[name]).Value = Encoding.UTF8.GetChars(b);
                            break;

                        case PropertyValueType.DateTime:
                            ((DateTimeValue)_values[name]).Value = Utility.ConvertMgDateTime(reader.GetDateTime(name));
                            break;

                        case PropertyValueType.Double:
                            ((DoubleValue)_values[name]).Value = reader.GetDouble(name);
                            break;
                        //case PropertyValueType.Feature:
                        case PropertyValueType.Geometry:
                            try
                            {
                                //TODO: See if SWIG issues come into play here
                                var geom = agfRw.Read(reader.GetGeometry(name));
                                var wkt = wktRw.Write(geom);
                                ((GeometryValue)_values[name]).Value = mgReader.Read(wkt);
                            }
                            catch //Invalid geometry fail!
                            {
                                ((GeometryValue)_values[name]).SetNull();
                            }
                            break;

                        case PropertyValueType.Int16:
                            ((Int16Value)_values[name]).Value = reader.GetInt16(name);
                            break;

                        case PropertyValueType.Int32:
                            ((Int32Value)_values[name]).Value = reader.GetInt32(name);
                            break;

                        case PropertyValueType.Int64:
                            ((Int64Value)_values[name]).Value = reader.GetInt64(name);
                            break;

                        case PropertyValueType.Single:
                            ((SingleValue)_values[name]).Value = reader.GetSingle(name);
                            break;

                        case PropertyValueType.String:
                            ((StringValue)_values[name]).Value = reader.GetString(name);
                            break;
                    }
                }
            }
        }
Beispiel #6
0
        public XmlRecord(XmlProperty[] properties, FixedWKTReader wktReader, XmlNodeList propertyNodes, string nameElement, string valueElement)
        {
            for (int i = 0; i < properties.Length; i++)
            {
                string name = properties[i].Name;
                _ordinalMap[i] = name;

                switch (properties[i].Type)
                {
                case PropertyValueType.Blob:
                    _values[name] = new BlobValue();
                    break;

                case PropertyValueType.Boolean:
                    _values[name] = new BooleanValue();
                    break;

                case PropertyValueType.Byte:
                    _values[name] = new ByteValue();
                    break;

                case PropertyValueType.Clob:
                    _values[name] = new ClobValue();
                    break;

                case PropertyValueType.DateTime:
                    _values[name] = new DateTimeValue();
                    break;

                case PropertyValueType.Double:
                    _values[name] = new DoubleValue();
                    break;

                case PropertyValueType.Feature:
                    _values[name] = new FeatureValue();
                    break;

                case PropertyValueType.Geometry:
                    _values[name] = new GeometryValue();
                    break;

                case PropertyValueType.Int16:
                    _values[name] = new Int16Value();
                    break;

                case PropertyValueType.Int32:
                    _values[name] = new Int32Value();
                    break;

                case PropertyValueType.Int64:
                    _values[name] = new Int64Value();
                    break;

                case PropertyValueType.Raster:
                    _values[name] = new RasterValue();
                    break;

                case PropertyValueType.Single:
                    _values[name] = new SingleValue();
                    break;

                case PropertyValueType.String:
                    _values[name] = new StringValue();
                    break;
                }
            }

            foreach (XmlNode propNode in propertyNodes)
            {
                var name      = propNode[nameElement].InnerText;
                var valueNode = propNode[valueElement];
                if (valueNode != null)
                {
                    var value = valueNode.InnerText;
                    switch (_values[name].Type)
                    {
                    case PropertyValueType.Blob:
                        ((BlobValue)_values[name]).Value = Encoding.UTF8.GetBytes(value);
                        break;

                    case PropertyValueType.Boolean:
                        ((BooleanValue)_values[name]).Value = XmlConvert.ToBoolean(value);
                        break;

                    case PropertyValueType.Byte:
                        ((ByteValue)_values[name]).Value = XmlConvert.ToByte(value);
                        break;

                    case PropertyValueType.Clob:
                        ((ClobValue)_values[name]).Value = value.ToCharArray();
                        break;

                    case PropertyValueType.DateTime:
                        var dt = ConvertToDateTime(value);
                        if (dt.HasValue)
                        {
                            ((DateTimeValue)_values[name]).Value = dt.Value;
                        }
                        break;

                    case PropertyValueType.Double:
                        ((DoubleValue)_values[name]).Value = XmlConvert.ToDouble(value);
                        break;

                    case PropertyValueType.Feature:
                        ((FeatureValue)_values[name]).Value = ConvertToFeatures(value);
                        break;

                    case PropertyValueType.Geometry:
                        ((GeometryValue)_values[name]).Value = wktReader.Read(value);
                        break;

                    case PropertyValueType.Int16:
                        ((Int16Value)_values[name]).Value = XmlConvert.ToInt16(value);
                        break;

                    case PropertyValueType.Int32:
                        ((Int32Value)_values[name]).Value = XmlConvert.ToInt32(value);
                        break;

                    case PropertyValueType.Int64:
                        ((Int64Value)_values[name]).Value = XmlConvert.ToInt64(value);
                        break;

                    case PropertyValueType.Raster:
                        ((RasterValue)_values[name]).Value = ConvertToRaster(value);
                        break;

                    case PropertyValueType.Single:
                        ((SingleValue)_values[name]).Value = XmlConvert.ToSingle(value);
                        break;

                    case PropertyValueType.String:
                        ((StringValue)_values[name]).Value = value;
                        break;
                    }
                }
            }
        }
Beispiel #7
0
        private void Bind(FdoRow row)
        {
            //Set all property values to null and then set the proper values
            foreach (string propName in currentValues.Keys)
            {
                //Get the [target] property name. If reverse-mapped to the [source], use the
                //mapped [source] property name. Otherwise it is assumed that [source] name
                //is the same as the [target] name
                string name = propName;
                if (_mappings[name] != null)
                {
                    name = _mappings[name];
                }

                LiteralValue lVal = currentValues[propName] as LiteralValue;
                if (lVal.LiteralValueType == LiteralValueType.LiteralValueType_Data)
                {
                    DataValue dVal = lVal as DataValue;
                    dVal.SetNull();

                    switch (dVal.DataType)
                    {
                    case DataType.DataType_BLOB:
                    {
                        byte [] blob = row[name] as byte[];
                        if (blob != null)
                        {
                            (dVal as BLOBValue).Data = blob;
                        }
                    }
                    break;

                    case DataType.DataType_Boolean:
                    {
                        if (row[name] != null)
                        {
                            (dVal as BooleanValue).Boolean = Convert.ToBoolean(row[name]);
                        }
                    }
                    break;

                    case DataType.DataType_Byte:
                    {
                        if (row[name] != null)
                        {
                            (dVal as ByteValue).Byte = Convert.ToByte(row[name]);
                        }
                    }
                    break;

                    case DataType.DataType_CLOB:
                    {
                        byte[] clob = row[name] as byte[];
                        if (clob != null)
                        {
                            (dVal as CLOBValue).Data = clob;
                        }
                    }
                    break;

                    case DataType.DataType_DateTime:
                    {
                        if (row[name] != null)
                        {
                            (dVal as DateTimeValue).DateTime = Convert.ToDateTime(row[name]);
                        }
                    }
                    break;

                    case DataType.DataType_Decimal:
                    {
                        if (row[name] != null)
                        {
                            (dVal as DecimalValue).Decimal = Convert.ToDouble(row[name]);
                        }
                    }
                    break;

                    case DataType.DataType_Double:
                    {
                        if (row[name] != null)
                        {
                            (dVal as DoubleValue).Double = Convert.ToDouble(row[name]);
                        }
                    }
                    break;

                    case DataType.DataType_Int16:
                    {
                        if (row[name] != null)
                        {
                            (dVal as Int16Value).Int16 = Convert.ToInt16(row[name]);
                        }
                    }
                    break;

                    case DataType.DataType_Int32:
                    {
                        if (row[name] != null)
                        {
                            (dVal as Int32Value).Int32 = Convert.ToInt32(row[name]);
                        }
                    }
                    break;

                    case DataType.DataType_Int64:
                    {
                        if (row[name] != null)
                        {
                            (dVal as Int64Value).Int64 = Convert.ToInt64(row[name]);
                        }
                    }
                    break;

                    case DataType.DataType_Single:
                    {
                        if (row[name] != null)
                        {
                            (dVal as SingleValue).Single = Convert.ToSingle(row[name]);
                        }
                    }
                    break;

                    case DataType.DataType_String:
                    {
                        if (row[name] != null)
                        {
                            (dVal as StringValue).String = row[name].ToString();
                        }
                    }
                    break;
                    }
                }
                else
                {
                    GeometryValue gVal = lVal as GeometryValue;
                    gVal.SetNull();

                    IGeometry geom = row[name] as IGeometry;
                    if (geom != null)
                    {
                        IGeometry origGeom = geom;
                        //HACK: Just for you SQL Server 2008!
                        if (geom.DerivedType == OSGeo.FDO.Common.GeometryType.GeometryType_Polygon ||
                            geom.DerivedType == OSGeo.FDO.Common.GeometryType.GeometryType_CurvePolygon ||
                            geom.DerivedType == OSGeo.FDO.Common.GeometryType.GeometryType_MultiCurvePolygon ||
                            geom.DerivedType == OSGeo.FDO.Common.GeometryType.GeometryType_MultiPolygon)
                        {
                            if (_conn.Provider.ToUpper().StartsWith("OSGEO.SQLSERVERSPATIAL"))
                            {
                                //This isn't the most optimal way, as the most optimal
                                //method according to RFC48 is to get the source rule and
                                //strictness and pass that to SpatialUtility.GetPolygonVertexOrderAction()
                                //along with the target rule and strictness. I don't think warping the
                                //existing API to address such a provider-specific corner case is worth it.
                                var caps = _clsDef.Capabilities;
                                var rule = caps.get_PolygonVertexOrderRule(name);
                                geom = SpatialUtility.FixPolygonVertexOrder(origGeom, rule);
                            }
                        }

                        if (geom != null)
                        {
                            gVal.Geometry = FdoGeometryFactory.Instance.GetFgf(geom);
                        }
                        else
                        {
                            gVal.Geometry = FdoGeometryFactory.Instance.GetFgf(origGeom);
                        }
                    }
                }
            }
        }
Beispiel #8
0
        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);
                }
            }
        }
Beispiel #9
0
        public XmlRecord(XmlProperty[] properties, FixedWKTReader wktReader, XmlNodeList propertyNodes, string nameElement, string valueElement)
        {
            for (int i = 0; i < properties.Length; i++)
            {
                string name = properties[i].Name;
                _ordinalMap[i] = name;

                switch (properties[i].Type)
                {
                    case PropertyValueType.Blob:
                        _values[name] = new BlobValue();
                        break;
                    case PropertyValueType.Boolean:
                        _values[name] = new BooleanValue();
                        break;
                    case PropertyValueType.Byte:
                        _values[name] = new ByteValue();
                        break;
                    case PropertyValueType.Clob:
                        _values[name] = new ClobValue();
                        break;
                    case PropertyValueType.DateTime:
                        _values[name] = new DateTimeValue();
                        break;
                    case PropertyValueType.Double:
                        _values[name] = new DoubleValue();
                        break;
                    case PropertyValueType.Feature:
                        _values[name] = new FeatureValue();
                        break;
                    case PropertyValueType.Geometry:
                        _values[name] = new GeometryValue();
                        break;
                    case PropertyValueType.Int16:
                        _values[name] = new Int16Value();
                        break;
                    case PropertyValueType.Int32:
                        _values[name] = new Int32Value();
                        break;
                    case PropertyValueType.Int64:
                        _values[name] = new Int64Value();
                        break;
                    case PropertyValueType.Raster:
                        _values[name] = new RasterValue();
                        break;
                    case PropertyValueType.Single:
                        _values[name] = new SingleValue();
                        break;
                    case PropertyValueType.String:
                        _values[name] = new StringValue();
                        break;
                }
            }

            foreach (XmlNode propNode in propertyNodes)
            {
                var name = propNode[nameElement].InnerText;
                var valueNode = propNode[valueElement];
                if (valueNode != null)
                {
                    var value = valueNode.InnerText;
                    switch (_values[name].Type)
                    {
                        case PropertyValueType.Blob:
                            ((BlobValue)_values[name]).Value = Encoding.UTF8.GetBytes(value);
                            break;
                        case PropertyValueType.Boolean:
                            ((BooleanValue)_values[name]).Value = XmlConvert.ToBoolean(value);
                            break;
                        case PropertyValueType.Byte:
                            ((ByteValue)_values[name]).Value = XmlConvert.ToByte(value);
                            break;
                        case PropertyValueType.Clob:
                            ((ClobValue)_values[name]).Value = value.ToCharArray();
                            break;
                        case PropertyValueType.DateTime:
                            var dt = ConvertToDateTime(value);
                            if (dt.HasValue)
                                ((DateTimeValue)_values[name]).Value = dt.Value;
                            break;
                        case PropertyValueType.Double:
                            ((DoubleValue)_values[name]).Value = XmlConvert.ToDouble(value);
                            break;
                        case PropertyValueType.Feature:
                            ((FeatureValue)_values[name]).Value = ConvertToFeatures(value);
                            break;
                        case PropertyValueType.Geometry:
                            ((GeometryValue)_values[name]).Value = wktReader.Read(value);
                            break;
                        case PropertyValueType.Int16:
                            ((Int16Value)_values[name]).Value = XmlConvert.ToInt16(value);
                            break;
                        case PropertyValueType.Int32:
                            ((Int32Value)_values[name]).Value = XmlConvert.ToInt32(value);
                            break;
                        case PropertyValueType.Int64:
                            ((Int64Value)_values[name]).Value = XmlConvert.ToInt64(value);
                            break;
                        case PropertyValueType.Raster:
                            ((RasterValue)_values[name]).Value = ConvertToRaster(value);
                            break;
                        case PropertyValueType.Single:
                            ((SingleValue)_values[name]).Value = XmlConvert.ToSingle(value);
                            break;
                        case PropertyValueType.String:
                            ((StringValue)_values[name]).Value = value;
                            break;
                    }
                }
            }
        }
Beispiel #10
0
        public Dictionary <string, ValueExpression> GetValues()
        {
            Dictionary <string, ValueExpression> values = new Dictionary <string, ValueExpression>();

            foreach (int idx in _modifiedRowIndices)
            {
                DataGridViewRow    row     = grdProperties.Rows[idx];
                string             name    = row.Cells[0].Value.ToString();
                PropertyDefinition propDef = row.Cells[0].Tag as PropertyDefinition;
                if (row.Cells[1].Value != null)
                {
                    string str = row.Cells[1].Value.ToString();
                    if (!string.IsNullOrEmpty(str))
                    {
                        ValueExpression expr = null;
                        if (propDef.PropertyType == PropertyType.PropertyType_DataProperty)
                        {
                            DataPropertyDefinition dp = propDef as DataPropertyDefinition;
                            switch (dp.DataType)
                            {
                            case DataType.DataType_Boolean:
                                expr = new BooleanValue(Convert.ToBoolean(str));
                                break;

                            case DataType.DataType_Byte:
                                expr = new ByteValue(Convert.ToByte(str));
                                break;

                            case DataType.DataType_DateTime:
                                expr = new DateTimeValue(Convert.ToDateTime(str));
                                break;

                            case DataType.DataType_Decimal:
                                expr = new DecimalValue(Convert.ToDouble(str));
                                break;

                            case DataType.DataType_Double:
                                expr = new DoubleValue(Convert.ToDouble(str));
                                break;

                            case DataType.DataType_Int16:
                                expr = new Int16Value(Convert.ToInt16(str));
                                break;

                            case DataType.DataType_Int32:
                                expr = new Int32Value(Convert.ToInt32(str));
                                break;

                            case DataType.DataType_Int64:
                                expr = new Int64Value(Convert.ToInt64(str));
                                break;

                            case DataType.DataType_Single:
                                expr = new SingleValue(Convert.ToSingle(str));
                                break;

                            case DataType.DataType_String:
                                expr = new StringValue(str);
                                break;

                            default:
                                throw new NotSupportedException("Unsupported data type: " + dp.DataType);
                            }
                        }
                        else if (propDef.PropertyType == PropertyType.PropertyType_GeometricProperty)
                        {
                            FdoGeometryFactory           fact = FdoGeometryFactory.Instance;
                            OSGeo.FDO.Geometry.IGeometry geom = fact.CreateGeometry(str);
                            byte[] fgf = fact.GetFgf(geom);
                            expr = new GeometryValue(fgf);
                            geom.Dispose();
                        }
                        else if (propDef.PropertyType == PropertyType.PropertyType_AssociationProperty)
                        {
                            // TODO: don't assume all values are strings! Use schema.
                            expr = new StringValue(str);
                        }
                        else if (propDef.PropertyType == PropertyType.PropertyType_ObjectProperty)
                        {
                            // TODO: don't assume all values are strings! Use schema.
                            expr = new StringValue(str);
                        }

                        if (expr != null)
                        {
                            values.Add(name, expr);
                        }
                    }
                }
            }
            return(values);
        }
Beispiel #11
0
        void ExportGeometry(IGeometry g)
        {
            // c.f. FdoToolbox bulk copy? - FdoBatchedOutputOperation
            using (IInsert cmd = m_Connection.CreateCommand(CommandType.CommandType_Insert) as IInsert)
            {
                cmd.SetFeatureClassName("FC");

                PropertyValueCollection pvc = cmd.PropertyValues;

                //PropertyValue pvId = new PropertyValue();
                //pvId.SetName("ID");
                //pvId.Value = new Int32Value(id);
                //pvc.Add(pvId);

                GeometryValue gv = new GeometryValue(m_Factory.GetFgf(g));
                PropertyValue pvGeom = new PropertyValue();
                pvGeom.SetName("Geometry");
                pvGeom.Value = gv;
                pvc.Add(pvGeom);

                try
                {
                    IFeatureReader reader = cmd.Execute();
                    reader.Dispose();
                    m_NumOk++;
                }

                catch
                {
                    m_NumFail++;
                }
            }
        }
Beispiel #12
0
        /// <summary>
        /// Gets the values.
        /// </summary>
        /// <returns></returns>
        public Dictionary <string, ValueExpression> GetValues()
        {
            Dictionary <string, ValueExpression> values = new Dictionary <string, ValueExpression>();

            foreach (DataGridViewRow row in grdProperties.Rows)
            {
                bool enabled = Convert.ToBoolean(row.Cells[0].Value);
                bool setNull = Convert.ToBoolean(row.Cells[1].Value);
                if (enabled)
                {
                    string             name    = row.Cells[2].Value.ToString();
                    PropertyDefinition propDef = row.Cells[2].Tag as PropertyDefinition;
                    if (setNull)
                    {
                        LiteralValue expr = null;
                        if (propDef.PropertyType == PropertyType.PropertyType_DataProperty)
                        {
                            DataPropertyDefinition dp = propDef as DataPropertyDefinition;
                            switch (dp.DataType)
                            {
                            case DataType.DataType_BLOB:
                                expr = new BLOBValue();
                                break;

                            case DataType.DataType_Boolean:
                                expr = new BooleanValue();
                                break;

                            case DataType.DataType_Byte:
                                expr = new ByteValue();
                                break;

                            case DataType.DataType_CLOB:
                                expr = new CLOBValue();
                                break;

                            case DataType.DataType_DateTime:
                                expr = new DateTimeValue();
                                break;

                            case DataType.DataType_Decimal:
                                expr = new DecimalValue();
                                break;

                            case DataType.DataType_Double:
                                expr = new DoubleValue();
                                break;

                            case DataType.DataType_Int16:
                                expr = new Int16Value();
                                break;

                            case DataType.DataType_Int32:
                                expr = new Int32Value();
                                break;

                            case DataType.DataType_Int64:
                                expr = new Int64Value();
                                break;

                            case DataType.DataType_Single:
                                expr = new SingleValue();
                                break;

                            case DataType.DataType_String:
                                expr = new StringValue();
                                break;
                            }
                        }
                        else if (propDef.PropertyType == PropertyType.PropertyType_GeometricProperty)
                        {
                            expr = new GeometryValue();
                        }

                        if (expr != null)
                        {
                            if (expr.LiteralValueType == LiteralValueType.LiteralValueType_Data)
                            {
                                (expr as DataValue).SetNull();
                            }
                            else
                            {
                                (expr as GeometryValue).SetNull();
                            }

                            values.Add(name, expr);
                        }
                    }
                    else
                    {
                        if (row.Cells[2].Value != null)
                        {
                            string str = row.Cells[3].Value.ToString();
                            if (!string.IsNullOrEmpty(str))
                            {
                                ValueExpression expr = null;
                                if (propDef.PropertyType == PropertyType.PropertyType_DataProperty)
                                {
                                    DataPropertyDefinition dp = propDef as DataPropertyDefinition;
                                    switch (dp.DataType)
                                    {
                                    case DataType.DataType_Boolean:
                                        expr = new BooleanValue(Convert.ToBoolean(str));
                                        break;

                                    case DataType.DataType_Byte:
                                        expr = new ByteValue(Convert.ToByte(str));
                                        break;

                                    case DataType.DataType_DateTime:
                                        expr = new DateTimeValue(Convert.ToDateTime(str));
                                        break;

                                    case DataType.DataType_Decimal:
                                        expr = new DecimalValue(Convert.ToDouble(str));
                                        break;

                                    case DataType.DataType_Double:
                                        expr = new DoubleValue(Convert.ToDouble(str));
                                        break;

                                    case DataType.DataType_Int16:
                                        expr = new Int16Value(Convert.ToInt16(str));
                                        break;

                                    case DataType.DataType_Int32:
                                        expr = new Int32Value(Convert.ToInt32(str));
                                        break;

                                    case DataType.DataType_Int64:
                                        expr = new Int64Value(Convert.ToInt64(str));
                                        break;

                                    case DataType.DataType_Single:
                                        expr = new SingleValue(Convert.ToSingle(str));
                                        break;

                                    case DataType.DataType_String:
                                        expr = new StringValue(str);
                                        break;

                                    default:
                                        throw new NotSupportedException("Unsupported data type: " + dp.DataType);
                                    }
                                }
                                else if (propDef.PropertyType == PropertyType.PropertyType_GeometricProperty)
                                {
                                    FdoGeometryFactory           fact = FdoGeometryFactory.Instance;
                                    OSGeo.FDO.Geometry.IGeometry geom = fact.CreateGeometry(str);
                                    byte[] fgf = fact.GetFgf(geom);
                                    expr = new GeometryValue(fgf);
                                    geom.Dispose();
                                }

                                if (expr != null)
                                {
                                    values.Add(name, expr);
                                }
                            }
                        }
                    }
                }
            }
            return(values);
        }
Beispiel #13
0
        public LocalNativeRecord(MgReader reader, FixedWKTReader mgReader, MgAgfReaderWriter agfRw, MgWktReaderWriter wktRw)
        {
            for (int i = 0; i < reader.GetPropertyCount(); i++)
            {
                string name = reader.GetPropertyName(i);

                _ordinalMap[i] = name;

                var pt = (PropertyValueType)reader.GetPropertyType(name);
                switch (pt)
                {
                    case PropertyValueType.Blob:
                        _values[name] = new BlobValue();
                        break;
                    case PropertyValueType.Boolean:
                        _values[name] = new BooleanValue();
                        break;
                    case PropertyValueType.Byte:
                        _values[name] = new ByteValue();
                        break;
                    case PropertyValueType.Clob:
                        _values[name] = new ClobValue();
                        break;
                    case PropertyValueType.DateTime:
                        _values[name] = new DateTimeValue();
                        break;
                    case PropertyValueType.Double:
                        _values[name] = new DoubleValue();
                        break;
                    case PropertyValueType.Feature:
                        _values[name] = new FeatureValue();
                        break;
                    case PropertyValueType.Geometry:
                        _values[name] = new GeometryValue();
                        break;
                    case PropertyValueType.Int16:
                        _values[name] = new Int16Value();
                        break;
                    case PropertyValueType.Int32:
                        _values[name] = new Int32Value();
                        break;
                    case PropertyValueType.Int64:
                        _values[name] = new Int64Value();
                        break;
                    case PropertyValueType.Raster:
                        _values[name] = new RasterValue();
                        break;
                    case PropertyValueType.Single:
                        _values[name] = new SingleValue();
                        break;
                    case PropertyValueType.String:
                        _values[name] = new StringValue();
                        break;
                }
            }

            for (int i = 0; i < reader.GetPropertyCount(); i++)
            {
                string name = _ordinalMap[i];
                GetByteReaderMethod getblob = () => { return reader.GetBLOB(name); };
                GetByteReaderMethod getclob = () => { return reader.GetCLOB(name); };
                GetByteReaderMethod getgeom = () => { return reader.GetGeometry(name); };
                if (!reader.IsNull(name))
                {
                    var pt = (PropertyValueType)reader.GetPropertyType(name);
                    switch (pt)
                    {
                        case PropertyValueType.Blob:
                            ((BlobValue)_values[name]).Value = Utility.StreamAsArray(new MgReadOnlyStream(getblob));
                            break;
                        case PropertyValueType.Boolean:
                            ((BooleanValue)_values[name]).Value = reader.GetBoolean(name);
                            break;
                        case PropertyValueType.Byte:
                            ((ByteValue)_values[name]).Value = reader.GetByte(name);
                            break;
                        case PropertyValueType.Clob:
                            byte [] b = Utility.StreamAsArray(new MgReadOnlyStream(getclob));
                            ((ClobValue)_values[name]).Value = Encoding.UTF8.GetChars(b);
                            break;
                        case PropertyValueType.DateTime:
                            ((DateTimeValue)_values[name]).Value = Utility.ConvertMgDateTime(reader.GetDateTime(name));
                            break;
                        case PropertyValueType.Double:
                            ((DoubleValue)_values[name]).Value = reader.GetDouble(name);
                            break;
                        //case PropertyValueType.Feature:
                        case PropertyValueType.Geometry:
                            try
                            {
                                //TODO: See if SWIG issues come into play here
                                var geom = agfRw.Read(reader.GetGeometry(name));
                                var wkt = wktRw.Write(geom);
                                ((GeometryValue)_values[name]).Value = mgReader.Read(wkt);
                            }
                            catch //Invalid geometry fail!
                            {
                                ((GeometryValue)_values[name]).SetNull();
                            }
                            break;
                        case PropertyValueType.Int16:
                            ((Int16Value)_values[name]).Value = reader.GetInt16(name);
                            break;
                        case PropertyValueType.Int32:
                            ((Int32Value)_values[name]).Value = reader.GetInt32(name);
                            break;
                        case PropertyValueType.Int64:
                            ((Int64Value)_values[name]).Value = reader.GetInt64(name);
                            break;
                        case PropertyValueType.Single:
                            ((SingleValue)_values[name]).Value = reader.GetSingle(name);
                            break;
                        case PropertyValueType.String:
                            ((StringValue)_values[name]).Value = reader.GetString(name);
                            break;
                    }
                }
            }
        }