Exemplo n.º 1
0
        public override UploadResult Upload(Stream stream, string fileName)
        {
            if (!CheckAuthorization())
            {
                return(null);
            }

            UploadResult result;
            string       sessionUrl = CreateSession(fileName);
            long         position   = 0;

            do
            {
                result = SendRequestFileRange(sessionUrl, stream, fileName, position, MaxSegmentSize);

                if (result.IsSuccess)
                {
                    position += MaxSegmentSize;
                }
                else
                {
                    SendRequest(HttpMethod.DELETE, sessionUrl);
                    break;
                }
            }while (position < stream.Length);

            if (result.IsSuccess)
            {
                OneDriveFileInfo uploadInfo = JsonConvert.DeserializeObject <OneDriveFileInfo>(result.Response);

                if (AutoCreateShareableLink)
                {
                    AllowReportProgress = false;

                    result.URL = CreateShareableLink(uploadInfo.id);
                }
                else
                {
                    result.URL = uploadInfo.webUrl;
                }
            }

            return(result);
        }
Exemplo n.º 2
0
        public override UploadResult Upload(Stream stream, string fileName)
        {
            if (!CheckAuthorization())
            {
                return(null);
            }

            Dictionary <string, string> args = new Dictionary <string, string>();

            args.Add("access_token", AuthInfo.Token.access_token);
            args.Add("overwrite", "true");
            args.Add("downsize_photo_uploads", "false");

            string folderPath;

            if (!string.IsNullOrEmpty(FolderID))
            {
                folderPath = URLHelpers.CombineURL(FolderID, "files");
            }
            else
            {
                folderPath = "me/skydrive/files";
            }

            string url = CreateQuery(URLHelpers.CombineURL("https://apis.live.net/v5.0", folderPath), args);

            UploadResult result = UploadData(stream, url, fileName);

            if (result.IsSuccess)
            {
                OneDriveFileInfo uploadInfo = JsonConvert.DeserializeObject <OneDriveFileInfo>(result.Response);

                if (AutoCreateShareableLink)
                {
                    result.URL = CreateShareableLink(uploadInfo.id);
                }
                else
                {
                    result.URL = uploadInfo.source;
                }
            }

            return(result);
        }
 public void OneDriveListFolders(OneDriveFileInfo fileEntry, TreeNode tnParent)
 {
     Application.DoEvents();
     OneDrive oneDrive = new OneDrive(Config.OneDriveOAuth2Info);
     OneDrivePathInfo oneDrivePathInfo = oneDrive.GetPathInfo(fileEntry.id);
     tnParent.Nodes.Clear();
     foreach (OneDriveFileInfo folder in oneDrivePathInfo.data.Where(x => x.id.StartsWith("folder.")))
     {
         OneDriveAddFolder(folder, tnParent);
     }
 }
        private void OneDriveAddFolder(OneDriveFileInfo folder, TreeNode tnParent)
        {
            TreeNode tn = new TreeNode(folder.name);
            tn.Tag = folder;
            tn.Nodes.Add(new TreeNode(Resources.UploadersConfigForm_OneDriveAddFolder_Querying_folders___));

            if (tnParent != null)
            {
                tnParent.Nodes.Add(tn);
            }
            else
            {
                tvOneDrive.Nodes.Add(tn);
            }
        }