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