|
|
@ -1,164 +1,221 @@
|
|
|
|
using System.Data;
|
|
|
|
using System.Collections;
|
|
|
|
|
|
|
|
using System.Data.Common;
|
|
|
|
using System.Diagnostics.CodeAnalysis;
|
|
|
|
using System.Diagnostics.CodeAnalysis;
|
|
|
|
using System.Text.Json.Nodes;
|
|
|
|
using System.Text.Json.Nodes;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Connected.ServiceModel.Client.Data;
|
|
|
|
namespace Connected.ServiceModel.Client.Data;
|
|
|
|
internal sealed class TableDataReader : IDataReader
|
|
|
|
internal sealed class TableDataReader : DbDataReader
|
|
|
|
{
|
|
|
|
{
|
|
|
|
public TableDataReader(JsonArray items)
|
|
|
|
public TableDataReader(JsonArray items)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Items = 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 override bool GetBoolean(int ordinal)
|
|
|
|
|
|
|
|
|
|
|
|
public void Close()
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
buffer ??= new byte[bufferOffset + length];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (var i = 0; i < length; i++)
|
|
|
|
|
|
|
|
buffer[bufferOffset + i] = bytes[dataOffset + i];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return length;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public byte GetByte(int i)
|
|
|
|
public override char GetChar(int ordinal)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
throw new NotImplementedException();
|
|
|
|
return GetValue<char>(ordinal);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public long GetBytes(int i, long fieldOffset, byte[]? buffer, int bufferoffset, int length)
|
|
|
|
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 char GetChar(int i)
|
|
|
|
public override string GetDataTypeName(int ordinal)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
throw new NotImplementedException();
|
|
|
|
/*
|
|
|
|
|
|
|
|
* TODO: resolve appropriate type
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
return typeof(string).Name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public long GetChars(int i, long fieldoffset, char[]? buffer, int bufferoffset, int length)
|
|
|
|
public override DateTime GetDateTime(int ordinal)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
throw new NotImplementedException();
|
|
|
|
return GetValue<DateTime>(ordinal);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public IDataReader GetData(int i)
|
|
|
|
public override decimal GetDecimal(int ordinal)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
throw new NotImplementedException();
|
|
|
|
return GetValue<decimal>(ordinal);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public string GetDataTypeName(int i)
|
|
|
|
public override double GetDouble(int ordinal)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
throw new NotImplementedException();
|
|
|
|
return GetValue<double>(ordinal);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public DateTime GetDateTime(int i)
|
|
|
|
public override IEnumerator GetEnumerator()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
throw new NotImplementedException();
|
|
|
|
return Items.GetEnumerator();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public decimal GetDecimal(int i)
|
|
|
|
[return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.PublicProperties)]
|
|
|
|
|
|
|
|
public override Type GetFieldType(int ordinal)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
throw new NotImplementedException();
|
|
|
|
/*
|
|
|
|
|
|
|
|
* TODO: resolve appropriate type
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
return typeof(string);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public double GetDouble(int i)
|
|
|
|
public override float GetFloat(int ordinal)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
throw new NotImplementedException();
|
|
|
|
return GetValue<float>(ordinal);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.PublicProperties)]
|
|
|
|
public override Guid GetGuid(int ordinal)
|
|
|
|
public Type GetFieldType(int i)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
throw new NotImplementedException();
|
|
|
|
return GetValue<Guid>(ordinal);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public float GetFloat(int i)
|
|
|
|
public override short GetInt16(int ordinal)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
throw new NotImplementedException();
|
|
|
|
return GetValue<short>(ordinal);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Guid GetGuid(int i)
|
|
|
|
public override int GetInt32(int ordinal)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
throw new NotImplementedException();
|
|
|
|
return GetValue<int>(ordinal);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public short GetInt16(int i)
|
|
|
|
public override long GetInt64(int ordinal)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
throw new NotImplementedException();
|
|
|
|
return GetValue<long>(ordinal);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public int GetInt32(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 long GetInt64(int i)
|
|
|
|
public override int GetOrdinal(string name)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
throw new NotImplementedException();
|
|
|
|
if (Current is null)
|
|
|
|
}
|
|
|
|
throw new NullReferenceException();
|
|
|
|
|
|
|
|
|
|
|
|
public string GetName(int i)
|
|
|
|
for (var i = 0; i < Current.Count; i++)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
throw new NotImplementedException();
|
|
|
|
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>();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public object GetValue(int i)
|
|
|
|
return Current.Count;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public bool NextResult()
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|