public async Task CreateFolderSharedLink_ValidResponse_ValidFolder()
        {
            /*** Arrange ***/
            _handler.Setup(h => h.ExecuteAsync <BoxFolder>(It.IsAny <IBoxRequest>()))
            .Returns(() => Task.FromResult <IBoxResponse <BoxFolder> >(new BoxResponse <BoxFolder>()
            {
                Status        = ResponseStatus.Success,
                ContentString = "{ \"type\": \"folder\", \"id\": \"11446498\", \"sequence_id\": \"1\", \"etag\": \"1\", \"name\": \"Pictures\", \"created_at\": \"2012-12-12T10:53:43-08:00\", \"modified_at\": \"2012-12-12T11:15:04-08:00\", \"description\": \"Some pictures I took\", \"size\": 629644, \"path_collection\": { \"total_count\": 1, \"entries\": [ { \"type\": \"folder\", \"id\": \"0\", \"sequence_id\": null, \"etag\": null, \"name\": \"All Files\" } ] }, \"created_by\": { \"type\": \"user\", \"id\": \"17738362\", \"name\": \"sean rose\", \"login\": \"[email protected]\" }, \"modified_by\": { \"type\": \"user\", \"id\": \"17738362\", \"name\": \"sean rose\", \"login\": \"[email protected]\" }, \"owned_by\": { \"type\": \"user\", \"id\": \"17738362\", \"name\": \"sean rose\", \"login\": \"[email protected]\" }, \"shared_link\": { \"url\": \"https://www.box.com/s/vspke7y05sb214wjokpk\", \"download_url\": \"https://www.box.com/shared/static/vspke7y05sb214wjokpk\", \"vanity_url\": null, \"is_password_enabled\": false, \"unshared_at\": null, \"download_count\": 0, \"preview_count\": 0, \"access\": \"open\", \"permissions\": { \"can_download\": true, \"can_preview\": true } }, \"folder_upload_email\": { \"access\": \"open\", \"email\": \"[email protected]\" }, \"parent\": { \"type\": \"folder\", \"id\": \"0\", \"sequence_id\": null, \"etag\": null, \"name\": \"All Files\" }, \"item_status\": \"active\", \"item_collection\": { \"total_count\": 1, \"entries\": [ { \"type\": \"file\", \"id\": \"5000948880\", \"sequence_id\": \"3\", \"etag\": \"3\", \"sha1\": \"134b65991ed521fcfe4724b7d814ab8ded5185dc\", \"name\": \"tigers.jpeg\" } ], \"offset\": 0, \"limit\": 100 } }"
            }));

            /*** Act ***/
            BoxSharedLinkRequest sharedLink = new BoxSharedLinkRequest()
            {
                Access = BoxSharedLinkAccessType.collaborators
            };

            BoxFolder f = await _foldersManager.CreateSharedLinkAsync("0", sharedLink);

            /*** Assert ***/
            Assert.AreEqual("folder", f.Type);
            Assert.AreEqual("11446498", f.Id);
            Assert.AreEqual("1", f.SequenceId);
            Assert.AreEqual("1", f.ETag);
            Assert.AreEqual("Pictures", f.Name);
        }
Exemplo n.º 2
0
        public async Task createSharedLink()
        {
            try
            {
                var items = await client.FoldersManager.GetFolderItemsAsync("0", 500, fields : new string[]
                                                                            { "id", "name" });

                foreach (var item in items.Entries)
                {
                    Console.WriteLine(item.Id + item.Name);
                }

                BoxSharedLinkRequest request = new BoxSharedLinkRequest()
                {
                    Access = BoxSharedLinkAccessType.open,
                };
                var link = await client.FoldersManager.CreateSharedLinkAsync("30787703220", request);

                var link2 = await client.FilesManager.CreateSharedLinkAsync("707877453", request);

                Console.WriteLine(link.SharedLink);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
        public async Task CreateWebLinkSharedLink_ValidResponse_ValidFile()
        {
            /*** Arrange ***/
            string      responseString = "{ \"type\": \"web_link\", \"id\": \"5000948880\", \"sequence_id\": \"3\", \"etag\": \"3\", \"sha1\": \"134b65991ed521fcfe4724b7d814ab8ded5185dc\", \"name\": \"tigers.jpeg\", \"description\": \"a picture of tigers\", \"size\": 629644, \"path_collection\": { \"total_count\": 2, \"entries\": [ { \"type\": \"folder\", \"id\": \"0\", \"sequence_id\": null, \"etag\": null, \"name\": \"All Files\" }, { \"type\": \"folder\", \"id\": \"11446498\", \"sequence_id\": \"1\", \"etag\": \"1\", \"name\": \"Pictures\" } ] }, \"created_at\": \"2012-12-12T10:55:30-08:00\", \"modified_at\": \"2012-12-12T11:04:26-08:00\", \"created_by\": { \"type\": \"user\", \"id\": \"17738362\", \"name\": \"sean rose\", \"login\": \"[email protected]\" }, \"modified_by\": { \"type\": \"user\", \"id\": \"17738362\", \"name\": \"sean rose\", \"login\": \"[email protected]\" }, \"owned_by\": { \"type\": \"user\", \"id\": \"17738362\", \"name\": \"sean rose\", \"login\": \"[email protected]\" }, \"shared_link\": { \"url\": \"https://www.box.com/s/rh935iit6ewrmw0unyul\", \"download_url\": \"https://www.box.com/shared/static/rh935iit6ewrmw0unyul.jpeg\", \"vanity_url\": null, \"is_password_enabled\": false, \"unshared_at\": null, \"download_count\": 0, \"preview_count\": 0, \"access\": \"open\", \"permissions\": { \"can_download\": true, \"can_preview\": true } }, \"parent\": { \"type\": \"folder\", \"id\": \"11446498\", \"sequence_id\": \"1\", \"etag\": \"1\", \"name\": \"Pictures\" }, \"item_status\": \"active\" }";
            IBoxRequest boxRequest     = null;
            Uri         webLinksUri    = new Uri(Constants.WebLinksEndpointString);

            Config.SetupGet(x => x.WebLinksEndpointUri).Returns(webLinksUri);
            Handler.Setup(h => h.ExecuteAsync <BoxWebLink>(It.IsAny <IBoxRequest>()))
            .Returns(Task.FromResult <IBoxResponse <BoxWebLink> >(new BoxResponse <BoxWebLink>()
            {
                Status        = ResponseStatus.Success,
                ContentString = responseString
            }))
            .Callback <IBoxRequest>(r => boxRequest = r);

            BoxSharedLinkRequest sharedLink = new BoxSharedLinkRequest()
            {
                Access = BoxSharedLinkAccessType.collaborators
            };

            /*** Act ***/
            BoxWebLink w = await _webLinkManager.CreateSharedLinkAsync("12345", sharedLink);

            /*** Assert ***/
            Assert.AreEqual(new Uri("https://api.box.com/2.0/web_links/12345"), boxRequest.AbsoluteUri);
            Assert.AreEqual(RequestMethod.Put, boxRequest.Method);
            Assert.AreEqual("{\"shared_link\":{\"access\":\"collaborators\"}}", boxRequest.Payload);

            Assert.AreEqual("5000948880", w.Id);
            Assert.AreEqual("3", w.SequenceId);
            Assert.AreEqual("3", w.ETag);
            Assert.AreEqual("https://www.box.com/s/rh935iit6ewrmw0unyul", w.SharedLink.Url);
        }
        public async Task CreateFileSharedLink_ValidResponse_ValidFile()
        {
            /*** Arrange ***/
            string responseString = "{ \"type\": \"file\", \"id\": \"5000948880\", \"sequence_id\": \"3\", \"etag\": \"3\", \"sha1\": \"134b65991ed521fcfe4724b7d814ab8ded5185dc\", \"name\": \"tigers.jpeg\", \"description\": \"a picture of tigers\", \"size\": 629644, \"path_collection\": { \"total_count\": 2, \"entries\": [ { \"type\": \"folder\", \"id\": \"0\", \"sequence_id\": null, \"etag\": null, \"name\": \"All Files\" }, { \"type\": \"folder\", \"id\": \"11446498\", \"sequence_id\": \"1\", \"etag\": \"1\", \"name\": \"Pictures\" } ] }, \"created_at\": \"2012-12-12T10:55:30-08:00\", \"modified_at\": \"2012-12-12T11:04:26-08:00\", \"created_by\": { \"type\": \"user\", \"id\": \"17738362\", \"name\": \"sean rose\", \"login\": \"[email protected]\" }, \"modified_by\": { \"type\": \"user\", \"id\": \"17738362\", \"name\": \"sean rose\", \"login\": \"[email protected]\" }, \"owned_by\": { \"type\": \"user\", \"id\": \"17738362\", \"name\": \"sean rose\", \"login\": \"[email protected]\" }, \"shared_link\": { \"url\": \"https://www.box.com/s/rh935iit6ewrmw0unyul\", \"download_url\": \"https://www.box.com/shared/static/rh935iit6ewrmw0unyul.jpeg\", \"vanity_url\": null, \"is_password_enabled\": false, \"unshared_at\": null, \"download_count\": 0, \"preview_count\": 0, \"access\": \"open\", \"permissions\": { \"can_download\": true, \"can_preview\": true } }, \"parent\": { \"type\": \"folder\", \"id\": \"11446498\", \"sequence_id\": \"1\", \"etag\": \"1\", \"name\": \"Pictures\" }, \"item_status\": \"active\" }";

            _handler.Setup(h => h.ExecuteAsync <BoxFile>(It.IsAny <IBoxRequest>()))
            .Returns(Task.FromResult <IBoxResponse <BoxFile> >(new BoxResponse <BoxFile>()
            {
                Status        = ResponseStatus.Success,
                ContentString = responseString
            }));

            BoxSharedLinkRequest sharedLink = new BoxSharedLinkRequest()
            {
                Access = BoxSharedLinkAccessType.collaborators
            };

            /*** Act ***/
            BoxFile f = await _filesManager.CreateSharedLinkAsync("0", sharedLink);

            /*** Assert ***/
            Assert.AreEqual("5000948880", f.Id);
            Assert.AreEqual("3", f.SequenceId);
            Assert.AreEqual("3", f.ETag);
            Assert.AreEqual("134b65991ed521fcfe4724b7d814ab8ded5185dc", f.Sha1);
            Assert.AreEqual("file", f.Type);
            Assert.AreEqual("sean rose", f.CreatedBy.Name);
            Assert.AreEqual("*****@*****.**", f.CreatedBy.Login);
            Assert.AreEqual("user", f.CreatedBy.Type);
            Assert.AreEqual("17738362", f.CreatedBy.Id);
        }
Exemplo n.º 5
0
        public async Task GetSharedLink_ValidRequest_ValidSharedLink()
        {
            BoxSharedLinkRequest linkReq = new BoxSharedLinkRequest()
            {
                Access = BoxSharedLinkAccessType.open
            };

            BoxFile fileLink = await _client.FilesManager.CreateSharedLinkAsync("11999421592", linkReq);

            Assert.AreEqual(BoxSharedLinkAccessType.open, fileLink.SharedLink.Access);
        }
Exemplo n.º 6
0
        public async Task GetSharedLink_ValidRequest_ValidSharedLink()
        {
            string imageFileId1 = "16894947279";

            BoxSharedLinkRequest linkReq = new BoxSharedLinkRequest()
            {
                Access = BoxSharedLinkAccessType.open
            };

            BoxFile fileLink = await _client.FilesManager.CreateSharedLinkAsync(imageFileId1, linkReq);

            Assert.AreEqual(BoxSharedLinkAccessType.open, fileLink.SharedLink.Access);
        }
        public async Task CreateSharedLinkAsync_ForExistingFolder_ShouldCreateSharedLinkToThatFolder()
        {
            var createdFolder = await CreateFolder(FolderId);

            var sharedLinkReq = new BoxSharedLinkRequest()
            {
                Access = BoxSharedLinkAccessType.open
            };

            BoxFolder folder = await UserClient.FoldersManager.CreateSharedLinkAsync(createdFolder.Id, sharedLinkReq);

            Assert.AreEqual(BoxSharedLinkAccessType.open, folder.SharedLink.Access);
        }
        public async Task DeleteSharedLinkAsync_ForExistingSharedLink_ShouldDeleteThisSharedLink()
        {
            var createdFolder = await CreateFolder(FolderId);

            var sharedLinkReq = new BoxSharedLinkRequest()
            {
                Access = BoxSharedLinkAccessType.open
            };
            await UserClient.FoldersManager.CreateSharedLinkAsync(createdFolder.Id, sharedLinkReq);

            var sharedLink = await UserClient.FoldersManager.DeleteSharedLinkAsync(createdFolder.Id);

            Assert.IsNull(sharedLink.SharedLink);
        }
        /// <summary>
        /// Used to create a shared link for this particular folder. In order to get default shared link status, set it to an empty access level.
        /// To delete a shared link use the DeleteSharedLinkAsync method of this class.
        /// </summary>
        /// <param name="id">Id of the folder to create shared link for</param>
        /// <param name="sharedLinkRequest">Shared link request object</param>
        /// <param name="fields">Attribute(s) to include in the response</param>
        /// <returns>A full folder object is returned if the ID is valid and if the shared link is created.</returns>
        public async Task <BoxFolder> CreateSharedLinkAsync(string id, BoxSharedLinkRequest sharedLinkRequest, List <string> fields = null)
        {
            id.ThrowIfNullOrWhiteSpace("id");

            BoxRequest request = new BoxRequest(_config.FoldersEndpointUri, id)
                                 .Method(RequestMethod.Put)
                                 .Param(ParamFields, fields)
                                 .Payload(_converter.Serialize(new BoxItemRequest()
            {
                SharedLink = sharedLinkRequest
            }));

            IBoxResponse <BoxFolder> response = await ToResponseAsync <BoxFolder>(request).ConfigureAwait(false);

            return(response.ResponseObject);
        }
        public async Task SharedItemsAsync_ForSharedFolder_ShouldReturnSharedFolder()
        {
            var folder = await CreateFolder();

            var password      = "******";
            var sharedLinkReq = new BoxSharedLinkRequest()
            {
                Access   = BoxSharedLinkAccessType.open,
                Password = password
            };
            var folderWithLink = await UserClient.FoldersManager.CreateSharedLinkAsync(folder.Id, sharedLinkReq);

            var sharedItem = await UserClient.SharedItemsManager.SharedItemsAsync(folderWithLink.SharedLink.Url, password);

            Assert.AreEqual(folderWithLink.Id, sharedItem.Id);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Used to create a shared link for this particular file. Please see here for more information on the permissions available for shared links.
        /// </summary>
        /// <param name="id"></param>
        /// <param name="sharedLinkRequest"></param>
        /// <returns></returns>
        public async Task <BoxFile> CreateSharedLinkAsync(string id, BoxSharedLinkRequest sharedLinkRequest, List <string> fields = null)
        {
            id.ThrowIfNullOrWhiteSpace("id");
            if (!sharedLinkRequest.ThrowIfNull("sharedLinkRequest").Access.HasValue)
            {
                throw new ArgumentNullException("sharedLink.Access");
            }

            BoxRequest request = new BoxRequest(_config.FilesEndpointUri, id)
                                 .Method(RequestMethod.Post)
                                 .Param(ParamFields, fields)
                                 .Payload(_converter.Serialize(new BoxItemRequest()
            {
                SharedLink = sharedLinkRequest
            }));

            IBoxResponse <BoxFile> response = await ToResponseAsync <BoxFile>(request).ConfigureAwait(false);

            return(response.ResponseObject);
        }
Exemplo n.º 12
0
        public async Task <JsonResult> GetSharedLink(string type, string id)
        {
            var client  = Initialise();
            var request = new BoxSharedLinkRequest()
            {
                Access = BoxSharedLinkAccessType.open
            };

            if (type == "file")
            {
                BoxFile file = await client.FilesManager.CreateSharedLinkAsync(id, request);

                _logger.LogInformation("Getting Shared link for File =>" + id);

                //Logging action to Database
                Task.Run(() => { RecordFileAction(client, id, "Share Link"); });

                return(Json(file.SharedLink.Url));
            }
            var folder = await client.FoldersManager.CreateSharedLinkAsync(id, request);

            _logger.LogInformation("Getting Shared link for Folder =>" + id);
            return(Json(folder.SharedLink.Url));
        }
Exemplo n.º 13
0
        private async Task RunCreate()
        {
            if (!string.IsNullOrEmpty(_path.Value()))
            {
                var json = false;
                if (base._json.HasValue() || this._home.GetBoxHomeSettings().GetOutputJsonSetting())
                {
                    json = true;
                }
                await base.ProcessSharedLinksFromFile(_id.Value, _path.Value(), base._t, json : json);

                return;
            }
            base.CheckForId(this._id.Value, this._app);
            if (base._t == BoxType.enterprise)
            {
                if (this._type.Value == String.Empty || (this._type.Value != SharedLinkSubCommandBase.BOX_FILE && this._type.Value != SharedLinkSubCommandBase.BOX_FOLDER))
                {
                    _app.ShowHelp();
                    throw new Exception("You must provide an item type for this command: choose file or folder");
                }
            }
            var boxClient         = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value());
            var sharedLinkRequest = new BoxSharedLinkRequest();

            if (this._access.HasValue())
            {
                sharedLinkRequest.Access = base.ResolveSharedLinkAccessType(this._access.Value());
            }
            if (this._password.HasValue())
            {
                sharedLinkRequest.Password = this._password.Value();
            }
            if (this._unsharedAt.HasValue())
            {
                sharedLinkRequest.UnsharedAt = GeneralUtilities.GetDateTimeFromString(this._unsharedAt.Value());
            }
            if (this._canDownload.HasValue())
            {
                sharedLinkRequest.Permissions          = new BoxPermissionsRequest();
                sharedLinkRequest.Permissions.Download = true;
            }
            if (base._t == BoxType.file || (this._type != null && this._type.Value == SharedLinkSubCommandBase.BOX_FILE))
            {
                var result = await boxClient.FilesManager.CreateSharedLinkAsync(this._id.Value, sharedLinkRequest);

                if (base._json.HasValue() || this._home.GetBoxHomeSettings().GetOutputJsonSetting())
                {
                    base.OutputJson(result);
                    return;
                }
                Reporter.WriteSuccess("Created shared link:");
                base.PrintSharedLink(result.SharedLink);
            }
            else if (base._t == BoxType.folder || (this._type != null && this._type.Value == SharedLinkSubCommandBase.BOX_FOLDER))
            {
                var result = await boxClient.FoldersManager.CreateSharedLinkAsync(this._id.Value, sharedLinkRequest);

                if (base._json.HasValue() || this._home.GetBoxHomeSettings().GetOutputJsonSetting())
                {
                    base.OutputJson(result);
                    return;
                }
                Reporter.WriteSuccess("Created shared link:");
                base.PrintSharedLink(result.SharedLink);
            }
            else
            {
                throw new Exception("Box type not supported for this command.");
            }
        }
Exemplo n.º 14
0
        public async Task FileWorkflow_ValidRequest_ValidResponse()
        {
            //file Ids of the two files to download
            string imageFileId1 = "16894947279";
            string imageFileId2 = "16894946307";

            // paths to store the two downloaded files
            var dlPath1 = string.Format(GetSaveFolderPath(), "thumbnail1.png");
            var dlPath2 = string.Format(GetSaveFolderPath(), "thumbnail2.png");

            //download 2 files
            using (FileStream fs = new FileStream(dlPath1, FileMode.OpenOrCreate))
            {
                Stream stream = await _client.FilesManager.DownloadStreamAsync(imageFileId1);

                await stream.CopyToAsync(fs);
            }

            using (FileStream fs = new FileStream(dlPath2, FileMode.OpenOrCreate))
            {
                Stream stream = await _client.FilesManager.DownloadStreamAsync(imageFileId2);

                await stream.CopyToAsync(fs);
            }

            // File name to use to upload files
            string uploadFileName = "testUpload.png";

            // Upload file at dlPath1
            BoxFile file;

            using (FileStream fs = new FileStream(dlPath1, FileMode.Open))
            {
                BoxFileRequest req = new BoxFileRequest()
                {
                    Name   = uploadFileName,
                    Parent = new BoxRequestEntity()
                    {
                        Id = "0"
                    }
                };

                file = await _client.FilesManager.UploadAsync(req, fs);
            }

            Assert.AreEqual(uploadFileName, file.Name, "Incorrect file name");
            Assert.AreEqual("0", file.Parent.Id, "Incorrect destination folder");

            // Upload file at dlPath2 as new version of 'file'
            BoxFile newFileVersion;

            using (FileStream fs = new FileStream(dlPath2, FileMode.Open))
            {
                newFileVersion = await _client.FilesManager.UploadNewVersionAsync(uploadFileName, file.Id, fs, file.ETag);
            }

            Assert.AreEqual(newFileVersion.Name, uploadFileName);
            Assert.AreEqual(newFileVersion.Parent.Id, "0");

            //View file versions (Requires upgraded acct)
            BoxCollection <BoxFileVersion> fileVersions = await _client.FilesManager.ViewVersionsAsync(newFileVersion.Id);

            Assert.AreEqual(fileVersions.TotalCount, 1, "Incorrect number of versions");

            foreach (var f in fileVersions.Entries)
            {
                Assert.AreEqual(uploadFileName, f.Name);
            }

            // Update the file name of a file
            string updateName = GetUniqueName();

            BoxFileRequest updateReq = new BoxFileRequest()
            {
                Id   = file.Id,
                Name = updateName
            };
            BoxFile fileUpdate = await _client.FilesManager.UpdateInformationAsync(updateReq);

            Assert.AreEqual(file.Id, fileUpdate.Id, "File Ids are not the same");
            Assert.AreEqual(updateName, fileUpdate.Name, "File Names are not the same");

            // Test create shared link
            BoxSharedLinkRequest linkReq = new BoxSharedLinkRequest()
            {
                Access = BoxSharedLinkAccessType.open
            };
            BoxFile fileWithLink = await _client.FilesManager.CreateSharedLinkAsync(newFileVersion.Id, linkReq);

            Assert.AreEqual(BoxSharedLinkAccessType.open, fileWithLink.SharedLink.Access, "Incorrect access for shared link");

            // Copy file in same folder
            string         copyName = GetUniqueName();
            BoxFileRequest copyReq  = new BoxFileRequest()
            {
                Id     = fileWithLink.Id,
                Name   = copyName,
                Parent = new BoxRequestEntity()
                {
                    Id = "0"
                }
            };
            BoxFile fileCopy = await _client.FilesManager.CopyAsync(copyReq);

            Assert.AreEqual(fileCopy.Name, copyName, "Incorrect Name for copied file");
            Assert.AreEqual(fileCopy.Parent.Id, "0", "Incorrect parent folder for copied file");

            // Test get file information
            BoxFile fileInfo = await _client.FilesManager.GetInformationAsync(fileWithLink.Id);

            Assert.AreEqual(updateName, fileWithLink.Name, "File name is incorrect");
            Assert.AreEqual("0", fileWithLink.Parent.Id, "Parent folder is incorrect");

            // Delete both files
            await _client.FilesManager.DeleteAsync(fileCopy.Id, fileCopy.ETag);

            await _client.FilesManager.DeleteAsync(fileWithLink.Id, fileWithLink.ETag);
        }
Exemplo n.º 15
0
        public async Task FolderWorkflow_LiveSession_ValidResponse()
        {
            string testName = GetUniqueName();

            // Test Create Folder
            BoxFolderRequest folderReq = new BoxFolderRequest()
            {
                Name   = testName,
                Parent = new BoxRequestEntity()
                {
                    Id = "0"
                }
            };

            BoxFolder f = await _client.FoldersManager.CreateAsync(folderReq);

            Assert.IsNotNull(f, "Folder was not created");
            Assert.AreEqual(testName, f.Name, "Folder with incorrect name was created");

            // Test Get Information
            BoxFolder fi = await _client.FoldersManager.GetInformationAsync(f.Id);

            Assert.AreEqual(f.Id, fi.Id, "Folder Ids are not identical");
            Assert.AreEqual(testName, fi.Name, "folder name is incorrect");

            // Test Create Shared Link
            BoxSharedLinkRequest sharedLinkReq = new BoxSharedLinkRequest()
            {
                Access = BoxSharedLinkAccessType.open
            };

            BoxFolder fsl = await _client.FoldersManager.CreateSharedLinkAsync(f.Id, sharedLinkReq);

            Assert.AreEqual(BoxSharedLinkAccessType.open, fsl.SharedLink.Access, "Shared link Access is not correct");

            // Test Update Folder Information
            string           newTestname = GetUniqueName();
            BoxFolderRequest updateReq   = new BoxFolderRequest()
            {
                Id                = f.Id,
                Name              = newTestname,
                SyncState         = BoxSyncStateType.not_synced,
                FolderUploadEmail = new BoxEmailRequest {
                    Access = "open"
                }
            };

            BoxFolder uf = await _client.FoldersManager.UpdateInformationAsync(updateReq);

            Assert.AreEqual(newTestname, uf.Name, "New folder name is not correct");

            // Test Copy Folder
            string           copyTestName = GetUniqueName();
            BoxFolderRequest copyReq      = new BoxFolderRequest()
            {
                Id     = f.Id,
                Parent = new BoxRequestEntity()
                {
                    Id = "0"
                },
                Name = copyTestName
            };

            BoxFolder f2 = await _client.FoldersManager.CopyAsync(copyReq);

            Assert.AreEqual(copyTestName, f2.Name, "Copied file does not have correct name");

            //Clean up - Delete Test Folders
            await _client.FoldersManager.DeleteAsync(f.Id, true);

            await _client.FoldersManager.DeleteAsync(f2.Id, true);
        }
Exemplo n.º 16
0
        public async Task FolderWorkflow_LiveSession_ValidResponse()
        {
            string testName = GetUniqueName();

            // Test Create Folder
            BoxFolderRequest folderReq = new BoxFolderRequest()
            {
                Name   = testName,
                Parent = new BoxRequestEntity()
                {
                    Id = "0"
                }
            };

            BoxFolder f = await _client.FoldersManager.CreateAsync(folderReq);

            Assert.AreEqual(testName, f.Name);

            // Test Get Information
            BoxFolder fi = await _client.FoldersManager.GetInformationAsync(f.Id);

            Assert.AreEqual(f.Id, fi.Id);
            Assert.AreEqual(testName, fi.Name);

            // Test Create Shared Link
            BoxSharedLinkRequest sharedLinkReq = new BoxSharedLinkRequest()
            {
                Access = BoxSharedLinkAccessType.open
            };

            BoxFolder fsl = await _client.FoldersManager.CreateSharedLinkAsync(f.Id, sharedLinkReq);

            Assert.AreEqual(BoxSharedLinkAccessType.open, fsl.SharedLink.Access);

            // Test Update Folder Information
            string           newTestname = GetUniqueName();
            BoxFolderRequest updateReq   = new BoxFolderRequest()
            {
                Id                = f.Id,
                Name              = newTestname,
                SyncState         = BoxSyncStateType.not_synced,
                FolderUploadEmail = new BoxEmailRequest {
                    Access = "open"
                }
            };

            BoxFolder uf = await _client.FoldersManager.UpdateInformationAsync(updateReq);

            Assert.AreEqual(newTestname, uf.Name);

            // Test Copy Folder
            string           copyTestName = GetUniqueName();
            BoxFolderRequest copyReq      = new BoxFolderRequest()
            {
                Id     = f.Id,
                Parent = new BoxRequestEntity()
                {
                    Id = "0"
                },
                Name = copyTestName
            };

            BoxFolder f2 = await _client.FoldersManager.CopyAsync(copyReq);

            Assert.AreEqual(copyTestName, f2.Name);

            // Test Delete Folder
            await _client.FoldersManager.DeleteAsync(f.Id, true);

            await _client.FoldersManager.DeleteAsync(f2.Id, true);
        }
Exemplo n.º 17
0
        public static void UploadFilesToBox(string releaseVersion, int lastBuild, out string sharedLinkUrl)
        {
            Console.Out.WriteLine("Uploading Files to the Box Server");
            var fullReleaseVersion = $"{releaseVersion}.{lastBuild}";
            var reader             = new StreamReader(ConfigurationManager.AppSettings.Get("BoxConfigPath"));
            var json   = reader.ReadToEnd();
            var config = BoxConfig.CreateFromJsonString(json);

            var       sdk    = new BoxJWTAuth(config);
            var       token  = sdk.AdminToken();
            BoxClient client = sdk.AdminClient(token);

            var releaseNumbers = releaseVersion.Split('.');
            var firstNumber    = releaseNumbers[0];
            var secondNumber   = releaseNumbers[1];

            var result = client.SearchManager.QueryAsync(query: $"Releases_{firstNumber}.{secondNumber}", type: "Folder").Result;

            string parentFolderId;

            if (result.TotalCount > 0)
            {
                parentFolderId = result.Entries.First().Id;
            }
            else //create parent release folder in the root folder
            {
                var folderRequest = new BoxFolderRequest
                {
                    Name   = $"Releases_{firstNumber}.{secondNumber}",
                    Parent = new BoxRequestEntity()
                    {
                        Id = "0"//root folder id
                    }
                };
                var createdFolder = client.FoldersManager.CreateAsync(folderRequest).Result;
                parentFolderId = createdFolder.Id;
            }

            string releaseFolderId;

            result = client.SearchManager.QueryAsync(query: releaseVersion, type: "Folder").Result;
            if (result.TotalCount > 0 && result.Entries.First().Parent.Id == parentFolderId)
            {
                releaseFolderId = result.Entries.First().Id; //Release Folder already exists in Box
            }
            else
            {
                var folderRequest = new BoxFolderRequest
                {
                    Name   = releaseVersion,
                    Parent = new BoxRequestEntity()
                    {
                        Id = parentFolderId
                    }
                };
                var createdFolder = client.FoldersManager.CreateAsync(folderRequest).Result;
                releaseFolderId = createdFolder.Id;
            }

            UploadFileToBox(client, $"GetScripts_Version_{fullReleaseVersion}.sql", $"{ConfigurationManager.AppSettings.Get("OutputFinalScriptPath")}{releaseVersion}/GetScripts_Version_{fullReleaseVersion}.sql", releaseFolderId);
            UploadFileToBox(client, $"Release_Notes_{fullReleaseVersion}.sql", $"{ConfigurationManager.AppSettings.Get("OutputFinalScriptPath")}{releaseVersion}/Release_Notes_{fullReleaseVersion}.txt", releaseFolderId);

            var sharedLinkParams = new BoxSharedLinkRequest()
            {
                Access = BoxSharedLinkAccessType.open
            };
            BoxFolder sharedFolder = client.FoldersManager.CreateSharedLinkAsync(parentFolderId, sharedLinkParams).Result;

            sharedLinkUrl = sharedFolder.SharedLink.Url;

            Console.Out.WriteLine($"Files Uploaded to the Box Server: {sharedLinkUrl}");
        }
Exemplo n.º 18
0
        public async Task FileWorkflow_ValidRequest_ValidResponse()
        {
            string fileName = "reimages.zip";
            string saveName = "reimages2.zip";


            string filePath = string.Format(savePath, fileName);
            string dlPath   = string.Format(savePath, saveName);

            // Test upload a file
            BoxFile file;

            using (FileStream fs = new FileStream(filePath, FileMode.Open))
            {
                BoxFileRequest req = new BoxFileRequest()
                {
                    Name   = "reimages.zip",
                    Parent = new BoxRequestEntity()
                    {
                        Id = "0"
                    }
                };

                file = await _client.FilesManager.UploadAsync(req, fs);
            }

            Assert.AreEqual(fileName, file.Name);
            Assert.AreEqual("0", file.Parent.Id);

            // Test upload a new version
            BoxFile newFile;

            using (FileStream fs = new FileStream(filePath, FileMode.Open))
            {
                newFile = await _client.FilesManager.UploadNewVersionAsync(fileName, file.Id, fs, file.ETag);
            }

            Assert.AreEqual(newFile.Name, fileName);
            Assert.AreEqual(newFile.Parent.Id, "0");

            // Test view file versions (Requires upgraded acct)
            //BoxCollection<BoxFile> versions = await _client.FilesManager.ViewVersionsAsync(newFile.Id);

            //Assert.AreEqual(versions.TotalCount, 2);
            //foreach (var f in versions.Entries)
            //{
            //    Assert.AreEqual(fileName, f.Name);
            //    Assert.AreEqual("0", f.Parent.Id);
            //}

            // Test update a file
            string         updateName = GetUniqueName();
            BoxFileRequest updateReq  = new BoxFileRequest()
            {
                Id          = file.Id,
                Name        = updateName,
                Description = updateName
            };
            BoxFile fileUpdate = await _client.FilesManager.UpdateInformationAsync(updateReq);

            Assert.AreEqual(file.Id, fileUpdate.Id);
            Assert.AreEqual(updateName, fileUpdate.Name);
            Assert.AreEqual(updateName, fileUpdate.Description);

            // Test create shared link
            BoxSharedLinkRequest linkReq = new BoxSharedLinkRequest()
            {
                Access = BoxSharedLinkAccessType.open
            };
            BoxFile fileLink = await _client.FilesManager.CreateSharedLinkAsync(newFile.Id, linkReq);

            Assert.AreEqual(BoxSharedLinkAccessType.open, fileLink.SharedLink.Access);

            // Test copy a file
            string         copyName = GetUniqueName();
            BoxFileRequest copyReq  = new BoxFileRequest()
            {
                Id     = newFile.Id,
                Name   = copyName,
                Parent = new BoxRequestEntity()
                {
                    Id = "0"
                }
            };
            BoxFile fileCopy = await _client.FilesManager.CopyAsync(copyReq);

            Assert.AreEqual(fileCopy.Name, copyName);
            Assert.AreEqual(fileCopy.Parent.Id, "0");

            // Test download a file
            using (FileStream fs = new FileStream(dlPath, FileMode.OpenOrCreate))
            {
                Stream stream = await _client.FilesManager.DownloadStreamAsync(file.Id);

                await stream.CopyToAsync(fs);
            }

            // Test get file information
            BoxFile fileInfo = await _client.FilesManager.GetInformationAsync(file.Id);

            Assert.AreEqual(updateName, fileInfo.Name);
            Assert.AreEqual("0", file.Parent.Id);

            BoxFile newFileInfo = await _client.FilesManager.GetInformationAsync(newFile.Id);

            Assert.AreEqual(updateName, newFileInfo.Name);
            Assert.AreEqual("0", newFileInfo.Parent.Id);

            // Test delete a file
            await _client.FilesManager.DeleteAsync(fileCopy.Id, fileCopy.ETag);

            await _client.FilesManager.DeleteAsync(newFile.Id, newFileInfo.ETag);
        }
Exemplo n.º 19
0
 public BoxFolderUpdateRequestMap()
 {
     Map(m => m.Id);
     Map(m => m.Name);
     Map(m => m.Description);
     Map(m => m.SyncState);
     Map(m => m.Parent).ConvertUsing <BoxRequestEntity>(row =>
     {
         var field = row.GetField("ParentId");
         if (string.IsNullOrEmpty(field))
         {
             return(null);
         }
         else
         {
             return(new BoxRequestEntity()
             {
                 Id = field
             });
         }
     });
     Map(m => m.FolderUploadEmail).ConvertUsing <BoxEmailRequest>(row =>
     {
         var field = row.GetField("FolderUploadEmailAccess");
         if (string.IsNullOrEmpty(field))
         {
             return(null);
         }
         else
         {
             return(new BoxEmailRequest()
             {
                 Access = field
             });
         }
     });
     Map(m => m.SharedLink).ConvertUsing <BoxSharedLinkRequest>(row =>
     {
         var access      = row.GetField("SharedLinkAccess");
         var password    = row.GetField("SharedLinkPassword");
         var unsharedAt  = row.GetField("SharedLinkUnsharedAt");
         var canDownload = row.GetField("SharedLinkCanDownload");
         if (string.IsNullOrEmpty(access) && string.IsNullOrEmpty(password) &&
             string.IsNullOrEmpty(unsharedAt) && string.IsNullOrEmpty(canDownload))
         {
             return(null);
         }
         else
         {
             var sharedLinkRequest = new BoxSharedLinkRequest();
             if (!string.IsNullOrEmpty(access))
             {
                 access = access.ToLower();
                 if (access == "open")
                 {
                     sharedLinkRequest.Access = BoxSharedLinkAccessType.open;
                 }
                 else if (access == "collaborators")
                 {
                     sharedLinkRequest.Access = BoxSharedLinkAccessType.collaborators;
                 }
                 else if (access == "company")
                 {
                     sharedLinkRequest.Access = BoxSharedLinkAccessType.company;
                 }
                 else
                 {
                     throw new Exception("Unsupported access type. Please use 'open', 'collaborators', or 'company'.");
                 }
             }
             if (!string.IsNullOrEmpty(password))
             {
                 sharedLinkRequest.Password = password;
             }
             if (!string.IsNullOrEmpty(unsharedAt))
             {
                 sharedLinkRequest.UnsharedAt = Convert.ToDateTime(unsharedAt);
             }
             if (!string.IsNullOrEmpty(canDownload))
             {
                 sharedLinkRequest.Permissions          = new BoxPermissionsRequest();
                 sharedLinkRequest.Permissions.Download = Convert.ToBoolean(canDownload);
             }
             return(sharedLinkRequest);
         }
     });
 }
Exemplo n.º 20
0
        public async Task FolderSharedLink_CreateAndDelete_ValidResponse()
        {
            string testName = GetUniqueName();

            // Test Create Folder
            BoxFolderRequest folderReq = new BoxFolderRequest()
            {
                Name   = testName,
                Parent = new BoxRequestEntity()
                {
                    Id = "0"
                }
            };

            BoxFolder f = await _client.FoldersManager.CreateAsync(folderReq);

            Assert.IsNotNull(f, "Folder was not created");
            Assert.AreEqual(testName, f.Name, "Folder with incorrect name was created");

            BoxSharedLinkRequest sharedLinkReq = new BoxSharedLinkRequest()
            {
                Access      = BoxSharedLinkAccessType.open,
                Permissions = new BoxPermissionsRequest
                {
                    Download = true,
                }
            };

            BoxFolder sl = await _client.FoldersManager.CreateSharedLinkAsync(f.Id, sharedLinkReq);

            Assert.AreEqual(sl.Id, f.Id);
            Assert.IsNotNull(sl.SharedLink);
            Assert.AreEqual(sl.SharedLink.Access, BoxSharedLinkAccessType.open);
            Assert.IsNotNull(sl.SharedLink.Permissions);
            Assert.AreEqual(sl.SharedLink.Permissions.CanDownload, true);


            sharedLinkReq = new BoxSharedLinkRequest()
            {
                Access      = null,
                Permissions = new BoxPermissionsRequest
                {
                    Download = false,
                }
            };

            sl = await _client.FoldersManager.CreateSharedLinkAsync(f.Id, sharedLinkReq);

            Assert.AreEqual(sl.Id, f.Id);
            Assert.IsNotNull(sl.SharedLink);
            Assert.AreEqual(sl.SharedLink.Access, BoxSharedLinkAccessType.open);
            Assert.IsNotNull(sl.SharedLink.Permissions);
            Assert.AreEqual(sl.SharedLink.Permissions.CanDownload, false);

            sl = await _client.FoldersManager.DeleteSharedLinkAsync(f.Id);

            Assert.AreEqual(sl.Id, f.Id);
            Assert.IsNull(sl.SharedLink);

            //Clean up - Delete Test Folders
            await _client.FoldersManager.DeleteAsync(f.Id, true);
        }