Exemplo n.º 1
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);
                }
            }
        }
Exemplo n.º 2
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);
                }
            }
        }
Exemplo n.º 3
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;
        }
Exemplo n.º 4
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);
        }