Ejemplo n.º 1
0
        private async static Task DownloadItem(DocumentServiceDefinition.DocumentServiceDefinitionClient documentClient)
        {
            var input = new DownloadItemRequest {
                Id = 9
            };

            string tempFileName  = $@"C:\Users\molnar.zsolt\DokuStore\temp_{DateTime.UtcNow.ToString("yyyyMMdd_HHmmss")}.tmp";
            string finalFileName = tempFileName;

            using (var reply = documentClient.DownloadItem(input))
            {
                await using (Stream fs = File.OpenWrite(tempFileName))
                {
                    await foreach (DataChunkResponse chunkMsg in reply.ResponseStream.ReadAllAsync().ConfigureAwait(false))
                    {
                        //Int64 totalSize = chunkMsg.FileSize;
                        string tempFinalFilePath = chunkMsg.FileName;

                        if (!string.IsNullOrEmpty(tempFinalFilePath))
                        {
                            finalFileName = chunkMsg.FileName;
                        }

                        fs.Write(chunkMsg.Chunk.ToByteArray());
                    }
                }
            }
            if (finalFileName != tempFileName)
            {
                File.Move(tempFileName, finalFileName);
            }
        }
Ejemplo n.º 2
0
        public void GivenValueInit_PropertyValueMustEqualGiven()
        {
            var chapter = new ComicChapter();
            var page    = new ComicPage();
            var req     = new DownloadItemRequest(chapter, page);

            Assert.AreEqual(chapter, req.Chapter);
            Assert.AreEqual(page, req.Page);
            req = new DownloadItemRequest(page);
            Assert.IsNull(req.Chapter);
            Assert.AreEqual(page, req.Page);
        }
Ejemplo n.º 3
0
 public async Task CallBatchEmit_AllTaskMustBeRun()
 {
     var provider = new ResourceComicProvider();
     var reqs     = new DownloadItemRequest[]
     {
         new DownloadItemRequest(null),
         new DownloadItemRequest(null),
         new DownloadItemRequest(null),
         new DownloadItemRequest(null),
     };
     var req        = new ComicDownloadRequest(new NullSaver(), null, null, new DownloadItemRequest[0], provider);
     var downloader = new ComicDownloader(new RecyclableMemoryStreamManager());
     await ComicDownloaderExtensions.BatchEmitAsync(downloader, req);
 }
Ejemplo n.º 4
0
        public void GivenValue_PropertyValueMustEqualGiven()
        {
            var saver = new NullComicSaver();
            var req   = new DownloadItemRequest[0];
            var prov  = new NullSourceProvider();
            var eq    = new ComicDownloadRequest(saver, null, null, req, prov);
            var chp   = new ComicChapter();
            var page  = new ComicPage();
            var ctx   = new DownloadListenerContext(eq, chp, page, default);

            Assert.AreEqual(eq, ctx.Request);
            Assert.AreEqual(chp, ctx.Chapter);
            Assert.AreEqual(page, ctx.Page);
            Assert.AreEqual(CancellationToken.None, ctx.Token);
        }
Ejemplo n.º 5
0
        private void MainActionButtonClick()
        {
            switch (mainActionButtonMode)
            {
            case MainActionButtonMode.START_DOWNLOAD:
                if (MainModel.AppSettings.Download.UseDownloadManager)
                {
                    Mirrors.MirrorConfiguration mirror = MainModel.Mirrors[downloadMirrorName];
                    DownloadItemRequest         downloadItemRequest = new DownloadItemRequest
                    {
                        DownloadPageUrl          = downloadUrl,
                        FileNameWithoutExtension = FileNameWithoutExtension,
                        FileExtension            = FileExtension.ToLower(),
                        Md5Hash = Md5Hash,
                        DownloadTransformations = GetDownloadTransformations(mirror),
                        RestartSessionOnTimeout = mirror.RestartSessionOnTimeout
                    };
                    MainModel.Downloader.EnqueueDownloadItems(new[] { downloadItemRequest });
                }
                else
                {
                    Process.Start(downloadUrl);
                }
                break;

            case MainActionButtonMode.SELECT_DOWNLOAD:
                SelectDownloadRequested?.Invoke(this, new SelectDownloadEventArgs(downloadId.Value));
                break;

            case MainActionButtonMode.OPEN_FILE:
                if (File.Exists(localFilePath))
                {
                    Process.Start(localFilePath);
                }
                else
                {
                    ShowMessage(localization.ErrorMessageTitle, localization.GetFileNotFoundErrorText(localFilePath));
                }
                break;
            }
        }
Ejemplo n.º 6
0
        public DownloadItemRequest GetForDownload(long uId, DbFileSystemItem[] items)
        {
            FileItem firstItem = GetDbItemByFileKey(uId, items[0].Key.ToString());

            if (items.Length == 1 && !firstItem.IsFolder.Value)
            {
                return(new DownloadItemRequest
                {
                    Data = firstItem.Data,
                    FileName = firstItem.Name
                });
            }
            else
            {
                var tmpPath = Path.Combine(webRootPath, "tmp", Guid.NewGuid().ToString());

                foreach (var item in items)
                {
                    FileItem _item = GetDbItemByFileKey(uId, item.Key.ToString());

                    MakeFiles(uId, Path.Combine(tmpPath, _item.Name), _item.Id);
                }


                var zipName = Guid.NewGuid().ToString() + ".zip";

                ZipFile.CreateFromDirectory(tmpPath, Path.Combine(webRootPath, "tmp", zipName));

                var result = new DownloadItemRequest
                {
                    Data     = File.ReadAllBytes(Path.Combine(webRootPath, "tmp", zipName)),
                    FileName = firstItem.Name + ".zip"
                };

                File.Delete(Path.Combine(webRootPath, "tmp", zipName));
                Directory.Delete(tmpPath, true);
                return(result);
            }
        }
Ejemplo n.º 7
0
 public override Task DownloadItem(DownloadItemRequest request, IServerStreamWriter <DataChunkResponse> responseStream, ServerCallContext context)
 {
     return(Task.FromResult(_documentManager.DownloadItem(request.Id, responseStream, context)));
 }