コード例 #1
0
ファイル: Program.cs プロジェクト: SOACAt/WebDAVClient
        private static async Task MainAsync()
        {
            // Basic authentication required
            IClient c = new Client(new NetworkCredential { UserName = "******" , Password = "******"});
            c.Server = "https://dav.dumptruck.goldenfrog.com/";
            c.BasePath = "/dav/";

            // List items in the root folder
            var files = await c.List();
            // Find first folder in the root folder
            var folder = files.FirstOrDefault(f => f.Href.EndsWith("/Test/"));
            // Load a specific folder
            var folderReloaded = await c.GetFolder(folder.Href);

            // List items in the folder
            var folderFiles = await c.List(folderReloaded.Href);
            // Find a file in the folder
            var folderFile = folderFiles.FirstOrDefault(f => f.IsCollection == false);

            var tempFileName = Path.GetTempFileName();

            // Download item into a temporary file
            using (var tempFile = File.OpenWrite(tempFileName))
            using (var stream = await c.Download(folderFile.Href))
                await stream.CopyToAsync(tempFile);

            // Update file back to webdav
            var tempName = Path.GetRandomFileName();
            using (var fileStream = File.OpenRead(tempFileName))
            {
                var fileUploaded = await c.Upload(folder.Href, fileStream, tempName);
            }
            
            // Create a folder
            var tempFolderName = Path.GetRandomFileName();
            var isfolderCreated = await c.CreateDir("/", tempFolderName);

            // Delete created folder
            var folderCreated = await c.GetFolder("/" + tempFolderName);
            await c.DeleteFolder(folderCreated.Href);
        }
コード例 #2
0
 public void Reset()
 {
     _client = null;
 }
コード例 #3
0
        public async Task <Client> GetClient()
        {
            if (_client != null)
            {
                return(_client);
            }

            if (!string.IsNullOrEmpty(await SecureStorage.GetAsync("WDServerAddress")) &&
                !string.IsNullOrEmpty(await SecureStorage.GetAsync("WDUsername")))
            {
                string username, serveraddress, password;
                username = await SecureStorage.GetAsync("WDUsername");

                password = await SecureStorage.GetAsync("WDPassword");

                serveraddress = await SecureStorage.GetAsync("WDServerAddress");

                try
                {
                    //var response = await OcsClient.GetServerStatusAsync(Configuration.ServerUrl);
                    //if (response == null)
                    //{
                    //var checkServerResponse = await NextcloudClient.NextcloudClient.GetServerStatus(credential.Resource, true);
                    //if (checkServerResponse != null)
                    //{
                    //    var dialogResult = await ShowServerCertificateErrorMessage(credential.Resource);
                    //    switch (dialogResult)
                    //    {
                    //        case ContentDialogResult.Primary:
                    //            try
                    //            {
                    //                SettingsService.Default.Value.LocalSettings.IgnoreServerCertificateErrors = true;
                    //                //response = await NextcloudClient.NextcloudClient.GetServerStatus(credential.Resource, SettingsService.Default.Value.LocalSettings.IgnoreServerCertificateErrors);
                    //            }
                    //            catch (System.Exception)
                    //            {
                    //                await ShowServerAddressNotFoundMessage(credential.Resource);
                    //                return null;
                    //            }
                    //            break;
                    //        case ContentDialogResult.None:
                    //        case ContentDialogResult.Secondary:
                    //            await ShowServerAddressNotFoundMessage(credential.Resource);
                    //            return null;
                    //        default:
                    //            break;
                    //    }
                    //}
                    //else
                    //{
                    //    await ShowServerAddressNotFoundMessage(credential.Resource);
                    //    return null;
                    //}
                    //    await ShowServerAddressNotFoundMessage(credential.Resource);
                    //    return null;
                    //}
                }
                catch
                {
                    //await ShowServerAddressNotFoundMessage(credential.Resource);
                    //return null;
                }

                _client = new WebDAVClient.Client(serveraddress, username, password);
            }



            return(_client);
        }