public override int SupportLevel(IDataHolder data, IBedValueReader holder) { if (holder.GetFieldType() == TypeStorage.ByteArray) { var img = ImageCellDataFrame.LoadImage(holder.GetByteArray()); if (img == null) { return(0); } img.Dispose(); return(10); } return(0); }
public static string GetStringValue(IBedValueReader holder) { var type = holder.GetFieldType(); if (type == TypeStorage.String) { return(holder.GetString()); } if (type == TypeStorage.ByteArray) { try { return(Encoding.UTF8.GetString(holder.GetByteArray())); } catch { } } return(""); }
public virtual string ReadHash(IBedValueReader reader, BedValueConvertor auxConv, BedValueHolder auxHolder) { switch (reader.GetFieldType()) { case TypeStorage.String: return(reader.GetString().ToLower()); case TypeStorage.ByteArray: { byte[] data = reader.GetByteArray(); if (data.Length == 32) { return(Encoding.UTF8.GetString(data)); } return(StringTool.EncodeHex(data).ToLower()); } } auxConv.ConvertValue(reader, TypeStorage.String, auxHolder); return(auxHolder.GetString()); }
public static void WriteField(IBedValueReader value, BinaryWriter fw) { var type = value.GetFieldType(); if (type == TypeStorage.Null) { fw.Write((byte)'\\'); fw.Write((byte)'N'); } else if (type == TypeStorage.ByteArray) { foreach (byte b in value.GetByteArray()) { var sb = new StringBuilder(); StringTool.EncodeOct(b, sb); fw.Write('\\'); fw.Write('\\'); fw.Write(Encoding.UTF8.GetBytes(sb.ToString())); } } else if (type.IsNumber()) { if (type.IsInteger()) { fw.Write(Encoding.UTF8.GetBytes(value.GetIntegerValue().ToString())); } else { fw.Write(Encoding.UTF8.GetBytes(value.GetRealValue().ToString(CultureInfo.InvariantCulture))); } } else { string s = String.Format(CultureInfo.InvariantCulture, "{0}", value.GetValue()); s = s.Replace("\\", "\\\\"); s = s.Replace("\t", "\\t"); s = s.Replace("\n", "\\n"); s = s.Replace("\r", "\\r"); fw.Write(Encoding.UTF8.GetBytes(s)); } }
public override int SupportLevel(IDataHolder data, IBedValueReader holder) { switch (holder.GetFieldType()) { case TypeStorage.String: return(3); case TypeStorage.ByteArray: try { Encoding.UTF8.GetString(holder.GetByteArray()); return(4); } catch { return(0); } default: return(1); } }
public static object BoxTypedValue(this IBedValueReader reader) { switch (reader.GetFieldType()) { case TypeStorage.Null: return(null); case TypeStorage.Boolean: return(reader.GetBoolean()); case TypeStorage.Byte: return(reader.GetByte()); case TypeStorage.Int16: return(reader.GetInt16()); case TypeStorage.Int32: return(reader.GetInt32()); case TypeStorage.Int64: return(reader.GetInt64()); case TypeStorage.SByte: return(reader.GetSByte()); case TypeStorage.UInt16: return(reader.GetUInt16()); case TypeStorage.UInt32: return(reader.GetUInt32()); case TypeStorage.UInt64: return(reader.GetUInt64()); case TypeStorage.Float: return(reader.GetFloat()); case TypeStorage.Double: return(reader.GetDouble()); case TypeStorage.Decimal: return(reader.GetDecimal()); case TypeStorage.DateTime: return(reader.GetDateTime()); case TypeStorage.DateTimeEx: return(reader.GetDateTimeEx()); case TypeStorage.DateEx: return(reader.GetDateEx()); case TypeStorage.TimeEx: return(reader.GetTimeEx()); case TypeStorage.ByteArray: return(reader.GetByteArray()); case TypeStorage.Guid: return(reader.GetGuid()); case TypeStorage.String: return(reader.GetString()); //case TypeStorage.Array: // return reader.GetArray(); } return(null); }
//public static void WriteTo(this IBedValueReader reader, BinaryWriter stream) //{ // switch (reader.GetFieldType()) // { // case TypeStorage.Null: // stream.Write((byte)TypeStorage.Null); // break; // case TypeStorage.Boolean: // stream.Write((byte)TypeStorage.Boolean); // stream.Write(reader.GetBoolean()); // break; // case TypeStorage.Byte: // stream.Write((byte)TypeStorage.Byte); // stream.Write(reader.GetByte()); // break; // case TypeStorage.Int16: // stream.Write((byte)TypeStorage.Int16); // stream.Write(reader.GetInt16()); // break; // case TypeStorage.Int32: // stream.Write((byte)TypeStorage.Int32); // stream.Write(reader.GetInt32()); // break; // case TypeStorage.Int64: // stream.Write((byte)TypeStorage.Int64); // stream.Write(reader.GetInt64()); // break; // case TypeStorage.Float: // stream.Write((byte)TypeStorage.Float); // stream.Write(reader.GetFloat()); // break; // case TypeStorage.Double: // stream.Write((byte)TypeStorage.Double); // stream.Write(reader.GetDouble()); // break; // case TypeStorage.Decimal: // stream.Write((byte)TypeStorage.Decimal); // stream.Write(reader.GetDecimal()); // break; // case TypeStorage.DateTime: // stream.Write((byte)TypeStorage.DateTime); // stream.Write(reader.GetDateTime().ToBinary()); // break; // case TypeStorage.DateTimeEx: // stream.Write((byte)TypeStorage.DateTime); // reader.GetDateTimeEx().WriteTo(stream); // break; // case TypeStorage.ByteArray: // { // byte[] val = reader.GetByteArray(); // stream.Write((byte)TypeStorage.ByteArray); // stream.Write7BitEncodedInt(val.Length); // stream.Write(val); // } // break; // case TypeStorage.Guid: // stream.Write((byte)TypeStorage.Guid); // stream.Write(reader.GetGuid().ToByteArray()); // break; // case TypeStorage.String: // stream.Write((byte)TypeStorage.String); // stream.Write(reader.GetString()); // break; // } //} public static void WriteTo(this IBedValueReader reader, IBedValueWriter writer) { switch (reader.GetFieldType()) { case TypeStorage.Null: writer.SetNull(); break; case TypeStorage.Boolean: writer.SetBoolean(reader.GetBoolean()); break; case TypeStorage.Byte: writer.SetByte(reader.GetByte()); break; case TypeStorage.Int16: writer.SetInt16(reader.GetInt16()); break; case TypeStorage.Int32: writer.SetInt32(reader.GetInt32()); break; case TypeStorage.Int64: writer.SetInt64(reader.GetInt64()); break; case TypeStorage.SByte: writer.SetSByte(reader.GetSByte()); break; case TypeStorage.UInt16: writer.SetUInt16(reader.GetUInt16()); break; case TypeStorage.UInt32: writer.SetUInt32(reader.GetUInt32()); break; case TypeStorage.UInt64: writer.SetUInt64(reader.GetUInt64()); break; case TypeStorage.Float: writer.SetFloat(reader.GetFloat()); break; case TypeStorage.Double: writer.SetDouble(reader.GetDouble()); break; case TypeStorage.Decimal: writer.SetDecimal(reader.GetDecimal()); break; case TypeStorage.DateTime: writer.SetDateTime(reader.GetDateTime()); break; case TypeStorage.DateTimeEx: writer.SetDateTimeEx(reader.GetDateTimeEx()); break; case TypeStorage.DateEx: writer.SetDateEx(reader.GetDateEx()); break; case TypeStorage.TimeEx: writer.SetTimeEx(reader.GetTimeEx()); break; case TypeStorage.ByteArray: writer.SetByteArray(reader.GetByteArray()); break; case TypeStorage.Guid: writer.SetGuid(reader.GetGuid()); break; case TypeStorage.String: writer.SetString(reader.GetString()); break; //case TypeStorage.Array: // writer.SetArray(reader.GetArray()); // break; } }
public static bool GetValueAsXml(IBedValueReader rec, ref string xtype, ref string xdata) { var type = rec.GetFieldType(); if (type == TypeStorage.Null) { return(false); } switch (type) { case TypeStorage.Boolean: xtype = "bool"; xdata = rec.GetBoolean() ? "1" : "0"; break; case TypeStorage.Byte: xtype = "byte"; xdata = rec.GetByte().ToString(CultureInfo.InvariantCulture); break; case TypeStorage.Int16: xtype = "i16"; xdata = rec.GetInt16().ToString(CultureInfo.InvariantCulture); break; case TypeStorage.Int32: xtype = "i32"; xdata = rec.GetInt32().ToString(CultureInfo.InvariantCulture); break; case TypeStorage.Int64: xtype = "i64"; xdata = rec.GetInt64().ToString(CultureInfo.InvariantCulture); break; case TypeStorage.SByte: xtype = "sbyte"; xdata = rec.GetSByte().ToString(CultureInfo.InvariantCulture); break; case TypeStorage.UInt16: xtype = "u16"; xdata = rec.GetUInt16().ToString(CultureInfo.InvariantCulture); break; case TypeStorage.UInt32: xtype = "u32"; xdata = rec.GetUInt32().ToString(CultureInfo.InvariantCulture); break; case TypeStorage.UInt64: xtype = "u64"; xdata = rec.GetUInt64().ToString(CultureInfo.InvariantCulture); break; case TypeStorage.DateTime: xtype = "datetime"; xdata = rec.GetDateTime().ToString("s", CultureInfo.InvariantCulture); break; case TypeStorage.DateTimeEx: xtype = "dtex"; xdata = rec.GetDateTimeEx().ToStringNormalized(); break; case TypeStorage.DateEx: xtype = "date"; xdata = rec.GetDateEx().ToStringNormalized(); break; case TypeStorage.TimeEx: xtype = "time"; xdata = rec.GetTimeEx().ToStringNormalized(); break; case TypeStorage.Decimal: xtype = "decimal"; xdata = rec.GetDecimal().ToString(CultureInfo.InvariantCulture); break; case TypeStorage.Float: xtype = "float"; xdata = rec.GetFloat().ToString(CultureInfo.InvariantCulture); break; case TypeStorage.Double: xtype = "double"; xdata = rec.GetDouble().ToString(CultureInfo.InvariantCulture); break; case TypeStorage.String: xtype = "str"; xdata = rec.GetString(); break; case TypeStorage.Guid: xtype = "guid"; xdata = rec.GetGuid().ToString(); break; case TypeStorage.ByteArray: { xtype = "blob"; byte[] data = rec.GetByteArray(); xdata = Convert.ToBase64String(data); } break; //case TypeStorage.Array: // { // xtype = "array"; // xdata = BedArray.ToString(rec.GetArray()); // } // break; } return(true); }