/// <summary> /// This method removes a specific resource from a webdav share /// </summary> /// <param name="session"></param> /// <param name="entry"></param> public override Boolean DeleteResource(IStorageProviderSession session, ICloudFileSystemEntry entry) { // get the credentials var creds = session.SessionToken as ICredentials; // build url var uriString = GetResourceUrl(session, entry, null); var uri = new Uri(uriString); // create the service var svc = new DavService(); // create the webrequest int errorCode; WebException e; svc.PerformSimpleWebCall(uri.ToString(), WebRequestMethodsEx.WebDAV.Delete, creds.GetCredential(null, null), null, out errorCode, out e); if (!HttpUtilityEx.IsSuccessCode(errorCode)) { return(false); } // remove from parent var parentDir = entry.Parent as BaseDirectoryEntry; if (parentDir != null) { parentDir.RemoveChildById(entry.Id); } return(true); }
public void CommitUploadStream(params object[] arg) { // convert the args var svc = arg[0] as DavService; var uploadRequest = arg[1] as HttpWebRequest; var fileSystemEntry = arg[2] as BaseFileEntry; var requestStream = arg[3] as WebRequestStream; // check if all data was written into stream if (requestStream.WrittenBytes != uploadRequest.ContentLength) { // nothing todo request was aborted return; } // perform the request int code; WebException e; svc.PerformWebRequest(uploadRequest, null, out code, out e); // check the ret value if (!HttpUtilityEx.IsSuccessCode(code)) { SharpBoxException.ThrowSharpBoxExceptionBasedOnHttpErrorCode(uploadRequest, (HttpStatusCode)code, e); } // adjust the lengt fileSystemEntry.Length = uploadRequest.ContentLength; }
/// <summary> /// This method generates a session to a webdav share via username and password /// </summary> /// <param name="token"></param> /// <param name="configuration"></param> /// <returns></returns> public override IStorageProviderSession CreateSession(ICloudStorageAccessToken token, ICloudStorageConfiguration configuration) { // cast the creds to the right type WebDavConfiguration config = configuration as WebDavConfiguration; // build service DavService svc = new DavService(); // check if url available int status = (int)HttpStatusCode.OK; WebException e = null; svc.PerformSimpleWebCall(config.ServiceLocator.ToString(), WebRequestMethodsEx.WebDAV.Options, (token as ICredentials).GetCredential(null, null), null, out status, out e); if (status == (int)HttpStatusCode.Unauthorized) { throw new UnauthorizedAccessException(); } else if (HttpUtilityEx.IsSuccessCode(status)) { return(new WebDavStorageProviderSession(token, config, this)); } else { return(null); } }