|
|
|
@ -1,221 +1,164 @@
|
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Data.Common;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Diagnostics.CodeAnalysis;
|
|
|
|
|
using System.Text.Json.Nodes;
|
|
|
|
|
|
|
|
|
|
namespace Connected.ServiceModel.Client.Data;
|
|
|
|
|
internal sealed class TableDataReader : DbDataReader
|
|
|
|
|
internal sealed class TableDataReader : IDataReader
|
|
|
|
|
{
|
|
|
|
|
public TableDataReader(JsonArray items)
|
|
|
|
|
{
|
|
|
|
|
Items = items;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override object this[int ordinal] => throw new NotImplementedException();
|
|
|
|
|
public object this[int i] => throw new NotImplementedException();
|
|
|
|
|
|
|
|
|
|
public override object this[string name] => throw new NotImplementedException();
|
|
|
|
|
public object this[string name] => throw new NotImplementedException();
|
|
|
|
|
|
|
|
|
|
private JsonArray Items { get; }
|
|
|
|
|
private int Index { get; set; } = -1;
|
|
|
|
|
private JsonObject? Current => Index < 0 ? null : Items[Index] as JsonObject;
|
|
|
|
|
public override int Depth => 1;
|
|
|
|
|
public override int FieldCount => Current is null ? 0 : Current.Count;
|
|
|
|
|
public int Depth => throw new NotImplementedException();
|
|
|
|
|
|
|
|
|
|
public override bool HasRows => Items.Any();
|
|
|
|
|
public bool IsClosed => throw new NotImplementedException();
|
|
|
|
|
|
|
|
|
|
public override bool IsClosed => false;
|
|
|
|
|
public int RecordsAffected => throw new NotImplementedException();
|
|
|
|
|
|
|
|
|
|
public override int RecordsAffected => Items.Count;
|
|
|
|
|
public int FieldCount => throw new NotImplementedException();
|
|
|
|
|
|
|
|
|
|
public override bool GetBoolean(int ordinal)
|
|
|
|
|
{
|
|
|
|
|
return GetValue<bool>(ordinal);
|
|
|
|
|
}
|
|
|
|
|
public JsonArray Items { get; }
|
|
|
|
|
|
|
|
|
|
public override byte GetByte(int ordinal)
|
|
|
|
|
public void Close()
|
|
|
|
|
{
|
|
|
|
|
return GetValue<byte>(ordinal);
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override long GetBytes(int ordinal, long dataOffset, byte[]? buffer, int bufferOffset, int length)
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
var value = GetValue<string>(ordinal);
|
|
|
|
|
var bytes = Convert.FromBase64String(value);
|
|
|
|
|
|
|
|
|
|
buffer ??= new byte[bufferOffset + length];
|
|
|
|
|
|
|
|
|
|
for (var i = 0; i < length; i++)
|
|
|
|
|
buffer[bufferOffset + i] = bytes[dataOffset + i];
|
|
|
|
|
|
|
|
|
|
return length;
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override char GetChar(int ordinal)
|
|
|
|
|
public bool GetBoolean(int i)
|
|
|
|
|
{
|
|
|
|
|
return GetValue<char>(ordinal);
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override long GetChars(int ordinal, long dataOffset, char[]? buffer, int bufferOffset, int length)
|
|
|
|
|
public byte GetByte(int i)
|
|
|
|
|
{
|
|
|
|
|
var value = GetValue<string>(ordinal);
|
|
|
|
|
var bytes = Convert.FromBase64String(value);
|
|
|
|
|
|
|
|
|
|
buffer ??= new char[bufferOffset + length];
|
|
|
|
|
|
|
|
|
|
for (var i = 0; i < length; i++)
|
|
|
|
|
buffer[bufferOffset + i] = (char)bytes[dataOffset + i];
|
|
|
|
|
|
|
|
|
|
return length;
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string GetDataTypeName(int ordinal)
|
|
|
|
|
public long GetBytes(int i, long fieldOffset, byte[]? buffer, int bufferoffset, int length)
|
|
|
|
|
{
|
|
|
|
|
/*
|
|
|
|
|
* TODO: resolve appropriate type
|
|
|
|
|
*/
|
|
|
|
|
return typeof(string).Name;
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override DateTime GetDateTime(int ordinal)
|
|
|
|
|
public char GetChar(int i)
|
|
|
|
|
{
|
|
|
|
|
return GetValue<DateTime>(ordinal);
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override decimal GetDecimal(int ordinal)
|
|
|
|
|
public long GetChars(int i, long fieldoffset, char[]? buffer, int bufferoffset, int length)
|
|
|
|
|
{
|
|
|
|
|
return GetValue<decimal>(ordinal);
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override double GetDouble(int ordinal)
|
|
|
|
|
public IDataReader GetData(int i)
|
|
|
|
|
{
|
|
|
|
|
return GetValue<double>(ordinal);
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override IEnumerator GetEnumerator()
|
|
|
|
|
public string GetDataTypeName(int i)
|
|
|
|
|
{
|
|
|
|
|
return Items.GetEnumerator();
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.PublicProperties)]
|
|
|
|
|
public override Type GetFieldType(int ordinal)
|
|
|
|
|
public DateTime GetDateTime(int i)
|
|
|
|
|
{
|
|
|
|
|
/*
|
|
|
|
|
* TODO: resolve appropriate type
|
|
|
|
|
*/
|
|
|
|
|
return typeof(string);
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override float GetFloat(int ordinal)
|
|
|
|
|
public decimal GetDecimal(int i)
|
|
|
|
|
{
|
|
|
|
|
return GetValue<float>(ordinal);
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override Guid GetGuid(int ordinal)
|
|
|
|
|
public double GetDouble(int i)
|
|
|
|
|
{
|
|
|
|
|
return GetValue<Guid>(ordinal);
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override short GetInt16(int ordinal)
|
|
|
|
|
[return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.PublicProperties)]
|
|
|
|
|
public Type GetFieldType(int i)
|
|
|
|
|
{
|
|
|
|
|
return GetValue<short>(ordinal);
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override int GetInt32(int ordinal)
|
|
|
|
|
public float GetFloat(int i)
|
|
|
|
|
{
|
|
|
|
|
return GetValue<int>(ordinal);
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override long GetInt64(int ordinal)
|
|
|
|
|
public Guid GetGuid(int i)
|
|
|
|
|
{
|
|
|
|
|
return GetValue<long>(ordinal);
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string GetName(int ordinal)
|
|
|
|
|
public short GetInt16(int i)
|
|
|
|
|
{
|
|
|
|
|
if (Current is null)
|
|
|
|
|
throw new NullReferenceException();
|
|
|
|
|
|
|
|
|
|
if (Current.ElementAt(ordinal).Key is string key)
|
|
|
|
|
return key;
|
|
|
|
|
|
|
|
|
|
throw new NullReferenceException();
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override int GetOrdinal(string name)
|
|
|
|
|
{
|
|
|
|
|
if (Current is null)
|
|
|
|
|
throw new NullReferenceException();
|
|
|
|
|
|
|
|
|
|
for (var i = 0; i < Current.Count; i++)
|
|
|
|
|
public int GetInt32(int i)
|
|
|
|
|
{
|
|
|
|
|
if (string.Equals(Current.ElementAt(i).Key, name, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
return i;
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string GetString(int ordinal)
|
|
|
|
|
public long GetInt64(int i)
|
|
|
|
|
{
|
|
|
|
|
return GetValue<string>(ordinal);
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override object GetValue(int ordinal)
|
|
|
|
|
public string GetName(int i)
|
|
|
|
|
{
|
|
|
|
|
return GetValue<object>(ordinal);
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override int GetValues(object[] values)
|
|
|
|
|
{
|
|
|
|
|
if (Current is null)
|
|
|
|
|
throw new NullReferenceException();
|
|
|
|
|
|
|
|
|
|
for (var i = 0; i < Current.Count; i++)
|
|
|
|
|
public int GetOrdinal(string name)
|
|
|
|
|
{
|
|
|
|
|
var value = Current.ElementAt(i);
|
|
|
|
|
|
|
|
|
|
if (value.Value is not null)
|
|
|
|
|
values[i] = value.Value.AsValue().GetValue<object>();
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Current.Count;
|
|
|
|
|
public DataTable? GetSchemaTable()
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override bool IsDBNull(int ordinal)
|
|
|
|
|
public string GetString(int i)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override bool NextResult()
|
|
|
|
|
public object GetValue(int i)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override bool Read()
|
|
|
|
|
{
|
|
|
|
|
if (Items.Count >= Index + 1)
|
|
|
|
|
public int GetValues(object[] values)
|
|
|
|
|
{
|
|
|
|
|
Index++;
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
public bool IsDBNull(int i)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private T GetValue<T>(int ordinal)
|
|
|
|
|
public bool NextResult()
|
|
|
|
|
{
|
|
|
|
|
return GetCurrentValue(ordinal).GetValue<T>();
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private JsonValue GetCurrentValue(int ordinal)
|
|
|
|
|
public bool Read()
|
|
|
|
|
{
|
|
|
|
|
if (Current is null)
|
|
|
|
|
throw new NullReferenceException();
|
|
|
|
|
|
|
|
|
|
if (Current.ElementAt(ordinal).Value is not JsonValue value)
|
|
|
|
|
throw new NullReferenceException();
|
|
|
|
|
//var items = AsyncUtils.RunSync(() => Service.Query(CommandText));
|
|
|
|
|
|
|
|
|
|
return value;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|