Beispiel #1
0
        public override async Task ExecuteAsync(string key, string phrase)
        {
            var gitRepoPath = await GitCommandTools.GetSelectedPathAsync(_repositoryBusiness, _talkAgent, _settingAgent);

            if (gitRepoPath == null)
            {
                return;
            }

            var before = _gitBusiness.Shell("status .", gitRepoPath).ToArray();

            var response = _gitBusiness.Shell("reset HEAD .", gitRepoPath).ToArray();

            if (!before.Last().Contains("files have changes"))
            {
                foreach (var line in response)
                {
                    await _talkAgent.SayAsync(line);
                }
            }
            else
            {
                await _talkAgent.SayAsync("There are no staged files.");
            }
        }
Beispiel #2
0
        public override async Task ExecuteAsync(string key, string phrase)
        {
            var gitRepoPath = await GitCommandTools.GetSelectedPathAsync(_repositoryBusiness, _talkAgent, _settingAgent);

            if (gitRepoPath == null)
            {
                return;
            }

            await _talkAgent.SayAsync("Starting to pull.");

            var response = _gitBusiness.Shell("pull", gitRepoPath).ToArray();

            if (!response.Any())
            {
                await _talkAgent.SayAsync("There is nothing to pull from origin. Everything is up-to-date.");
            }
            else
            {
                foreach (var line in response)
                {
                    await _talkAgent.SayAsync(line);
                }
            }
        }
Beispiel #3
0
        public override async Task ExecuteAsync(string key, string phrase)
        {
            //TODO: Check the settings to se how you should address the assestent. The help should reclect how you talk to her.
            await _talkAgent.SayAsync("When you talk to me you should always say my name at the beginning or the end of the sentence. You can also start or end the sentence with the world please.");

            var commands = _commandAgent.Commands.Select(x => x.Name).ToAndList();

            await _talkAgent.SayAsync("I understand the following commands. " + commands + ".");
        }
Beispiel #4
0
        public override async Task ExecuteAsync(string key, string phrase)
        {
            var hasSetting  = _settingAgent.HasSetting(Constants.BitchName);
            var currentName = _settingAgent.GetSetting(Constants.BitchName, Constants.DefaultBitchName);

            var names = GetDefaultNames(Constants.DefaultBitchName);

            if (File.Exists("Names.txt"))
            {
                names.AddRange(File.ReadAllLines("Names.txt"));
            }

            var response  = new Answer <bool>(false);
            var bitchName = new Answer <string>(names.First());

            while (!response.Response)
            {
                //TODO: Remove this line after that the text-input question is enabled. Before we have that this will result in an infinite loop.
                if (_settingAgent.GetSetting("Muted", false))
                {
                    await _talkAgent.SayAsync("You are muted to me, so I will not hear what you are saying. Microphone mute is enabled automatically when there is a technical problem. You can also do this manually.");

                    return;
                }
                //TODO: ^^ This crappy part above, remove it when the AskAsnyc method can handle manual user input that does not come from the microphone ^^

                bitchName = await _talkAgent.AskAsync("What do you want my name to be?", names.Select(x => new QuestionAnswerAlternative <string> {
                    Phrases = new List <string> {
                        x
                    }, Response = x
                }).ToList(), 5000);

                response = await _talkAgent.AskAsync(string.Format("So you want my name to be {0}?", bitchName.Response), new List <QuestionAnswerAlternative <bool> > {
                    new QuestionAnswerAlternative <bool> {
                        Phrases = new List <string> {
                            "Yes"
                        }, Response = true, IsDefault = hasSetting
                    }, new QuestionAnswerAlternative <bool> {
                        Phrases = new List <string> {
                            "No"
                        }, Response = false, IsDefault = !hasSetting
                    }
                });
            }

            _settingAgent.SetSetting(Constants.BitchName, bitchName.Response);
            App.RegisterCommands();
            await _talkAgent.SayAsync(string.Format("Allright, {0} it is.", bitchName.Response));
        }
Beispiel #5
0
        public async Task <Answer <T> > AskAsync <T>(string question, List <QuestionAnswerAlternative <T> > alternatives, int millisecondsTimeout = 3000)
        {
            if (_settingAgent.GetSetting("Muted", false))
            {
                //TODO: Show dialog where the anser can be entered. The dialog should have the same timeout as the default answer.
                //There should be one answer for each alternative, up to a limit, where there will be a drop down.
                //If there are no set alternatives, there should be a text input box for answers.
                //Also look at the other question functions: AskYesNoAsync, AskFolderAsync and AskStringAsync. And align them as well.
                return(GetDefaultAnswer(alternatives));
            }

            try
            {
                using (var listenerAgent = new ListenerAgent <T>(_eventHub, alternatives))
                {
                    listenerAgent.HeardSomethingEvent += EventHub_HeardSomethingEvent;

                    var listenId = Guid.NewGuid();
                    _eventHub.InvokeStartListeningEvent(listenId);

                    await _talkAgent.SayAsync(question);

                    listenerAgent.StartListening();

                    var r = await Task.Factory.StartNew(() =>
                    {
                        if (!_responseEvent.WaitOne(millisecondsTimeout))
                        {
                            return(GetDefaultAnswer(alternatives));
                        }

                        var selectedAlternative = alternatives.First(x => x.Phrases.Any(y => y == _responsePhrase));
                        return(new Answer <T>(selectedAlternative.Response));
                    });

                    _eventHub.InvokeDoneListeningEvent(listenId);

                    return(r);
                }
            }
            catch (InvalidOperationException exception)
            {
                CompositeRoot.Instance.TalkAgent.SayAsync("Oups, now we have problems! " + exception.Message);
                _settingAgent.SetSetting("Muted", true);
            }

            return(GetDefaultAnswer(alternatives));
        }
Beispiel #6
0
        public override async Task ExecuteAsync(string key, string phrase)
        {
            var gitRepoPath = await GitCommandTools.GetSelectedPathAsync(_repositoryBusiness, _talkAgent, _settingAgent);

            if (gitRepoPath == null)
            {
                return;
            }

            await _talkAgent.SayAsync("Starting to push.");

            var retry = true;

            while (retry)
            {
                retry = false;

                var response = _gitBusiness.Shell("push", gitRepoPath).ToArray();
                if (response.First().Contains("warning: push.default is unset"))
                {
                    //Set push mode to simple
                    var isSetToSimple = await _questionAgent.AskYesNoAsync("The push behaviour has not been set. Is it allright if I set it to simple?");

                    if (isSetToSimple)
                    {
                        var response2 = _gitBusiness.Shell("config --global push.default simple", gitRepoPath).ToArray();
                        foreach (var line in response2)
                        {
                            await _talkAgent.SayAsync(line);
                        }

                        retry = true;
                    }
                }
                else
                {
                    foreach (var line in response)
                    {
                        await _talkAgent.SayAsync(line);
                    }
                }
            }
        }
Beispiel #7
0
        public static async Task <string> GetSelectedPathAsync(IRepositoryBusines repositoryBusiness, ITalkAgent talkAgent, ISettingAgent settingAgent)
        {
            var gitRepoPath = repositoryBusiness.GetSelectedPath();

            if (string.IsNullOrEmpty(gitRepoPath))
            {
                var repos = settingAgent.GetSettings <string>("Repositories");
                if (!repos.Any())
                {
                    await talkAgent.SayAsync("You need to open a repository before you can ask for status.");
                }
                else
                {
                    await talkAgent.SayAsync("You need to select a repository before you can ask for status.");
                }
            }

            return(gitRepoPath);
        }
Beispiel #8
0
        public override async Task ExecuteAsync(string key, string phrase)
        {
            var gitRepoPath = await GitCommandTools.GetSelectedPathAsync(_repositoryBusiness, _talkAgent, _settingAgent);

            if (gitRepoPath == null)
            {
                return;
            }

            var before   = _gitBusiness.Shell("status .", gitRepoPath).ToArray();
            var response = _gitBusiness.Shell("add .", gitRepoPath).ToArray();

            if (before.Last().Contains("files have changes"))
            {
                await _talkAgent.SayAsync(string.Format("{0} files have been staged.", before.Last().Split(' ')[0]));
            }
            else
            {
                await _talkAgent.SayAsync("There are no changes to stage.");
            }
        }
Beispiel #9
0
        public async override Task ExecuteAsync(string key, string phrase)
        {
            var response = await _questionAgent.AskYesNoAsync("Are you sure?");

            if (response)
            {
                InvokeCloseDownEvent();
            }
            else
            {
                await _talkAgent.SayAsync("I am still here for you.");
            }
        }
Beispiel #10
0
        public override async Task ExecuteAsync(string key, string phrase)
        {
            var gitRepoPath = await GitCommandTools.GetSelectedPathAsync(_repositoryBusiness, _talkAgent, _settingAgent);

            if (gitRepoPath == null)
            {
                return;
            }

            if (await _questionAgent.AskYesNoAsync("Are you sure you want to reset all changes?"))
            {
                var response = _gitBusiness.Shell("reset --hard", gitRepoPath).ToArray();
                foreach (var line in response)
                {
                    await _talkAgent.SayAsync(line);
                }
            }
            else
            {
                await _talkAgent.SayAsync("All your files have been left untouched.");
            }
        }
Beispiel #11
0
        public async override Task ExecuteAsync(string key, string phrase)
        {
            string path = null;

            while (path == null)
            {
                path = await _questionAgent.AskFolderAsync("Please select the folder where the repository is located.");

                if (path == null)
                {
                    await _talkAgent.SayAsync("Okey, so you changed your mind.");

                    return;
                }

                if (!System.IO.Directory.Exists(path + "\\.git"))
                {
                    await _talkAgent.SayAsync("I cannot find the '.git' folder in this path.");

                    path = null;
                }
            }

            var name = await _questionAgent.AskStringAsync("What name do you want for the repository?");

            if (!string.IsNullOrEmpty(name))
            {
                _settingAgent.SetSetting("Repositories", name, path);
                await _talkAgent.SayAsync("I have selected repository " + name + " for you.");

                _repositoryBusiness.Select(name);
                _repositoryBusiness.Add(name, path);
            }
            else
            {
                await _talkAgent.SayAsync("Open repository was aborted.");
            }
        }
Beispiel #12
0
        public override async Task ExecuteAsync(string key, string phrase)
        {
            var gitRepoPath = await GitCommandTools.GetSelectedPathAsync(_repositoryBusiness, _talkAgent, _settingAgent);

            if (gitRepoPath == null)
            {
                return;
            }

            var response = _gitBusiness.Shell("status", gitRepoPath);

            foreach (var line in response)
            {
                await _talkAgent.SayAsync(line);
            }
        }
Beispiel #13
0
        public async Task SearchAsync()
        {
            var drives = System.IO.Directory.GetLogicalDrives();

            foreach (var drive in drives)
            {
                var gitFolders = FindGitFolders(drive);
                foreach (var gitFolder in gitFolders)
                {
                    var gitFolderPath = gitFolder.Replace("\\.git", string.Empty);
                    var gitRepoName   = gitFolderPath.Substring(gitFolderPath.LastIndexOf("\\", StringComparison.Ordinal) + 1);
                    await _talkAgent.SayAsync("Found git repo " + gitRepoName + ".");

                    _repositoryBusiness.Add(gitRepoName, gitFolderPath);
                }
            }
        }
Beispiel #14
0
        public override async Task ExecuteAsync(string key, string phrase)
        {
            bool autoStart;

            if (phrase.Contains("enable") || phrase.Contains("on"))
            {
                autoStart = true;
            }
            else if (phrase.Contains("disable") || phrase.Contains("off"))
            {
                autoStart = false;
            }
            else
            {
                autoStart = await _questionAgent.AskYesNoAsync("Do you want GitBitch to start automatically when windows starts?");
            }

            await _talkAgent.SayAsync("Autostart is " + (autoStart ? "enabled" : "disabled") + ".");

            _settingAgent.UseAutoStart(autoStart);
        }
Beispiel #15
0
        public override async Task ExecuteAsync(string key, string phrase)
        {
            var gitRepoPath = await GitCommandTools.GetSelectedPathAsync(_repositoryBusiness, _talkAgent, _settingAgent);

            if (gitRepoPath == null)
            {
                return;
            }

            var statusResponse = _gitBusiness.Shell("status", gitRepoPath).ToArray();

            if (!statusResponse.Any(x => x.Contains("are to be committed") || x.Contains("have changes")))
            {
                await _talkAgent.SayAsync("There are no changes to commit.");

                return;
            }

            var    extraFlag     = string.Empty;
            string commitMessage = null;

            if (phrase.Contains("stage"))
            {
                extraFlag += " -a";
            }

            if (phrase.Contains("amend"))
            {
                extraFlag    += " --amend";
                commitMessage = "--no-edit";
            }

            if (string.IsNullOrEmpty(commitMessage))
            {
                commitMessage = "-m \"" + await _questionAgent.AskStringAsync("Enter a commit message") + "\"";
            }

            var retry = true;

            while (retry)
            {
                retry = false;

                var response = _gitBusiness.Shell("commit " + commitMessage + extraFlag, gitRepoPath).ToArray();
                if (response.Any(x => x.Contains("no changes added to commit")))
                {
                    var stage = await _questionAgent.AskYesNoAsync("No files has been staged yet. Do you want to stage all changes and commit all that?");

                    if (stage)
                    {
                        var stageResponse = _gitBusiness.Shell("add .", gitRepoPath).ToArray();
                        retry = true;
                    }
                    else
                    {
                        await _talkAgent.SayAsync("Allright.");
                    }
                }
                else
                {
                    foreach (var line in response)
                    {
                        await _talkAgent.SayAsync(line);
                    }
                }
            }
        }
Beispiel #16
0
 public async override Task ExecuteAsync(string key, string phrase)
 {
     _repositoryBusiness.Select(key);
     await _talkAgent.SayAsync("Repo " + key + " has been selected.");
 }
Beispiel #17
0
 public async override Task ExecuteAsync(string key, string phrase)
 {
     var repos = _settingAgent.GetSettings <string>("Repositories");
     await _talkAgent.SayAsync(string.Format("You can choose between " + repos.Keys.ToAndList() + "."));
 }