Esempio n. 1
0
        public void Run(bool firstRun)
        {
            Logger.Trace("Run - CurrentDirectory {0}", NPath.CurrentDirectory);

            var gitExecutablePath = SystemSettings.Get(Constants.GitInstallPathKey)?.ToNPath();

            if (gitExecutablePath.HasValue && gitExecutablePath.Value.FileExists()) // we have a git path
            {
                Logger.Trace("Using git install path from settings: {0}", gitExecutablePath);
                InitializeEnvironment(gitExecutablePath.Value);
            }
            else // we need to go find git
            {
                Logger.Trace("No git path found in settings");

                var initEnvironmentTask = new ActionTask <NPath>(CancellationToken, (_, path) => InitializeEnvironment(path))
                {
                    Affinity = TaskAffinity.UI
                };
                var findExecTask = new FindExecTask("git", CancellationToken)
                                   .FinallyInUI((b, ex, path) => {
                    if (b && path.IsInitialized)
                    {
                        Logger.Trace("FindExecTask Success: {0}", path);
                        InitializeEnvironment(path);
                    }
                    else
                    {
                        Logger.Warning("FindExecTask Failure");
                        Logger.Error("Git not found");
                    }
                });

                var installDetails = new GitInstallDetails(Environment.UserCachePath, true);
                var gitInstaller   = new GitInstaller(Environment, CancellationToken, installDetails);

                // if successful, continue with environment initialization, otherwise try to find an existing git installation
                gitInstaller.SetupGitIfNeeded(initEnvironmentTask, findExecTask);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Initialize environment after finding where git is. This needs to run on the main thread
        /// </summary>
        /// <param name="gitExecutablePath"></param>
        /// <param name="octorunScriptPath"></param>
        private void InitializeEnvironment(NPath gitExecutablePath)
        {
            SetupMetrics();

            if (!gitExecutablePath.IsInitialized)
            {
                isBusy = false;
                return;
            }

            Environment.GitExecutablePath = gitExecutablePath;
            Environment.User.Initialize(GitClient);

            var afterGitSetup = new ActionTask(CancellationToken, RestartRepository)
                                .ThenInUI(InitializeUI);

            ITask task = afterGitSetup;

            if (Environment.IsWindows)
            {
                var credHelperTask = GitClient.GetConfig("credential.helper", GitConfigSource.Global);
                credHelperTask.OnEnd += (thisTask, credentialHelper, success, exception) =>
                {
                    if (!success || string.IsNullOrEmpty(credentialHelper))
                    {
                        Logger.Warning("No Windows CredentialHelper found: Setting to wincred");
                        thisTask
                        .Then(GitClient.SetConfig("credential.helper", "wincred", GitConfigSource.Global))
                        .Then(afterGitSetup);
                    }
                    else
                    {
                        thisTask.Then(afterGitSetup);
                    }
                };
                task = credHelperTask;
            }
            task.Start();
        }
Esempio n. 3
0
        public void SetupGitIfNeeded(ActionTask <NPath> onSuccess, ITask onFailure)
        {
            Logger.Trace("SetupGitIfNeeded");

            if (!environment.IsWindows)
            {
                onFailure.Start();
                return;
            }

            new ActionTask(cancellationToken, () => {
                if (IsGitExtracted())
                {
                    Logger.Trace("SetupGitIfNeeded: Skipped");
                    onSuccess.PreviousResult = installDetails.GitExecutablePath;
                    onSuccess.Start();
                }
                else
                {
                    ExtractPortableGit(onSuccess, onFailure);
                }
            }).Start();
        }
Esempio n. 4
0
        /// <summary>
        /// Initialize environment after finding where git is. This needs to run on the main thread
        /// </summary>
        /// <param name="gitExecutablePath"></param>
        /// <param name="octorunScriptPath"></param>
        private void InitializeEnvironment(NPath gitExecutablePath, NPath octorunScriptPath)
        {
            var afterGitSetup = new ActionTask(CancellationToken, RestartRepository)
                                .ThenInUI(InitializeUI);

            Environment.GitExecutablePath = gitExecutablePath;
            Environment.OctorunScriptPath = octorunScriptPath;
            Environment.User.Initialize(GitClient);
            SetupMetrics();

            if (Environment.IsWindows)
            {
                GitClient
                .GetConfig("credential.helper", GitConfigSource.Global)
                .Then((b, credentialHelper) => {
                    if (!string.IsNullOrEmpty(credentialHelper))
                    {
                        Logger.Trace("Windows CredentialHelper: {0}", credentialHelper);
                        afterGitSetup.Start();
                    }
                    else
                    {
                        Logger.Warning("No Windows CredentialHelper found: Setting to wincred");

                        GitClient.SetConfig("credential.helper", "wincred", GitConfigSource.Global)
                        .Then(afterGitSetup)
                        .Start();
                    }
                })
                .Start();
            }
            else
            {
                afterGitSetup.Start();
            }
        }
Esempio n. 5
0
        static void Main(string[] args)
        {
            var taskManager = new TaskManager();
            var syncContext = new ThreadSynchronizationContext(taskManager.Token);

            taskManager.UIScheduler = new SynchronizationContextTaskScheduler(syncContext);
            var env            = new DefaultEnvironment();
            var processManager = new ProcessManager(env, new ProcessEnvironment(env), taskManager.Token);



            ConsoleKey key;

            while ((key = Console.ReadKey().Key) != ConsoleKey.Escape)
            {
                if (key == ConsoleKey.Enter)
                {
                    {
                        //var task = new GitConfigListTask(GitConfigSource.NonSpecified, cts.Token).Configure(processManager);

                        //var other = new FuncTask<List<KeyValuePair<string, string>>, bool>(cts.Token, d =>
                        //{
                        //    Console.WriteLine("Results! {0}", d.Count);
                        //    Thread.Sleep(1000);
                        //    return true;
                        //}, task);
                        //other.Name = "Other";
                        //other.Affinity = TaskAffinity.Concurrent;

                        //other.OnStart += tt => Console.WriteLine(String.Format("Executing id:{0} thread:{1}", tt.Task.Id, Thread.CurrentThread.ManagedThreadId));
                        //other.OnEnd += tt => Console.WriteLine(String.Format("Finished id:{0} thread:{1}", tt.Task.Id, Thread.CurrentThread.ManagedThreadId));


                        //var final = new FuncTask<bool, bool>(cts.Token, d => d, other);
                        //final.Name = "Final";
                        //final.Affinity = TaskAffinity.UI;

                        //final.OnStart += tt => Console.WriteLine(String.Format("Executing id:{0} thread:{1}", tt.Task.Id, Thread.CurrentThread.ManagedThreadId));
                        //final.OnEnd += tt => Console.WriteLine(String.Format("Finished id:{0} thread:{1}", tt.Task.Id, Thread.CurrentThread.ManagedThreadId));

                        //taskManager.Schedule(task, other, final);
                    }

                    {
                        //var task = new GitConfigListTask(GitConfigSource.NonSpecified, cts.Token)
                        //    .ConfigureGitProcess(processManager)
                        //    .Schedule(taskManager);
                        //task
                        //    .ContinueWithUI((success, result) => Console.WriteLine("{0} Result? {1} {2}", Thread.CurrentThread.ManagedThreadId, success,
                        //        success ? String.Join(";", result.Take(10).Select(x => x.Key + "=" + x.Value).ToArray()) : "error", false));
                    }

                    {
                        //var task = new GitConfigGetTask("user.name", GitConfigSource.NonSpecified, cts.Token)
                        //    .ConfigureGitProcess(processManager)

                        //    .Schedule(taskManager);
                        //task
                        //    .ContinueWithUI((success, result) =>
                        //    {
                        //        Console.WriteLine("{0} Result? {1} {2}", Thread.CurrentThread.ManagedThreadId, success, result);
                        //        return 1;
                        //    }, true);
                    }

                    {
                        //var task = new GitConfigGetTask("user.name", GitConfigSource.NonSpecified, cts.Token).ConfigureGitProcess(processManager);
                        //var other = new GitConfigListTask(GitConfigSource.Global, cts.Token).ConfigureGitProcess(processManager);
                        //var another = new ActionTask(cts.Token, () => Console.WriteLine("And we are done"));
                        //task.Then(other).Then(another);
                        //task.Schedule(taskManager);
                        //other.Schedule(taskManager);
                        //another.Schedule(taskManager);
                    }

                    {
                        for (int i = 0; i < 5; i++)
                        {
                            var first = new GitConfigGetTask("user.name", GitConfigSource.NonSpecified, taskManager.Token)
                            {
                                Affinity = TaskAffinity.Concurrent
                            }.Configure(processManager);
                            var second = new GitConfigListTask(GitConfigSource.Global, taskManager.Token)
                            {
                                Affinity = TaskAffinity.Concurrent
                            }.Configure(processManager);
                            var third = new ActionTask(taskManager.Token, _ => Console.WriteLine("And we are done"))
                            {
                                Affinity = TaskAffinity.UI
                            };
                            second.Then(third);
                            taskManager.Schedule(first, second);
                        }
                    }
                }
            }

            taskManager.Stop();

            Console.WriteLine("Done");
            Console.Read();
        }
Esempio n. 6
0
        public void Run(bool firstRun)
        {
            Logger.Trace("Run - CurrentDirectory {0}", NPath.CurrentDirectory);
            isBusy = true;

            var endTask = new ActionTask <GitInstaller.GitInstallationState>(CancellationToken,
                                                                             (_, state) => InitializeEnvironment(state))
            {
                Affinity = TaskAffinity.UI
            };

            ITask <string> setExistingEnvironmentPath;

            if (Environment.IsMac)
            {
                setExistingEnvironmentPath = new SimpleProcessTask(CancellationToken, "bash".ToNPath(), "-c \"/usr/libexec/path_helper\"")
                                             .Configure(ProcessManager, dontSetupGit: true)
                                             .Catch(e => true) // make sure this doesn't throw if the task fails
                                             .Then((success, path) => success ? path?.Split(new[] { "\"" }, StringSplitOptions.None)[1] : null);
            }
            else
            {
                setExistingEnvironmentPath = new FuncTask <string>(CancellationToken, () => null);
            }

            setExistingEnvironmentPath.OnEnd += (t, path, success, ex) =>
            {
                if (path != null)
                {
                    Logger.Trace("Existing Environment Path Original:{0} Updated:{1}", Environment.Path, path);
                    Environment.Path = path;
                }
            };

            var setupOctorun          = new OctorunInstaller(Environment, TaskManager).SetupOctorunIfNeeded();
            var setOctorunEnvironment = new ActionTask <NPath>(CancellationToken,
                                                               (s, octorunPath) => Environment.OctorunScriptPath = octorunPath);

            var getGitFromSettings = new FuncTask <NPath>(CancellationToken, () =>
            {
                var gitExecutablePath = SystemSettings.Get(Constants.GitInstallPathKey)?.ToNPath();
                if (gitExecutablePath.HasValue && gitExecutablePath.Value.FileExists()) // we have a git path
                {
                    Logger.Trace("Using git install path from settings: {0}", gitExecutablePath);
                    return(gitExecutablePath.Value);
                }
                return(NPath.Default);
            });

            getGitFromSettings.OnEnd += (t, path, _, __) =>
            {
                if (path.IsInitialized)
                {
                    var state = new GitInstaller.GitInstallationState {
                        GitExecutablePath = path,
                        GitIsValid        = true
                    };
                    endTask.PreviousResult = state;
                    endTask.Start();
                    return;
                }
                Logger.Trace("Using portable git");

                var setupGit = new GitInstaller(Environment, ProcessManager, TaskManager).SetupGitIfNeeded();
                t.Then(setupGit);
                setupGit.Finally((s, state) =>
                {
                    endTask.PreviousResult = state;
                    endTask.Start();
                });
                setupGit.Progress(progressReporter.UpdateProgress);
                // append installer task to top chain
            };

            var setupChain = setExistingEnvironmentPath.Then(setupOctorun);

            setupChain.OnEnd += (t, path, _, __) =>
            {
                t.GetEndOfChain().Then(setOctorunEnvironment).Then(getGitFromSettings);
            };

            setupChain.Start();
        }
Esempio n. 7
0
 public static ITask Then <T>(this ITask task, ActionTask <T> nextTask, T valueForNextTask, TaskRunOptions runOptions = TaskRunOptions.OnSuccess)
 {
     Guard.ArgumentNotNull(nextTask, nameof(nextTask));
     nextTask.PreviousResult = valueForNextTask;
     return(task.Then(nextTask, runOptions));
 }