예제 #1
0
        public void should_return_author_byline_for_a_japanese_article()
        {
            var author1 = ItemBuilder.anItem(db)
                          .havingName("Author1")
                          .havingSitecoreTemplateID(ID.Parse(ID.NewID))
                          .havingField("Title", "田中 正朗")
                          .havingLanguages("ja")
                          .BuildDBItemWithFields();

            var author2 = ItemBuilder.anItem(db)
                          .havingName("Author2")
                          .havingSitecoreTemplateID(ID.NewID)
                          .havingField("Title", "田中 正朗")
                          .havingLanguages("ja")
                          .BuildDBItemWithFields();

            var article = ItemBuilder.anItem(db)
                          .havingName(@"アジア太平洋地域におけるプライベートエクイティ: リバウンド、グローバリゼーション、その他の動き")
                          .havingSitecoreID(Guid.NewGuid().ToString())
                          .havingMultiListField("Authors", author1, author2)
                          .havingLanguages("ja")
                          .BuildDBItemWithFields();

            var authorAPI = new AuthorAPI(db);
            //Both Authors empty
            var authors = authorAPI.GetAuthors(article);

            Assert.IsNotNull(authors);
            Assert.AreEqual("田中 正朗", authors[0]);
        }
예제 #2
0
        protected override async Task <ExitCode> Run()
        {
            var hash = Hash.FromBase64(NoPatchHash);

            Console.WriteLine(await AuthorAPI.NoPatch(hash, Rationale));
            return(ExitCode.Ok);
        }
예제 #3
0
        public void should_return_author_byline_for_an_article_in_case_of_more_than_two_authors()
        {
            var author1 = ItemBuilder.anItem(db)
                          .havingSitecoreTemplateID(ID.NewID)
                          .havingName("Author1")
                          .havingField("Title", "David Chinn")
                          .BuildDBItemWithFields();

            var author2 = ItemBuilder.anItem(db)
                          .havingSitecoreTemplateID(ID.NewID)
                          .havingName("Author2")
                          .havingField("Title", "Ondrej Burkacky")
                          .BuildDBItemWithFields();


            var author3 = ItemBuilder.anItem(db)
                          .havingSitecoreTemplateID(ID.NewID)
                          .havingName("Author3")
                          .havingField("Title", "Kevin Dehoff")
                          .BuildDBItemWithFields();

            var article = ItemBuilder.anItem(db)
                          .havingName(@"Internaltional Defense Sales")
                          .havingSitecoreID(Guid.NewGuid().ToString())
                          .havingMultiListField("Authors", author1, author2, author3)
                          .BuildDBItemWithFields();

            var authorAPI = new AuthorAPI(db);
            //Both authors same as given above
            var articleByline = authorAPI.GetAuthors(article);


            Assert.IsNotNull(articleByline);
        }
예제 #4
0
        public AuthorFilesVM(SettingsVM vm) : base(vm.MWVM)
        {
            IsUploading = _isUploading;
            Picker      = new FilePickerVM(this);

            _isVisible = AuthorAPI.HaveAuthorAPIKey.Select(h => h ? Visibility.Visible : Visibility.Collapsed)
                         .ToProperty(this, x => x.IsVisible);

            SelectFile = Picker.ConstructTypicalPickerCommand(IsUploading.StartWith(false).Select(u => !u));

            HyperlinkCommand = ReactiveCommand.Create(() => Clipboard.SetText(FinalUrl));

            Upload = ReactiveCommand.Create(async() =>
            {
                _isUploading.OnNext(true);
                try
                {
                    FinalUrl = await AuthorAPI.UploadFile(Picker.TargetPath,
                                                          progress => UploadProgress = progress);
                }
                catch (Exception ex)
                {
                    FinalUrl = ex.ToString();
                }
                finally
                {
                    _isUploading.OnNext(false);
                }
            }, IsUploading.StartWith(false).Select(u => !u)
                                            .CombineLatest(Picker.WhenAnyValue(t => t.TargetPath).Select(f => f != null),
                                                           (a, b) => a && b));
        }
예제 #5
0
        protected override async Task <ExitCode> Run()
        {
            var files = await AuthorAPI.GetMyFiles();

            foreach (var file in files)
            {
                Console.WriteLine(file);
            }
            return(0);
        }
예제 #6
0
        public AuthorFilesVM(SettingsVM vm) : base(vm.MWVM)
        {
            IsUploading = _isUploading;
            Picker      = new FilePickerVM(this);

            _isVisible = AuthorAPI.HaveAuthorAPIKey.Select(h => h ? Visibility.Visible : Visibility.Collapsed)
                         .ToProperty(this, x => x.IsVisible);

            SelectFile = Picker.ConstructTypicalPickerCommand(IsUploading.StartWith(false).Select(u => !u));

            HyperlinkCommand = ReactiveCommand.Create(() => Clipboard.SetText(FinalUrl));

            ManageFiles = ReactiveCommand.Create(async() =>
            {
                var authorApiKey = await AuthorAPI.GetAPIKey();
                Utils.OpenWebsite(new Uri($"{Consts.WabbajackBuildServerUri}author_controls/login/{authorApiKey}"));
            });

            Upload = ReactiveCommand.Create(async() =>
            {
                _isUploading.OnNext(true);
                try
                {
                    using var queue = new WorkQueue();
                    var result      = await(await Client.Create()).UploadFile(queue, Picker.TargetPath,
                                                                              (msg, progress) =>
                    {
                        FinalUrl       = msg;
                        UploadProgress = (double)progress;
                    });
                    FinalUrl = result.ToString();
                }
                catch (Exception ex)
                {
                    FinalUrl = ex.ToString();
                }
                finally
                {
                    FinalUrl = FinalUrl.Replace(" ", "%20");
                    _isUploading.OnNext(false);
                }
            }, IsUploading.StartWith(false).Select(u => !u)
                                            .CombineLatest(Picker.WhenAnyValue(t => t.TargetPath).Select(f => f != default),
                                                           (a, b) => a && b));
        }
예제 #7
0
        public async Task CanUploadFilesUsingClientApi()
        {
            using (var file = new TempFile())
            {
                var data = new byte[1024 * 1024 * 8 * 4];
                await using (var fs = file.Path.Create())
                {
                    await fs.WriteAsync(data);
                }

                Utils.Log($"Uploading {file.Path.Size.ToFileSizeString()} file");
                var result = await AuthorAPI.UploadFile(file.Path,
                                                        progress => Utils.Log($"Uploading : {progress * 100}%"), Fixture.APIKey);

                Utils.Log($"Result {result}");
                Assert.StartsWith("https://wabbajackpush.b-cdn.net/" + (string)file.Path.FileNameWithoutExtension, result);
            }
        }
예제 #8
0
        private async Task RevalidateLists()
        {
            var result = await AuthorAPI.UpdateServerModLists();

            Assert.NotNull(result);

            var sql      = Fixture.GetService <SqlService>();
            var settings = Fixture.GetService <AppSettings>();
            var job      = await sql.GetJob();

            Assert.NotNull(job);
            Assert.IsType <UpdateModLists>(job.Payload);


            job.Result = await job.Payload.Execute(sql, settings);

            await sql.FinishJob(job);

            Assert.Equal(JobResultType.Success, job.Result.ResultType);
        }
예제 #9
0
        public async Task CanNotifyOfInis()
        {
            var archive =
                new Archive(
                    new NexusDownloader.State
            {
                Game   = Game.SkyrimSpecialEdition,
                ModID  = long.MaxValue >> 3,
                FileID = long.MaxValue >> 3,
            })
            {
                Name = Guid.NewGuid().ToString()
            };

            Assert.True(await AuthorAPI.UploadPackagedInis(new[] { archive }));

            var SQL = Fixture.GetService <SqlService>();
            var job = await SQL.GetJob();

            Assert.NotNull(job);
            Assert.IsType <IndexJob>(job.Payload);
            var payload = (IndexJob)job.Payload;

            Assert.IsType <NexusDownloader.State>(payload.Archive.State);

            var casted = (NexusDownloader.State)payload.Archive.State;

            Assert.Equal(Game.SkyrimSpecialEdition, casted.Game);

            // Insert the record into SQL
            await SQL.AddDownloadState(Hash.FromHex("00e8bbbf591f61a3"), casted);

            // Enqueue the same file again
            Assert.True(await AuthorAPI.UploadPackagedInis(new[] { archive }));

            // File is aleady indexed so nothing gets enqueued
            Assert.Null(await SQL.GetJob());
        }
예제 #10
0
        public async Task TestCanPurgeModInfo()
        {
            var sqlService = Fixture.GetService <SqlService>();
            var modId      = long.MaxValue >> 3;
            await sqlService.AddNexusModFiles(Game.SkyrimSpecialEdition, modId, DateTime.Now,
                                              new NexusApiClient.GetModFilesResponse {
                files = new List <NexusFileInfo>
                {
                    new NexusFileInfo
                    {
                        file_name = "blerg"
                    }
                }
            });

            var api = await NexusApiClient.Get();

            var modInfoResponse = await api.GetModFiles(Game.SkyrimSpecialEdition, modId);

            Assert.Single(modInfoResponse.files);
            Assert.Equal("blerg", modInfoResponse.files.First().file_name);

            await AuthorAPI.PurgeNexusModInfo(modId);
        }
예제 #11
0
        public AuthorFilesVM(SettingsVM vm) : base(vm.MWVM)
        {
            var sub = new Subject <double>();

            Queue.Status.Select(s => (double)s.ProgressPercent).Subscribe(v =>
            {
                UploadProgress = v;
            });
            IsVisible = AuthorAPI.HasAPIKey ? Visibility.Visible : Visibility.Collapsed;

            SelectFile = ReactiveCommand.Create(() =>
            {
                var fod = UIUtils.OpenFileDialog("*|*");
                if (fod != null)
                {
                    SelectedFile = fod;
                }
            });

            Upload = ReactiveCommand.Create(async() =>
            {
                SelectedFile = await AuthorAPI.UploadFile(Queue, SelectedFile);
            });
        }
예제 #12
0
        public async Task CanIndexAndUpdateFiles()
        {
            var _sql = Fixture.GetService <SqlService>();

            await using var conn = await _sql.Open();

            await conn.ExecuteAsync("DELETE FROM dbo.NoPatch");

            var settings = Fixture.GetService <AppSettings>();

            settings.ValidateModUpgrades = false;
            var validator = Fixture.GetService <ListValidator>();
            var nonNexus  = Fixture.GetService <NonNexusDownloadValidator>();
            var modLists  = await MakeModList("CanIndexAndUpdateFiles.txt");

            Consts.ModlistMetadataURL = modLists.ToString();


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

            patcher.NoCleaning = true;

            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();

            var oldArchive = new Archive(new NexusDownloader.State {
                Game = Game.Enderal, ModID = 42, FileID = 10
            })
            {
                Size = oldFileData.Length,
                Hash = oldDataHash
            };
            var newArchive = new Archive(new NexusDownloader.State {
                Game = Game.Enderal, ModID = 42, FileID = 11
            })
            {
                Size = newFileData.Length,
                Hash = newDataHash
            };

            await IngestData(archiver, oldFileData);
            await IngestData(archiver, newFileData);

            await sql.EnqueueDownload(oldArchive);

            var oldDownload = await sql.GetNextPendingDownload();

            await oldDownload.Finish(sql);

            await sql.EnqueueDownload(newArchive);

            var newDownload = await sql.GetNextPendingDownload();

            await newDownload.Finish(sql);


            await Assert.ThrowsAsync <HttpException>(async() => await ClientAPI.GetModUpgrade(oldArchive, newArchive, TimeSpan.Zero, TimeSpan.Zero));

            Assert.True(await patcher.Execute() > 1);

            Assert.Equal(new Uri("https://test-files.wabbajack.org/79223277e28e1b7b_3286c571d95f5666"), await ClientAPI.GetModUpgrade(oldArchive, newArchive, TimeSpan.Zero, TimeSpan.Zero));

            Assert.Equal("Purged", await AuthorAPI.NoPatch(oldArchive.Hash, "Testing NoPatch"));

            await Assert.ThrowsAsync <HttpException>(async() => await ClientAPI.GetModUpgrade(oldArchive, newArchive, TimeSpan.Zero, TimeSpan.Zero));

            Assert.True(await sql.IsNoPatch(oldArchive.Hash));
        }
예제 #13
0
 protected override async Task <int> Run()
 {
     Console.WriteLine($"Job ID: {await AuthorAPI.UpdateServerModLists()}");
     return(0);
 }
예제 #14
0
 protected override async Task <ExitCode> Run()
 {
     Console.WriteLine(await AuthorAPI.DeleteFile(Name));
     return(0);
 }
예제 #15
0
 protected override async Task <ExitCode> Run()
 {
     CLIUtils.Log($"Job ID: {await AuthorAPI.UpdateNexusCache()}");
     return(0);
 }
예제 #16
0
 protected override async Task <int> Run()
 {
     Console.WriteLine($"Job ID: {await AuthorAPI.UpdateNexusCache()}");
     return(0);
 }
예제 #17
0
 protected override async Task <ExitCode> Run()
 {
     Console.WriteLine(await AuthorAPI.GetServerLog());
     return(0);
 }
예제 #18
0
 protected override async Task <ExitCode> Run()
 {
     CLIUtils.Log($"Job ID: {await AuthorAPI.UpdateServerModLists()}");
     return(0);
 }
예제 #19
0
 protected override async Task <ExitCode> Run()
 {
     Console.WriteLine(await AuthorAPI.PurgeNexusModInfo(ModId));
     return(ExitCode.Ok);
 }