示例#1
0
        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;
        }
示例#2
0
        public void CommitUploadStream(params object[] arg)
        {
            // convert the args
            OAuthService   svc             = arg[0] as OAuthService;
            HttpWebRequest uploadRequest   = arg[1] as HttpWebRequest;
            long           uploadSize      = (long)arg[2];
            BaseFileEntry  fileSystemEntry = arg[3] as BaseFileEntry;

#if !WINDOWS_PHONE && !MONODROID
            WebRequestStream requestStream = arg[4] as WebRequestStream;

            // check if all data was written into stream
            if (requestStream.WrittenBytes != uploadRequest.ContentLength)
            {
                // nothing todo request was aborted
                return;
            }
#endif

            // perform the request
            int          code;
            WebException e;
            svc.PerformWebRequest(uploadRequest, null, out code, out e);

            // check the ret value
            if (code != (int)HttpStatusCode.OK)
            {
                SharpBoxException.ThrowSharpBoxExceptionBasedOnHttpErrorCode(uploadRequest, (HttpStatusCode)code, e);
            }

            // set the length
            fileSystemEntry.Length = uploadSize;
        }
示例#3
0
        protected static PluginException TranslateSharpboxException(SharpBoxException exception)
        {
            if (exception == null)
            {
                throw new ArgumentNullException("exception");
            }

            PluginErrorCodes errorCode;

            switch (exception.ErrorCode)
            {
            case SharpBoxErrorCodes.ErrorCouldNotContactStorageService:
                errorCode = PluginErrorCodes.CouldNotContactStorageService;
                break;

            case SharpBoxErrorCodes.ErrorCouldNotRetrieveDirectoryList:
                errorCode = PluginErrorCodes.CouldNotRetrieveDirectoryList;
                break;

            case SharpBoxErrorCodes.ErrorCreateOperationFailed:
                errorCode = PluginErrorCodes.CreateOperationFailed;
                break;

            case SharpBoxErrorCodes.ErrorFileNotFound:
                errorCode = PluginErrorCodes.FileNotFound;
                break;

            case SharpBoxErrorCodes.ErrorInsufficientDiskSpace:
                errorCode = PluginErrorCodes.InsufficientDiskSpace;
                break;

            case SharpBoxErrorCodes.ErrorInvalidCredentialsOrConfiguration:
                errorCode = PluginErrorCodes.InvalidCredentialsOrConfiguration;
                break;

            case SharpBoxErrorCodes.ErrorInvalidFileOrDirectoryName:
                errorCode = PluginErrorCodes.InvalidFileOrDirectoryName;
                break;

            case SharpBoxErrorCodes.ErrorTransferAbortedManually:
                errorCode = PluginErrorCodes.TransferAbortedManually;
                break;

            default:
                errorCode = PluginErrorCodes.PluginError;
                break;
            }

            return(new PluginException(errorCode, "Error", exception));
        }
        public void CommitUploadStream(params object[] arg)
        {
            // convert the args
            var svc             = arg[0] as OAuthService;
            var uploadRequest   = arg[1] as HttpWebRequest;
            var uploadSize      = (long)arg[2];
            var fileSystemEntry = arg[3] as BaseFileEntry;

#if !WINDOWS_PHONE && !MONODROID
            var requestStream = arg[4] as WebRequestStream;

            // check if all data was written into stream
            if (requestStream.WrittenBytes != uploadRequest.ContentLength)
            {
                // nothing todo request was aborted
                return;
            }
#endif

            // perform the request
            int          code;
            WebException e;
            svc.PerformWebRequest(uploadRequest, null, out code, out e);

            // check the ret value
            if (code != (int)HttpStatusCode.OK)
            {
                SharpBoxException.ThrowSharpBoxExceptionBasedOnHttpErrorCode(uploadRequest, (HttpStatusCode)code, e);
            }

            if (fileSystemEntry != null)
            {
                fileSystemEntry.Length = uploadSize;
                fileSystemEntry.Id     = fileSystemEntry.ParentID != "/" ? fileSystemEntry.ParentID + "/" + fileSystemEntry.Name : fileSystemEntry.Name;

                var parent = fileSystemEntry.Parent as BaseDirectoryEntry;
                if (parent != null)
                {
                    parent.RemoveChildById(fileSystemEntry.Name);
                    parent.AddChild(fileSystemEntry);
                }
            }
        }
示例#5
0
        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 rUploadSession = uploadSession as ResumableUploadSession;
                rUploadSession.FileId = rUploadSession.ParentId != "/" ? rUploadSession.ParentId + "/" + rUploadSession.FileName : rUploadSession.FileName;


                //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;
            }
        }