コード例 #1
0
        public async Task CanUploadAndDownloadMirroredFiles()
        {
            var file = new TempFile();
            await file.Path.WriteAllBytesAsync(RandomData(1024 * 1024 * 6));

            var dataHash = await file.Path.FileHashAsync();

            await Fixture.GetService <ArchiveMaintainer>().Ingest(file.Path);

            Assert.True(Fixture.GetService <ArchiveMaintainer>().HaveArchive(dataHash));

            var sql = Fixture.GetService <SqlService>();

            await sql.UpsertMirroredFile(new MirroredFile
            {
                Created   = DateTime.UtcNow,
                Rationale = "Test File",
                Hash      = dataHash
            });

            var uploader = Fixture.GetService <MirrorUploader>();

            Assert.Equal(1, await uploader.Execute());


            var archive = new Archive(new HTTPDownloader.State(MakeURL(dataHash.ToString())))
            {
                Hash = dataHash,
                Size = file.Path.Size
            };

            var file2 = new TempFile();
            await DownloadDispatcher.DownloadWithPossibleUpgrade(archive, file2.Path);
        }
コード例 #2
0
        public async Task TestEndToEndArchiveUpdating()
        {
            var settings = Fixture.GetService <AppSettings>();

            settings.ValidateModUpgrades = false;

            var modLists = await MakeModList("TestEndToEndArchiveUpdating.txt");

            Consts.ModlistMetadataURL = modLists.ToString();


            var downloader = Fixture.GetService <ArchiveDownloader>();
            var archiver   = Fixture.GetService <ArchiveMaintainer>();
            var patcher    = Fixture.GetService <PatchBuilder>();

            var sql         = Fixture.GetService <SqlService>();
            var oldFileData = Encoding.UTF8.GetBytes("Cheese for Everyone!");
            var newFileData = Encoding.UTF8.GetBytes("Forks for Everyone!");
            var oldDataHash = oldFileData.xxHash();
            var newDataHash = newFileData.xxHash();

            await "TestEndToEndArchiveUpdating.txt".RelativeTo(Fixture.ServerPublicFolder).WriteAllBytesAsync(oldFileData);

            var oldArchive = new Archive(new HTTPDownloader.State(MakeURL("TestEndToEndArchiveUpdating.txt")))
            {
                Size = oldFileData.Length,
                Hash = oldDataHash
            };

            await IngestData(archiver, oldFileData);

            await sql.EnqueueDownload(oldArchive);

            var oldDownload = await sql.GetNextPendingDownload();

            await oldDownload.Finish(sql);


            // Now update the file
            await "TestEndToEndArchiveUpdating.txt".RelativeTo(Fixture.ServerPublicFolder).WriteAllBytesAsync(newFileData);


            await using var tempFile = new TempFile();
            var pendingRequest = DownloadDispatcher.DownloadWithPossibleUpgrade(oldArchive, tempFile.Path);

            for (var times = 0; await downloader.Execute() == 0 && times < 40; times++)
            {
                await Task.Delay(TimeSpan.FromMilliseconds(200));
            }


            for (var times = 0; await patcher.Execute() == 0 && times < 40; times++)
            {
                await Task.Delay(TimeSpan.FromMilliseconds(200));
            }

            Assert.True(await pendingRequest);
            Assert.Equal(oldDataHash, await tempFile.Path.FileHashAsync());
        }
コード例 #3
0
ファイル: AInstaller.cs プロジェクト: LordOfRhun/wabbajack
        public async Task<bool> DownloadArchive(Archive archive, bool download, AbsolutePath? destination = null)
        {
            try
            {
                if (destination == null) 
                    destination = DownloadFolder.Combine(archive.Name);
                await DownloadDispatcher.DownloadWithPossibleUpgrade(archive, destination.Value);
            }
            catch (Exception ex)
            {
                Utils.Log($"Download error for file {archive.Name}");
                Utils.Log(ex.ToString());
                return false;
            }

            return false;
        }
コード例 #4
0
        public async Task <bool> DownloadArchive(Archive archive, bool download, AbsolutePath?destination = null)
        {
            try
            {
                destination ??= DownloadFolder.Combine(archive.Name);

                var result = await DownloadDispatcher.DownloadWithPossibleUpgrade(archive, destination.Value);

                if (result == DownloadDispatcher.DownloadResult.Update)
                {
                    await destination.Value.MoveToAsync(destination.Value.Parent.Combine(archive.Hash.ToHex()));
                }
            }
            catch (Exception ex)
            {
                Utils.Log($"Download error for file {archive.Name}");
                Utils.Log(ex.ToString());
                return(false);
            }

            return(false);
        }