Exemple #1
0
        private JsWorkerBuilder AddMethod(MethodDocsOptions opts, Func <JsWorkerMethodDocs> docsGetter)
        {
            if (_docs.Methods.ContainsKey(opts.MethodName))
            {
                throw new InvalidOperationException($"Метод с названием '{opts.MethodName}' уже определен в классе {_docs.WorkerName}");
            }

            var docsPointer = docsGetter();

            _docs.Methods.Add(opts.MethodName, docsPointer);
            return(this);
        }
Exemple #2
0
 internal static JsWorkerMethodDocs GetAction(Action action, MethodDocsOptions opts)
 {
     return(new JsWorkerMethodDocs
     {
         Description = MethodDescription.Create(null, null, opts),
         Method = new JsWorkerMethodBase
         {
             FunctionLink = (p, srv) =>
             {
                 action();
                 return new JsWorkerMethodResult
                 {
                     Result = null,
                 };
             }
         }
     });
 }
Exemple #3
0
 internal static JsWorkerMethodDocs GetTask(Func <Task> task, MethodDocsOptions opts)
 {
     return(new JsWorkerMethodDocs
     {
         Description = MethodDescription.Create(null, null, opts),
         Method = new JsWorkerMethodBase
         {
             FunctionLink = (p, srv) =>
             {
                 task().ConfigureAwait(true).GetAwaiter().GetResult();
                 return new JsWorkerMethodResult
                 {
                     Result = null,
                 };
             }
         }
     });
 }
Exemple #4
0
        internal static JsWorkerMethodDocs GetFunc <TResult>(Func <TResult> func, MethodDocsOptions opts)
        {
            return(new JsWorkerMethodDocs
            {
                Description = MethodDescription.Create(typeof(TResult), null, opts),
                Method = new JsWorkerMethodBase
                {
                    FunctionLink = (p, srv) =>
                    {
                        var result = func();

                        return new JsWorkerMethodResult
                        {
                            Result = result
                        };
                    }
                }
            });
        }
Exemple #5
0
 internal static JsWorkerMethodDocs GetTask <T1>(Func <T1, Task> task, MethodDocsOptions opts)
 {
     return(new JsWorkerMethodDocs
     {
         Description = MethodDescription.Create(null, new List <Type> {
             typeof(T1)
         }, opts),
         Method = new JsWorkerMethodBase
         {
             FunctionLink = (p, srv) =>
             {
                 task(p.GetParameter <T1>()).ConfigureAwait(true).GetAwaiter().GetResult();
                 return new JsWorkerMethodResult
                 {
                     Result = null,
                 };
             }
         }
     });
 }
Exemple #6
0
 internal static JsWorkerMethodDocs GetAction <T1>(Action <T1> action, MethodDocsOptions opts)
 {
     return(new JsWorkerMethodDocs
     {
         Description = MethodDescription.Create(null, new List <Type> {
             typeof(T1)
         }, opts),
         Method = new JsWorkerMethodBase
         {
             FunctionLink = (p, srv) =>
             {
                 action(p.GetParameter <T1>());
                 return new JsWorkerMethodResult
                 {
                     Result = null,
                 };
             }
         }
     });
 }
Exemple #7
0
 /// <summary>
 /// Добавить метод
 /// </summary>
 /// <typeparam name="T1"></typeparam>
 /// <typeparam name="TResult"></typeparam>
 /// <param name="func"></param>
 /// <param name="opts"></param>
 /// <returns></returns>
 public JsWorkerBuilder AddMethodViaTask <T1, TResult>(Func <T1, Task <TResult> > func, MethodDocsOptions opts)
 {
     return(AddMethod(opts, () => JsFuncBuilder.GetTask(func, opts)));
 }
Exemple #8
0
 /// <summary>
 /// Добавить метод
 /// </summary>
 /// <typeparam name="T1"></typeparam>
 /// <typeparam name="T2"></typeparam>
 /// <param name="func"></param>
 /// <param name="opts"></param>
 /// <returns></returns>
 public JsWorkerBuilder AddMethodViaAction <T1, T2>(Action <T1, T2> func, MethodDocsOptions opts)
 {
     return(AddMethod(opts, () => JsFuncBuilder.GetAction(func, opts)));
 }
Exemple #9
0
        internal static JsWorkerMethodDocs GetFunc <T1, T2, T3, TResult>(Func <T1, T2, T3, TResult> func, MethodDocsOptions opts)
        {
            return(new JsWorkerMethodDocs
            {
                Description = MethodDescription.Create(typeof(TResult), new List <Type> {
                    typeof(T1), typeof(T2), typeof(T3)
                }, opts),
                Method = new JsWorkerMethodBase
                {
                    FunctionLink = (p, srv) =>
                    {
                        var result = func(p.GetParameter <T1>(), p.GetParameter <T2>(), p.GetParameter <T3>());

                        return new JsWorkerMethodResult
                        {
                            Result = result
                        };
                    }
                }
            });
        }
 /// <summary>
 /// Добавить метод
 /// </summary>
 /// <typeparam name="T1"></typeparam>
 /// <typeparam name="T2"></typeparam>
 /// <typeparam name="TResult"></typeparam>
 /// <param name="func"></param>
 /// <param name="opts"></param>
 /// <returns></returns>
 public JsWorkerServiceMethodBuilder <TService> AddMethodViaTaskWithResult <T1, T2, TResult>(Func <TService, T1, T2, Task <TResult> > func, MethodDocsOptions opts)
 {
     return(AddMethod(opts, () => JsServiceFuncBuilder.GetTask(func, opts)));
 }
Exemple #11
0
        internal static JsWorkerMethodDocs GetFunc <TService, T, TResult>(Func <TService, T, TResult> func, MethodDocsOptions opts)
        {
            return(new JsWorkerMethodDocs
            {
                Description = MethodDescription.Create(typeof(TResult), new List <Type> {
                    typeof(T)
                }, opts),
                Method = new JsWorkerMethodBase
                {
                    FunctionLink = (p, srv) =>
                    {
                        var service = srv.GetRequiredService <TService>();

                        var result = func(service, p.GetParameter <T>());

                        return new JsWorkerMethodResult
                        {
                            Result = result
                        };
                    }
                }
            });
        }
Exemple #12
0
        internal static JsWorkerMethodDocs GetTask <TService, T1, T2, TResult>(Func <TService, T1, T2, Task <TResult> > task, MethodDocsOptions opts)
        {
            return(new JsWorkerMethodDocs
            {
                Description = MethodDescription.Create(typeof(TResult), new List <Type> {
                    typeof(T1), typeof(T2)
                }, opts),
                Method = new JsWorkerMethodBase
                {
                    FunctionLink = (p, srv) =>
                    {
                        var service = srv.GetRequiredService <TService>();

                        return new JsWorkerMethodResult
                        {
                            Result = task(service, p.GetParameter <T1>(), p.GetParameter <T2>()).ConfigureAwait(true).GetAwaiter().GetResult(),
                        };
                    }
                }
            });
        }
Exemple #13
0
 internal static JsWorkerMethodDocs GetAction <TService, T1, T2>(Action <TService, T1, T2> action, MethodDocsOptions opts)
 {
     return(new JsWorkerMethodDocs
     {
         Description = MethodDescription.Create(null, new List <Type> {
             typeof(T1), typeof(T2)
         }, opts),
         Method = new JsWorkerMethodBase
         {
             FunctionLink = (p, srv) =>
             {
                 var service = srv.GetRequiredService <TService>();
                 action(service, p.GetParameter <T1>(), p.GetParameter <T2>());
                 return new JsWorkerMethodResult
                 {
                     Result = null,
                 };
             }
         }
     });
 }
Exemple #14
0
 internal static JsWorkerMethodDocs GetAction <TService>(Action <TService> action, MethodDocsOptions opts)
 {
     return(new JsWorkerMethodDocs
     {
         Description = MethodDescription.Create(null, null, opts),
         Method = new JsWorkerMethodBase
         {
             FunctionLink = (p, srv) =>
             {
                 var service = srv.GetRequiredService <TService>();
                 action(service);
                 return new JsWorkerMethodResult
                 {
                     Result = null,
                 };
             }
         }
     });
 }
 /// <summary>
 /// Добавить метод
 /// </summary>
 /// <param name="func"></param>
 /// <param name="opts"></param>
 /// <returns></returns>
 public JsWorkerServiceMethodBuilder <TService> AddMethodViaAction(Action <TService> func, MethodDocsOptions opts)
 {
     return(AddMethod(opts, () => JsServiceFuncBuilder.GetAction(func, opts)));
 }
 /// <summary>
 /// Добавить метод
 /// </summary>
 /// <typeparam name="T1"></typeparam>
 /// <typeparam name="T2"></typeparam>
 /// <typeparam name="T3"></typeparam>
 /// <typeparam name="TResult"></typeparam>
 /// <param name="func"></param>
 /// <param name="opts"></param>
 /// <returns></returns>
 public JsWorkerServiceMethodBuilder <TService> AddMethodViaFunction <T1, T2, T3, TResult>(Func <TService, T1, T2, T3, TResult> func, MethodDocsOptions opts)
 {
     return(AddMethod(opts, () => JsServiceFuncBuilder.GetFunc(func, opts)));
 }
Exemple #17
0
 /// <summary>
 /// Добавить метод
 /// </summary>
 /// <typeparam name="T1"></typeparam>
 /// <typeparam name="T2"></typeparam>
 /// <typeparam name="TResult"></typeparam>
 /// <param name="func"></param>
 /// <param name="opts"></param>
 /// <returns></returns>
 public JsWorkerBuilder AddMethodViaFunction <T1, T2, TResult>(Func <T1, T2, TResult> func, MethodDocsOptions opts)
 {
     return(AddMethod(opts, () => JsFuncBuilder.GetFunc(func, opts)));
 }
 /// <summary>
 /// Добавить метод
 /// </summary>
 /// <param name="func"></param>
 /// <param name="opts"></param>
 /// <returns></returns>
 public JsWorkerServiceMethodBuilder <TService> AddMethodViaTask(Func <TService, Task> func, MethodDocsOptions opts)
 {
     return(AddMethod(opts, () => JsServiceFuncBuilder.GetTask(func, opts)));
 }