public static bool DoConnection(SynologyConnection syno)
        {
            Console.WriteLine("Info");
            var resInfo = syno.Api().Info().GetInfo();

            Console.WriteLine(JsonConvert.SerializeObject(resInfo));

            Console.WriteLine("Auth Login");
            var resLogin = syno.Api().Auth().Login(new LoginParameters
            {
                Username = LoginData.Username,
                Password = LoginData.Password
            });

            Console.WriteLine(JsonConvert.SerializeObject(resLogin));

            if (resLogin.Error == null || (resLogin.Error != null && resLogin.Error.Code == 403))
            {
                if (resLogin.Error != null && resLogin.Error.Code == 403)
                {
                    GetOtp(syno, ref resLogin);
                }

                if (resLogin.Error == null)
                {
                    return(true);
                }
            }

            return(false);
        }
        public static bool DoConnection(SynologyConnection syno)
        {
            Console.WriteLine("Info");
            var resInfo = syno.Api().Info().GetInfo();

            Console.WriteLine(JsonConvert.SerializeObject(resInfo));

            Console.WriteLine("Auth Login");
            var resLogin = syno.Api().Auth().Login(new LoginParameters
            {
                Username = LoginData.Username,
                Password = LoginData.Password
            });

            Console.WriteLine(JsonConvert.SerializeObject(resLogin));

            if (resLogin.Error == null || (resLogin.Error != null && resLogin.Error.Code == 403))
            {
                if (resLogin.Error != null && resLogin.Error.Code == 403)
                {
                    GetOtp(syno, ref resLogin);
                }

                if (resLogin.Error == null)
                {
                    return true;
                }

            }

            return false;
        }
        public static void GetOtp(SynologyConnection syno, ref ResultData <AuthResult> resLogin)
        {
            do
            {
                Console.Write("Otp Code: ");

                var otp = Console.ReadLine();

                if (string.IsNullOrWhiteSpace(otp))
                {
                    resLogin.Error = new ResultError {
                        Code = 404
                    };
                    continue;
                }

                resLogin = syno.Api().Auth().Login(new LoginParameters
                {
                    Username = LoginData.Username,
                    Password = LoginData.Password,
                    OtpCode  = otp
                });

                Console.WriteLine(JsonConvert.SerializeObject(resLogin));
            }while (resLogin.Error != null && resLogin.Error.Code == 404);
        }
        public static void GetOtp(SynologyConnection syno, ref ResultData<AuthResult> resLogin)
        {
            do
            {
                Console.Write("Otp Code: ");

                var otp = Console.ReadLine();

                if (string.IsNullOrWhiteSpace(otp))
                {
                    resLogin.Error = new ResultError { Code = 404 };
                    continue;
                }

                resLogin = syno.Api().Auth().Login(new LoginParameters
                {
                    Username = LoginData.Username,
                    Password = LoginData.Password,
                    OtpCode = otp
                });

                Console.WriteLine(JsonConvert.SerializeObject(resLogin));
            }
            while (resLogin.Error != null && resLogin.Error.Code == 404);
        }
Esempio n. 5
0
 public static T Api(SynologyConnection connection) => connection.Api <T>();