public static Task <Either <RfcErrorInfo, TResult> > CallFunction <TResult>(this IRfcContext context, string functionName, Func <Task <Either <RfcErrorInfo, IFunction> >, Task <Either <RfcErrorInfo, TResult> > > Output) { return(context.CreateFunction(functionName).Use( func => func .BindAsync(context.InvokeFunction).Map(i => func) .Apply(Output))); }
private static async Task <long> RunPerformanceTest02(IRfcContext context, int rows = 0) { var watch = Stopwatch.StartNew(); var cancelSource = new CancellationTokenSource(); cancelSource.CancelAfter(500); var result = await context.CallFunction("ZYANCO_PT_READ_2", func => SetRows(func, rows), func => func.MapTable("ET_DATA", s => from char40 in s.GetField <string>("FIELD_CHAR40") from char01 in s.GetField <string>("FIELD_CHAR01") from int04 in s.GetField <int>("FIELD_INT4") from str in s.GetField <string>("FIELD_STRING") select new TestData { Char01 = char01, Char40 = char40, Int04 = int04, String = str } ), cancelSource.Token).ToEither(); result.IfLeft(l => Console.WriteLine(l.Message)); watch.Stop(); return(watch.ElapsedMilliseconds); }
/// <summary> /// CallFunction without input or output. /// </summary> /// <param name="context">RFC context</param> /// <param name="functionName">ABAP function name</param> /// <param name="cancellationToken"></param> /// <returns>Unit</returns> public static EitherAsync <RfcErrorInfo, Unit> CallFunctionOneWay( this IRfcContext context, string functionName, CancellationToken cancellationToken = default) { return(context.CreateFunction(functionName).Use( func => func.Bind(f => context.InvokeFunction(f, cancellationToken)))); }
private static async Task RunIntegrationTests(IRfcContext context) { Console.WriteLine("*** BEGIN OF Integration Tests ***"); await RunIntegrationTest01(context); await RunIntegrationTest02(context); Console.WriteLine("*** END OF Integration Tests ***"); }
/// <summary> /// CallFunction with RfcErrorInfo lifted output. /// </summary> /// <typeparam name="TResult"></typeparam> /// <param name="context">RFC context</param> /// <param name="functionName">ABAP function name</param> /// <param name="Output">Output function lifted in either monad.</param> /// <param name="cancellationToken"></param> /// <returns>Result of output mapping function.</returns> public static EitherAsync <RfcErrorInfo, TResult> CallFunction <TResult>( this IRfcContext context, string functionName, Func <Either <RfcErrorInfo, IFunction>, Either <RfcErrorInfo, TResult> > Output, CancellationToken cancellationToken = default) { return(context.CreateFunction(functionName).Use( ef => ef.Bind(func => from _ in context.InvokeFunction(func, cancellationToken) from output in Output(Prelude.Right(func)).ToAsync() select output) )); }
public CompanyController(IRfcContext rfcContext) { _rfcContext = rfcContext; }
public static EitherAsync <RfcErrorInfo, IEnumerable <CompanyModel> > GetCompanies(this IRfcContext rfcContext) { return(rfcContext.CallFunction("BAPI_COMPANYCODE_GETLIST", Output: f => f .MapTable("COMPANYCODE_LIST", s => from code in s.GetField <string>("COMP_CODE") from name in s.GetField <string>("COMP_NAME") select new CompanyModel { Code = code, Name = name }))); }
/// <summary> /// Commits current transaction in ABAP backend and waits for the commit to be completed. /// This method accepts a <see cref="EitherAsync{RfcErrorInfo,R1}"/> with any right value and returns it after commit. /// </summary> /// <typeparam name="R1">Type of function result</typeparam> /// <param name="self"></param> /// <param name="context"></param> /// <returns>A <see cref="EitherAsync{RfcErrorInfo,R1}"/> with the Right value of argument self or the left value.</returns> public static EitherAsync <RfcErrorInfo, R1> CommitAndWait <R1>(this EitherAsync <RfcErrorInfo, R1> self, IRfcContext context) { return(self.Bind(res => context.CommitAndWait().Map(u => res))); }
public static Task <Either <RfcErrorInfo, R1> > Commit <R1>(this Task <Either <RfcErrorInfo, R1> > self, IRfcContext context) { return(self.BindAsync(res => context.Commit().MapAsync(u => res))); }
public static Task <Either <RfcErrorInfo, Unit> > CallFunction(this IRfcContext context, string functionName) { return(context.CreateFunction(functionName).Use( func => func.BindAsync(context.InvokeFunction))); }
public static Task <Either <RfcErrorInfo, Unit> > CallFunctionAsUnit <TRInput, TResult>(this IRfcContext context, string functionName, Func <Task <Either <RfcErrorInfo, IFunction> >, Task <Either <RfcErrorInfo, TRInput> > > Input, Func <Task <Either <RfcErrorInfo, IFunction> >, Task <Either <RfcErrorInfo, TResult> > > Output) { return(context.CreateFunction(functionName).Use( func => func .Apply(Input).BindAsync(i => func) .BindAsync(context.InvokeFunction).Map(i => func) .Apply(Output)).MapAsync(f => Unit.Default)); }
private static async Task RunIntegrationTest02(IRfcContext context) { Console.WriteLine("Integration Tests 02 (I/O field with dictionary)"); // ReSharper disable StringLiteralTypo var inputData = new TypesTestData { ACCP = "123456", CHAR = "AB", CLNT = "ABC", CUKY = "ABCDE", CURR = 9.12, DATS = DateTime.MaxValue.Date, DEC = 1.999M, FLTP = +1E-6143, INT1 = 1, INT2 = 32767, INT4 = 2147483647, LANG = "A", LCHR = RandomString(256), LRAW = RandomByteArray(256), NUMC = "123", PREC = 99, QUAN = 99.123, RAW = RandomByteArray(10), SSTRING = RandomString(10), TIMS = default(DateTime).Add(new TimeSpan(23, 59, 59)), STRING = "ABCDE", RAWSTRING = RandomByteArray(300), UNIT = "ABC" }; var outputDictionary = await context.CallFunction("ZYANCO_IT_1", Input : f => f.SetStructure("IS_IN", s => s .SetField("FIELD_ACCP", inputData.ACCP) .SetField("FIELD_CHAR", inputData.CHAR) .SetField("FIELD_CLNT", inputData.CLNT) .SetField("FIELD_CUKY", inputData.CUKY) .SetField("FIELD_CURR", inputData.CURR) .SetField("FIELD_DATS", inputData.DATS) .SetField("FIELD_DEC", inputData.DEC) .SetField("FIELD_FLTP", inputData.FLTP) .SetField("FIELD_INT1", inputData.INT1) .SetField("FIELD_INT2", inputData.INT2) .SetField("FIELD_INT4", inputData.INT4) .SetField("FIELD_LANG", inputData.LANG) .SetField("FIELD_LCHR", inputData.LCHR) .SetField("FIELD_LRAW", inputData.LRAW) .SetField("FIELD_NUMC", inputData.NUMC) .SetField("FIELD_PREC", inputData.PREC) .SetField("FIELD_QUAN", inputData.QUAN) .SetField("FIELD_RAW", inputData.RAW) .SetField("FIELD_SSTRING", inputData.SSTRING) .SetField("FIELD_TIMS", inputData.TIMS) .SetField("FIELD_STRING", inputData.STRING) .SetField("FIELD_RAWSTRING", inputData.RAWSTRING) .SetField("FIELD_UNIT", inputData.UNIT) ), Output : f => f.MapStructure("ES_ECHO", s => s.ToDictionary())) .Match( r => r, l => { Console.WriteLine(l.Message); return(new Dictionary <string, AbapValue>()); }); var outputData = await context.CallFunction("ZYANCO_IT_1", Input : f => f.SetStructure("IS_IN", es => es.Bind(s => s.SetFromDictionary(outputDictionary))), Output : f => f.MapStructure("ES_ECHO", s => // ReSharper disable InconsistentNaming // ReSharper disable IdentifierTypo from fieldACCP in s.GetField <string>("FIELD_ACCP") from fieldCHAR in s.GetField <string>("FIELD_CHAR") from fieldCLNT in s.GetField <string>("FIELD_CLNT") from fieldCUKY in s.GetField <string>("FIELD_CUKY") from fieldCURR in s.GetField <double>("FIELD_CURR") from fieldDATS in s.GetField <DateTime>("FIELD_DATS") from fieldDEC in s.GetField <decimal>("FIELD_DEC") from fieldFLTP in s.GetField <double>("FIELD_FLTP") from fieldINT1 in s.GetField <int>("FIELD_INT1") from fieldINT2 in s.GetField <short>("FIELD_INT2") from fieldINT4 in s.GetField <int>("FIELD_INT4") from fieldLANG in s.GetField <string>("FIELD_LANG") from fieldLCHR in s.GetField <string>("FIELD_LCHR") from fieldLRAW in s.GetField <byte[]>("FIELD_LRAW") from fieldNUMC in s.GetField <string>("FIELD_NUMC") from fieldPREC in s.GetField <int>("FIELD_PREC") from fieldQUAN in s.GetField <double>("FIELD_QUAN") from fieldRAW in s.GetField <byte[]>("FIELD_RAW") from fieldSSTRING in s.GetField <string>("FIELD_SSTRING") from fieldTIMS in s.GetField <DateTime>("FIELD_TIMS") from fieldSTRING in s.GetField <string>("FIELD_STRING") from fieldRAWSTRING in s.GetField <byte[]>("FIELD_RAWSTRING") from fieldUNIT in s.GetField <string>("FIELD_UNIT") // ReSharper restore InconsistentNaming // ReSharper restore IdentifierTypo select new TypesTestData { ACCP = fieldACCP, CHAR = fieldCHAR, CLNT = fieldCLNT, CUKY = fieldCUKY, CURR = fieldCURR, DATS = fieldDATS, DEC = fieldDEC, FLTP = fieldFLTP, INT1 = fieldINT1, INT2 = fieldINT2, INT4 = fieldINT4, LANG = fieldLANG, LCHR = fieldLCHR, LRAW = fieldLRAW, NUMC = fieldNUMC, PREC = fieldPREC, QUAN = fieldQUAN, RAW = fieldRAW, SSTRING = fieldSSTRING, TIMS = fieldTIMS, STRING = fieldSTRING, RAWSTRING = fieldRAWSTRING, UNIT = fieldUNIT })).Match( r => r, l => { Console.WriteLine(l.Message); return(new TypesTestData()); }); // ReSharper restore StringLiteralTypo var compareLogic = new CompareLogic(new ComparisonConfig() { MaxDifferences = int.MaxValue }); var result = compareLogic.Compare(inputData, outputData); Console.WriteLine(!result.AreEqual ? result.DifferencesString : "Test succeed"); }