public void DownloadFile_WhenUnsecureConnectionType_TrySecureDownloadFirst()
        {
            secureFilePayloadServiceMock.IsSecureConnection(filePayload).Returns(false);

            systemUnderTest.DownloadFile(filePayload);

            Received.InOrder(() =>
            {
                secureFilePayloadServiceMock.EnableSecureFilePayload(filePayload);
                downloadServiceMock.DownloadFile(filePayload);
            });
        }
コード例 #2
0
        /// <summary>
        /// Main entry point for the lambda
        /// </summary>
        /// <param name="context"></param>
        public async Task Handle(ILambdaContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            var apiKey        = _configurationService.FlickrApiKey;
            var apiSecret     = _configurationService.FlickrApiSecret;
            var userId        = _configurationService.FlickrUserId;
            var bucketName    = _configurationService.S3Bucket;
            var s3Region      = _configurationService.AwsRegion;
            var resizeToWidth = _configurationService.ResizeToWidth;

            // download file from flickr
            var url = await _flickrService.GetLastUploadedPhotoUrl(apiKey, apiSecret, userId, PhotoSize.Small);

            if (!string.IsNullOrWhiteSpace(url))
            {
                var downloadedFile = _downloadService.DownloadFile(url);
                var resizedFile    = _imageService.ResizeImage(downloadedFile, resizeToWidth);

                var key = _configurationService.S3UploadKey;
                await _s3FileService.UploadFile(resizedFile, bucketName, key, s3Region);
            }
        }
コード例 #3
0
        public IEnumerable <ChannelModel> WrappChannels()
        {
            IEnumerable <ChannelModel> retModels = null;

            try
            {
                var file = _downloadService.DownloadFile(
                    "https://edem.tv/playlists/uplist/1c2da6c7d34477003a5b8e8acc9903b7/edem_pl.m3u8", "edem.m3u8");

                if (string.IsNullOrEmpty(file) == false)
                {
                    retModels = ExtractChanlesFromFile(file);
                }
                else
                {
                    //TODO message to user
                    _logger.Error("failed to get file");
                }

                return(retModels);
            }
            catch (Exception e)
            {
                _logger.Error(e.Message);
                return(null);
            }
        }
コード例 #4
0
        public void DownloadFile()
        {
            DownloadTracker.NewFile();
            DownloadTracker.SetProgress(0, 0);

            PauseIcon      = FontAwesomeIcon.Pause;
            Download.State = CurrentDownloadState.Download;
            _downloadService.DownloadFile(Download);
        }
        public void DownloadFile_WhenSecureConnectionType_OnlyTrySecureDownload()
        {
            var webException = new WebException();

            secureFilePayloadServiceMock.IsSecureConnection(filePayload).Returns(true);

            var firstCall = true;

            downloadServiceMock.When(service => service.DownloadFile(filePayload)).Do(info =>
            {
                if (firstCall)
                {
                    firstCall = false;
                    throw webException;
                }
            });

            Assert.Throws(Is.EqualTo(webException), () => systemUnderTest.DownloadFile(filePayload));

            secureFilePayloadServiceMock.DidNotReceive().DisableSecureFilePayload(Arg.Any <FilePayload>());
            loggingServiceMock.Received().LogException(webException);
        }
コード例 #6
0
        public void DownloadFile(FilePayload filePayload)
        {
            bool originalWasNotSecure = !secureFilePayloadService.IsSecureConnection(filePayload);

            try
            {
                secureFilePayloadService.EnableSecureFilePayload(filePayload);
                downloadService.DownloadFile(filePayload);
            }
            catch (WebException webException)
            {
                loggingService.LogException(webException);

                if (originalWasNotSecure)
                {
                    secureFilePayloadService.DisableSecureFilePayload(filePayload);
                    downloadService.DownloadFile(filePayload);
                }
                else
                {
                    throw;
                }
            }
        }
コード例 #7
0
        public void SaveAs(WebBook book, string path)
        {
            var fileName = string.Format(FileTemplate, $"{path}\\", book.Name);

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            if (new DirectoryInfo(path).GetFiles().Any(f => f.Name.Contains(book.Name)))
            {
                return;
            }

            DocX doc = DocX.Create(fileName);

            doc.DifferentFirstPage = true;
            doc.AddFooters();

            InsertImage(doc, _download.DownloadFile(book.ImageUrl, book.Name));
            foreach (var page in book.Pages)
            {
                foreach (var data in page.WebBookTexts)
                {
                    switch (data)
                    {
                    case WebBookHeader _:
                        InsertHeader(doc, data.Text);
                        break;

                    case WebBookParagraph _:
                        InsertParagraph(doc, data.Text);
                        break;
                    }
                }
            }

            var even = doc.Footers.Even.InsertParagraph("Page №");

            even.Alignment = Alignment.center;
            even.AppendPageNumber(PageNumberFormat.normal);
            var odd = doc.Footers.Odd.InsertParagraph("Page №");

            odd.Alignment = Alignment.center;
            odd.AppendPageNumber(PageNumberFormat.normal);

            doc.Save();
        }
コード例 #8
0
        public void DownloadFile_WhenInvoked_StatsDownloadIsPerformed()
        {
            InvokeDownloadFile();

            Received.InOrder(async() =>
            {
                loggingServiceMock.LogVerbose("DownloadStatsFile Invoked");
                fileDownloadDatabaseServiceMock.IsAvailable();
                fileDownloadDatabaseServiceMock.UpdateToLatest();
                dateTimeServiceMock.DateTimeNow();
                loggingServiceMock.LogVerbose($"Stats file download started: {dateTime}");
                fileDownloadDatabaseServiceMock.FileDownloadStarted(Arg.Any <FilePayload>());
                fileDownloadMinimumWaitTimeServiceMock.IsMinimumWaitTimeMet(Arg.Any <FilePayload>());
                filePayloadSettingsServiceMock.SetFilePayloadDownloadDetails(Arg.Any <FilePayload>());
                downloadServiceMock.DownloadFile(Arg.Any <FilePayload>());
                dateTimeServiceMock.DateTimeNow();
                loggingServiceMock.LogVerbose($"Stats file download completed: {dateTime}");
                await filePayloadUploadServiceMock.UploadFile(Arg.Any <FilePayload>());
                resourceCleanupServiceMock.Cleanup(Arg.Any <FileDownloadResult>());
                loggingServiceMock.LogResult(Arg.Any <FileDownloadResult>());
            });
        }
コード例 #9
0
 private void DownloadFile(FilePayload filePayload)
 {
     downloadService.DownloadFile(filePayload);
 }
コード例 #10
0
 public async Task <IActionResult> Download([FromRoute] string context, [FromRoute] int id)
 {
     return(_downloadService.DownloadFile(context, id));
 }