Пример #1
0
 public PatcherStoreListingVm(
     GitPatcherInitVm gitInit,
     PatcherListing listing,
     RepositoryListing repositoryListing,
     INavigateTo navigate)
 {
     Repository = new RepositoryStoreListingVm(repositoryListing);
     Raw        = listing;
     try
     {
         Name = Raw.Customization?.Nickname ?? Path.GetFileName(Raw.ProjectPath).TrimEnd(".csproj");
     }
     catch (Exception)
     {
         Name = "Error";
     }
     _isSelected = gitInit.WhenAnyValue(x => x.SelectedPatcher)
                   .Select(x => x == this)
                   .ToGuiProperty(this, nameof(IsSelected));
     OpenWebsite = ReactiveCommand.Create(() => navigate.Navigate(RepoPath));
     AddCommand  = ReactiveCommand.CreateFromTask(async() =>
     {
         await gitInit.AddStorePatcher(this);
     });
 }
Пример #2
0
 public PatcherStoreListingVM(GitPatcherInitVM gitInit, PatcherListing listing, RepositoryStoreListingVM repo)
 {
     Repository = repo;
     Raw        = listing;
     try
     {
         Name = Raw.Customization?.Nickname ?? Path.GetFileName(Raw.ProjectPath).TrimEnd(".csproj");
     }
     catch (Exception)
     {
         Name = "Error";
     }
     _IsSelected = gitInit.WhenAnyValue(x => x.SelectedPatcher)
                   .Select(x => x == this)
                   .ToGuiProperty(this, nameof(IsSelected));
     OpenWebsite = ReactiveCommand.Create(() => Utility.NavigateToPath(RepoPath));
     AddCommand  = ReactiveCommand.Create(() =>
     {
         gitInit.AddStorePatcher(this);
     });
 }
Пример #3
0
        public async Task <PatcherListing[]> Construct(Dependent dep, IEnumerable <string> projs)
        {
            var gitHubClient = _githubClientProvider.Client;

            return((await projs
                    .ToAsyncEnumerable()
                    .SelectAwait(async proj =>
            {
                var listing = new PatcherListing()
                {
                    ProjectPath = proj,
                };
                try
                {
                    var metaPath = Path.Combine(Path.GetDirectoryName(proj) !, Constants.MetaFileName);
                    System.Console.WriteLine($"{dep} retrieving meta path for {proj}");
                    IReadOnlyList <RepositoryContent>?content;
                    try
                    {
                        content = await gitHubClient.Repository.Content.GetAllContents(dep.User, dep.Repository, metaPath);
                    }
                    catch (Exception e)
                    {
                        System.Console.WriteLine($"{dep} no meta path found for {proj}");
                        return null;
                    }
                    _apiUsagePrinter.Print();
                    if (content.Count != 1)
                    {
                        System.Console.WriteLine($"{dep} no meta path found for {proj}");
                        return null;
                    }
                    System.Console.WriteLine($"{dep} retrieved meta path for {proj}");
                    var customization = JsonSerializer.Deserialize <PatcherCustomization>(content[0].Content, _jsonOptions.Options) !;
                    if (string.IsNullOrWhiteSpace(customization.Nickname))
                    {
                        customization.Nickname = $"{dep.User}/{dep.Repository}";
                    }
                    listing.Customization = customization;

                    // Backwards compatibility
                    try
                    {
                        using var doc = JsonDocument.Parse(content[0].Content);
                        foreach (var elem in doc.RootElement.EnumerateObject())
                        {
                            if (elem.NameEquals("HideByDefault") &&
                                elem.Value.GetBoolean())
                            {
                                customization.Visibility = VisibilityOptions.IncludeButHide;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        System.Console.WriteLine($"{proj} Error handling backwards compatibility: {ex}");
                    }
                }
                catch (Octokit.NotFoundException)
                {
                }
                catch (Octokit.ApiException)
                {
                }
                catch (Exception ex)
                {
                    System.Console.WriteLine($"{proj} Error constructing listing: {ex}");
                    return null;
                }
                await Task.Delay(500);
                return listing;
            })
                    .ToListAsync())
                   .NotNull()
                   .Where(listing =>
            {
                if (listing.Customization?.Visibility == VisibilityOptions.Exclude)
                {
                    System.Console.WriteLine($"{dep} excluding {listing.ProjectPath}");
                    return false;
                }
                return true;
            })
                   .ToArray());
        }