Compare commits

..

No commits in common. '309706a4bb170644380f614fea6a3c0b7cd30d65' and 'aa378613d69050c03b05bc4f9fda08a745a24b82' have entirely different histories.

@ -7,9 +7,9 @@ root = true
#### Core EditorConfig Options #### #### Core EditorConfig Options ####
# Indentation and spacing # Indentation and spacing
indent_size = 3 indent_size = 4
indent_style = tab indent_style = tab
tab_width = 3 tab_width = 4
# New line preferences # New line preferences
end_of_line = crlf end_of_line = crlf

@ -1,125 +1,61 @@
using System.Collections; using System.Data;
using System.Data.Common;
namespace Connected.ServiceModel.Client.Data; namespace Connected.ServiceModel.Client.Data;
internal sealed class DataParameterCollection : DbParameterCollection internal sealed class DataParameterCollection : List<IDbDataParameter>, IDataParameterCollection
{ {
private readonly object _syncRoot = new(); public object this[string parameterName]
public DataParameterCollection()
{ {
Items = new(); get
}
private List<DbParameter> Items { get; }
public override int Count => Items.Count;
public override object SyncRoot => _syncRoot;
public override int Add(object value)
{ {
if (value is not DbParameter parameter) foreach (var parameter in this)
throw new InvalidCastException(nameof(DbParameter));
Items.Add(parameter);
return Items.Count - 1;
}
public override void AddRange(Array values)
{ {
foreach (var item in values) if (string.Equals(parameter.ParameterName, parameterName, StringComparison.OrdinalIgnoreCase))
Add(item); return parameter;
} }
public override void Clear() throw new NullReferenceException(nameof(IDbDataParameter));
{
Items.Clear();
} }
set
public override bool Contains(object value)
{ {
return Items.Contains(value); if (value is not IDbDataParameter parameter)
} throw new InvalidCastException(nameof(IDbDataParameter));
public override bool Contains(string value) var idx = IndexOf(parameterName);
{
return Items.FirstOrDefault(f => string.Equals(f.ParameterName, value, StringComparison.OrdinalIgnoreCase)) is not null;
}
public override void CopyTo(Array array, int index) if (idx < 0)
{ throw new NullReferenceException(nameof(IDbDataParameter));
foreach (var item in array)
{
Insert(index, item);
index++;
}
}
public override IEnumerator GetEnumerator() this[idx] = parameter;
{
return Items.GetEnumerator();
} }
public override int IndexOf(object value)
{
if (value is not DbParameter parameter)
throw new InvalidCastException(nameof(DbParameter));
return Items.IndexOf(parameter);
} }
public override int IndexOf(string parameterName) public bool Contains(string parameterName)
{ {
if (Items.FirstOrDefault(f => string.Equals(f.ParameterName, parameterName, StringComparison.OrdinalIgnoreCase)) is DbParameter parameter) foreach (var parameter in this)
return Items.IndexOf(parameter);
return -1;
}
public override void Insert(int index, object value)
{
if (value is not DbParameter parameter)
throw new InvalidCastException(nameof(DbParameter));
Items.Insert(index, parameter);
}
public override void Remove(object value)
{ {
if (value is not DbParameter parameter) if (string.Equals(parameter.ParameterName, parameterName, StringComparison.OrdinalIgnoreCase))
throw new InvalidCastException(nameof(DbParameter)); return true;
Items.Remove(parameter);
} }
public override void RemoveAt(int index) return false;
{
Items.RemoveAt(index);
} }
public override void RemoveAt(string parameterName) public int IndexOf(string parameterName)
{ {
if (Items.FirstOrDefault(f => string.Equals(f.ParameterName, parameterName, StringComparison.OrdinalIgnoreCase)) is DbParameter parameter) for (var i = 0; i < Count; i++)
Items.Remove(parameter);
}
protected override DbParameter GetParameter(int index)
{ {
return Items[index]; var current = this[i];
}
protected override DbParameter GetParameter(string parameterName) if (string.Equals(current.ParameterName, parameterName, StringComparison.OrdinalIgnoreCase))
{ return i;
return Items.First(f => string.Equals(f.ParameterName, parameterName, StringComparison.OrdinalIgnoreCase));
} }
protected override void SetParameter(int index, DbParameter value) return -1;
{
Items[index] = value;
} }
protected override void SetParameter(string parameterName, DbParameter value) public void RemoveAt(string parameterName)
{ {
Items[IndexOf(parameterName)] = value; if (this[parameterName] is IDbDataParameter target)
Remove(target);
} }
} }

@ -1,5 +1,4 @@
using System.Data; using System.Data;
using System.Diagnostics.CodeAnalysis;
using Connected.ServiceModel.Client.Data.Remote; using Connected.ServiceModel.Client.Data.Remote;
namespace Connected.ServiceModel.Client.Data; namespace Connected.ServiceModel.Client.Data;
@ -19,7 +18,6 @@ internal sealed class TableConnection : IDbConnection
/// <summary> /// <summary>
/// The connection string (URL) used when performing the requests. /// The connection string (URL) used when performing the requests.
/// </summary> /// </summary>
[AllowNull]
public string ConnectionString { get; set; } public string ConnectionString { get; set; }
/// <summary> /// <summary>
/// The request timeout in seconds. /// The request timeout in seconds.

@ -1,96 +1,64 @@
using System.Data; using System.Data;
using System.Data.Common;
using System.Diagnostics.CodeAnalysis;
using System.Text;
using Connected.ServiceModel.Client.Data.Remote; using Connected.ServiceModel.Client.Data.Remote;
namespace Connected.ServiceModel.Client.Data; namespace Connected.ServiceModel.Client.Data;
internal sealed class TableDataCommand : DbCommand internal sealed class TableDataCommand : IDbCommand
{ {
public TableDataCommand(RemoteTableService tables) public TableDataCommand(RemoteTableService tables)
{ {
Parameters = new DataParameterCollection(); Parameters = new DataParameterCollection();
Tables = tables; Tables = tables;
} }
public string CommandText { get; set; }
public int CommandTimeout { get; set; }
public CommandType CommandType { get; set; }
public IDbConnection? Connection { get; set; }
public new DataParameterCollection Parameters { get; } public IDataParameterCollection Parameters { get; }
public RemoteTableService Tables { get; }
[AllowNull]
public override string CommandText { get; set; }
public override int CommandTimeout { get; set; } = 120;
public override CommandType CommandType { get; set; } = CommandType.Text;
protected override DbConnection? DbConnection { get; set; }
protected override DbParameterCollection DbParameterCollection => Parameters;
protected override DbTransaction? DbTransaction { get; set; }
public override bool DesignTimeVisible { get; set; }
public override UpdateRowSource UpdatedRowSource { get; set; }
protected override DbParameter CreateDbParameter() public IDbTransaction? Transaction { get; set; }
{ public UpdateRowSource UpdatedRowSource { get; set; }
return new TableDataParameter(); public RemoteTableService Tables { get; }
}
public override async Task<int> ExecuteNonQueryAsync(CancellationToken cancellationToken) public void Cancel()
{ {
await Tables.Update(ParseCommandText());
return 0;
} }
public override int ExecuteNonQuery() public IDbDataParameter CreateParameter()
{ {
AsyncUtils.RunSync(() => Tables.Update(ParseCommandText())); return new TableDataParameter();
return 0;
} }
protected override async Task<DbDataReader> ExecuteDbDataReaderAsync(CommandBehavior behavior, CancellationToken cancellationToken) public void Dispose()
{ {
return new TableDataReader(await Tables.Query(ParseCommandText()));
}
protected override DbDataReader ExecuteDbDataReader(CommandBehavior behavior)
{
return new TableDataReader(AsyncUtils.RunSync(() => Tables.Query(ParseCommandText())));
} }
private string ParseCommandText() public int ExecuteNonQuery()
{ {
var text = new StringBuilder(CommandText); AsyncUtils.RunSync(() => Tables.Update(CommandText));
foreach (IDbDataParameter parameter in Parameters) return 0;
text = text.Replace(parameter.ParameterName, ParseValue(parameter));
return text.ToString();
} }
private static string? ParseValue(IDbDataParameter parameter) public IDataReader ExecuteReader()
{ {
if (parameter.Value is null || parameter.Value == DBNull.Value) return new TableDataReader(AsyncUtils.RunSync(() => Tables.Query(CommandText)));
return "null";
return parameter.DbType switch
{
DbType.AnsiString or DbType.String or DbType.AnsiStringFixedLength or DbType.StringFixedLength or DbType.Xml => $"'{parameter.Value}'",
_ => parameter.Value.ToString(),
};
} }
public override void Cancel() public IDataReader ExecuteReader(CommandBehavior behavior)
{ {
return new TableDataReader(AsyncUtils.RunSync(() => Tables.Query(CommandText)));
} }
public override object? ExecuteScalar() public object? ExecuteScalar()
{ {
var reader = ExecuteReader(); throw new NotImplementedException();
if (reader.Read())
return reader[0];
return null;
} }
public override void Prepare() public void Prepare()
{ {
throw new NotImplementedException();
} }
} }

@ -1,8 +1,8 @@
using System.Data; using System.Data;
using System.Data.Common;
using Connected.Annotations; using Connected.Annotations;
using Connected.Data.Storage; using Connected.Data.Storage;
using Connected.ServiceModel.Client.Data.Remote; using Connected.ServiceModel.Client.Data.Remote;
using Microsoft.Data.SqlClient;
namespace Connected.ServiceModel.Client.Data; namespace Connected.ServiceModel.Client.Data;
@ -19,7 +19,7 @@ internal sealed class TableDataConnection : DatabaseConnection
{ {
if (cmd.Parameters.Count > 0) if (cmd.Parameters.Count > 0)
{ {
foreach (DbParameter i in cmd.Parameters) foreach (SqlParameter i in cmd.Parameters)
i.Value = DBNull.Value; i.Value = DBNull.Value;
return; return;
@ -30,7 +30,7 @@ internal sealed class TableDataConnection : DatabaseConnection
foreach (var i in command.Operation.Parameters) foreach (var i in command.Operation.Parameters)
{ {
cmd.Parameters.Add(new TableDataParameter cmd.Parameters.Add(new SqlParameter
{ {
ParameterName = i.Name, ParameterName = i.Name,
DbType = i.Type, DbType = i.Type,
@ -39,17 +39,17 @@ internal sealed class TableDataConnection : DatabaseConnection
} }
} }
protected override object? GetParameterValue(IDbCommand command, string parameterName) protected override object GetParameterValue(IDbCommand command, string parameterName)
{ {
if (command is TableDataCommand cmd) if (command is SqlCommand cmd)
return cmd.Parameters[parameterName].Value; return cmd.Parameters[parameterName].Value;
return null; return null;
} }
protected override void SetParameterValue(IDbCommand command, string parameterName, object? value) protected override void SetParameterValue(IDbCommand command, string parameterName, object value)
{ {
if (command is TableDataCommand cmd) if (command is SqlCommand cmd)
cmd.Parameters[parameterName].Value = value; cmd.Parameters[parameterName].Value = value;
} }

@ -1,20 +1,16 @@
using System.Data; using System.Data;
using System.Data.Common;
namespace Connected.ServiceModel.Client.Data; namespace Connected.ServiceModel.Client.Data;
internal class TableDataParameter : DbParameter internal class TableDataParameter : IDbDataParameter
{ {
public override DbType DbType { get; set; } public byte Precision { get; set; }
public override ParameterDirection Direction { get; set; } public byte Scale { get; set; }
public override bool IsNullable { get; set; } public int Size { get; set; }
public override string? ParameterName { get; set; } public DbType DbType { get; set; }
public override int Size { get; set; } public ParameterDirection Direction { get; set; }
public override string? SourceColumn { get; set; } public bool IsNullable { get; set; }
public override bool SourceColumnNullMapping { get; set; } public string ParameterName { get; set; }
public override object? Value { get; set; } public string SourceColumn { get; set; }
public DataRowVersion SourceVersion { get; set; }
public override void ResetDbType() public object? Value { get; set; }
{
}
} }

@ -1,221 +1,164 @@
using System.Collections; using System.Data;
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 : DbDataReader internal sealed class TableDataReader : IDataReader
{ {
public TableDataReader(JsonArray items) public TableDataReader(JsonArray items)
{ {
Items = 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; } public int Depth => throw new NotImplementedException();
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 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) public JsonArray Items { get; }
{
return GetValue<bool>(ordinal);
}
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); throw new NotImplementedException();
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 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); throw new NotImplementedException();
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 override string GetDataTypeName(int ordinal) public long GetBytes(int i, long fieldOffset, byte[]? buffer, int bufferoffset, int length)
{ {
/* throw new NotImplementedException();
* TODO: resolve appropriate type
*/
return typeof(string).Name;
} }
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 DateTime GetDateTime(int i)
public override Type GetFieldType(int ordinal)
{ {
/* throw new NotImplementedException();
* TODO: resolve appropriate type
*/
return typeof(string);
} }
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 NotImplementedException();
throw new NullReferenceException();
if (Current.ElementAt(ordinal).Key is string key)
return key;
throw new NullReferenceException();
} }
public override int GetOrdinal(string name) public int GetInt32(int i)
{
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)) throw new NotImplementedException();
return i;
} }
return -1; public long GetInt64(int i)
}
public override string GetString(int ordinal)
{ {
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) public int GetOrdinal(string name)
{
if (Current is null)
throw new NullReferenceException();
for (var i = 0; i < Current.Count; i++)
{ {
var value = Current.ElementAt(i); throw new NotImplementedException();
if (value.Value is not null)
values[i] = value.Value.AsValue().GetValue<object>();
} }
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() public int GetValues(object[] values)
{
if (Items.Count >= Index + 1)
{ {
Index++; throw new NotImplementedException();
return true;
} }
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) //var items = AsyncUtils.RunSync(() => Service.Query(CommandText));
throw new NullReferenceException();
if (Current.ElementAt(ordinal).Value is not JsonValue value)
throw new NullReferenceException();
return value; return false;
} }
} }

@ -67,7 +67,7 @@ internal sealed class TableReader<T> : TableCommand, IStorageReader<T>
public async Task<IDataReader> OpenReader() public async Task<IDataReader> OpenReader()
{ {
if (Connection is null) if (Connection is null)
throw new NullReferenceException(nameof(Connection)); return default;
return await Connection.OpenReader(this); return await Connection.OpenReader(this);
} }

@ -2,9 +2,9 @@
namespace Connected.ServiceModel.Client.Net; namespace Connected.ServiceModel.Client.Net;
internal sealed class SelectUrl : ServiceFunction<ConnectedServerUrlArgs, string?> internal sealed class SelectUrl : ServiceFunction<ConnectedServerUrlArgs, string>
{ {
private const string Root = "https://localhost:7069";//"https://connected.tompit.com"; private const string Root = "https://localhost:61599";//"https://connected.tompit.com";
protected override async Task<string?> OnInvoke() protected override async Task<string?> OnInvoke()
{ {
await Task.CompletedTask; await Task.CompletedTask;

Loading…
Cancel
Save