public void GetAttachmentIdFromPath_WorksForRelativePath()
        {
            var pwd       = Directory.GetCurrentDirectory();
            var localDirs = new LocalDirs(pwd);
            var path      = localDirs.GetAttachmentFile(_attachment).FullName;

            localDirs.GetAttachmentIdFromPath(path).ShouldBe(_attachment.Id.ToString());
        }
Exemplo n.º 2
0
        public Task <FileInfo> GetAttachment(Attachment attachment)
        {
            var file = _localDirs.GetAttachmentFile(attachment);

            if (file.Exists)
            {
                Logger.Debug("Downloaded attachment found: {file}", file.FullName);
                return(Task.FromResult(file));
            }

            Logger.Debug("Downloaded attachment not found: {file}", file.FullName);
            return(Task.FromResult((FileInfo)null));
        }
        public void GetRelativePath_RemovesWorkingDirectory()
        {
            var pwd       = Directory.GetCurrentDirectory();
            var localDirs = new LocalDirs(pwd);
            var file      = localDirs.GetAttachmentFile(_attachment);

            var path = localDirs.GetRelativePath(file);

            path.ShouldContain($"{_s}{_attachment.Id.ToString()}{_s}");
            path.ShouldContain($"{_s}{_attachment.Filename}");

            var newFile = localDirs.GetFileFromRelativePath(path);

            newFile.FullName.ShouldBe(file.FullName);
        }
Exemplo n.º 4
0
        public async Task <FileInfo> GetAttachment(Attachment attachment)
        {
            Logger.Debug("Downloading attachment {attachmentId}", attachment.Id);

            var zipFile = _localDirs.GetAttachmentFile(attachment);

            using (var wc = new WebClient())
            {
                string encodedUserNameAndPassword = Convert.ToBase64String(Encoding.UTF8.GetBytes(_jiraApiSettings.JiraUsername + ":" + _jiraApiSettings.JiraToken));

                wc.Headers.Remove(HttpRequestHeader.Authorization);
                wc.Headers.Add(HttpRequestHeader.Authorization, "Basic " + encodedUserNameAndPassword);
                await wc.DownloadFileTaskAsync(attachment.Content, zipFile.FullName);
            }

            return(zipFile);
        }