Ejemplo n.º 1
0
        public async override Task <T> DoAsync <T>(params object[] data)
        {
            if (typeof(T) == typeof(AuthResult))
            {
                if (data.Count() < 2)
                {
                    throw new InvalidDataException();
                }
                var data_str = data.Reinterpret <string>();

                try
                {
                    return((T)(object) await Attempt((string)data[0], (string)data[1]));
                }
                catch (Exception)
                {
                    return((T)(object)AuthResult.BuildServerError());
                }
            }
            else if (typeof(T) == typeof(User))
            {
                try
                {
                    return((T)(object) await AttemptToken());
                }
                catch (Exception)
                {
                    return((T)(object)CurrentUser);
                }
            }
            else
            {
                throw new InvalidCastException();
            }
        }
Ejemplo n.º 2
0
        public override T Do <T>(params object[] data)
        {
            if (typeof(T) == typeof(AuthResult))
            {
                if (data.Count() < 2)
                {
                    throw new InvalidDataException();
                }
                var data_str = data.Reinterpret <string>();

                try
                {
                    var result = Attempt(data_str[0], data_str[1]);
                    result.Wait();

                    return((T)(object)result.GetAwaiter().GetResult());
                }
                catch (Exception)
                {
                    return((T)(object)AuthResult.BuildServerError());
                }
            }
            else if (typeof(T) == typeof(User))
            {
                try
                {
                    var result = AttemptToken();
                    result.Wait();

                    return((T)(object)CurrentUser);
                }
                catch (Exception)
                {
                    return((T)(object)null);
                }
            }
            else
            {
                throw new InvalidCastException();
            }
        }