Esempio n. 1
0
 public override bool TryOpen([NotNull] string path, out IProject project, out string failureReason)
 {
     try
     {
         var rootFs   = new ReadOnlyFileSystem(path);
         var metadata = Validate(rootFs);
         var p        = new MagicTranslatorProject();
         p.Init(metadata, rootFs);
         project       = p;
         failureReason = "";
         return(true);
     }
     catch (FileNotFoundException)
     {
         failureReason = "This is not a valid Magic Translator project: metadata.json file is missing.";
     }
     catch (JsonSerializationException)
     {
         failureReason = "This is not a valid Magic Translator project: the metadata.json is not valid.";
     }
     catch (InvalidDataException ex)
     {
         failureReason = $"This is not a valid Magic Translator project: ${ex.Message}";
     }
     project = null;
     return(false);
 }
Esempio n. 2
0
    public void Listing()
    {
        using var project =
                  new MagicTranslatorProject.MagicTranslatorProject(
                      Path.Combine(
                          TestDataPaths.MagicTranslatorTestDir,
                          "Basic"));

        Assert.Equal(new [] { "/VOL00000010", "/VOL00000020" }, project.Root.Children.Select(vol => vol.ReadableIdentifier).OrderBy(x => x));
        Assert.Equal(
            new [] {
            "Character: Invincible Super Hero",
            "Character: Lame Guy",
            "N/A",
            "Chapter Title",
            "Narrator",
            "SFX"
        }.OrderBy(x => x),
            project.Root.AllCharacters.Select(ch => ch.ToString()).OrderBy(x => x));
        Assert.Equal(
            new [] { "/VOL00000010/CH00000001", "/VOL00000010/CH00000002" }.OrderBy(x => x),
            project.Root.Children
            .First(vol => vol.ReadableIdentifier == "/VOL00000010")
            .Children
            .Select(ch => ch.ReadableIdentifier)
            .OrderBy(x => x));

        Assert.Equal(
            new [] { "/VOL00000010/CH00000001/P00000001", "/VOL00000010/CH00000001/P00000002" }.OrderBy(x => x),
            project.Root.Children
            .First(vol => vol.ReadableIdentifier == "/VOL00000010")
            .Children
            .First(ch => ch.ReadableIdentifier == "/VOL00000010/CH00000001")
            .Children
            .Select(p => p.ReadableIdentifier)
            .OrderBy(x => x));

        Assert.Equal(
            new [] { "UNLIMITED POWER!!", "menacing" }.OrderBy(x => x),
            project.Root.Children
            .First(vol => vol.ReadableIdentifier == "/VOL00000010")
            .Children
            .First(ch => ch.ReadableIdentifier == "/VOL00000010/CH00000001")
            .Children
            .First(p => p.ReadableIdentifier == "/VOL00000010/CH00000001/P00000002")
            .Children
            .Select(capture => capture.Translation.TranslatedText)
            .OrderBy(x => x));
    }