Beispiel #1
0
        public FileSystemEntry CreateDirectory(string path)
        {
            FileSystemEntry fileSystemEntry = null;
            string          itemType        = null;
            string          parentPath      = "";// + RemoveLastFolderFromPath(path);
            string          parentFolderId  = GetFileOrFolderIDfromPath(parentPath, ref itemType);

            try
            {
                var boxEntityRequest = new BoxRequestEntity()
                {
                    Id = parentFolderId, Type = BoxType.folder
                };
                BoxFolderRequest folderRequest = new BoxFolderRequest()
                {
                    Parent = boxEntityRequest
                };
                var createDirectory = boxClient.FoldersManager.CreateAsync(folderRequest);
                createDirectory.Wait();
                fileSystemEntry = GetEntry(path);
            }
            catch (Exception e)
            {
                if (e.InnerException != null)
                {
                    EventLog.WriteEntry("Box SMB", e.Message + " Inner Exception: " + e.InnerException.Message, EventLogEntryType.Error);
                }
                else
                {
                    EventLog.WriteEntry("Box SMB", e.Message, EventLogEntryType.Error);
                }
            }

            return(fileSystemEntry);
        }
Beispiel #2
0
        public async Task CreateSignRequest_RequiredParams_Success()
        {
            /*** Arrange ***/
            IBoxRequest boxRequest = null;

            Handler.Setup(h => h.ExecuteAsync <BoxSignRequest>(It.IsAny <IBoxRequest>()))
            .Returns(Task.FromResult <IBoxResponse <BoxSignRequest> >(new BoxResponse <BoxSignRequest>()
            {
                Status        = ResponseStatus.Success,
                ContentString = LoadFixtureFromJson("Fixtures/BoxSignRequest/CreateSignRequest200.json")
            }))
            .Callback <IBoxRequest>(r => boxRequest = r);;

            var sourceFiles = new List <BoxSignRequestCreateSourceFile>
            {
                new BoxSignRequestCreateSourceFile()
                {
                    Id = "12345"
                }
            };

            var signers = new List <BoxSignRequestSignerCreate>
            {
                new BoxSignRequestSignerCreate()
                {
                    Email = "*****@*****.**",
                    Role  = BoxSignRequestSignerRole.signer,
                }
            };

            var parentFolder = new BoxRequestEntity()
            {
                Id   = "12345",
                Type = BoxType.folder
            };

            var request = new BoxSignRequestCreateRequest
            {
                SourceFiles  = sourceFiles,
                Signers      = signers,
                ParentFolder = parentFolder,
            };

            /*** Act ***/
            var response = await _signRequestsManager.CreateSignRequestAsync(request);

            /*** Assert ***/
            // Request check
            Assert.IsNotNull(boxRequest);
            Assert.AreEqual(RequestMethod.Post, boxRequest.Method);
            Assert.AreEqual(new Uri("https://api.box.com/2.0/sign_requests"), boxRequest.AbsoluteUri);
            Assert.IsTrue(boxRequest.Payload.ContainsKeyValue("signers[0].role", "signer"));

            // Response check
            Assert.AreEqual(1, response.SourceFiles.Count);
            Assert.AreEqual("12345", response.SourceFiles[0].Id);
            Assert.AreEqual(1, response.Signers.Count);
            Assert.AreEqual("*****@*****.**", response.Signers[0].Email);
            Assert.AreEqual("12345", response.ParentFolder.Id);
        }
        public async Task WebhookTests_LiveSession()
        {
            const string TRIGGER1 = "FILE.PREVIEWED";
            const string TRIGGER2 = "FILE.DOWNLOADED";
            const string ADDRESS1 = "https://example1.com";
            const string ADDRESS2 = "https://example2.com";

            //first remove any dangling webhooks from previous failed tests
            var existingWebhooks = await _client.WebhooksManager.GetWebhooksAsync(autoPaginate : true);

            foreach (var wh in existingWebhooks.Entries)
            {
                await _client.WebhooksManager.DeleteWebhookAsync(wh.Id);
            }

            //create a new webhook on a file
            BoxRequestEntity target = new BoxRequestEntity()
            {
                Id = "16894937051", Type = BoxType.file
            };
            var triggers = new List <string>()
            {
                TRIGGER1
            };
            BoxWebhookRequest whr = new BoxWebhookRequest()
            {
                Target = target, Address = ADDRESS1, Triggers = triggers
            };
            var webhook = await _client.WebhooksManager.CreateWebhookAsync(whr);

            Assert.IsNotNull(webhook, "Failed to create webhook");
            Assert.AreEqual(TRIGGER1, webhook.Triggers.First(), "Webhook trigger does not match");
            Assert.AreEqual(ADDRESS1, webhook.Address, "Webhook address does not match");

            //get a webhook
            var fetchedWebhook = await _client.WebhooksManager.GetWebhookAsync(webhook.Id);

            Assert.AreEqual(fetchedWebhook.Id, webhook.Id, "Failed to get webhook");

            //update a webhook
            triggers = new List <string>()
            {
                TRIGGER1, TRIGGER2
            };
            whr = new BoxWebhookRequest()
            {
                Id = webhook.Id, Address = ADDRESS2, Triggers = triggers
            };
            var updatedWebhook = await _client.WebhooksManager.UpdateWebhookAsync(whr);

            Assert.IsTrue(updatedWebhook.Triggers.Contains(TRIGGER1), "Webhook trigger does not match");
            Assert.IsTrue(updatedWebhook.Triggers.Contains(TRIGGER2), "Webhook trigger does not match");
            Assert.AreEqual(ADDRESS2, updatedWebhook.Address, "Webhook address does not match");

            //delete a webhook
            var result = await _client.WebhooksManager.DeleteWebhookAsync(webhook.Id);

            Assert.IsTrue(result, "Failed to delete webhook");
        }
Beispiel #4
0
        public async Task CopyFileRequest_Success()
        {
            /*** Arrange ***/
            IBoxRequest boxRequest = null;

            Handler.Setup(h => h.ExecuteAsync <BoxFileRequestObject>(It.IsAny <IBoxRequest>()))
            .Returns(Task.FromResult <IBoxResponse <BoxFileRequestObject> >(new BoxResponse <BoxFileRequestObject>()
            {
                Status        = ResponseStatus.Success,
                ContentString = LoadFixtureFromJson("Fixtures/BoxFileRequest/CopyFileRequest200.json")
            }))
            .Callback <IBoxRequest>(r => boxRequest = r);

            var folder = new BoxRequestEntity()
            {
                Id   = "44444",
                Type = BoxType.folder
            };
            var copyRequest = new BoxFileRequestCopyRequest
            {
                Folder = folder
            };

            /*** Act ***/
            BoxFileRequestObject response = await _fileRequestsManager.CopyFileRequestAsync("42037322", copyRequest);

            /*** Assert ***/
            // Request check
            Assert.IsNotNull(boxRequest);
            Assert.AreEqual(RequestMethod.Post, boxRequest.Method);
            Assert.AreEqual(new Uri("https://api.box.com/2.0/file_requests/42037322/copy"), boxRequest.AbsoluteUri);

            // Response check
            Assert.AreEqual("42037322", response.Id);
            Assert.AreEqual(DateTimeOffset.Parse("2020-09-28T10:53:43-08:00"), response.CreatedAt);
            Assert.AreEqual("*****@*****.**", response.CreatedBy.Login);
            Assert.AreEqual("Aaron Levie", response.CreatedBy.Name);
            Assert.AreEqual("Following documents are requested for your process", response.Description);
            Assert.AreEqual("1", response.Etag);
            Assert.AreEqual(DateTimeOffset.Parse("2020-09-28T10:53:43-08:00"), response.ExpiresAt);
            Assert.AreEqual("44444", response.Folder.Id);
            Assert.AreEqual("Contracts2", response.Folder.Name);
            Assert.AreEqual(true, response.IsDescriptionRequired);
            Assert.AreEqual(true, response.IsEmailRequired);
            Assert.AreEqual(BoxFileRequestStatus.active, response.Status);
            Assert.AreEqual("Please upload documents", response.Title);
            Assert.AreEqual(DateTimeOffset.Parse("2020-09-28T10:53:43-08:00"), response.UpdatedAt);
            Assert.AreEqual("11446498", response.UpdatedBy.Id);
            Assert.AreEqual("*****@*****.**", response.UpdatedBy.Login);
            Assert.AreEqual("Aaron Levie", response.UpdatedBy.Name);
            Assert.AreEqual("/f/19e57f40ace247278a8e3d336678c64a", response.Url);
        }
Beispiel #5
0
        private static void InviteUser(string UserEmail, IBoxConfig config, BoxClient boxClient)
        {
            Console.WriteLine($"🔰 Initiate User invite...");
            var inviteEmail = new BoxActionableByRequest()
            {
                Login = UserEmail
            };
            var inviteId = new BoxRequestEntity()
            {
                Id = config.EnterpriseId, Type = new BoxType()
            };

            boxClient.UsersManager.InviteUserToEnterpriseAsync(new BoxUserInviteRequest()
            {
                Enterprise = inviteId, ActionableBy = inviteEmail
            });
            Console.WriteLine($"🏁 User invited to enterprise account");
        }
Beispiel #6
0
        public async Task GetRepresentationContentAsync_E2E()
        {
            // Create stream from string content
            var assembly = Assembly.GetExecutingAssembly();
            var names    = Assembly.GetExecutingAssembly().GetManifestResourceNames();

            using (var fileStream = assembly.GetManifestResourceStream("Box.V2.Test.Integration.Properties.smalltestpdf.resources"))
            {
                var fileRequest  = new BoxFileRequest();
                var parentFolder = new BoxRequestEntity
                {
                    Type = BoxType.folder,
                    Id   = "0"
                };
                fileRequest.Parent = parentFolder;
                fileRequest.Name   = DateTime.Now.Ticks + ".pdf";
                var file = await _client.FilesManager.UploadAsync(fileRequest, fileStream);

                var repRequest = new BoxRepresentationRequest
                {
                    FileId    = file.Id,
                    XRepHints = "[png?dimensions=1024x1024]"
                };
                Stream assetStream = await _client.FilesManager.GetRepresentationContentAsync(repRequest, "1.png");

                // Delete the file when done
                await _client.FilesManager.DeleteAsync(file.Id);

                var memStream = new MemoryStream();
                await assetStream.CopyToAsync(memStream);

                byte[] assetBytes = memStream.ToArray();

                Assert.IsTrue(assetBytes.Length > 4096, "Downlaoded asset contained " + assetBytes.Length + " but should contain more than 4 KB");
            }
        }
        public async Task CreateRetentionPolicy_OptionalParams_Success()
        {
            /*** Arrange ***/
            string policyName      = "Tax Documents";
            int    retentionLength = 365;
            string policyType      = "finite";
            string policyAction    = "permanently_delete";
            string notifiedUserID  = "12345";
            string responseString  = "{"
                                     + "\"type\": \"retention_policy\","
                                     + "\"id\": \"123456789\","
                                     + "\"policy_name\": \"" + policyName + "\","
                                     + "\"policy_type\": \"" + policyType + "\","
                                     + "\"retention_length\": " + retentionLength + ","
                                     + "\"disposition_action\": \"" + policyAction + "\","
                                     + "\"status\": \"active\","
                                     + "\"created_by\": {"
                                     + " \"type\": \"user\","
                                     + " \"id\": \"11993747\","
                                     + " \"name\": \"Sean\","
                                     + " \"login\": \"[email protected]\""
                                     + "},"
                                     + "\"created_at\": \"2015-05-01T11:12:54-07:00\","
                                     + "\"modified_at\": null,"
                                     + "\"can_owner_extend_retention\": true,"
                                     + "\"are_owners_notified\": true,"
                                     + "\"custom_notification_recipients\": ["
                                     + "  {"
                                     + "    \"type\": \"user\","
                                     + "    \"id\": \"" + notifiedUserID + "\""
                                     + "  }"
                                     + "]"
                                     + "}";

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

            /*** Act ***/
            BoxRetentionPolicyRequest requestParams = new BoxRetentionPolicyRequest();

            requestParams.AreOwnersNotified       = true;
            requestParams.CanOwnerExtendRetention = true;
            BoxRequestEntity notifiedUser = new BoxRequestEntity();

            notifiedUser.Type = BoxType.user;
            notifiedUser.Id   = notifiedUserID;
            requestParams.CustomNotificationRecipients = new List <BoxRequestEntity>()
            {
                notifiedUser
            };
            requestParams.PolicyName        = policyName;
            requestParams.PolicyType        = policyType;
            requestParams.RetentionLength   = retentionLength;
            requestParams.DispositionAction = policyAction;
            BoxRetentionPolicy results = await _retentionPoliciesManager.CreateRetentionPolicyAsync(requestParams);

            /*** Assert ***/
            Assert.AreEqual(policyAction, results.DispositionAction);
            Assert.AreEqual(policyName, results.PolicyName);
            Assert.AreEqual(policyType, results.PolicyType);
            Assert.AreEqual(retentionLength.ToString(), results.RetentionLength);
            Assert.AreEqual(true, results.CanOwnerExtendRetention);
            Assert.AreEqual(true, results.AreOwnersNotified);
            Assert.IsNotNull(results.CustomNotificationRecipients);
            Assert.AreEqual(1, results.CustomNotificationRecipients.Count);
            Assert.AreEqual(notifiedUserID, results.CustomNotificationRecipients[0].Id);
        }
Beispiel #8
0
        public async Task CreateSignRequest_OptionalParams_Success()
        {
            /*** Arrange ***/
            IBoxRequest boxRequest = null;

            Handler.Setup(h => h.ExecuteAsync <BoxSignRequest>(It.IsAny <IBoxRequest>()))
            .Returns(Task.FromResult <IBoxResponse <BoxSignRequest> >(new BoxResponse <BoxSignRequest>()
            {
                Status        = ResponseStatus.Success,
                ContentString = LoadFixtureFromJson("Fixtures/BoxSignRequest/CreateSignRequest200.json")
            }))
            .Callback <IBoxRequest>(r => boxRequest = r);;

            var sourceFiles = new List <BoxSignRequestCreateSourceFile>
            {
                new BoxSignRequestCreateSourceFile()
                {
                    Id = "12345"
                }
            };

            var signers = new List <BoxSignRequestSignerCreate>
            {
                new BoxSignRequestSignerCreate()
                {
                    Email = "*****@*****.**"
                }
            };

            var parentFolder = new BoxRequestEntity()
            {
                Id   = "12345",
                Type = BoxType.folder
            };

            var request = new BoxSignRequestCreateRequest
            {
                IsDocumentPreparationNeeded = true,
                AreRemindersEnabled         = true,
                AreTextSignaturesEnabled    = true,
                DaysValid    = 2,
                EmailMessage = "Hello! Please sign the document below",
                EmailSubject = "Sign Request from Acme",
                ExternalId   = "123",
                SourceFiles  = sourceFiles,
                Signers      = signers,
                ParentFolder = parentFolder,
                PrefillTags  = new List <BoxSignRequestPrefillTag>
                {
                    new BoxSignRequestPrefillTag
                    (
                        "1234",
                        "text"
                    )
                }
            };

            /*** Act ***/
            var response = await _signRequestsManager.CreateSignRequestAsync(request);

            /*** Assert ***/
            // Request check
            Assert.IsNotNull(boxRequest);
            Assert.AreEqual(RequestMethod.Post, boxRequest.Method);
            Assert.AreEqual(new Uri("https://api.box.com/2.0/sign_requests"), boxRequest.AbsoluteUri);

            // Response check
            Assert.AreEqual(1, response.SourceFiles.Count);
            Assert.AreEqual("12345", response.SourceFiles[0].Id);
            Assert.AreEqual(1, response.Signers.Count);
            Assert.AreEqual("*****@*****.**", response.Signers[0].Email);
            Assert.AreEqual("12345", response.ParentFolder.Id);
            Assert.IsTrue(response.IsDocumentPreparationNeeded);
            Assert.IsTrue(response.AreRemindersEnabled);
            Assert.IsTrue(response.AreTextSignaturesEnabled);
            Assert.AreEqual(2, response.DaysValid);
            Assert.AreEqual("Hello! Please sign the document below", response.EmailMessage);
            Assert.AreEqual("Sign Request from Acme", response.EmailSubject);
            Assert.AreEqual("123", response.ExternalId);
            Assert.AreEqual(1, response.PrefillTags.Count);
            Assert.AreEqual("1234", response.PrefillTags[0].DocumentTagId);
            Assert.AreEqual("text", response.PrefillTags[0].TextValue);
            Assert.AreEqual(DateTimeOffset.Parse("2021-04-26T08:12:13.982Z"), response.PrefillTags[0].DateValue);
        }