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;
            }
        }
        public void CommitUploadSession(IStorageProviderSession session, IResumableUploadSession uploadSession)
        {
            if (uploadSession.Status == ResumableUploadSessionStatus.Started)
            {
                var requestService = new OAuthService();
                var request = requestService.CreateWebRequest(GetCommitUploadSessionUrl(session, uploadSession),
                                                              "POST",
                                                              null,
                                                              null,
                                                              ((DropBoxStorageProviderSession)session).Context,
                                                              (DropBoxToken)session.SessionToken,
                                                              new Dictionary<string, string> {{"upload_id", uploadSession.GetItem<string>("UploadId")}});

                int httpStatusCode;
                WebException httpException;
                requestService.PerformWebRequest(request, null, out httpStatusCode, out httpException);

                if (httpStatusCode != (int)HttpStatusCode.OK)
                    SharpBoxException.ThrowSharpBoxExceptionBasedOnHttpErrorCode((HttpWebRequest)request, (HttpStatusCode)httpStatusCode, httpException);

                var file = (BaseFileEntry)uploadSession.File;
                file.Length = uploadSession.BytesToTransfer;
                file.Id = file.ParentID != "/" ? file.ParentID + "/" + file.Name : file.Name;

                var parent = file.Parent as BaseDirectoryEntry;
                if (parent != null)
                {
                    parent.RemoveChildById(file.Name);
                    parent.AddChild(file);
                }

                ((ResumableUploadSession)uploadSession).Status = ResumableUploadSessionStatus.Completed;
            }
        }
        public override Stream CreateDownloadStream(IStorageProviderSession session, ICloudFileSystemEntry fileSystemEntry)
        {
            // build the url 
            var url = GetDownloadFileUrlInternal(session, fileSystemEntry);

            // build the service
            var svc = new OAuthService();

            // get the dropbox session
            var dropBoxSession = session as DropBoxStorageProviderSession;

            // create webrequst 
            var requestProtected = svc.CreateWebRequest(url, WebRequestMethodsEx.Http.Get, null, null, dropBoxSession.Context, (DropBoxToken) dropBoxSession.SessionToken, null);

            // get the response
            var response = svc.GetWebResponse(requestProtected);

            // get the data stream
            var orgStream = svc.GetResponseStream(response);

            // build the download stream
            var dStream = new BaseFileEntryDownloadStream(orgStream, fileSystemEntry);

            // put the disposable on the stack
            dStream._DisposableObjects.Push(response);

            // go ahead
            return dStream;
        }