Exemplo n.º 1
0
        public ActionResult ProcessJob(Job job)
        {
            var sharedLink   = job.Profile.DropboxSettings.CreateShareLink;
            var sharedFolder = job.TokenReplacer.ReplaceTokens(job.Profile.DropboxSettings.SharedFolder);

            var accountId             = job.Profile.DropboxSettings.AccountId;
            var currentDropBoxAccount = job.Accounts.DropboxAccounts.First(s => s.AccountId.Equals(accountId));

            if (sharedLink)
            {
                var sharedLinks = _dropboxService.UploadFileWithSharing(
                    currentDropBoxAccount.AccessToken,
                    sharedFolder, job.OutputFiles,
                    job.Profile.DropboxSettings.EnsureUniqueFilenames);
                if (sharedLinks != null)
                {
                    // first remove full path from filepath
                    foreach (var item in sharedLinks)
                    {
                        item.FilePath = item.FilePath.Split('/').Last();
                    }

                    var fullLinks = sharedLinks.Select(item => $"{item.FilePath} ( {item.SharedUrl} )").ToList();
                    var htmlLinks = sharedLinks.Select(item => $"<a href = '{item.SharedUrl}'>{item.FilePath}</a>").ToList();
                    job.TokenReplacer.AddToken(new ListToken("DROPBOXFULLLINKS", fullLinks));
                    job.TokenReplacer.AddToken(new ListToken("DROPBOXHTMLLINKS", htmlLinks));
                }
            }
            else
            {
                _dropboxService.UploadFiles(currentDropBoxAccount.AccessToken, sharedFolder, job.OutputFiles, job.Profile.DropboxSettings.EnsureUniqueFilenames);
            }

            return(new ActionResult());
        }
        public void UploadFileWithSharedLink_CheckIsTokenReplacerFilledWithLink()
        {
            _profile.DropboxSettings.Enabled         = true;
            _profile.DropboxSettings.CreateShareLink = true;


            var action = new DropboxAction(_dropboxService);

            _job = new Job(new JobInfo(), _profile, new JobTranslations(), _accounts);
            _dropboxService.UploadFileWithSharing("", _profile.DropboxSettings.SharedFolder, _job.OutputFiles, false).Returns(
                new List <DropboxFileMetaData>
            {
                new DropboxFileMetaData {
                    FilePath = "/File1.pdf", SharedUrl = "htttps://dropbox.com/File1.pdf"
                },
                new DropboxFileMetaData {
                    FilePath = "/File2.pdf", SharedUrl = "htttps://dropbox.com/File2.pdf"
                }
            });

            action.ProcessJob(_job);
            var tokenNames = _job.TokenReplacer.GetTokenNames(false);

            Assert.Contains("DROPBOXHTMLLINKS", tokenNames);
            Assert.Contains("DROPBOXFULLLINKS", tokenNames);
        }
Exemplo n.º 3
0
        public void UploadFileWithSharedLink_CheckIsTokenReplacerFilledWithLink()
        {
            _profile.DropboxSettings.CreateShareLink = true;

            _job = new Job(new JobInfo(), _profile, _accounts);
            _dropboxService.UploadFileWithSharing(_accessToken, _profile.DropboxSettings.SharedFolder, _job.OutputFiles, false, _job.OutputFileTemplate).Returns(
                new DropboxFileMetaData
            {
                Filename = "/File1.pdf",
                ShareUrl = "htttps://dropbox.com/File1.pdf"
            });
            _dropboxAction.ProcessJob(_job);
            var tokenNames = _job.TokenReplacer.GetTokenNames(false);

            Assert.Contains("DROPBOXHTMLLINKS", tokenNames);
            Assert.Contains("DROPBOXFULLLINKS", tokenNames);
        }
Exemplo n.º 4
0
        public ActionResult ProcessJob(Job job)
        {
            _logger.Debug("Launched Dropbox Action");

            ApplyPreSpecifiedTokens(job);
            var actionResult = Check(job.Profile, job.Accounts, CheckLevel.Job);

            if (!actionResult)
            {
                return(actionResult);
            }

            var sharedLink  = job.Profile.DropboxSettings.CreateShareLink;
            var shareFolder = job.TokenReplacer.ReplaceTokens(job.Profile.DropboxSettings.SharedFolder);

            var currentDropBoxAccount = job.Accounts.GetDropboxAccount(job.Profile);

            if (sharedLink)
            {
                try
                {
                    var shareLink = _dropboxService.UploadFileWithSharing(
                        currentDropBoxAccount.AccessToken,
                        shareFolder, job.OutputFiles,
                        job.Profile.DropboxSettings.EnsureUniqueFilenames, job.OutputFileTemplate);
                    if (shareLink == null)
                    {
                        return(new ActionResult(ErrorCode.Dropbox_Upload_And_Share_Error));
                    }

                    job.ShareLinks.DropboxShareUrl = shareLink.ShareUrl;

                    shareLink.Filename = shareLink.Filename.Split('/').Last();
                    job.TokenReplacer.AddToken(new StringToken("DROPBOXFULLLINKS", $"{shareLink.Filename} ( {shareLink.ShareUrl} )"));
                    job.TokenReplacer.AddToken(new StringToken("DROPBOXHTMLLINKS", $"<a href = '{shareLink.ShareUrl}'>{shareLink.Filename}</a>"));
                }
                catch
                {
                    return(new ActionResult(ErrorCode.Dropbox_Upload_And_Share_Error));
                }
            }
            else
            {
                var result = _dropboxService.UploadFiles(currentDropBoxAccount.AccessToken, shareFolder, job.OutputFiles, job.Profile.DropboxSettings.EnsureUniqueFilenames, job.OutputFileTemplate);
                if (result == false)
                {
                    return(new ActionResult(ErrorCode.Dropbox_Upload_Error));
                }
            }

            return(new ActionResult());
        }
Exemplo n.º 5
0
        public ActionResult ProcessJob(Job job)
        {
            var sharedLink   = job.Profile.DropboxSettings.CreateShareLink;
            var sharedFolder = job.TokenReplacer.ReplaceTokens(job.Profile.DropboxSettings.SharedFolder);

            var accountId             = job.Profile.DropboxSettings.AccountId;
            var currentDropBoxAccount = job.Accounts.DropboxAccounts.First(s => s.AccountId.Equals(accountId));

            if (sharedLink)
            {
                try
                {
                    var sharedLinks = _dropboxService.UploadFileWithSharing(
                        currentDropBoxAccount.AccessToken,
                        sharedFolder, job.OutputFiles,
                        job.Profile.DropboxSettings.EnsureUniqueFilenames, job.OutputFilenameTemplate);
                    if (sharedLinks == null)
                    {
                        return(new ActionResult(ErrorCode.Dropbox_Upload_And_Share_Error));
                    }
                    sharedLinks.FilePath = sharedLinks.FilePath.Split('/').Last();
                    job.TokenReplacer.AddToken(new StringToken("DROPBOXFULLLINKS", $"{sharedLinks.FilePath} ( {sharedLinks.SharedUrl} )"));
                    job.TokenReplacer.AddToken(new StringToken("DROPBOXHTMLLINKS", $"<a href = '{sharedLinks.SharedUrl}'>{sharedLinks.FilePath}</a>"));
                    if (job.Profile.AutoSave.Enabled == false)
                    {
                        ShowWindowWithSharedLinks(sharedLinks);
                    }
                }
                catch
                {
                    return(new ActionResult(ErrorCode.Dropbox_Upload_And_Share_Error));
                }
            }
            else
            {
                var result = _dropboxService.UploadFiles(currentDropBoxAccount.AccessToken, sharedFolder, job.OutputFiles, job.Profile.DropboxSettings.EnsureUniqueFilenames, job.OutputFilenameTemplate);
                if (result == false)
                {
                    return(new ActionResult(ErrorCode.Dropbox_Upload_Error));
                }
            }


            return(new ActionResult());
        }