public override ICloudFileSystemEntry RequestResource(IStorageProviderSession session, string Name, ICloudDirectoryEntry parent) { //declare the requested entry ICloudFileSystemEntry fsEntry = null; // lets have a look if we are on the root node if (parent == null) { // just create the root entry fsEntry = GenericStorageProviderFactory.CreateDirectoryEntry(session, Name, parent); } else { // ok we have a parent, let's retrieve the resource // from his child list fsEntry = parent.GetChild(Name, false); } // now that we create the entry just update the chuld if (fsEntry != null && fsEntry is ICloudDirectoryEntry) RefreshResource(session, fsEntry as ICloudDirectoryEntry); // go ahead return fsEntry; }
public override bool DeleteResource(IStorageProviderSession session, ICloudFileSystemEntry entry) { // get the creds ICredentials creds = ((GenericNetworkCredentials) session.SessionToken).GetCredential(null, null); // generate the loca path String uriPath = GetResourceUrl(session, entry, null); // removed the file if (entry is ICloudDirectoryEntry) { // we need an empty directory foreach (ICloudFileSystemEntry child in (ICloudDirectoryEntry) entry) { DeleteResource(session, child); } // remove the directory return _ftpService.FtpDeleteEmptyDirectory(uriPath, creds); } else { // remove the file return _ftpService.FtpDeleteFile(uriPath, creds); } }
public void RefreshDirectoryContent(IStorageProviderSession session, BaseDirectoryEntry entry) { if (entry == null) return; var url = String.Format(GoogleDocsConstants.GoogleDocsContentsUrlFormat, entry.Id.ReplaceFirst("_", "%3a")); var parameters = new Dictionary<string, string> { { "max-results", "1000" } }; try { while (!String.IsNullOrEmpty(url)) { var request = CreateWebRequest(session, url, "GET", parameters); var response = (HttpWebResponse)request.GetResponse(); var rs = response.GetResponseStream(); var feedXml = new StreamReader(rs).ReadToEnd(); var childs = GoogleDocsXmlParser.ParseEntriesXml(session, feedXml); entry.AddChilds(childs); url = GoogleDocsXmlParser.ParseNext(feedXml); } } catch (WebException) { } }
public void RefreshDirectoryContent(IStorageProviderSession session, ICloudDirectoryEntry directory) { String uri = String.Format(SkyDriveConstants.FilesAccessUrlFormat, directory.Id); uri = SignUri(session, uri); WebRequest request = WebRequest.Create(uri); WebResponse response = request.GetResponse(); using (var rs = response.GetResponseStream()) { if (rs == null) throw new SharpBoxException(SharpBoxErrorCodes.ErrorCouldNotRetrieveDirectoryList); String json = new StreamReader(rs).ReadToEnd(); var childs = SkyDriveJsonParser.ParseListOfEntries(session, json) .Select(x => x as BaseFileEntry).Where(x => x != null).ToArray(); if (childs.Length == 0 || !(directory is BaseDirectoryEntry)) throw new SharpBoxException(SharpBoxErrorCodes.ErrorCouldNotRetrieveDirectoryList); var directoryBase = directory as BaseDirectoryEntry; directoryBase.AddChilds(childs); } }
public bool RemoveResource(IStorageProviderSession session, ICloudFileSystemEntry resource, RemoveMode mode) { String url; Dictionary<String, String> parameters = null; if (mode == RemoveMode.FromParentCollection) { var pId = (resource.Parent != null ? resource.Parent.Id : GoogleDocsConstants.RootFolderId).ReplaceFirst("_", "%3a"); url = String.Format("{0}/{1}/contents/{2}", GoogleDocsConstants.GoogleDocsFeedUrl, pId, resource.Id.ReplaceFirst("_", "%3a")); } else { url = String.Format(GoogleDocsConstants.GoogleDocsResourceUrlFormat, resource.Id.ReplaceFirst("_", "%3a")); parameters = new Dictionary<string, string> {{"delete", "true"}}; } var request = CreateWebRequest(session, url, "DELETE", parameters); request.Headers.Add("If-Match", "*"); try { var response = (HttpWebResponse)request.GetResponse(); if (response.StatusCode == HttpStatusCode.OK) return true; } catch (WebException) { } return false; }
/// <summary> /// This method closes the established session to a service provider /// </summary> public void Close() { // close the session _Service.CloseSession(_Session); // remove reference _Session = null; }
public override void RefreshResource(IStorageProviderSession session, ICloudFileSystemEntry resource) { // nothing to do for files if (!(resource is ICloudDirectoryEntry)) return; // Refresh schild RefreshChildsOfDirectory(session, resource as ICloudDirectoryEntry); }
public DropBoxAccountInfo GetAccountInfo(IStorageProviderSession session) { // request the json object via oauth int code; var res = DropBoxRequestParser.RequestResourceByUrl(GetUrlString(DropBoxGetAccountInfo, session.ServiceConfiguration), this, session, out code); // parse the jason stuff return new DropBoxAccountInfo(res); }
public BaseFileEntry(String Name, long Length, DateTime Modified, IStorageProviderService service, IStorageProviderSession session) { this.Name = Name; this.Length = Length; this.Modified = Modified; _service = new CachedServiceWrapper(service); //NOTE: Caching _session = session; IsDeleted = false; }
public void RefreshResource(IStorageProviderSession session, ICloudFileSystemEntry resource) { var cached = FsCache.Get(GetSessionKey(session), GetCacheKey(session, null, resource), null) as ICloudDirectoryEntry; if (cached == null || cached.HasChildrens == nChildState.HasNotEvaluated) { _service.RefreshResource(session, resource); FsCache.Add(GetSessionKey(session), GetCacheKey(session, null, resource), resource); } }
public static String PerformRequest(IStorageProviderSession session, String uri, String method, String data, bool signUri, int countAttempts) { if (String.IsNullOrEmpty(method)) method = "GET"; if (!String.IsNullOrEmpty(data) && method == "GET") return null; if (signUri) uri = SignUri(session, uri); int attemptsToComplete = countAttempts; while (attemptsToComplete > 0) { WebRequest request = WebRequest.Create(uri); request.Method = method; request.Timeout = 5000; if (!signUri) request.Headers.Add("Authorization", "Bearer " + GetValidToken(session).AccessToken); if (!String.IsNullOrEmpty(data)) { byte[] bytes = Encoding.UTF8.GetBytes(data); request.ContentType = "application/json"; request.ContentLength = bytes.Length; using (var rs = request.GetRequestStream()) { rs.Write(bytes, 0, bytes.Length); } } try { WebResponse response = request.GetResponse(); using (var rs = response.GetResponseStream()) { if (rs != null) { return new StreamReader(rs).ReadToEnd(); } } return null; } catch (WebException exception) { attemptsToComplete--; if (exception.Response != null && ((HttpWebResponse)exception.Response).StatusCode == HttpStatusCode.NotFound) return null; } } return null; }
public override ICloudFileSystemEntry RequestResource(IStorageProviderSession session, String nameOrID, ICloudDirectoryEntry parent) { /* In this method name could be either requested resource name or it's ID. * In first case just refresh the parent and then search child with an appropriate. * In second case it does not matter if parent is null or not a parent because we use only resource ID. */ if (SkyDriveHelpers.IsResourceID(nameOrID) || nameOrID.Equals("/") && parent == null) //If request by ID or root folder requested { String uri = SkyDriveHelpers.IsResourceID(nameOrID) ? String.Format("{0}/{1}", SkyDriveConstants.BaseAccessUrl, nameOrID) : SkyDriveConstants.RootAccessUrl; uri = SignUri(session, uri); WebRequest request = WebRequest.Create(uri); WebResponse response = request.GetResponse(); using (var rs = response.GetResponseStream()) { if (rs != null) { String json = new StreamReader(rs).ReadToEnd(); ICloudFileSystemEntry entry = SkyDriveJsonParser.ParseSingleEntry(session, json); return entry; } } } else { String uri = parent != null ? String.Format(SkyDriveConstants.FilesAccessUrlFormat, parent.Id) : SkyDriveConstants.RootAccessUrl + "/files"; uri = SignUri(session, uri); WebRequest request = WebRequest.Create(uri); WebResponse response = request.GetResponse(); using (var rs = response.GetResponseStream()) { if (rs != null) { String json = new StreamReader(rs).ReadToEnd(); var entry = SkyDriveJsonParser.ParseListOfEntries(session, json).FirstOrDefault(x => x.Name.Equals(nameOrID)); if (entry != null && parent != null && parent is BaseDirectoryEntry) (parent as BaseDirectoryEntry).AddChild(entry as BaseFileEntry); return entry; } } } return null; }
public static BaseFileEntry UpdateObjectFromJsonString(String jsonMessage, BaseFileEntry objectToUpdate, IStorageProviderService service, IStorageProviderSession session) { // verify if we have a directory or a file var jc = new JsonHelper(); if (!jc.ParseJsonMessage(jsonMessage)) throw new SharpBoxException(SharpBoxErrorCodes.ErrorInvalidFileOrDirectoryName); var isDir = jc.GetBooleanProperty("is_dir"); // create the entry BaseFileEntry dbentry; Boolean bEntryOk; if (isDir) { if (objectToUpdate == null) dbentry = new BaseDirectoryEntry("Name", 0, DateTime.Now, service, session); else dbentry = objectToUpdate as BaseDirectoryEntry; bEntryOk = BuildDirectyEntry(dbentry as BaseDirectoryEntry, jc, service, session); } else { if (objectToUpdate == null) dbentry = new BaseFileEntry("Name", 0, DateTime.Now, service, session); else dbentry = objectToUpdate; bEntryOk = BuildFileEntry(dbentry, jc); } // parse the childs and fill the entry as self if (!bEntryOk) throw new SharpBoxException(SharpBoxErrorCodes.ErrorCouldNotContactStorageService); // set the is deleted flag try { // try to read the is_deleted property dbentry.IsDeleted = jc.GetBooleanProperty("is_deleted"); } catch (Exception) { // the is_deleted proprty is missing (so it's not a deleted file or folder) dbentry.IsDeleted = false; } // return the child return dbentry; }
public override ICloudFileSystemEntry RequestResource(IStorageProviderSession session, string Name, ICloudDirectoryEntry parent) { // build path String path; if (Name.Equals("/")) path = session.ServiceConfiguration.ServiceLocator.LocalPath; else if (parent == null) path = Path.Combine(path = session.ServiceConfiguration.ServiceLocator.LocalPath, Name); else path = new Uri(GetResourceUrl(session, parent, Name)).LocalPath; // check if file exists if (File.Exists(path)) { // create the fileinfo FileInfo fInfo = new FileInfo(path); BaseFileEntry bf = new BaseFileEntry(fInfo.Name, fInfo.Length, fInfo.LastWriteTimeUtc, this, session) {Parent = parent}; // add to parent if (parent != null) (parent as BaseDirectoryEntry).AddChild(bf); // go ahead return bf; } // check if directory exists else if (Directory.Exists(path)) { // build directory info DirectoryInfo dInfo = new DirectoryInfo(path); // build bas dir BaseDirectoryEntry dir = CreateEntryByFileSystemInfo(dInfo, session, parent) as BaseDirectoryEntry; if (Name.Equals("/")) dir.Name = "/"; // add to parent if (parent != null) (parent as BaseDirectoryEntry).AddChild(dir); // refresh the childs RefreshChildsOfDirectory(session, dir); // go ahead return dir; } else return null; }
private static ICloudFileSystemEntry ParseSingleEntry(IStorageProviderSession session, String json, JsonHelper parser) { if (json == null) return null; if (parser == null) parser = CreateParser(json); if (ContainsError(json, false, parser)) return null; BaseFileEntry entry; var type = parser.GetProperty("type"); if (!IsFolderType(type) && !IsFileType(type)) return null; var id = parser.GetProperty("id"); var name = parser.GetProperty("name"); var parentID = parser.GetProperty("parent_id"); var uploadLocation = parser.GetProperty("upload_location"); var updatedTime = Convert.ToDateTime(parser.GetProperty("updated_time")).ToUniversalTime(); if (IsFolderType(type)) { int count = parser.GetPropertyInt("count"); entry = new BaseDirectoryEntry(name, count, updatedTime, session.Service, session) {Id = id}; } else { var size = Convert.ToInt64(parser.GetProperty("size")); entry = new BaseFileEntry(name, size, updatedTime, session.Service, session) {Id = id}; } entry[SkyDriveConstants.UploadLocationKey] = uploadLocation; if (!String.IsNullOrEmpty(parentID)) { entry.ParentID = SkyDriveConstants.RootIDRegex.IsMatch(parentID) ? "/" : parentID; } else { entry.Name = "/"; entry.Id = "/"; } entry[SkyDriveConstants.InnerIDKey] = id; entry[SkyDriveConstants.TimestampKey] = DateTime.UtcNow.ToString(CultureInfo.InvariantCulture); return entry; }
/// <summary> /// /// </summary> /// <param name="session"></param> /// <param name="Name"></param> /// <param name="modifiedDate"></param> /// <param name="parent"></param> /// <returns></returns> public static ICloudDirectoryEntry CreateDirectoryEntry(IStorageProviderSession session, string Name, DateTime modifiedDate, ICloudDirectoryEntry parent) { // build up query url var newObj = new BaseDirectoryEntry(Name, 0, modifiedDate, session.Service, session); // case the parent if possible if (parent != null) { var objparent = parent as BaseDirectoryEntry; objparent.AddChild(newObj); } return newObj; }
private static OAuth20Token GetValidToken(IStorageProviderSession session) { var token = session.SessionToken as OAuth20Token; if (token == null) throw new ArgumentException("Can not retrieve valid oAuth 2.0 token from given session", "session"); if (token.IsExpired) { token = (OAuth20Token)SkyDriveAuthorizationHelper.RefreshToken(token); var sdSession = session as SkyDriveStorageProviderSession; if (sdSession != null) { sdSession.SessionToken = token; } } return token; }
/// <summary> /// This method opens a session for the implemented storage provider based on an existing /// security token. /// </summary> /// <param name="configuration"></param> /// <param name="token"></param> /// <returns></returns> public ICloudStorageAccessToken Open(ICloudStorageConfiguration configuration, ICloudStorageAccessToken token) { // Verify the compatibility of the credentials if (!_Service.VerifyAccessTokenType(token)) throw new SharpBoxException(SharpBoxErrorCodes.ErrorInvalidCredentialsOrConfiguration); // create a new session _Session = _Service.CreateSession(token, configuration); // check the session if (_Session == null) throw new SharpBoxException(SharpBoxErrorCodes.ErrorInvalidCredentialsOrConfiguration); // return the accesstoken token return _Session.SessionToken; }
public static String RequestResourceByUrl(String url, Dictionary<String, String> parameters, IStorageProviderService service, IStorageProviderSession session, out int netErrorCode) { // cast the dropbox session var dropBoxSession = session as DropBoxStorageProviderSession; // instance the oAuthServer var svc = new OAuthService(); var urlhash = new KeyValuePair<string, string>(); if (!string.IsNullOrEmpty(url) && url.Contains("/metadata/")) { //Add the hash attr if any urlhash = SessionHashStorage.Get(session.SessionToken.ToString(), url, () => new KeyValuePair<string, string>()); } if (!string.IsNullOrEmpty(urlhash.Key) && !string.IsNullOrEmpty(urlhash.Value)) { //Add params if (parameters == null) parameters = new Dictionary<string, string>(); parameters.Add("hash", urlhash.Key); } // build the webrequest to protected resource var request = svc.CreateWebRequest(url, WebRequestMethodsEx.Http.Get, null, null, dropBoxSession.Context, (DropBoxToken) dropBoxSession.SessionToken, parameters); // get the error code WebException ex; // perform a simple webrequest using (Stream s = svc.PerformWebRequest(request, null, out netErrorCode, out ex, (code) => !string.IsNullOrEmpty(urlhash.Key) && !string.IsNullOrEmpty(urlhash.Value) && code == 304)/*to check code without downloading*/) { if (!string.IsNullOrEmpty(urlhash.Key) && !string.IsNullOrEmpty(urlhash.Value) && netErrorCode == 304) { return urlhash.Value; } if (s == null) return ""; // read the memory stream and convert to string var response = new StreamReader(s).ReadToEnd(); return response; } }
/// <summary> /// This method request information about a resource /// </summary> /// <param name="session"></param> /// <param name="Name"></param> /// <param name="parent"></param> /// <returns></returns> public override ICloudFileSystemEntry RequestResource(IStorageProviderSession session, string Name, ICloudDirectoryEntry parent) { // build url String uriString = GetResourceUrl(session, parent, null); uriString = PathHelper.Combine(uriString, Name); // get the data List<BaseFileEntry> childs = null; BaseFileEntry requestResource = RequestResourceFromWebDavShare(session, uriString, out childs); // check errors if (requestResource == null) return null; // rename the root if (Name.Equals("/")) requestResource.Name = "/"; // init parent child relation if (parent != null) { BaseDirectoryEntry parentDir = parent as BaseDirectoryEntry; parentDir.AddChild(requestResource); } // check if we have to add childs if (!(requestResource is BaseDirectoryEntry)) return requestResource; else { BaseDirectoryEntry requestedDir = requestResource as BaseDirectoryEntry; // add the childs foreach (BaseFileEntry child in childs) { requestedDir.AddChild(child); } } // go ahead return requestResource; }
public static String RequestResourceByUrl(String url, Dictionary <String, String> parameters, IStorageProviderService service, IStorageProviderSession session, out int netErrorCode) { // cast the dropbox session var dropBoxSession = session as DropBoxStorageProviderSession; // instance the oAuthServer var svc = new OAuthService(); var urlhash = new KeyValuePair <string, string>(); if (!string.IsNullOrEmpty(url) && url.Contains("/metadata/")) { //Add the hash attr if any urlhash = SessionHashStorage.Get(session.SessionToken.ToString(), url, () => new KeyValuePair <string, string>()); } if (!string.IsNullOrEmpty(urlhash.Key) && !string.IsNullOrEmpty(urlhash.Value)) { //Add params if (parameters == null) { parameters = new Dictionary <string, string>(); } parameters.Add("hash", urlhash.Key); } // build the webrequest to protected resource var request = svc.CreateWebRequest(url, WebRequestMethodsEx.Http.Get, null, null, dropBoxSession.Context, (DropBoxToken)dropBoxSession.SessionToken, parameters); // get the error code WebException ex; // perform a simple webrequest using (Stream s = svc.PerformWebRequest(request, null, out netErrorCode, out ex, (code) => !string.IsNullOrEmpty(urlhash.Key) && !string.IsNullOrEmpty(urlhash.Value) && code == 304) /*to check code without downloading*/) { if (!string.IsNullOrEmpty(urlhash.Key) && !string.IsNullOrEmpty(urlhash.Value) && netErrorCode == 304) { return(urlhash.Value); } if (s == null) { return(""); } // read the memory stream and convert to string var response = new StreamReader(s).ReadToEnd(); return(response); } }
private BaseFileEntry RequestResourceFromWebDavShare(IStorageProviderSession session, String resourceUrl, out List<BaseFileEntry> childs) { // get the credebtials ICredentials creds = session.SessionToken as ICredentials; // build the dav service DavService svc = new DavService(); // the result WebDavRequestResult RequestResult; try { // create the web request WebRequest request = svc.CreateWebRequestPROPFIND(resourceUrl, creds.GetCredential(null, null)); // get the response using (HttpWebResponse response = svc.GetWebResponse(request) as HttpWebResponse) { if (response.StatusCode == HttpStatusCode.Moved) { // get the new uri String newUri = response.Headers["Location"]; // close the response response.Close(); // redo it return RequestResourceFromWebDavShare(session, newUri, out childs); } else { // get the response stream using (Stream data = svc.GetResponseStream(response)) { if (data == null) { childs = null; return null; } // build the file entries RequestResult = WebDavRequestParser.CreateObjectsFromNetworkStream(data, resourceUrl, this, session, WebDavNameBaseFilterCallback); // close the stream data.Close(); } // close the response response.Close(); } } // get the request fileentry and fill the childs if (RequestResult.Self == null) { childs = null; return null; } // set the childs childs = RequestResult.Childs; // go ahead return RequestResult.Self; } catch (WebException) { childs = null; return null; } }
public override bool RenameResource(IStorageProviderSession session, ICloudFileSystemEntry fsentry, string newName) { var path = DropBoxResourceIDHelpers.GetResourcePath(fsentry).ReplaceLast(fsentry.Name, newName); return(MoveOrRenameItem(session as DropBoxStorageProviderSession, fsentry as BaseFileEntry, path)); }
private string GetCacheKey(IStorageProviderSession session, string nameOrId, ICloudFileSystemEntry parent) { return(GetResourceUrl(session, parent, nameOrId)); }
public ICloudFileSystemEntry RequestResource(IStorageProviderSession session, string name, ICloudDirectoryEntry parent) { return(FsCache.Get(GetSessionKey(session), GetCacheKey(session, name, parent), () => _service.RequestResource(session, name, parent))); }
private static IEnumerable <ICloudFileSystemEntry> RequestContentByUrl(IStorageProviderSession session, String url) { String json = SkyDriveRequestHelper.PerformRequest(session, url); return(SkyDriveJsonParser.ParseListOfEntries(session, json) ?? new List <ICloudFileSystemEntry>()); }
private static ICloudFileSystemEntry RequestResourseByUrl(IStorageProviderSession session, String url) { String json = SkyDriveRequestHelper.PerformRequest(session, url); return(SkyDriveJsonParser.ParseSingleEntry(session, json)); }
private String WebDavNameBaseFilterCallback(String targetUrl, IStorageProviderService service, IStorageProviderSession session, String NameBase) { // call our virtual method return(OnNameBase(targetUrl, service, session, NameBase)); }
protected virtual String OnNameBase(String targetUrl, IStorageProviderService service, IStorageProviderSession session, String NameBase) { return(NameBase); }
public override void CommitStreamOperation(IStorageProviderSession session, ICloudFileSystemEntry fileSystemEntry, nTransferDirection Direction, Stream NotDisposedStream) { }
private BaseFileEntry RequestResourceFromWebDavShare(IStorageProviderSession session, String resourceUrl, out List <BaseFileEntry> childs) { // get the credebtials ICredentials creds = session.SessionToken as ICredentials; // build the dav service DavService svc = new DavService(); // the result WebDavRequestResult RequestResult; try { // create the web request WebRequest request = svc.CreateWebRequestPROPFIND(resourceUrl, creds.GetCredential(null, null)); // get the response using (HttpWebResponse response = svc.GetWebResponse(request) as HttpWebResponse) { if (response.StatusCode == HttpStatusCode.Moved) { // get the new uri String newUri = response.Headers["Location"]; // close the response response.Close(); // redo it return(RequestResourceFromWebDavShare(session, newUri, out childs)); } else { // get the response stream using (Stream data = svc.GetResponseStream(response)) { if (data == null) { childs = null; return(null); } // build the file entries RequestResult = WebDavRequestParser.CreateObjectsFromNetworkStream(data, resourceUrl, this, session, WebDavNameBaseFilterCallback); // close the stream data.Close(); } // close the response response.Close(); } } // get the request fileentry and fill the childs if (RequestResult.Self == null) { childs = null; return(null); } // set the childs childs = RequestResult.Childs; // go ahead return(RequestResult.Self); } catch (WebException) { childs = null; return(null); } }
public Stream CreateUploadStream(IStorageProviderSession session, ICloudFileSystemEntry fileSystemEntry, long uploadSize) { return(_service.CreateUploadStream(session, fileSystemEntry, uploadSize)); }
public IResumableUploadSession CreateUploadSession(IStorageProviderSession session, ICloudFileSystemEntry fileSystemEntry, long bytesToTransfer) { return(_service.CreateUploadSession(session, fileSystemEntry, bytesToTransfer)); }
public void AbortUploadSession(IStorageProviderSession session, IResumableUploadSession uploadSession) { _service.AbortUploadSession(session, uploadSession); }
public static BaseFileEntry CreateObjectsFromJsonString(String jsonMessage, IStorageProviderService service, IStorageProviderSession session) { return(UpdateObjectFromJsonString(jsonMessage, null, service, session)); }
public bool CopyResource(IStorageProviderSession session, ICloudFileSystemEntry fsentry, ICloudDirectoryEntry newParent) { FsCache.Reset(GetSessionKey(session), string.Empty); return(_service.CopyResource(session, fsentry, newParent)); }
public static BaseFileEntry UpdateObjectFromJsonString(String jsonMessage, BaseFileEntry objectToUpdate, IStorageProviderService service, IStorageProviderSession session) { // verify if we have a directory or a file var jc = new JsonHelper(); if (!jc.ParseJsonMessage(jsonMessage)) { throw new SharpBoxException(SharpBoxErrorCodes.ErrorInvalidFileOrDirectoryName); } var isDir = jc.GetBooleanProperty("is_dir"); // create the entry BaseFileEntry dbentry; Boolean bEntryOk; if (isDir) { if (objectToUpdate == null) { dbentry = new BaseDirectoryEntry("Name", 0, DateTime.Now, service, session); } else { dbentry = objectToUpdate as BaseDirectoryEntry; } bEntryOk = BuildDirectyEntry(dbentry as BaseDirectoryEntry, jc, service, session); } else { if (objectToUpdate == null) { dbentry = new BaseFileEntry("Name", 0, DateTime.Now, service, session); } else { dbentry = objectToUpdate; } bEntryOk = BuildFileEntry(dbentry, jc); } // parse the childs and fill the entry as self if (!bEntryOk) { throw new SharpBoxException(SharpBoxErrorCodes.ErrorCouldNotContactStorageService); } // set the is deleted flag try { // try to read the is_deleted property dbentry.IsDeleted = jc.GetBooleanProperty("is_deleted"); } catch (Exception) { // the is_deleted proprty is missing (so it's not a deleted file or folder) dbentry.IsDeleted = false; } // return the child return(dbentry); }
public static void UpdateResourceByXml(IStorageProviderSession session, out ICloudFileSystemEntry resource, String xml) { var parsed = GoogleDocsXmlParser.ParseEntriesXml(session, xml).Single(); resource = parsed; }
public override void CommitStreamOperation(IStorageProviderSession session, ICloudFileSystemEntry entry, nTransferDirection direction, Stream stream) { }
private static Boolean BuildDirectyEntry(BaseDirectoryEntry dirEntry, JsonHelper jh, IStorageProviderService service, IStorageProviderSession session) { // build the file entry part if (!BuildFileEntry(dirEntry, jh)) return false; // now take the content var content = jh.GetListProperty("contents"); if (content.Count == 0) return true; // remove all childs dirEntry.ClearChilds(); // add the childs foreach (var jsonContent in content) { // parse the item var jc = new JsonHelper(); if (!jc.ParseJsonMessage(jsonContent)) continue; // check if we have a directory var isDir = jc.GetBooleanProperty("is_dir"); BaseFileEntry fentry; if (isDir) { fentry = new BaseDirectoryEntry("Name", 0, DateTime.Now, service, session); } else { fentry = new BaseFileEntry("Name", 0, DateTime.Now, service, session); } // build the file attributes BuildFileEntry(fentry, jc); // establish parent child realtionship dirEntry.AddChild(fentry); } // set the length dirEntry.Length = dirEntry.Count; // go ahead return true; }
public ICloudFileSystemEntry CreateResource(IStorageProviderSession session, string name, ICloudDirectoryEntry parent) { return(_service.CreateResource(session, name, parent)); }
protected virtual String OnNameBase(String targetUrl, IStorageProviderService service, IStorageProviderSession session, String NameBase) { return NameBase; }
private static string GetSessionKey(IStorageProviderSession session) { return(session.GetType().Name + " " + session.SessionToken); }
public void UploadChunk(IStorageProviderSession session, IResumableUploadSession uploadSession, Stream stream, long chunkLength) { _service.UploadChunk(session, uploadSession, stream, chunkLength); }
private bool CopyResource(IStorageProviderSession session, ICloudFileSystemEntry fsentry, String newTargetUrl) { var config = session.ServiceConfiguration as WebDavConfiguration; var creds = session.SessionToken as ICredentials; var uriString = PathHelper.Combine(config.ServiceLocator.ToString(), GenericHelper.GetResourcePath(fsentry)); var uri = new Uri(uriString); var uriTarget = new Uri(newTargetUrl); var errorCode = new DavService().PerformCopyWebRequest(uri.ToString(), uriTarget.ToString(), creds.GetCredential(null, null)); return errorCode == HttpStatusCode.Created || errorCode == HttpStatusCode.NoContent; }
public BaseDirectoryEntry(String Name, long Length, DateTime Modified, IStorageProviderService service, IStorageProviderSession session) : base(Name, Length, Modified, service, session) { }
private String WebDavNameBaseFilterCallback(String targetUrl, IStorageProviderService service, IStorageProviderSession session, String NameBase) { // call our virtual method return OnNameBase(targetUrl, service, session, NameBase); }
public bool DeleteResource(IStorageProviderSession session, ICloudFileSystemEntry entry) { FsCache.Reset(GetSessionKey(session), string.Empty); return(_service.DeleteResource(session, entry)); }
public CloudStorageLimits GetLimits(IStorageProviderSession session) { return(_service.GetLimits(session)); }
public override ICloudFileSystemEntry RequestResource(IStorageProviderSession session, String name, ICloudDirectoryEntry parent) { /* In this method name could be either requested resource name or it's ID. * In first case just refresh the parent and then search child with an appropriate. * In second case it does not matter if parent is null or not a parent because we use only resource ID. */ if (SkyDriveHelpers.HasResourceID(name) || name.Equals("/") && parent == null) //If request by ID or root folder requested { var id = SkyDriveHelpers.GetResourceID(name); var uri = id != String.Empty ? String.Format("{0}/{1}", SkyDriveConstants.BaseAccessUrl, id) : SkyDriveConstants.RootAccessUrl; if (SkyDriveHelpers.IsFolderID(id)) { var contents = new List <ICloudFileSystemEntry>(); /*var completeContent = new AutoResetEvent(false); * ThreadPool.QueueUserWorkItem(state => * { * contents.AddRange(RequestContentByUrl(session, uri + "/files")); * ((AutoResetEvent) state).Set(); * }, completeContent); * * var completeEntry = new AutoResetEvent(false); * ThreadPool.QueueUserWorkItem(state => * { * entry = RequestResourseByUrl(session, uri) as BaseDirectoryEntry; * ((AutoResetEvent) state).Set(); * }, completeEntry); * * WaitHandle.WaitAll(new WaitHandle[] {completeContent, completeEntry});*/ var entry = RequestResourseByUrl(session, uri) as BaseDirectoryEntry; contents.AddRange(RequestContentByUrl(session, uri + "/files")); if (entry != null && contents.Any()) { entry.AddChilds(contents.Cast <BaseFileEntry>()); } return(entry); } return(RequestResourseByUrl(session, uri)); } else { String uri; if (SkyDriveHelpers.HasParentID(name)) { uri = String.Format(SkyDriveConstants.FilesAccessUrlFormat, SkyDriveHelpers.GetParentID(name)); } else if (parent != null) { uri = String.Format(SkyDriveConstants.FilesAccessUrlFormat, parent.GetPropertyValue(SkyDriveConstants.InnerIDKey)); } else { uri = SkyDriveConstants.RootAccessUrl + "/files"; } name = Path.GetFileName(name); var entry = RequestContentByUrl(session, uri).FirstOrDefault(x => x.Name.Equals(name)); return(entry); } }
public bool RenameResource(IStorageProviderSession session, ICloudFileSystemEntry fsentry, string newName) { FsCache.Reset(GetSessionKey(session), string.Empty); return(_service.RenameResource(session, fsentry, newName)); }
public static String RequestResourceByUrl(String url, IStorageProviderService service, IStorageProviderSession session, out int netErrorCode) { return RequestResourceByUrl(url, null, service, session, out netErrorCode); }
public static String RequestResourceByUrl(String url, IStorageProviderService service, IStorageProviderSession session, out int netErrorCode) { return(RequestResourceByUrl(url, null, service, session, out netErrorCode)); }
public static void Addhash(string url, string hash, string response, IStorageProviderSession session) { SessionHashStorage.Add(session.SessionToken.ToString(), url, new KeyValuePair<string, string>(hash, response)); }
private static Boolean BuildDirectyEntry(BaseDirectoryEntry dirEntry, JsonHelper jh, IStorageProviderService service, IStorageProviderSession session) { // build the file entry part if (!BuildFileEntry(dirEntry, jh)) { return(false); } // now take the content var content = jh.GetListProperty("contents"); if (content.Count == 0) { return(true); } // remove all childs dirEntry.ClearChilds(); // add the childs foreach (var jsonContent in content) { // parse the item var jc = new JsonHelper(); if (!jc.ParseJsonMessage(jsonContent)) { continue; } // check if we have a directory var isDir = jc.GetBooleanProperty("is_dir"); BaseFileEntry fentry; if (isDir) { fentry = new BaseDirectoryEntry("Name", 0, DateTime.Now, service, session); } else { fentry = new BaseFileEntry("Name", 0, DateTime.Now, service, session); } // build the file attributes BuildFileEntry(fentry, jc); // establish parent child realtionship dirEntry.AddChild(fentry); } // set the length dirEntry.Length = dirEntry.Count; // go ahead return(true); }
public static BaseFileEntry CreateObjectsFromJsonString(String jsonMessage, IStorageProviderService service, IStorageProviderSession session) { return UpdateObjectFromJsonString(jsonMessage, null, service, session); }
public static void Addhash(string url, string hash, string response, IStorageProviderSession session) { SessionHashStorage.Add(session.SessionToken.ToString(), url, new KeyValuePair <string, string>(hash, response)); }
public BaseFileEntryDataTransfer(ICloudFileSystemEntry fileSystemEntry, IStorageProviderService service, IStorageProviderSession session) { _fsEntry = fileSystemEntry; _session = session; _service = service; }
public void CloseSession(IStorageProviderSession session) { FsCache.Reset(GetSessionKey(session), string.Empty); _service.CloseSession(session); }