コード例 #1
0
        public async Task <(string?MutagenVersion, string?SynthesisVersion)> GetLatestVersions(Version?dotNetVersion, bool includePrerelease)
        {
            try
            {
                if (dotNetVersion == null)
                {
                    Log.Logger.Error("Can not query for latest nuget versions as there is not dotnet SDK installed.");
                    return(null, null);
                }
                Log.Logger.Information("Querying for latest published library versions");
                var bootstrapProjectDir = new DirectoryPath(Path.Combine(Execution.Paths.WorkingDirectory, "VersionQuery"));
                bootstrapProjectDir.DeleteEntireFolder();
                bootstrapProjectDir.Create();
                var slnPath = Path.Combine(bootstrapProjectDir.Path, "VersionQuery.sln");
                SolutionInitialization.CreateSolutionFile(slnPath);
                var projPath = Path.Combine(bootstrapProjectDir.Path, "VersionQuery.csproj");
                SolutionInitialization.CreateProject(projPath, GameCategory.Skyrim, insertOldVersion: true);
                SolutionInitialization.AddProjectToSolution(slnPath, projPath);
                var ret = await DotNetCommands.QuerySynthesisVersions(projPath, current : false, includePrerelease : includePrerelease, CancellationToken.None);

                Log.Logger.Information("Latest published library versions:");
                Log.Logger.Information($"  Mutagen: {ret.MutagenVersion}");
                Log.Logger.Information($"  Synthesis: {ret.SynthesisVersion}");
                return(ret.MutagenVersion ?? this.MutagenVersion, ret.SynthesisVersion ?? this.SynthesisVersion);
            }
            catch (Exception ex)
            {
                Log.Logger.Error(ex, "Error querying for latest nuget versions");
                return(null, null);
            }
        }
コード例 #2
0
        public TempFolder GetRepository(
            out string remote,
            out string local,
            bool createPatcherFiles = true)
        {
            var folder = Utility.GetTempFolder();

            local = Path.Combine(folder.Dir.Path, "Local");
            Repository.Init(local);
            remote = Path.Combine(folder.Dir.Path, "Remote");
            Repository.Init(remote, isBare: true);

            Directory.CreateDirectory(local);
            using var localRepo = new Repository(local);
            File.AppendAllText(Path.Combine(local, AFile), "Hello there");
            Commands.Stage(localRepo, AFile);
            var sig = Signature;

            localRepo.Commit("Initial commit", sig, sig);

            if (createPatcherFiles)
            {
                var files = SolutionInitialization.CreateSolutionFile(Path.Combine(local, SlnPath))
                            .And(SolutionInitialization.CreateProject(Path.Combine(local, ProjPath), GameCategory.Skyrim));
                SolutionInitialization.AddProjectToSolution(Path.Combine(local, SlnPath), Path.Combine(local, ProjPath));
                foreach (var path in files)
                {
                    Commands.Stage(localRepo, path);
                }
                localRepo.Commit("Added solution", sig, sig);
            }

            var remoteRef = localRepo.Network.Remotes.Add("origin", remote);
            var master    = localRepo.Branches[DefaultBranch];

            localRepo.Branches.Update(
                master,
                b => b.Remote         = remoteRef.Name,
                b => b.UpstreamBranch = master.CanonicalName);
            localRepo.Network.Push(master);

            return(folder);
        }
コード例 #3
0
        public ExistingSolutionInitVM()
        {
            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: SolutionInitialization.ValidateProjectPath(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(profile) =>
                {
                    var patcher = new SolutionPatcherVM(profile);
                    SolutionInitialization.CreateProject(i.validation.Value, patcher.Profile.Release.ToCategory());
                    SolutionInitialization.AddProjectToSolution(i.sln.Value, i.validation.Value);
                    patcher.SolutionPath.TargetPath = i.sln.Value;
                    patcher.ProjectSubpath = Path.Combine(i.proj, $"{i.proj}.csproj");
                    return patcher.AsEnumerable();
                }));
            });
        }
コード例 #4
0
        public NewSolutionInitVM()
        {
            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: SolutionInitialization.ValidateProjectPath(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(profile) =>
                {
                    var patcher = new SolutionPatcherVM(profile);
                    SolutionInitialization.CreateSolutionFile(i.sln.Value);
                    SolutionInitialization.CreateProject(i.validation.Value, patcher.Profile.Release.ToCategory());
                    SolutionInitialization.AddProjectToSolution(i.sln.Value, i.validation.Value);
                    SolutionInitialization.GenerateGitIgnore(Path.GetDirectoryName(i.sln.Value) !);
                    patcher.SolutionPath.TargetPath = i.sln.Value;
                    var projName = Path.GetFileNameWithoutExtension(i.validation.Value);
                    patcher.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);
        }