예제 #1
0
        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);
        }
예제 #2
0
        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 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;
        }
예제 #5
0
        public void CreateExDownloadTest()
        {
            var fileData = File.ReadAllBytes(TorrentFile);

            using (SynologyConnection connection = new SynologyConnection(TestHost))
            {
                if (!DoConnection(connection))
                {
                    Assert.Fail("The connection to synology server failed.");
                }

                var result = connection.DownloadStation().TaskEx().Create(new TaskCreateExParameters
                {
                    Destination = "home/Downloads",
                    Filename    = Path.GetFileName(TorrentFile),
                    File        = fileData,
                });

                Assert.IsTrue(result.Success, $"The create download failed with error code : {result.Error?.Code}");
                Assert.IsNotNull(result.Data, "The data object is null (check json parsing)");
                Assert.IsNotNull(result.Data.TaskIds, "The task id list object is null (check json parsing)");

                var deleteResult = connection.DownloadStation().Task().Delete(new DownloadStation.Task.Parameters.TaskDeleteParameters
                {
                    Ids = result.Data.TaskIds.ToArray()
                });

                Assert.IsTrue(deleteResult.Success, $"The delete download failed with error code : {deleteResult.Error?.Code}");
            }
        }
예제 #6
0
        public void SuccessUpload()
        {
            var fileData = File.ReadAllBytes("SynologyUploadTestFile.txt");

            using (SynologyConnection connection = new SynologyConnection(TestHost))
            {
                if (!DoConnection(connection))
                {
                    Assert.Fail("The connection to synology server failed.");
                }

                var result = connection.FileStation().Upload().Upload(new UploadParameters
                {
                    DestinationPath = "/temp",
                    Overwrite       = true,
                    FileName        = "SynologyUploadTestFile.txt",
                    FileData        = fileData,
                });
            }
        }
예제 #7
0
 public Api(SynologyConnection connection)
     : base(connection)
 {
 }
예제 #8
0
파일: Api.cs 프로젝트: waffle-iron/Synology
 public Api(SynologyConnection connection) : base(connection)
 {
 }
예제 #9
0
 public AudioStationApi(SynologyConnection connection)
     : base(connection)
 {
 }
예제 #10
0
 public static T Api(SynologyConnection connection) => connection.Api <T>();
예제 #11
0
 public DownloadStationApi(SynologyConnection connection) : base(connection)
 {
 }
예제 #12
0
        public void CreateExDownloadTest()
        {
            var fileData = File.ReadAllBytes(TorrentFile);

            using (SynologyConnection connection = new SynologyConnection(TestHost))
            {
                if (!DoConnection(connection))
                {
                    Assert.Fail("The connection to synology server failed.");
                }

                var result = connection.DownloadStation().TaskEx().Create(new TaskCreateExParameters
                {
                    Destination = "home/Downloads",
                    Filename = Path.GetFileName(TorrentFile),
                    File = fileData,
                });

                Assert.IsTrue(result.Success, $"The create download failed with error code : {result.Error?.Code}");
                Assert.IsNotNull(result.Data, "The data object is null (check json parsing)");
                Assert.IsNotNull(result.Data.TaskIds, "The task id list object is null (check json parsing)");

                var deleteResult = connection.DownloadStation().Task().Delete(new DownloadStation.Task.Parameters.TaskDeleteParameters
                {
                    Ids = result.Data.TaskIds.ToArray()
                });

                Assert.IsTrue(deleteResult.Success, $"The delete download failed with error code : {deleteResult.Error?.Code}");
            }
        }
예제 #13
0
 public VideoStationApi(SynologyConnection connection) : base(connection)
 {
 }
예제 #14
0
 public FileStationApi(SynologyConnection connection) : base(connection)
 {
 }
예제 #15
0
 public SurveillanceStationApi(SynologyConnection connection) : base(connection)
 {
 }
예제 #16
0
 protected SynologyApi(SynologyConnection connection)
 {
     Connection = connection;
 }
예제 #17
0
 public AudioStationApi(SynologyConnection connection) : base(connection)
 {
 }