Exemplo n.º 1
0
        private static T MethodResult <T>(this ISynologyRequest request, string name, params object[] parameters) where T : ResultData
        {
            var type            = request.GetType();
            var methods         = type.GetMethods();
            var filteredMethods = methods.Where(t => t.CustomAttributes.Any(a => a.AttributeType == typeof(RequestMethodAttribute)));
            var method          = filteredMethods.FirstOrDefault(t => t.GetCustomAttributes(typeof(RequestMethodAttribute), true).Cast <RequestMethodAttribute>().FirstOrDefault()?.Name == name);
            var response        = method?.Invoke(request, parameters);

            return(response as T);
        }
Exemplo n.º 2
0
        private static async Task <T> MethodResultAsync <T>(this ISynologyRequest request, string name, params object[] parameters) where T : ResultData
        {
            var type            = request.GetType();
            var methods         = type.GetMethods();
            var filteredMethods = methods.Where(t => t.CustomAttributes.Any(a => a.AttributeType == typeof(RequestMethodAttribute)));
            var method          = filteredMethods.FirstOrDefault(t => (typeof(Task) == t.ReturnType || typeof(Task <>) == t.ReturnType.GetGenericTypeDefinition()) && t.GetCustomAttributes(typeof(RequestMethodAttribute), true).Cast <RequestMethodAttribute>().FirstOrDefault()?.Name == name);
            var response        = await(Task <T>) method?.Invoke(request, parameters);

            return(response as T);
        }
Exemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="request"></param>
        /// <param name="methodName"></param>
        protected SynologyParameters(ISynologyRequest request, [CallerMemberName] string methodName = null)
        {
            var method = request.GetType().GetMethod(methodName);

            if (method != null)
            {
                if (method.GetCustomAttribute(typeof(RequestMethodAttribute)) is RequestMethodAttribute attr)
                {
                    Method = attr.Name;
                }
                else
                {
                    throw new Exception("RequestMethodAttribute not found on caller method.");
                }
            }
            else
            {
                throw new Exception("Caller Method not found.");
            }

            Version = 1;
        }
Exemplo n.º 4
0
 public SynologyRequestParameters(ISynologyRequest request, [CallerMemberName] string methodName = null) : base(request, methodName)
 {
 }
Exemplo n.º 5
0
 internal static ResultData <T> Method <T>(this ISynologyRequest request, string name, params object[] parameters) => request.MethodResult <ResultData <T> >(name, parameters);
Exemplo n.º 6
0
 /// <summary>
 /// Posts the data async.
 /// </summary>
 /// <returns>The data async.</returns>
 /// <param name="request">Request.</param>
 /// <param name="parameters">Parameters.</param>
 internal static async Task <ResultData> PostDataAsync(this ISynologyRequest request, SynologyPostParameters parameters) => await request.Api.PostDataAsync(await request.CgiPathAsync(), request.ApiName, parameters);
Exemplo n.º 7
0
 internal static async Task <ResultData <T> > MethodAsync <T>(this ISynologyRequest request, string name, params object[] parameters) => await request.MethodResultAsync <ResultData <T> >(name, parameters);