Ejemplo n.º 1
0
        public OctorunTask(CancellationToken token, IKeychain keychain, IEnvironment environment,
                           string arguments,
                           IOutputProcessor <OctorunResult> processor = null)
            : base(token, processor ?? new OctorunResultOutputProcessor())
        {
            this.clientId        = ApplicationInfo.ClientId;
            this.clientSecret    = ApplicationInfo.ClientSecret;
            this.pathToNodeJs    = environment.NodeJsExecutablePath;
            this.pathToOctorunJs = environment.OctorunScriptPath;
            this.arguments       = $"\"{pathToOctorunJs}\" {arguments}";

            var cloneUrl = environment.Repository?.CloneUrl;
            var host     = String.IsNullOrEmpty(cloneUrl)
                ? UriString.ToUriString(HostAddress.GitHubDotComHostAddress.WebUri)
                : new UriString(cloneUrl.ToRepositoryUri()
                                .GetComponents(UriComponents.SchemeAndServer, UriFormat.SafeUnescaped));

            var adapter = keychain.Connect(host);

            if (adapter.Credential?.Token != null)
            {
                userToken = adapter.Credential.Token;
            }
            else
            {
                // use a cached adapter if there is one filled out
                adapter = keychain.LoadFromSystem(host);
                if (adapter != null)
                {
                    userToken = adapter.Credential.Token;
                }
            }
        }
Ejemplo n.º 2
0
        public ApiClient(UriString hostUrl, IKeychain keychain, IProcessManager processManager, ITaskManager taskManager, IEnvironment environment)
        {
            Guard.ArgumentNotNull(keychain, nameof(keychain));

            var host = String.IsNullOrEmpty(hostUrl)
                ? UriString.ToUriString(HostAddress.GitHubDotComHostAddress.WebUri)
                : new UriString(hostUrl.ToRepositoryUri()
                                .GetComponents(UriComponents.SchemeAndServer, UriFormat.SafeUnescaped));

            HostAddress         = HostAddress.Create(host);
            OriginalUrl         = host;
            this.keychain       = keychain;
            this.processManager = processManager;
            this.taskManager    = taskManager;
            this.environment    = environment;
            loginManager        = new LoginManager(keychain, processManager, taskManager, environment);
        }
Ejemplo n.º 3
0
        private void SignOut(object obj)
        {
            UriString host;

            if (Repository != null && Repository.CloneUrl != null && Repository.CloneUrl.IsValidUri)
            {
                host = new UriString(Repository.CloneUrl.ToRepositoryUri()
                                     .GetComponents(UriComponents.SchemeAndServer, UriFormat.SafeUnescaped));
            }
            else
            {
                host = UriString.ToUriString(HostAddress.GitHubDotComHostAddress.WebUri);
            }

            var apiClient = ApiClient.Create(host, Platform.Keychain);

            apiClient.Logout(host);
        }
Ejemplo n.º 4
0
        private void SignOut(object obj)
        {
            UriString host;

            if (Repository != null && Repository.CloneUrl != null && Repository.CloneUrl.IsValidUri)
            {
                host = new UriString(Repository.CloneUrl.ToRepositoryUri()
                                     .GetComponents(UriComponents.SchemeAndServer, UriFormat.SafeUnescaped));
            }
            else
            {
                host = UriString.ToUriString(HostAddress.GitHubDotComHostAddress.WebUri);
            }

            var apiClient = new ApiClient(host, Platform.Keychain, Manager.ProcessManager, Manager.TaskManager, Environment.NodeJsExecutablePath, Environment.OctorunScriptPath);

            apiClient.Logout(host).FinallyInUI((s, e) => Redraw());
        }
Ejemplo n.º 5
0
        public void LoginWithToken(string token, Action <bool> result)
        {
            Guard.ArgumentNotNull(token, "token");
            Guard.ArgumentNotNull(result, "result");

            new FuncTask <bool>(taskManager.Token,
                                () => loginManager.LoginWithToken(UriString.ToUriString(HostAddress.WebUri), token))
            .FinallyInUI((success, ex, res) =>
            {
                if (!success)
                {
                    logger.Warning(ex);
                    result(false);
                    return;
                }

                result(res);
            })
            .Start();
        }
Ejemplo n.º 6
0
        private void MaybeUpdateData()
        {
            UriString host = null;

            if (!HasRepository || String.IsNullOrEmpty(Repository.CloneUrl))
            {
                var firstConnection = Platform.Keychain.Connections.FirstOrDefault();
                if (firstConnection != null)
                {
                    host = firstConnection.Host;
                }
                else
                {
                    host = UriString.ToUriString(HostAddress.GitHubDotComHostAddress.WebUri);
                }
            }
            else
            {
                host = new UriString(Repository.CloneUrl.ToRepositoryUri()
                                     .GetComponents(UriComponents.SchemeAndServer, UriFormat.SafeUnescaped));
            }

            connection = Platform.Keychain.Connections.FirstOrDefault(x => x.Host.ToUriString() == host);

            if (repositoryProgressHasUpdate)
            {
                if (repositoryProgress != null)
                {
                    repositoryProgressMessage = repositoryProgress.Message;
                    repositoryProgressValue   = repositoryProgress.Percentage;
                    if (progressMessageClearTime == -1f || progressMessageClearTime < EditorApplication.timeSinceStartup + DefaultNotificationTimeout)
                    {
                        progressMessageClearTime = EditorApplication.timeSinceStartup + DefaultNotificationTimeout;
                    }
                }
                else
                {
                    repositoryProgressMessage = "";
                    repositoryProgressValue   = 0;
                    progressMessageClearTime  = -1f;
                }
                repositoryProgressHasUpdate = false;
            }

            if (appManagerProgressHasUpdate)
            {
                if (appManagerProgress != null)
                {
                    appManagerProgressValue   = appManagerProgress.Percentage;
                    appManagerProgressMessage = appManagerProgress.Message;
                }
                else
                {
                    appManagerProgressValue   = 0;
                    appManagerProgressMessage = "";
                }
                appManagerProgressHasUpdate = false;
            }

            string updatedRepoRemote = null;
            string updatedRepoUrl    = Localization.DefaultRepoUrl;

            var shouldUpdateContentFields = false;

            if (currentTrackingStatusHasUpdate)
            {
                currentTrackingStatusHasUpdate = false;
                statusAhead  = Repository.CurrentAhead;
                statusBehind = Repository.CurrentBehind;
            }

            if (currentStatusEntriesHasUpdate)
            {
                currentStatusEntriesHasUpdate = false;
                var currentChanges = Repository.CurrentChanges;
                hasItemsToCommit = currentChanges != null &&
                                   currentChanges.Any(entry => entry.Status != GitFileStatus.Ignored && !entry.Staged);
            }

            if (currentBranchAndRemoteHasUpdate)
            {
                hasRemote = false;
            }

            if (Repository != null)
            {
                if (currentBranch == null || currentRemoteName == null || currentBranchAndRemoteHasUpdate)
                {
                    currentBranchAndRemoteHasUpdate = false;

                    var    repositoryCurrentBranch = Repository.CurrentBranch;
                    string updatedRepoBranch;
                    if (repositoryCurrentBranch.HasValue)
                    {
                        updatedRepoBranch      = repositoryCurrentBranch.Value.Name;
                        isTrackingRemoteBranch = !string.IsNullOrEmpty(repositoryCurrentBranch.Value.Tracking);
                    }
                    else
                    {
                        updatedRepoBranch      = null;
                        isTrackingRemoteBranch = false;
                    }

                    var repositoryCurrentRemote = Repository.CurrentRemote;
                    if (repositoryCurrentRemote.HasValue)
                    {
                        hasRemote         = true;
                        updatedRepoRemote = repositoryCurrentRemote.Value.Name;
                        if (!string.IsNullOrEmpty(repositoryCurrentRemote.Value.Url))
                        {
                            updatedRepoUrl = repositoryCurrentRemote.Value.Url;
                        }
                    }

                    if (currentRemoteName != updatedRepoRemote)
                    {
                        currentRemoteName         = updatedRepoRemote;
                        shouldUpdateContentFields = true;
                    }

                    if (currentBranch != updatedRepoBranch)
                    {
                        currentBranch             = updatedRepoBranch;
                        shouldUpdateContentFields = true;
                    }

                    if (currentRemoteUrl != updatedRepoUrl)
                    {
                        currentRemoteUrl          = updatedRepoUrl;
                        shouldUpdateContentFields = true;
                    }
                }
            }
            else
            {
                isTrackingRemoteBranch = false;

                if (currentRemoteName != null)
                {
                    currentRemoteName         = null;
                    shouldUpdateContentFields = true;
                }

                if (currentBranch != null)
                {
                    currentBranch             = null;
                    shouldUpdateContentFields = true;
                }

                if (currentRemoteUrl != Localization.DefaultRepoUrl)
                {
                    currentRemoteUrl          = Localization.DefaultRepoUrl;
                    shouldUpdateContentFields = true;
                }
            }

            if (shouldUpdateContentFields || currentBranchContent == null || currentRemoteUrlContent == null)
            {
                currentBranchContent = new GUIContent(currentBranch, Localization.Window_RepoBranchTooltip);

                if (currentRemoteName != null)
                {
                    currentRemoteUrlContent = new GUIContent(currentRemoteUrl, string.Format(Localization.Window_RepoUrlTooltip, currentRemoteName));
                }
                else
                {
                    currentRemoteUrlContent = new GUIContent(currentRemoteUrl, Localization.Window_RepoNoUrlTooltip);
                }
            }
        }