Beispiel #1
0
        internal static void Populate(MgPropertyCollection props, IMutableRecord record)
        {
            for (int i = 0; i < record.FieldCount; i++)
            {
                var    pt   = record.GetPropertyType(i);
                string name = record.GetName(i);
                if (record.IsNull(i))
                {
                    switch (pt)
                    {
                    case PropertyValueType.Blob:
                    {
                        var propVal = new MgBlobProperty(name, null);
                        propVal.SetNull(true);
                        props.Add(propVal);
                    }
                    break;

                    case PropertyValueType.Boolean:
                    {
                        var propVal = new MgBooleanProperty(name, false);
                        propVal.SetNull(true);
                        props.Add(propVal);
                    }
                    break;

                    case PropertyValueType.Byte:
                    {
                        var propVal = new MgByteProperty(name, 0);
                        propVal.SetNull(true);
                        props.Add(propVal);
                    }
                    break;

                    case PropertyValueType.Clob:
                    {
                        var propVal = new MgClobProperty(name, null);
                        propVal.SetNull(true);
                        props.Add(propVal);
                    }
                    break;

                    case PropertyValueType.DateTime:
                    {
                        var propVal = new MgDateTimeProperty(name, null);
                        propVal.SetNull(true);
                        props.Add(propVal);
                    }
                    break;

                    case PropertyValueType.Double:
                    {
                        var propVal = new MgDoubleProperty(name, 0.0);
                        propVal.SetNull(true);
                        props.Add(propVal);
                    }
                    break;

                    case PropertyValueType.Geometry:
                    {
                        var propVal = new MgGeometryProperty(name, null);
                        propVal.SetNull(true);
                        props.Add(propVal);
                    }
                    break;

                    case PropertyValueType.Int16:
                    {
                        var propVal = new MgInt16Property(name, 0);
                        propVal.SetNull(true);
                        props.Add(propVal);
                    }
                    break;

                    case PropertyValueType.Int32:
                    {
                        var propVal = new MgInt32Property(name, 0);
                        propVal.SetNull(true);
                        props.Add(propVal);
                    }
                    break;

                    case PropertyValueType.Int64:
                    {
                        var propVal = new MgInt64Property(name, 0L);
                        propVal.SetNull(true);
                        props.Add(propVal);
                    }
                    break;

                    case PropertyValueType.Single:
                    {
                        var propVal = new MgSingleProperty(name, 0.0f);
                        propVal.SetNull(true);
                        props.Add(propVal);
                    }
                    break;

                    case PropertyValueType.String:
                    {
                        var propVal = new MgStringProperty(name, "");
                        propVal.SetNull(true);
                        props.Add(propVal);
                    }
                    break;

                    default:
                        throw new NotSupportedException();
                    }
                }
                else
                {
                    switch (pt)
                    {
                    case PropertyValueType.Blob:
                    {
                        var bytes = record.GetBlob(i);
                        var br    = new MgByteSource(bytes, bytes.Length);
                        var bv    = new MgBlobProperty(name, br.GetReader());
                        props.Add(bv);
                    }
                    break;

                    case PropertyValueType.Boolean:
                    {
                        props.Add(new MgBooleanProperty(name, record.GetBoolean(i)));
                    }
                    break;

                    case PropertyValueType.Byte:
                    {
                        props.Add(new MgByteProperty(name, record.GetByte(i)));
                    }
                    break;

                    case PropertyValueType.Clob:
                    {
                        var bytes = record.GetBlob(i);
                        var br    = new MgByteSource(bytes, bytes.Length);
                        var bv    = new MgClobProperty(name, br.GetReader());
                        props.Add(bv);
                    }
                    break;

                    case PropertyValueType.DateTime:
                    {
                        var dt  = record.GetDateTime(i);
                        var mdt = new MgDateTime((short)dt.Year, (short)dt.Month, (short)dt.Day, (short)dt.Hour, (short)dt.Minute, (short)dt.Second, dt.Millisecond * 1000);
                        props.Add(new MgDateTimeProperty(name, mdt));
                    }
                    break;

                    case PropertyValueType.Double:
                    {
                        props.Add(new MgDoubleProperty(name, record.GetDouble(i)));
                    }
                    break;

                    case PropertyValueType.Geometry:
                    {
                        MgByteReader agf = GeomConverter.GetAgf(record.GetGeometry(i));
                        props.Add(new MgGeometryProperty(name, agf));
                    }
                    break;

                    case PropertyValueType.Int16:
                    {
                        props.Add(new MgInt16Property(name, record.GetInt16(i)));
                    }
                    break;

                    case PropertyValueType.Int32:
                    {
                        props.Add(new MgInt32Property(name, record.GetInt32(i)));
                    }
                    break;

                    case PropertyValueType.Int64:
                    {
                        props.Add(new MgInt64Property(name, record.GetInt64(i)));
                    }
                    break;

                    case PropertyValueType.Single:
                    {
                        props.Add(new MgSingleProperty(name, record.GetSingle(i)));
                    }
                    break;

                    case PropertyValueType.String:
                    {
                        props.Add(new MgStringProperty(name, record.GetString(i)));
                    }
                    break;

                    default:
                        throw new NotSupportedException();
                    }
                }
            }
        }
Beispiel #2
0
        internal static void Update(MgPropertyCollection props, IRecord record)
        {
            if (props.Count != record.FieldCount)
            {
                throw new InvalidOperationException("Number of values to update does not match. Ensure the MgPropertyCollection was initialized first with PropertyUtil.Populate() first and that the input IRecord comes from the same source used to initialize this MgPropertyCollection"); //LOCALIZEME
            }
            //Flip the null bit first
            for (int i = 0; i < props.Count; i++)
            {
                var p  = props.GetItem(i);
                var np = p as MgNullableProperty;
                if (np != null)
                {
                    np.SetNull(true);
                }

                string name = p.Name;
                if (!record.IsNull(name))
                {
                    switch (p.PropertyType)
                    {
                    case MgPropertyType.Blob:
                    {
                        var bytes = record.GetBlob(name);
                        var bs    = new MgByteSource(bytes, bytes.Length);
                        ((MgBlobProperty)p).SetValue(bs.GetReader());
                    }
                    break;

                    case MgPropertyType.Boolean:
                    {
                        ((MgBooleanProperty)p).SetValue(record.GetBoolean(name));
                    }
                    break;

                    case MgPropertyType.Byte:
                    {
                        ((MgByteProperty)p).SetValue(record.GetByte(name));
                    }
                    break;

                    case MgPropertyType.Clob:
                    {
                        var bytes = record.GetBlob(name);
                        var bs    = new MgByteSource(bytes, bytes.Length);
                        ((MgClobProperty)p).SetValue(bs.GetReader());
                    }
                    break;

                    case MgPropertyType.DateTime:
                    {
                        var dt  = record.GetDateTime(i);
                        var mdt = new MgDateTime((short)dt.Year, (short)dt.Month, (short)dt.Day, (short)dt.Hour, (short)dt.Minute, (short)dt.Second, dt.Millisecond * 1000);
                        ((MgDateTimeProperty)p).SetValue(mdt);
                    }
                    break;

                    case MgPropertyType.Decimal:
                    case MgPropertyType.Double:
                    {
                        ((MgDoubleProperty)p).SetValue(record.GetDouble(name));
                    }
                    break;

                    case MgPropertyType.Geometry:
                    {
                        var agf = GeomConverter.GetAgf(record.GetGeometry(name));
                        ((MgGeometryProperty)p).SetValue(agf);
                    }
                    break;

                    case MgPropertyType.Int16:
                    {
                        ((MgInt16Property)p).SetValue(record.GetInt16(name));
                    }
                    break;

                    case MgPropertyType.Int32:
                    {
                        ((MgInt32Property)p).SetValue(record.GetInt32(name));
                    }
                    break;

                    case MgPropertyType.Int64:
                    {
                        ((MgInt64Property)p).SetValue(record.GetInt64(name));
                    }
                    break;

                    case MgPropertyType.Single:
                    {
                        ((MgSingleProperty)p).SetValue(record.GetSingle(name));
                    }
                    break;

                    case MgPropertyType.String:
                    {
                        ((MgStringProperty)p).SetValue(record.GetString(name));
                    }
                    break;

                    default:
                        throw new NotSupportedException();
                    }
                }
            }
        }