public static FSharpValueOption <T> ExecuteQuerySingleVoption <T>(SqlConnection?existingConn, string?connStr, Action <SqlConnection> configureNewConn, Action <SqlCommand> configureCmd, Action <SqlDataReader> initOrdinals, Func <SqlDataReader, T> getItem) { if (existingConn is not null) { using var cmd = existingConn.CreateCommand(); configureCmd(cmd); using var reader = cmd.ExecuteReader(CommandBehavior.SingleResult | CommandBehavior.SingleRow); if (reader.Read()) { initOrdinals(reader); return(FSharpValueOption <T> .Some(getItem(reader))); } return(FSharpValueOption <T> .None); } else if (connStr is not null) { using var conn = new SqlConnection(connStr); configureNewConn(conn); conn.Open(); using var cmd = conn.CreateCommand(); configureCmd(cmd); using var reader = cmd.ExecuteReader(CommandBehavior.SingleResult | CommandBehavior.SingleRow); if (reader.Read()) { initOrdinals(reader); return(FSharpValueOption <T> .Some(getItem(reader))); } return(FSharpValueOption <T> .None); } else { throw new Exception($"{nameof(existingConn)} and {nameof(connStr)} may not both be null"); } }
public IViewBuilder ContentMultiple(string property, IEnumerable <Types.IView> content) { var getter = FSharpValueOption <FSharpFunc <TView, object> > .Some(FuncConvert.FromFunc <TView, object>(control => control.Children)); var setter = FSharpValueOption <FSharpFunc <Tuple <TView, object>, Unit> > .None; var list = Microsoft.FSharp.Collections.ListModule.OfSeq(content); Attrs.Add(Avalonia.FuncUI.Builder.AttrBuilder <TView> .CreateContentMultiple(property, getter, setter, list)); return(this); }
public FSharpValueOption <T> Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options) { if (reader.TryReadNil()) { return(FSharpValueOption <T> .None); } IFormatterResolver resolver = options.Resolver; options.Security.DepthStep(ref reader); T value = resolver.GetFormatterWithVerify <T>().Deserialize(ref reader, options);; reader.Depth--; return(FSharpValueOption <T> .Some(value)); }
public IViewBuilder Property <TValue>(string property, TValue value, Func <TView, TValue> getter, Action <TView, TValue> setter, Func <TValue, TValue, bool> comparer) { var cmp = comparer == null ? FSharpValueOption <FSharpFunc <Tuple <object, object>, bool> > .None : FSharpValueOption <FSharpFunc <Tuple <object, object>, bool> > .Some(FuncConvert.FromFunc <Tuple <object, object>, bool>(t => comparer((TValue)t.Item1, (TValue)t.Item2))); var get = getter == null ? FSharpValueOption <FSharpFunc <TView, TValue> > .None : FSharpValueOption <FSharpFunc <TView, TValue> > .Some(FuncConvert.FromFunc(getter)); var set = setter == null ? FSharpValueOption <FSharpFunc <Tuple <TView, TValue>, Unit> > .None : FSharpValueOption <FSharpFunc <Tuple <TView, TValue>, Unit> > .Some(FuncConvert.FromAction <Tuple <TView, TValue> >(tup => setter(tup.Item1, tup.Item2))); Attrs.Add(Avalonia.FuncUI.Builder.AttrBuilder <TView> .CreateProperty(property, value, get, set, cmp)); return(this); }
public static async Task <FSharpValueOption <T> > ExecuteQuerySingleAsyncVoption <T>(SqlConnection?existingConn, SqlTransaction?tran, string?connStr, Action <SqlConnection> configureNewConn, Action <SqlCommand> configureCmd, Action <SqlDataReader> initOrdinals, Func <SqlDataReader, T> getItem, IEnumerable <TempTableData> tempTableData, CancellationToken ct) { if (existingConn is not null) { await LoadTempTablesAsync(existingConn, tempTableData, tran, ct); await using var cmd = existingConn.CreateCommand(); ConfigureCommand(cmd, tran, configureCmd); await using var reader = await cmd.ExecuteReaderAsync(CommandBehavior.SingleResult | CommandBehavior.SingleRow, ct).ConfigureAwait(false); if (!await reader.ReadAsync(ct).ConfigureAwait(false)) { return(FSharpValueOption <T> .None); } initOrdinals(reader); return(FSharpValueOption <T> .Some(getItem(reader))); } // ReSharper disable once InvertIf if (connStr is not null) { await using var conn = new SqlConnection(connStr); configureNewConn(conn); await conn.OpenAsync(ct).ConfigureAwait(false); await LoadTempTablesAsync(conn, tempTableData, tran, ct); await using var cmd = conn.CreateCommand(); configureCmd(cmd); await using var reader = await cmd.ExecuteReaderAsync(CommandBehavior.SingleResult | CommandBehavior.SingleRow, ct).ConfigureAwait(false); if (!await reader.ReadAsync(ct).ConfigureAwait(false)) { return(FSharpValueOption <T> .None); } initOrdinals(reader); return(FSharpValueOption <T> .Some(getItem(reader))); } throw new Exception($"{nameof(existingConn)} and {nameof(connStr)} may not both be null"); }
public static async Task <FSharpValueOption <T> > ExecuteQuerySingleAsyncVoption <T>(SqlConnection?existingConn, string?connStr, Action <SqlConnection> configureNewConn, Action <SqlCommand> configureCmd, Action <SqlDataReader> initOrdinals, Func <SqlDataReader, T> getItem, CancellationToken ct) { if (existingConn is not null) { using var cmd = existingConn.CreateCommand(); configureCmd(cmd); using var reader = await cmd.ExecuteReaderAsync(CommandBehavior.SingleResult | CommandBehavior.SingleRow, ct).ConfigureAwait(false); if (await reader.ReadAsync(ct).ConfigureAwait(false)) { initOrdinals(reader); return(FSharpValueOption <T> .Some(getItem(reader))); } return(FSharpValueOption <T> .None); } else if (connStr is not null) { using var conn = new SqlConnection(connStr); configureNewConn(conn); await conn.OpenAsync(ct).ConfigureAwait(false); using var cmd = conn.CreateCommand(); configureCmd(cmd); using var reader = await cmd.ExecuteReaderAsync(CommandBehavior.SingleResult | CommandBehavior.SingleRow, ct).ConfigureAwait(false); if (await reader.ReadAsync(ct).ConfigureAwait(false)) { initOrdinals(reader); return(FSharpValueOption <T> .Some(getItem(reader))); } return(FSharpValueOption <T> .None); } else { throw new Exception($"{nameof(existingConn)} and {nameof(connStr)} may not both be null"); } }
public static FSharpValueOption <T> ExecuteQuerySingleVoption <T>(SqlConnection?existingConn, SqlTransaction?tran, string?connStr, Action <SqlConnection> configureNewConn, Action <SqlCommand> configureCmd, Action <SqlDataReader> initOrdinals, Func <SqlDataReader, T> getItem, IEnumerable <TempTableData> tempTableData) { if (existingConn is not null) { LoadTempTables(existingConn, tempTableData, tran); using var cmd = existingConn.CreateCommand(); ConfigureCommand(cmd, tran, configureCmd); using var reader = cmd.ExecuteReader(CommandBehavior.SingleResult | CommandBehavior.SingleRow); if (!reader.Read()) { return(FSharpValueOption <T> .None); } initOrdinals(reader); return(FSharpValueOption <T> .Some(getItem(reader))); } // ReSharper disable once InvertIf if (connStr is not null) { using var conn = new SqlConnection(connStr); configureNewConn(conn); conn.Open(); LoadTempTables(conn, tempTableData, tran); using var cmd = conn.CreateCommand(); configureCmd(cmd); using var reader = cmd.ExecuteReader(CommandBehavior.SingleResult | CommandBehavior.SingleRow); if (!reader.Read()) { return(FSharpValueOption <T> .None); } initOrdinals(reader); return(FSharpValueOption <T> .Some(getItem(reader))); } throw new Exception($"{nameof(existingConn)} and {nameof(connStr)} may not both be null"); }
public IViewBuilder Property <TValue>(AvaloniaProperty property, TValue value, Func <TValue, TValue, bool> comparer) { Attrs.Add(Avalonia.FuncUI.Builder.AttrBuilder <TView> .CreateProperty(property, value, FSharpValueOption <FSharpFunc <Tuple <object, object>, bool> > .Some(FuncConvert.FromFunc <Tuple <object, object>, bool>(t => comparer((TValue)t.Item1, (TValue)t.Item2))))); return(this); }