public static async Task TestLock(WebDavClient webDavClient) { var response = await webDavClient.Lock("http://mywebdav:88/1.txt", new LockParameters { LockScope = LockScope.Shared, Owner = new PrincipalLockOwner("Chuck Norris"), Timeout = TimeSpan.FromSeconds(120) }); var token = string.Empty; foreach (var @lock in response.ActiveLocks) { token = @lock.LockToken; PrintActiveLock(@lock); } await webDavClient.Unlock("http://mywebdav:88/1.txt", token); Console.WriteLine("Unlocked!"); var response2 = await webDavClient.Lock("http://mywebdav:88/2.txt"); var token2 = response2.ActiveLocks.First().LockToken; var deleteResponse = await webDavClient.Delete("http://mywebdav:88/2.txt"); if (!deleteResponse.IsSuccessful) { Console.WriteLine("Can't delete a resource. It's locked!"); } deleteResponse = await webDavClient.Delete("http://mywebdav:88/2.txt", new DeleteParameters { LockToken = token2 }); if (deleteResponse.IsSuccessful) { Console.WriteLine("The resource was deleted."); } }
/// <summary> /// Удалить файл /// </summary> /// <param name="path">Полный путь к файлу</param> public bool DeleteFile(string path) { try { switch (typeSunc) { #region SFTP case TypeSunc.SFTP: { // Удаляем файл sftp.Delete(path); break; } #endregion #region FTP/FTPS case TypeSunc.FTP: { // Удаляем файл ftp.DeleteFile(path); break; } #endregion case TypeSunc.WebDav: { var res = webDav.Delete(path).Result; if (!res.IsSuccessful) { report.Base("DeleteFile", path, res); } break; } case TypeSunc.OneDrive: { oneDrive.Delete(path).Wait(); break; } } return(true); } catch (Exception ex) { report.Base("DeleteFile", path, ex.ToString()); return(false); } }
public async void When_RequestIsFailed_Should_ReturnStatusCode500() { var client = new WebDavClient().SetWebDavDispatcher(Dispatcher.MockFaulted()); var response = await client.Delete("http://example.com/file"); Assert.Equal(500, response.StatusCode); }
public async void When_RequestIsSuccessfull_Should_ReturnStatusCode200() { var client = new WebDavClient().SetWebDavDispatcher(Dispatcher.Mock()); var response1 = await client.Delete("http://example.com/file"); var response2 = await client.Delete(new Uri("http://example.com/file")); var response3 = await client.Delete("http://example.com/file", new DeleteParameters()); var response4 = await client.Delete(new Uri("http://example.com/file"), new DeleteParameters()); Assert.Equal(200, response1.StatusCode); Assert.Equal(200, response2.StatusCode); Assert.Equal(200, response3.StatusCode); Assert.Equal(200, response4.StatusCode); }
public async Task <bool> DeletePackage(ApplicationVersion version) { var fileName = BuildPackageFilename(version); var response = await client.Delete(fileName); return(response.IsSuccessful); }
/// <summary> /// Remove the Directory at the given destination Uri and /// returns wheter the deletion was successfull /// </summary> /// <param name="dstUri"></param> /// <returns></returns> public bool Remove(CancellationToken cancleToken, string dstUri) { dstUri = _config.Remote.RemoteFolderPath.RemoveTailingSlashes() + dstUri; try { _logger.Debug("Deleting remote resource " + dstUri); WebDavResponse res = _webDavClient.Delete(dstUri, new DeleteParameters() { CancellationToken = cancleToken, }).Result; if (res.IsSuccessful) { _logger.Debug("Deleting remote resource " + dstUri + " was successfull"); return(true); } else if (res.StatusCode == 404) { //In case a not found it returned -> The ressource has allready bin //deleted, therefore deleting the Ressource was successfull _logger.Debug("Remote ressource " + dstUri + " has allready been deleted. Return success."); return(true); } else { _logger.Error("Deleting resource" + dstUri + " failed!"); } } catch (Exception exc) { _logger.Error("Unhandled exception occured while deleting remote resource: " + dstUri, exc); } return(false); }
public async Task DeleteItemAsync(List <DavItem> items) { var client = new WebDavClient(new Uri(Configuration.ServerUrl, UriKind.RelativeOrAbsolute), Configuration.Credential); foreach (var item in items) { await client.Delete(new Uri(item.EntityId, UriKind.RelativeOrAbsolute)); } }
public async void When_IsCalledWithCancellationToken_Should_SendRequestWithIt() { var cts = new CancellationTokenSource(); var dispatcher = Dispatcher.Mock(); var client = new WebDavClient().SetWebDavDispatcher(dispatcher); await client.Delete("http://example.com/file", new DeleteParameters { CancellationToken = cts.Token }); await dispatcher.Received(1) .Send(Arg.Any <Uri>(), HttpMethod.Delete, Arg.Is <RequestParameters>(x => !x.Headers.Any() && x.Content == null), cts.Token); }
public async void When_IsCalledWithDefaultArguments_Should_SendDeleteRequest() { var requestUri = new Uri("http://example.com/file"); var dispatcher = Dispatcher.Mock(); var client = new WebDavClient().SetWebDavDispatcher(dispatcher); await client.Delete(requestUri); await dispatcher.Received(1) .Send(requestUri, HttpMethod.Delete, Arg.Is <RequestParameters>(x => !x.Headers.Any() && x.Content == null), CancellationToken.None); }
public async void When_IsCalledWithLockToken_Should_SetIfHeader() { var requestUri = new Uri("http://example.com/file"); var dispatcher = Dispatcher.Mock(); var client = new WebDavClient().SetWebDavDispatcher(dispatcher); await client.Delete(requestUri, new DeleteParameters { LockToken = "urn:uuid:e71d4fae-5dec-22d6-fea5-00a0c91e6be4" }); await dispatcher.Received(1) .Send(requestUri, HttpMethod.Delete, Arg.Is(Predicates.CompareHeader("If", "(<urn:uuid:e71d4fae-5dec-22d6-fea5-00a0c91e6be4>)")), CancellationToken.None); }
JsonResult IDriver.Remove(IEnumerable <string> targets) { RemoveResponse answer = new RemoveResponse(); foreach (string item in targets) { string decodedItem = this.DecodeTarget(this.GetCorectTarget(item)); client.Delete(decodedItem); answer.Removed.Add(item); } return(Json(answer)); }
public async Task Delete(string relativeFilePath) { using (var client = new WebDavClient(_webDavClientParams)) { var res = await client.Delete(relativeFilePath); if (res.StatusCode == 404) { throw new FileNotFoundException($"Not found {relativeFilePath}."); } if (res.StatusCode != 204) { var msg = $"Cannot delete object! ({res.StatusCode} {res.Description})"; _logger.LogError(msg); throw new ArgumentException(msg); } } }
public void updloadIfChecked() { if (!this._repo.settings.useWebDav) { return; } this._repo.isIndetermerminate = true; WebDavClient webDavClient = createClient(); if (this._repo.settings.zipping) { this._repo.taskDescription = "Deleting old zip file..."; WebDavResponse response = webDavClient.Delete(Path.Combine(this._repo.settings.webDavBasePath, Path.GetFileName(this._repo.getLocalZipPath()))).Result; using (var fileStream = File.OpenRead(this._repo.getLocalZipPath())) { this._repo.taskDescription = "Uploading zip file..."; response = webDavClient.PutFile(Path.Combine(this._repo.settings.webDavBasePath, Path.GetFileName(this._repo.getLocalZipPath())), fileStream).Result; }; } }
private static async Task TestWebDav() { using (var webDavClient = new WebDavClient(new WebDavClientParams { BaseAddress = new Uri("http://mywebdav:88/") })) { await webDavClient.Copy("1.txt", "_2.txt"); await webDavClient.Move("http://mywebdav:88/_2.txt", "2.txt"); await webDavClient.Mkcol("http://mywebdav:88/mydir"); await webDavClient.PutFile("http://mywebdav:88/mydir/test.txt", File.OpenRead("test.txt"), "text/plain"); await webDavClient.Move("mydir/test.txt", "http://mywebdav:88/mydir/test_ren.txt"); await webDavClient.Copy("http://mywebdav:88/mydir/", "http://mywebdav:88/mydir1/"); await webDavClient.Copy("http://mywebdav:88/mydir/", "http://mywebdav:88/mydir2/", new CopyParameters { ApplyTo = ApplyTo.Copy.ResourceOnly }); using (var response = await webDavClient.GetRawFile("http://mywebdav:88/mydir/test_ren.txt")) using (var reader = new StreamReader(response.Stream)) { var fileOutput = await reader.ReadToEndAsync(); Console.WriteLine(fileOutput); } await TestPropfind(webDavClient); await TestSearch(webDavClient); await TestLock(webDavClient); await TestPropatch(webDavClient); await webDavClient.Delete("http://mywebdav:88/mydir"); } }
public ActionResult DeleteFile(string deletingFileUri) { Guid token = CheckSessionAuthState(CurrentUser, _authService); if (token == Guid.Empty) { return(Json(new { status = "Error", errorCode = "401", errorMessage = "" }, JsonRequestBehavior.AllowGet)); } string message = ""; string deletingFileName = deletingFileUri; WebDavClient webDavClient = Helper.InitWebDav(token, _authService); // new WebDavClient(deletingFileUri, Model.UserInfo.User.Login, Model.UserInfo.User.Password); webDavClient.Delete(deletingFileUri); if (webDavClient.LastError != null) { message = "Ошибка удаления файла"; } else { message = "Файл: " + deletingFileName + " успешно удален"; } return(Json(new { status = "ok", errorCode = "", errorMessage = "", message }, JsonRequestBehavior.AllowGet)); }
public void runSync() { saveBtn.Sensitive = false; progressBar.Visible = true; IWebDavClient _client = new WebDavClient(); var clientParams = new WebDavClientParams { BaseAddress = new Uri(db.webDavHost), Credentials = new NetworkCredential(db.webDavUsername, db.webDavPass) }; _client = new WebDavClient(clientParams); Thread t = new Thread(async() => { System.Timers.Timer ti = new System.Timers.Timer(200); ti.Elapsed += (delegate { progressBar.Pulse(); }); ti.Start(); var result = await _client.Propfind(db.webDavHost + "/Money"); if (result.IsSuccessful) { bool containsDb = false; foreach (var res in result.Resources) { if (res.Uri.EndsWith("database.mdb")) //Check if we have the database online { containsDb = true; break; } } if (containsDb) { //Let's grab the online version var resultInner = await _client.GetRawFile(db.webDavHost + "/Money/database.mdb"); StreamReader reader = new StreamReader(resultInner.Stream); string json = reader.ReadToEnd(); Database oDb = JsonConvert.DeserializeObject <Database>(json); //Check if modDateTime is newer than current database //if so replace local with online if (oDb.modDateTime < db.modDateTime) { File.WriteAllText(dbPath, json); db = null; oDb = null; db = new Database(dbPath); } else //Else upload local to online { //First delete the online version var resultInnerInner = await _client.Delete(db.webDavHost + "/Money/database.mdb"); if (resultInnerInner.IsSuccessful) { var resultInnerInnerInner = await _client.PutFile(db.webDavHost + "/Money/database.mdb", File.OpenRead(dbPath)); if (!resultInnerInnerInner.IsSuccessful) { Gtk.Application.Invoke(delegate { new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, false, "Failed to upload database. Sync error " + resultInnerInner.StatusCode + " (" + resultInnerInner.Description + ")").Show(); }); } } else { Gtk.Application.Invoke(delegate { new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, false, "Failed to delete out-of-sync online database. Sync error " + resultInnerInner.StatusCode + " (" + resultInnerInner.Description + ")").Show(); }); } } Gtk.Application.Invoke(delegate { db.Save(dbPath); this.Close(); }); } else { var resultInner = await _client.PutFile(db.webDavHost + "/Money/database.mdb", File.OpenRead(dbPath)); if (!resultInner.IsSuccessful) { Gtk.Application.Invoke(delegate { new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, false, "Sync error " + resultInner.StatusCode + " (" + resultInner.Description + ")").Show(); }); } else { Gtk.Application.Invoke(delegate { db.Save(dbPath); this.Close(); }); } } } else if (result.StatusCode == 404) { var resultInner = await _client.Mkcol("Money"); if (resultInner.IsSuccessful) { resultInner = await _client.PutFile(db.webDavHost + "/Money/database.mdb", File.OpenRead(dbPath)); if (!resultInner.IsSuccessful) { Gtk.Application.Invoke(delegate { new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, false, "Sync error " + resultInner.StatusCode + " (" + resultInner.Description + ")").Show(); }); } else { Gtk.Application.Invoke(delegate { db.Save(dbPath); this.Close(); }); } } else { Gtk.Application.Invoke(delegate { new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, false, "Sync error " + resultInner.StatusCode + " (" + resultInner.Description + ")").Show(); }); } } else { Gtk.Application.Invoke(delegate { new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, false, "Sync error " + result.StatusCode + " (" + result.Description + ")").Show(); }); } ti.Stop(); Gtk.Application.Invoke(delegate { progressBar.Visible = false; saveBtn.Sensitive = true; }); }); t.Start(); }
protected override void DeleteFile(string path) { _webdavClient.Delete(path); }
private void button2_Click(object sender, EventArgs e) { client.Delete("_2.txt"); }