예제 #1
0
 public GroupFactory(
     Func <GroupVm> groupCreator,
     IPatcherFactory patcherFactory)
 {
     _groupCreator   = groupCreator;
     _patcherFactory = patcherFactory;
 }
예제 #2
0
 public CliPatcherInitVm(
     IPatcherNameVm nameVm,
     IPatcherInitializationVm init,
     IShowHelpSetting showHelpSetting,
     IPathToExecutableInputVm executableInputVm,
     IPatcherFactory factory)
 {
     _init                     = init;
     Factory                   = factory;
     NameVm                    = nameVm;
     ShowHelpSetting           = showHelpSetting;
     ExecutableInput           = executableInputVm;
     _canCompleteConfiguration = executableInputVm.WhenAnyValue(x => x.Picker.ErrorState)
                                 .Cast <ErrorResponse, ErrorResponse>()
                                 .ToGuiProperty(this, nameof(CanCompleteConfiguration), ErrorResponse.Success);
 }
        public ExistingSolutionInitVm(
            IGameCategoryContext gameCategoryContext,
            IPatcherFactory patcherFactory,
            IValidateProjectPath validateProjectPath,
            ICreateProject createProject,
            IAddProjectToSolution addProjectToSolution)
        {
            SolutionPath.PathType         = PathPickerVM.PathTypeOptions.File;
            SolutionPath.ExistCheckOption = PathPickerVM.CheckOptions.On;
            SolutionPath.Filters.Add(new CommonFileDialogFilter("Solution", ".sln"));

            var validation = Observable.CombineLatest(
                SolutionPath.PathState(),
                this.WhenAnyValue(x => x.ProjectName),
                (sln, proj) => (sln, proj, validation: validateProjectPath.Validate(proj, sln)))
                             .Replay(1)
                             .RefCount();

            _projectError = validation
                            .Select(i => (ErrorResponse)i.validation)
                            .ToGuiProperty <ErrorResponse>(this, nameof(ProjectError), ErrorResponse.Success);

            InitializationCall = validation
                                 .Select((i) =>
            {
                if (!i.sln.Succeeded)
                {
                    return(i.sln.BubbleFailure <InitializerCall>());
                }
                if (!i.validation.Succeeded)
                {
                    return(i.validation.BubbleFailure <InitializerCall>());
                }
                return(GetResponse <InitializerCall> .Succeed(async() =>
                {
                    createProject.Create(gameCategoryContext.Category, i.validation.Value);
                    addProjectToSolution.Add(i.sln.Value, i.validation.Value);
                    var patcher = patcherFactory.GetSolutionPatcher(new SolutionPatcherSettings()
                    {
                        SolutionPath = i.sln.Value,
                        ProjectSubpath = Path.Combine(i.proj, $"{i.proj}.csproj"),
                    });
                    return patcher.AsEnumerable();
                }));
            });
        }
예제 #4
0
        public GitPatcherInitVm(
            IPatcherInitializationVm init,
            ILogger logger,
            IPatcherFactory patcherFactory,
            INavigateTo navigateTo,
            IPathSanitation pathSanitation,
            PatcherStoreListingVm.Factory listingVmFactory,
            IRegistryListingsProvider listingsProvider,
            PatcherInitRenameValidator renamer)
        {
            _init           = init;
            _patcherFactory = patcherFactory;
            _renamer        = renamer;
            _pathSanitation = pathSanitation;
            Patcher         = patcherFactory.GetGitPatcher();

            _canCompleteConfiguration = this.WhenAnyValue(x => x.Patcher.RepoClonesValid.Valid)
                                        .Select(x => ErrorResponse.Create(x))
                                        .ToGuiProperty(this, nameof(CanCompleteConfiguration), ErrorResponse.Success);

            PatcherRepos = Observable.Return(Unit.Default)
                           .ObserveOn(RxApp.TaskpoolScheduler)
                           .SelectTask(async _ =>
            {
                try
                {
                    var customization = listingsProvider.Get(CancellationToken.None);

                    if (customization.Failed)
                    {
                        return(Observable.Empty <IChangeSet <PatcherStoreListingVm> >());
                    }

                    return(customization.Value
                           .SelectMany(repo =>
                    {
                        return repo.Patchers
                        .Select(p =>
                        {
                            return listingVmFactory(this, p, repo);
                        });
                    })
                           .AsObservableChangeSet());
                }
                catch (Exception ex)
                {
                    logger.Error(ex, "Error downloading patcher listing");
                    Error = ErrorResponse.Fail(ex);
                }
                return(Observable.Empty <IChangeSet <PatcherStoreListingVm> >());
            })
                           .Switch()
                           .Sort(Comparer <PatcherStoreListingVm> .Create((x, y) => x.Name.CompareTo(y.Name)))
                           .Filter(this.WhenAnyValue(x => x.ShowAll)
                                   .DistinctUntilChanged()
                                   .Select(show => new Func <PatcherStoreListingVm, bool>(
                                               (p) =>
            {
                if (p.Raw.Customization?.Visibility is VisibilityOptions.Visible)
                {
                    return(true);
                }
                else if (p.Raw.Customization?.Visibility is VisibilityOptions.IncludeButHide)
                {
                    return(show);
                }
                else if (p.Raw.Customization?.Visibility is VisibilityOptions.Exclude)
                {
                    return(false);                                                                               // just in case.
                }
                else
                {
                    return(true);
                }
            })))
                           .Filter(this.WhenAnyValue(x => x.Search)
                                   .Debounce(TimeSpan.FromMilliseconds(350), RxApp.MainThreadScheduler)
                                   .Select(x => x.Trim())
                                   .DistinctUntilChanged()
                                   .Select(search =>
            {
                if (string.IsNullOrWhiteSpace(search))
                {
                    return(new Func <PatcherStoreListingVm, bool>(_ => true));
                }
                return(new Func <PatcherStoreListingVm, bool>(
                           (p) =>
                {
                    if (p.Name.Contains(search, StringComparison.OrdinalIgnoreCase))
                    {
                        return true;
                    }
                    if (p.Raw.Customization?.OneLineDescription?.Contains(search, StringComparison.OrdinalIgnoreCase) ?? false)
                    {
                        return true;
                    }
                    return false;
                }));
            }))
                           .ObserveOn(RxApp.MainThreadScheduler)
                           .ToObservableCollection(this);

            OpenPopulationInfoCommand = ReactiveCommand.Create(() => navigateTo.Navigate(Constants.ListingRepositoryAddress));
            ClearSearchCommand        = ReactiveCommand.Create(() => Search = string.Empty);
        }
예제 #5
0
        public NewSolutionInitVm(
            IGameCategoryContext gameCategoryContext,
            IPatcherFactory patcherFactory,
            IValidateProjectPath validateProjectPath,
            ICreateSolutionFile createSolutionFile,
            ICreateProject createProject,
            IAddProjectToSolution addProjectToSolution,
            IGenerateGitIgnore gitIgnore)
        {
            ParentDirPath.PathType         = PathPickerVM.PathTypeOptions.Folder;
            ParentDirPath.ExistCheckOption = PathPickerVM.CheckOptions.On;

            _solutionPath = Observable.CombineLatest(
                this.ParentDirPath.PathState(),
                this.WhenAnyValue(x => x.SolutionName),
                (parentDir, slnName) =>
            {
                if (string.IsNullOrWhiteSpace(slnName))
                {
                    return(GetResponse <string> .Fail(val: slnName, reason: "Solution needs a name."));
                }

                // Will reevaluate once parent dir is fixed
                if (parentDir.Failed)
                {
                    return(GetResponse <string> .Succeed(value: slnName));
                }
                try
                {
                    var slnPath = Path.Combine(parentDir.Value, slnName);
                    if (File.Exists(slnPath))
                    {
                        return(GetResponse <string> .Fail(val: slnName, reason: $"Target solution folder cannot already exist as a file: {slnPath}"));
                    }
                    if (Directory.Exists(slnPath) &&
                        (Directory.EnumerateFiles(slnPath).Any() ||
                         Directory.EnumerateDirectories(slnPath).Any()))
                    {
                        return(GetResponse <string> .Fail(val: slnName, reason: $"Target solution folder must be empty: {slnPath}"));
                    }
                    return(GetResponse <string> .Succeed(Path.Combine(slnPath, $"{slnName}.sln")));
                }
                catch (ArgumentException)
                {
                    return(GetResponse <string> .Fail(val: slnName, reason: "Improper solution name. Go simpler."));
                }
            })
                            .ToGuiProperty(this, nameof(SolutionPath));

            var validation = Observable.CombineLatest(
                this.ParentDirPath.PathState(),
                this.WhenAnyValue(x => x.SolutionName),
                this.WhenAnyValue(x => x.SolutionPath),
                this.WhenAnyValue(x => x.ProjectName),
                (parentDir, slnName, sln, proj) =>
            {
                // Use solution name if proj empty.
                if (string.IsNullOrWhiteSpace(proj))
                {
                    proj = SolutionNameProcessor(slnName);
                }
                return(parentDir, sln, proj, validation: validateProjectPath.Validate(proj, sln));
            })
                             .Replay(1)
                             .RefCount();

            _projectError = validation
                            .Select(i => (ErrorResponse)i.validation)
                            .ToGuiProperty <ErrorResponse>(this, nameof(ProjectError), ErrorResponse.Success);

            InitializationCall = validation
                                 .Select((i) =>
            {
                if (i.parentDir.Failed)
                {
                    return(i.parentDir.BubbleFailure <InitializerCall>());
                }
                if (i.sln.Failed)
                {
                    return(i.sln.BubbleFailure <InitializerCall>());
                }
                if (i.validation.Failed)
                {
                    return(i.validation.BubbleFailure <InitializerCall>());
                }
                return(GetResponse <InitializerCall> .Succeed(async() =>
                {
                    var projName = Path.GetFileNameWithoutExtension(i.validation.Value);
                    createSolutionFile.Create(i.sln.Value);
                    createProject.Create(gameCategoryContext.Category, i.validation.Value);
                    addProjectToSolution.Add(i.sln.Value, i.validation.Value);
                    gitIgnore.Generate(Path.GetDirectoryName(i.sln.Value) !);
                    var patcher = patcherFactory.GetSolutionPatcher(new SolutionPatcherSettings()
                    {
                        SolutionPath = i.sln.Value,
                        ProjectSubpath = Path.Combine(projName, $"{projName}.csproj")
                    });
                    return patcher.AsEnumerable();
                }));
            });

            _projectNameWatermark = this.WhenAnyValue(x => x.SolutionName)
                                    .Select(x => string.IsNullOrWhiteSpace(x) ? "The name of the patcher" : SolutionNameProcessor(x))
                                    .ToGuiProperty <string>(this, nameof(ProjectNameWatermark), string.Empty);
        }