"));
54 | }
55 | }
56 | }
--------------------------------------------------------------------------------
/GitHubExtension.Test/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/GitHubExtension/ViewModel/LabelModel.cs:
--------------------------------------------------------------------------------
1 | // **********************************************************************************
2 | // The MIT License (MIT)
3 | //
4 | // Copyright (c) 2014 Rob Prouse
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy of
7 | // this software and associated documentation files (the "Software"), to deal in
8 | // the Software without restriction, including without limitation the rights to
9 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
10 | // the Software, and to permit persons to whom the Software is furnished to do so,
11 | // subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in all
14 | // copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 | //
23 | // **********************************************************************************
24 |
25 | using System;
26 | using Alteridem.GitHub.Extension.Interfaces;
27 | using Octokit;
28 |
29 | namespace Alteridem.GitHub.Extension.ViewModel
30 | {
31 | public class LabelModel : BaseViewModel, ILabel
32 | {
33 | private readonly Label _label;
34 | private bool _checked;
35 |
36 | public LabelModel(Label label)
37 | {
38 | _checked = false;
39 | _label = label;
40 | }
41 |
42 | public string Name
43 | {
44 | get { return _label.Name; }
45 | }
46 |
47 | public string Color
48 | {
49 | get { return _label.Color; }
50 | }
51 |
52 | public Uri Url
53 | {
54 | get { return _label.Url; }
55 | }
56 |
57 | public bool Checked
58 | {
59 | get { return _checked; }
60 | set
61 | {
62 | if (Equals(value, _checked)) return;
63 | _checked = value;
64 | OnPropertyChanged();
65 | }
66 | }
67 | }
68 | }
--------------------------------------------------------------------------------
/GitHubExtension.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 2013
4 | VisualStudioVersion = 12.0.31101.0
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GitHubExtension", "GitHubExtension\GitHubExtension.csproj", "{848A709C-6756-4790-BBAE-C13D1C7D496C}"
7 | EndProject
8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{49156AED-CE96-446A-B09C-3282E05A6F17}"
9 | ProjectSection(SolutionItems) = preProject
10 | .editorconfig = .editorconfig
11 | .gitattributes = .gitattributes
12 | .gitignore = .gitignore
13 | CHANGELOG.md = CHANGELOG.md
14 | Checklist.md = Checklist.md
15 | LICENSE = LICENSE
16 | README.md = README.md
17 | EndProjectSection
18 | EndProject
19 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GitHubIssues", "GitHubIssues\GitHubIssues.csproj", "{64740CE5-68C6-4B63-B607-831BF8C205F0}"
20 | EndProject
21 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GitHubExtension.Test", "GitHubExtension.Test\GitHubExtension.Test.csproj", "{CF36DB6C-FA8F-4102-B042-9BC990202DE9}"
22 | EndProject
23 | Global
24 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
25 | Debug|Any CPU = Debug|Any CPU
26 | Release|Any CPU = Release|Any CPU
27 | EndGlobalSection
28 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
29 | {848A709C-6756-4790-BBAE-C13D1C7D496C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
30 | {848A709C-6756-4790-BBAE-C13D1C7D496C}.Debug|Any CPU.Build.0 = Debug|Any CPU
31 | {848A709C-6756-4790-BBAE-C13D1C7D496C}.Release|Any CPU.ActiveCfg = Release|Any CPU
32 | {848A709C-6756-4790-BBAE-C13D1C7D496C}.Release|Any CPU.Build.0 = Release|Any CPU
33 | {64740CE5-68C6-4B63-B607-831BF8C205F0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
34 | {64740CE5-68C6-4B63-B607-831BF8C205F0}.Debug|Any CPU.Build.0 = Debug|Any CPU
35 | {64740CE5-68C6-4B63-B607-831BF8C205F0}.Release|Any CPU.ActiveCfg = Release|Any CPU
36 | {64740CE5-68C6-4B63-B607-831BF8C205F0}.Release|Any CPU.Build.0 = Release|Any CPU
37 | {CF36DB6C-FA8F-4102-B042-9BC990202DE9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
38 | {CF36DB6C-FA8F-4102-B042-9BC990202DE9}.Debug|Any CPU.Build.0 = Debug|Any CPU
39 | {CF36DB6C-FA8F-4102-B042-9BC990202DE9}.Release|Any CPU.ActiveCfg = Release|Any CPU
40 | {CF36DB6C-FA8F-4102-B042-9BC990202DE9}.Release|Any CPU.Build.0 = Release|Any CPU
41 | EndGlobalSection
42 | GlobalSection(SolutionProperties) = preSolution
43 | HideSolutionNode = FALSE
44 | EndGlobalSection
45 | EndGlobal
46 |
--------------------------------------------------------------------------------
/GitHubExtension/View/IssueEditor.xaml.cs:
--------------------------------------------------------------------------------
1 | // **********************************************************************************
2 | // The MIT License (MIT)
3 | //
4 | // Copyright (c) 2014 Rob Prouse
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy of
7 | // this software and associated documentation files (the "Software"), to deal in
8 | // the Software without restriction, including without limitation the rights to
9 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
10 | // the Software, and to permit persons to whom the Software is furnished to do so,
11 | // subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in all
14 | // copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 | //
23 | // **********************************************************************************
24 |
25 | #region Using Directives
26 |
27 | using System.Windows;
28 | using Alteridem.GitHub.Extension.Interfaces;
29 | using Alteridem.GitHub.Extension.ViewModel;
30 | using Octokit;
31 |
32 | #endregion
33 |
34 | namespace Alteridem.GitHub.Extension.View
35 | {
36 | ///
37 | /// Interaction logic for EditIssue.xaml
38 | ///
39 | public partial class IssueEditor : IIssueEditor
40 | {
41 | private readonly IssueEditorViewModel _gitHubViewModel;
42 |
43 | public IssueEditor()
44 | {
45 | InitializeComponent();
46 | _gitHubViewModel = Factory.Get();
47 | DataContext = _gitHubViewModel;
48 | }
49 |
50 | public Window Window { get { return this; } }
51 |
52 | ///
53 | /// Sets the issue to add/edit. If null, we are adding, if set, we edit
54 | ///
55 | /// The issue.
56 | public void SetIssue(Octokit.Issue issue)
57 | {
58 | _gitHubViewModel.SetIssue(issue);
59 | }
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/GitHubExtension.Test/Mocks/OutputWriterMock.cs:
--------------------------------------------------------------------------------
1 | // **********************************************************************************
2 | // The MIT License (MIT)
3 | //
4 | // Copyright (c) 2014 Rob Prouse
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy of
7 | // this software and associated documentation files (the "Software"), to deal in
8 | // the Software without restriction, including without limitation the rights to
9 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
10 | // the Software, and to permit persons to whom the Software is furnished to do so,
11 | // subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in all
14 | // copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 | //
23 | // **********************************************************************************
24 |
25 | #region Using Directives
26 |
27 | using Alteridem.GitHub.Logging;
28 |
29 | #endregion
30 |
31 | namespace Alteridem.GitHub.Extension.Test.Mocks
32 | {
33 | public class OutputWriterMock : BaseOutputWriter
34 | {
35 | public bool WriteMessageCalled { get; set; }
36 | public bool ShowMessageCalled { get; set; }
37 | public string LastMessageWritten { get; set; }
38 | public string LastMessageShown { get; set; }
39 |
40 | ///
41 | /// Logs the specified message.
42 | ///
43 | /// The message.
44 | protected override void WriteMessage(string message)
45 | {
46 | WriteMessageCalled = true;
47 | LastMessageWritten = message;
48 | }
49 |
50 | ///
51 | /// Shows the specified message.
52 | ///
53 | /// The message.
54 | protected override void ShowMessage(string message)
55 | {
56 | ShowMessageCalled = true;
57 | LastMessageShown = message;
58 | }
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/GitHubExtension.Test/Model/RepositoryHelperTest.cs:
--------------------------------------------------------------------------------
1 | using Alteridem.GitHub.Model;
2 | using NUnit.Framework;
3 | using System;
4 | using System.IO;
5 | using System.Linq;
6 | using System.Reflection;
7 |
8 | namespace Alteridem.GitHub.Extension.Test.Model
9 | {
10 | [TestFixture]
11 | public class RepositoryHelperTest
12 | {
13 | [Test]
14 | public void CanGetGitRemotes()
15 | {
16 | // Gets the Git remotes for the repository that this source is
17 | // maintained in. Assumes that one of the remotes is on GitHub
18 | var path = Assembly.GetExecutingAssembly().Location;
19 | var root = RepositoryHelper.GetRemotes(path).ToArray();
20 |
21 | Assert.That(root, Is.Not.Null);
22 | Assert.That(root.Length, Is.GreaterThan(0));
23 | }
24 |
25 | [Test]
26 | public void CanFindRootOfRepositoryFromFile()
27 | {
28 | var path = Assembly.GetExecutingAssembly().Location;
29 | var root = RepositoryHelper.FindRepositoryRoot(path);
30 | Assert.That(root, Is.Not.Null);
31 | Assert.That(root, Does.Exist);
32 | }
33 |
34 | [Test]
35 | public void CanFindRootOfRepositoryFromDirectory()
36 | {
37 | var path = Assembly.GetExecutingAssembly().Location;
38 | var file = new FileInfo(path);
39 | path = file.DirectoryName;
40 |
41 | var root = RepositoryHelper.FindRepositoryRoot(path);
42 | Assert.That(root, Is.Not.Null);
43 | Assert.That(root, Does.Exist);
44 | }
45 |
46 | [Test]
47 | public void NotRepositoryReturnsNull()
48 | {
49 | string windowDir = Environment.GetFolderPath(Environment.SpecialFolder.Windows);
50 | Assert.That(windowDir, Is.Not.Null.And.Not.Empty);
51 |
52 | var root = RepositoryHelper.FindRepositoryRoot(windowDir);
53 | Assert.That(root, Is.Null);
54 | }
55 |
56 | [Test]
57 | public void NotValidFileOrDirectoryReturnsNull()
58 | {
59 | var root = RepositoryHelper.FindRepositoryRoot("C:\\Garbage\\Does\\Not\\Exist");
60 | Assert.That(root, Is.Null);
61 | }
62 |
63 | [TestCase(null)]
64 | [TestCase("")]
65 | [TestCase(" ")]
66 | public void NullOrEmptyPathThrowsAnArgumentException(string path)
67 | {
68 | Assert.That(() => RepositoryHelper.FindRepositoryRoot(path), Throws.ArgumentException);
69 | }
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/GitHubIssues/Model/OptionsPage.cs:
--------------------------------------------------------------------------------
1 | // **********************************************************************************
2 | // The MIT License (MIT)
3 | //
4 | // Copyright (c) 2015 Rob Prouse
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy of
7 | // this software and associated documentation files (the "Software"), to deal in
8 | // the Software without restriction, including without limitation the rights to
9 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
10 | // the Software, and to permit persons to whom the Software is furnished to do so,
11 | // subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in all
14 | // copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 | //
23 | // **********************************************************************************
24 |
25 | #region Using Directives
26 |
27 | using System;
28 | using System.ComponentModel;
29 | using System.Runtime.InteropServices;
30 | using Microsoft.VisualStudio.Shell;
31 |
32 | using Alteridem.GitHub.Styles;
33 |
34 | #endregion
35 |
36 | namespace Alteridem.GitHub.Model
37 | {
38 | [ClassInterface(ClassInterfaceType.AutoDual)]
39 | [ComVisible(true)]
40 | public class OptionsPage : DialogPage
41 | {
42 | [Category("Interface")]
43 | [DisplayName("Issue Theme")]
44 | [Description("A light or dark background for the Issue window")]
45 | public IssueTheme IssueTheme { get; set; }
46 |
47 | [Category("Interface")]
48 | [DisplayName("Hide Repositories Without Issues")]
49 | [Description("Hides all repositories from the selection list that do not have open or closed issues")]
50 | public bool HideRepositoriesWithNoIssues { get; set; }
51 |
52 | [Category("Repositories")]
53 | [DisplayName("Disable Auto-Select Repository")]
54 | [Description("Disables automatically selecting the repository based on the code you are working on")]
55 | public bool DisableAutoSelectRepository { get; set; }
56 | }
57 | }
--------------------------------------------------------------------------------
/GitHubExtension/View/VisualStudioMessageBox.cs:
--------------------------------------------------------------------------------
1 | // **********************************************************************************
2 | // The MIT License (MIT)
3 | //
4 | // Copyright (c) 2014 Rob Prouse
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy of
7 | // this software and associated documentation files (the "Software"), to deal in
8 | // the Software without restriction, including without limitation the rights to
9 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
10 | // the Software, and to permit persons to whom the Software is furnished to do so,
11 | // subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in all
14 | // copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 | //
23 | // **********************************************************************************
24 |
25 | using Alteridem.GitHub.Extensions;
26 | using System;
27 | using Microsoft.VisualStudio.Shell;
28 | using Microsoft.VisualStudio.Shell.Interop;
29 |
30 | namespace Alteridem.GitHub.Extension.View
31 | {
32 | public static class VisualStudioMessageBox
33 | {
34 | public static int Show(string message)
35 | {
36 | var uiShell = ServiceProvider.GlobalProvider.GetService();
37 | if (uiShell == null)
38 | return -1;
39 |
40 | Guid clsid = Guid.Empty;
41 | int result;
42 | Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(uiShell.ShowMessageBox(
43 | 0,
44 | ref clsid,
45 | "GitHub Extension",
46 | message,
47 | string.Empty,
48 | 0,
49 | OLEMSGBUTTON.OLEMSGBUTTON_OK,
50 | OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST,
51 | OLEMSGICON.OLEMSGICON_INFO,
52 | 0, // false
53 | out result));
54 | return result;
55 | }
56 | }
57 | }
--------------------------------------------------------------------------------
/GitHubExtension/View/WebBrowserBehavior.cs:
--------------------------------------------------------------------------------
1 | // **********************************************************************************
2 | // The MIT License (MIT)
3 | //
4 | // Copyright (c) 2014 Rob Prouse
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy of
7 | // this software and associated documentation files (the "Software"), to deal in
8 | // the Software without restriction, including without limitation the rights to
9 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
10 | // the Software, and to permit persons to whom the Software is furnished to do so,
11 | // subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in all
14 | // copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 | //
23 | // **********************************************************************************
24 |
25 | using System.Windows;
26 | using System.Windows.Controls;
27 |
28 | namespace Alteridem.GitHub.Extension.View
29 | {
30 | public class WebBrowserBehavior
31 | {
32 | public static readonly DependencyProperty HtmlProperty = DependencyProperty.RegisterAttached(
33 | "Html",
34 | typeof(string),
35 | typeof(WebBrowserBehavior),
36 | new FrameworkPropertyMetadata(OnHtmlChanged));
37 |
38 | [AttachedPropertyBrowsableForType(typeof(WebBrowser))]
39 | public static string GetHtml(WebBrowser d)
40 | {
41 | return (string)d.GetValue(HtmlProperty);
42 | }
43 |
44 | public static void SetHtml(WebBrowser d, string value)
45 | {
46 | d.SetValue(HtmlProperty, value);
47 | }
48 |
49 | static void OnHtmlChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e)
50 | {
51 | WebBrowser webBrowser = dependencyObject as WebBrowser;
52 | var str = e.NewValue as string;
53 | if (webBrowser != null && !string.IsNullOrWhiteSpace(str) )
54 | webBrowser.NavigateToString(str);
55 | }
56 | }
57 | }
--------------------------------------------------------------------------------
/GitHubExtension/ViewModel/BaseUserViewModel.cs:
--------------------------------------------------------------------------------
1 | // **********************************************************************************
2 | // The MIT License (MIT)
3 | //
4 | // Copyright (c) 2014 Rob Prouse
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy of
7 | // this software and associated documentation files (the "Software"), to deal in
8 | // the Software without restriction, including without limitation the rights to
9 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
10 | // the Software, and to permit persons to whom the Software is furnished to do so,
11 | // subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in all
14 | // copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 | //
23 | // **********************************************************************************
24 |
25 | #region Using Directives
26 |
27 | using System.Windows.Input;
28 | using Alteridem.GitHub.Annotations;
29 | using Alteridem.GitHub.Extension.Interfaces;
30 | using Alteridem.GitHub.Extension.View;
31 |
32 | #endregion
33 |
34 | namespace Alteridem.GitHub.Extension.ViewModel
35 | {
36 | public class BaseUserViewModel : BaseGitHubViewModel
37 | {
38 | private ICommand _loginCommand;
39 |
40 | public BaseUserViewModel()
41 | {
42 | LoginCommand = new RelayCommand(p => Login(), p => true);
43 | }
44 |
45 | [NotNull]
46 | public ICommand LoginCommand
47 | {
48 | get { return _loginCommand; }
49 | set
50 | {
51 | if (Equals(value, _loginCommand)) return;
52 | _loginCommand = value;
53 | OnPropertyChanged();
54 | }
55 | }
56 |
57 | public bool LoggedIn
58 | {
59 | get { return GitHubApi.LoggedIn; }
60 | }
61 |
62 | public void Login()
63 | {
64 | if (GitHubApi.LoggedIn)
65 | {
66 | GitHubApi.Logout();
67 | return;
68 | }
69 |
70 | var dlg = Factory.Get();
71 | dlg.ShowModal();
72 | }
73 | }
74 | }
--------------------------------------------------------------------------------
/GitHubExtension/View/OutputWriter.cs:
--------------------------------------------------------------------------------
1 | // **********************************************************************************
2 | // The MIT License (MIT)
3 | //
4 | // Copyright (c) 2014 Rob Prouse
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy of
7 | // this software and associated documentation files (the "Software"), to deal in
8 | // the Software without restriction, including without limitation the rights to
9 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
10 | // the Software, and to permit persons to whom the Software is furnished to do so,
11 | // subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in all
14 | // copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 | //
23 | // **********************************************************************************
24 |
25 | using System.ComponentModel.Composition;
26 | using Alteridem.GitHub.Logging;
27 | using Microsoft.VisualStudio.Utilities;
28 | using Tvl.VisualStudio.OutputWindow.Interfaces;
29 |
30 | namespace Alteridem.GitHub.Extension.View
31 | {
32 | public class OutputWriter : BaseOutputWriter
33 | {
34 | public const string GitHubOutputWindowPaneName = "GitHub";
35 |
36 | #pragma warning disable 169 // The field 'fieldName' is never used
37 | [Export]
38 | [Name(GitHubOutputWindowPaneName)]
39 | private static OutputWindowDefinition GitHubOutputWindowDefinition;
40 | #pragma warning restore 169
41 |
42 | ///
43 | /// Logs the specified message.
44 | ///
45 | /// The message.
46 | protected override void WriteMessage(string message)
47 | {
48 | var pane = Factory.Get();
49 | if (pane != null)
50 | pane.WriteLine(message);
51 | }
52 |
53 | ///
54 | /// Shows the specified message.
55 | ///
56 | /// The message.
57 | protected override void ShowMessage(string message)
58 | {
59 | VisualStudioMessageBox.Show(message);
60 | }
61 | }
62 | }
--------------------------------------------------------------------------------
/GitHubIssues/Logging/IOutputWriter.cs:
--------------------------------------------------------------------------------
1 | // **********************************************************************************
2 | // The MIT License (MIT)
3 | //
4 | // Copyright (c) 2014 Rob Prouse
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy of
7 | // this software and associated documentation files (the "Software"), to deal in
8 | // the Software without restriction, including without limitation the rights to
9 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
10 | // the Software, and to permit persons to whom the Software is furnished to do so,
11 | // subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in all
14 | // copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 | //
23 | // **********************************************************************************
24 |
25 | using System;
26 |
27 | namespace Alteridem.GitHub.Logging
28 | {
29 | ///
30 | /// Interface for logging and showing messages to the user
31 | ///
32 | public interface IOutputWriter
33 | {
34 | ///
35 | /// Shows the specified message to the user.
36 | ///
37 | /// The level at which to log the message
38 | /// The message.
39 | void Write(LogLevel level, string message);
40 |
41 | ///
42 | /// Shows the specified message to the user.
43 | ///
44 | /// The level at which to log the message
45 | /// The message.
46 | /// Arguments to the message
47 | void Write(LogLevel level, string message, params object[] args);
48 |
49 | ///
50 | /// Shows the specified message to the user along with the exception information.
51 | ///
52 | /// The level at which to log the message
53 | /// The message.
54 | /// The exception.
55 | void Write(LogLevel level, string message, Exception ex);
56 | }
57 | }
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
65 | # Resharper DotSettings files are in Unix Format
66 | *.DotSettings text eol=lf
67 |
--------------------------------------------------------------------------------
/GitHubExtension.Test/ViewModel/UserTest.cs:
--------------------------------------------------------------------------------
1 | // **********************************************************************************
2 | // The MIT License (MIT)
3 | //
4 | // Copyright (c) 2014 Rob Prouse
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy of
7 | // this software and associated documentation files (the "Software"), to deal in
8 | // the Software without restriction, including without limitation the rights to
9 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
10 | // the Software, and to permit persons to whom the Software is furnished to do so,
11 | // subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in all
14 | // copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 | //
23 | // **********************************************************************************
24 |
25 | #region Using Directives
26 |
27 | using System;
28 | using Alteridem.GitHub.Extension.Interfaces;
29 | using Alteridem.GitHub.Extension.Test.Mocks;
30 | using Alteridem.GitHub.Extension.ViewModel;
31 | using Alteridem.GitHub.Model;
32 | using NUnit.Framework;
33 |
34 | #endregion
35 |
36 | namespace Alteridem.GitHub.Extension.Test.ViewModel
37 | {
38 | [TestFixture]
39 | public class UserTest
40 | {
41 | private UserViewModel _viewModel;
42 |
43 | [SetUp]
44 | public void SetUp()
45 | {
46 | Factory.Rebind().To().InScope(o => this);
47 | Factory.Rebind().To();
48 | _viewModel = Factory.Get();
49 | }
50 |
51 | [Test]
52 | public void TestCanLogin()
53 | {
54 | var api = Factory.Get();
55 | api.Logout();
56 | Assert.That(api.LoggedIn, Is.False);
57 |
58 | _viewModel.Login();
59 |
60 | Assert.That(api.LoggedIn, Is.True);
61 | }
62 |
63 | [Test]
64 | public void TestCanLogout()
65 | {
66 | var api = Factory.Get();
67 | api.Login("user", "pass", null);
68 | Assert.That(api.LoggedIn, Is.True);
69 |
70 | _viewModel.Login();
71 |
72 | Assert.That(api.LoggedIn, Is.False);
73 | }
74 | }
75 | }
--------------------------------------------------------------------------------
/GitHubIssues/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/GitHubExtension.Test/Model/RepositoryWrapperTest.cs:
--------------------------------------------------------------------------------
1 | // **********************************************************************************
2 | // The MIT License (MIT)
3 | //
4 | // Copyright (c) 2014 Rob Prouse
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy of
7 | // this software and associated documentation files (the "Software"), to deal in
8 | // the Software without restriction, including without limitation the rights to
9 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
10 | // the Software, and to permit persons to whom the Software is furnished to do so,
11 | // subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in all
14 | // copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 | //
23 | // **********************************************************************************
24 |
25 | #region Using Directives
26 |
27 | using System;
28 | using Alteridem.GitHub.Model;
29 | using NUnit.Framework;
30 | using Octokit;
31 |
32 | #endregion
33 |
34 | namespace Alteridem.GitHub.Extension.Test.Model
35 | {
36 | [TestFixture]
37 | public class RepositoryWrapperTest
38 | {
39 | private RepositoryWrapper _one;
40 | private RepositoryWrapper _two;
41 | private RepositoryWrapper _three;
42 |
43 | [OneTimeSetUp]
44 | public void FixtureSetUp()
45 | {
46 | _one = CreateWrapper(1, "test");
47 | _two = CreateWrapper(1, "test");
48 | _three = CreateWrapper(3, "three");
49 | }
50 |
51 | private RepositoryWrapper CreateWrapper(int id, string name)
52 | {
53 | var repository = new Repository(null, null, null, null, null, null, null, id, null, name, "", "", "", "",
54 | false, false, 0, 0, 0, "master", 1, null, DateTimeOffset.Now, DateTimeOffset.Now, null, null, null, null,
55 | true, true, true);
56 | return new RepositoryWrapper(repository);
57 |
58 | }
59 |
60 | [Test]
61 | public void TestEquals()
62 | {
63 | Assert.That(_one, Is.EqualTo(_two));
64 | Assert.That(_one.Equals(_two), Is.True);
65 | }
66 |
67 | [Test]
68 | public void TestNotEquals()
69 | {
70 | Assert.That(_one, Is.Not.EqualTo(_three));
71 | Assert.That(_one.Equals(_three), Is.False);
72 | }
73 | }
74 | }
--------------------------------------------------------------------------------
/GitHubExtension.Test/Model/CredentialCacheTest.cs:
--------------------------------------------------------------------------------
1 | // **********************************************************************************
2 | // The MIT License (MIT)
3 | //
4 | // Copyright (c) 2014 Rob Prouse
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy of
7 | // this software and associated documentation files (the "Software"), to deal in
8 | // the Software without restriction, including without limitation the rights to
9 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
10 | // the Software, and to permit persons to whom the Software is furnished to do so,
11 | // subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in all
14 | // copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 | //
23 | // **********************************************************************************
24 |
25 | #region Using Directives
26 |
27 | using System;
28 | using Alteridem.GitHub.Model;
29 | using NUnit.Framework;
30 |
31 | #endregion
32 |
33 | namespace Alteridem.GitHub.Extension.Test.Model
34 | {
35 | [TestFixture]
36 | public class CredentialCacheTest
37 | {
38 | [Test]
39 | public void TestRoundTrip()
40 | {
41 | var credentials = new CredentialCache { Logon = "user", Password = "password", AccessToken = string.Empty };
42 | var cache = credentials.ToString();
43 | Assert.That(cache, Is.Not.Null);
44 | Assert.That(cache, Does.Contain("user"));
45 | Assert.That(cache, Does.Not.Contain("password"));
46 |
47 | var parsed = CredentialCache.FromString(cache);
48 | Assert.That(parsed, Is.Not.Null);
49 | Assert.That(parsed.Logon, Is.EqualTo("user"));
50 | Assert.That(parsed.Password, Is.EqualTo("password"));
51 | Assert.That(parsed.AccessToken, Is.EqualTo(string.Empty));
52 | }
53 |
54 | [Test]
55 | public void FromNullStringReturnsNull()
56 | {
57 | Assert.That(CredentialCache.FromString(null), Is.Null);
58 | }
59 |
60 | [Test]
61 | public void FromEmptyStringReturnsNull()
62 | {
63 | Assert.That(CredentialCache.FromString(string.Empty), Is.Null);
64 | }
65 |
66 | [Test]
67 | public void FromBlankStringReturnsNull()
68 | {
69 | Assert.That(CredentialCache.FromString(" "), Is.Null);
70 | }
71 | }
72 | }
--------------------------------------------------------------------------------
/GitHubExtension.Test/ViewModel/IssueListRefreshTest.cs:
--------------------------------------------------------------------------------
1 | // **********************************************************************************
2 | // The MIT License (MIT)
3 | //
4 | // Copyright (c) 2014 Rob Prouse
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy of
7 | // this software and associated documentation files (the "Software"), to deal in
8 | // the Software without restriction, including without limitation the rights to
9 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
10 | // the Software, and to permit persons to whom the Software is furnished to do so,
11 | // subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in all
14 | // copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 | //
23 | // **********************************************************************************
24 |
25 | #region Using Directives
26 |
27 | using System.ComponentModel.Composition.Hosting;
28 | using Alteridem.GitHub.Extension.Interfaces;
29 | using Alteridem.GitHub.Extension.Test.Mocks;
30 | using Alteridem.GitHub.Extension.ViewModel;
31 | using Alteridem.GitHub.Model;
32 | using NUnit.Framework;
33 | using Moq;
34 |
35 | #endregion
36 |
37 | namespace Alteridem.GitHub.Extension.Test.ViewModel
38 | {
39 | [TestFixture]
40 | public class IssueListRefreshTest
41 | {
42 | private Mock _mockApi;
43 | private IssueListViewModel _viewModel;
44 |
45 | [SetUp]
46 | public void SetUp()
47 | {
48 | var mockCache = new Mock();
49 | _mockApi = new Mock(mockCache.Object);
50 | Factory.Rebind().ToConstant(_mockApi.Object);
51 | _viewModel = Factory.Get();
52 | }
53 |
54 | [Test]
55 | public void IssuesAreRefreshed()
56 | {
57 | _viewModel.RefreshCommand.Execute(null);
58 |
59 | _mockApi.Verify(x => x.GetIssues());
60 | }
61 |
62 | [Test]
63 | public void MilestonesAreRefreshed()
64 | {
65 | _viewModel.RefreshCommand.Execute(null);
66 |
67 | _mockApi.Verify(x => x.GetMilestones());
68 | }
69 |
70 | [Test]
71 | public void LabelsAreRefreshed()
72 | {
73 | _viewModel.RefreshCommand.Execute(null);
74 |
75 | _mockApi.Verify(x => x.GetLabels());
76 | }
77 | }
78 | }
--------------------------------------------------------------------------------
/GitHubExtension.Test/ViewModel/LoginTest.cs:
--------------------------------------------------------------------------------
1 | // **********************************************************************************
2 | // The MIT License (MIT)
3 | //
4 | // Copyright (c) 2014 Rob Prouse
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy of
7 | // this software and associated documentation files (the "Software"), to deal in
8 | // the Software without restriction, including without limitation the rights to
9 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
10 | // the Software, and to permit persons to whom the Software is furnished to do so,
11 | // subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in all
14 | // copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 | //
23 | // **********************************************************************************
24 |
25 | #region Using Directives
26 |
27 | using System;
28 | using System.Threading;
29 | using System.Windows.Controls;
30 | using Alteridem.GitHub.Extension.Interfaces;
31 | using Alteridem.GitHub.Extension.Test.Mocks;
32 | using Alteridem.GitHub.Extension.ViewModel;
33 | using Alteridem.GitHub.Model;
34 | using NUnit.Framework;
35 |
36 | #endregion
37 |
38 | namespace Alteridem.GitHub.Extension.Test.ViewModel
39 | {
40 | [TestFixture]
41 | [Apartment(ApartmentState.STA)]
42 | public class LoginTest
43 | {
44 | private LoginViewModel _gitHubViewModel;
45 |
46 | [SetUp]
47 | public void SetUp()
48 | {
49 | Factory.Rebind().To().InScope(o => this);
50 | Factory.Rebind().To();
51 | _gitHubViewModel = Factory.Get();
52 | }
53 |
54 | [Test]
55 | public void TestCanLogon()
56 | {
57 | _gitHubViewModel.Username = "";
58 | Assert.That(_gitHubViewModel.CanLogon(), Is.False);
59 | _gitHubViewModel.Username = "user";
60 | Assert.That(_gitHubViewModel.CanLogon(), Is.True);
61 | }
62 |
63 | [Test]
64 | public void TestLogon()
65 | {
66 | var api = Factory.Get();
67 | api.Logout();
68 | Assert.That(api.LoggedIn, Is.False);
69 |
70 | _gitHubViewModel.Username = "user";
71 | _gitHubViewModel.Logon(new PasswordBox());
72 |
73 | Assert.That(api.LoggedIn, Is.True);
74 | }
75 | }
76 | }
--------------------------------------------------------------------------------
/GitHubExtension/View/Controls/UserView.xaml:
--------------------------------------------------------------------------------
1 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
22 |
51 |
52 |
53 |
--------------------------------------------------------------------------------
/GitHubExtension.Test/Converters/StringToColorConverterTest.cs:
--------------------------------------------------------------------------------
1 | // **********************************************************************************
2 | // The MIT License (MIT)
3 | //
4 | // Copyright (c) 2014 Rob Prouse
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy of
7 | // this software and associated documentation files (the "Software"), to deal in
8 | // the Software without restriction, including without limitation the rights to
9 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
10 | // the Software, and to permit persons to whom the Software is furnished to do so,
11 | // subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in all
14 | // copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 | //
23 | // **********************************************************************************
24 |
25 | #region Using Directives
26 |
27 | using System;
28 | using System.Globalization;
29 | using System.Windows.Media;
30 | using Alteridem.GitHub.Converters;
31 | using NUnit.Framework;
32 | using NUnit.Framework.Constraints;
33 |
34 | #endregion
35 |
36 | namespace Alteridem.GitHub.Extension.Test.Converters
37 | {
38 | [TestFixture]
39 | public class StringToColorConverterTest
40 | {
41 | [TestCase("FF0000", 0xFF, 0x00, 0x00)]
42 | [TestCase("FFFFFF", 0xFF, 0xFF, 0xFF)]
43 | [TestCase("336699", 0x33, 0x66, 0x99)]
44 | [TestCase("FFF", 0xFF, 0xFF, 0xFF)]
45 | public void TestColorConversion(string str, byte r, byte g, byte b)
46 | {
47 | var converter = new StringToColorConverter();
48 | var result = converter.Convert(str, typeof(SolidColorBrush), null, CultureInfo.CurrentCulture) as SolidColorBrush;
49 | Assert.That(result, Is.Not.Null);
50 | Assert.That(result.Color.A, Is.EqualTo(0xFF));
51 | Assert.That(result.Color.R, Is.EqualTo(r));
52 | Assert.That(result.Color.G, Is.EqualTo(g));
53 | Assert.That(result.Color.B, Is.EqualTo(b));
54 | }
55 |
56 | [TestCase("")]
57 | [TestCase("#FFFFFF")]
58 | [TestCase("Red")]
59 | public void TestInvalidColorReturnsTransparent(string str)
60 | {
61 | var converter = new StringToColorConverter();
62 | var result = converter.Convert(str, typeof(SolidColorBrush), null, CultureInfo.CurrentCulture) as SolidColorBrush;
63 | Assert.That( result, Is.Not.Null );
64 | Assert.That( result.Color.A, Is.EqualTo( 0x00 ) );
65 | }
66 | }
67 | }
--------------------------------------------------------------------------------
/GitHubIssues/Converters/StringToColorConverter.cs:
--------------------------------------------------------------------------------
1 | // **********************************************************************************
2 | // The MIT License (MIT)
3 | //
4 | // Copyright (c) 2014 Rob Prouse
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy of
7 | // this software and associated documentation files (the "Software"), to deal in
8 | // the Software without restriction, including without limitation the rights to
9 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
10 | // the Software, and to permit persons to whom the Software is furnished to do so,
11 | // subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in all
14 | // copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 | //
23 | // **********************************************************************************
24 |
25 | using System;
26 | using System.Globalization;
27 | using System.Windows.Data;
28 | using System.Windows.Media;
29 |
30 | namespace Alteridem.GitHub.Converters
31 | {
32 | public class StringToColorConverter : IValueConverter
33 | {
34 | ///
35 | /// Converts a value.
36 | ///
37 | ///
38 | /// A converted value. If the method returns null, the valid null value is used.
39 | ///
40 | /// The value produced by the binding source.The type of the binding target property.The converter parameter to use.The culture to use in the converter.
41 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
42 | {
43 | var colorString = value as string;
44 | var color = colorString.ParseColor();
45 | return new SolidColorBrush(color);
46 | }
47 |
48 | ///
49 | /// Converts a value.
50 | ///
51 | ///
52 | /// A converted value. If the method returns null, the valid null value is used.
53 | ///
54 | /// The value that is produced by the binding target.The type to convert to.The converter parameter to use.The culture to use in the converter.
55 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
56 | {
57 | return null;
58 | }
59 | }
60 | }
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 |
4 | # User-specific files
5 | *.suo
6 | *.user
7 | *.sln.docstates
8 | .vs
9 |
10 | # Build results
11 |
12 | [Dd]ebug/
13 | [Rr]elease/
14 | x64/
15 | build/
16 | [Bb]in/
17 | [Oo]bj/
18 |
19 | # Enable "build/" folder in the NuGet Packages folder since NuGet packages use it for MSBuild targets
20 | !packages/*/build/
21 |
22 | # MSTest test Results
23 | [Tt]est[Rr]esult*/
24 | [Bb]uild[Ll]og.*
25 |
26 | *_i.c
27 | *_p.c
28 | *.ilk
29 | *.meta
30 | *.obj
31 | *.pch
32 | *.pdb
33 | *.pgc
34 | *.pgd
35 | *.rsp
36 | *.sbr
37 | *.tlb
38 | *.tli
39 | *.tlh
40 | *.tmp
41 | *.tmp_proj
42 | *.log
43 | *.vspscc
44 | *.vssscc
45 | .builds
46 | *.pidb
47 | *.log
48 | *.scc
49 |
50 | # Visual C++ cache files
51 | ipch/
52 | *.aps
53 | *.ncb
54 | *.opensdf
55 | *.sdf
56 | *.cachefile
57 |
58 | # Visual C# cache files
59 | *.sln.ide/
60 |
61 | # Visual Studio profiler
62 | *.psess
63 | *.vsp
64 | *.vspx
65 |
66 | # Guidance Automation Toolkit
67 | *.gpState
68 |
69 | # ReSharper is a .NET coding add-in
70 | _ReSharper*/
71 | *.[Rr]e[Ss]harper
72 |
73 | # TeamCity is a build add-in
74 | _TeamCity*
75 |
76 | # DotCover is a Code Coverage Tool
77 | *.dotCover
78 |
79 | # NCrunch
80 | *.ncrunch*
81 | .*crunch*.local.xml
82 |
83 | # Installshield output folder
84 | [Ee]xpress/
85 |
86 | # DocProject is a documentation generator add-in
87 | DocProject/buildhelp/
88 | DocProject/Help/*.HxT
89 | DocProject/Help/*.HxC
90 | DocProject/Help/*.hhc
91 | DocProject/Help/*.hhk
92 | DocProject/Help/*.hhp
93 | DocProject/Help/Html2
94 | DocProject/Help/html
95 |
96 | # Click-Once directory
97 | publish/
98 |
99 | # Publish Web Output
100 | *.Publish.xml
101 |
102 | # NuGet Packages Directory
103 | ## TODO: If you have NuGet Package Restore enabled, uncomment the next line
104 | #packages/
105 |
106 | # Windows Azure Build Output
107 | csx
108 | *.build.csdef
109 |
110 | # Windows Store app package directory
111 | AppPackages/
112 |
113 | # Others
114 | sql/
115 | *.Cache
116 | ClientBin/
117 | [Ss]tyle[Cc]op.*
118 | ~$*
119 | *~
120 | *.dbmdl
121 | *.[Pp]ublish.xml
122 | *.pfx
123 | *.publishsettings
124 |
125 | # RIA/Silverlight projects
126 | Generated_Code/
127 |
128 | # Backup & report files from converting an old project file to a newer
129 | # Visual Studio version. Backup files are not needed, because we have git ;-)
130 | _UpgradeReport_Files/
131 | Backup*/
132 | UpgradeLog*.XML
133 | UpgradeLog*.htm
134 |
135 | # SQL Server files
136 | App_Data/*.mdf
137 | App_Data/*.ldf
138 |
139 |
140 | #LightSwitch generated files
141 | GeneratedArtifacts/
142 | _Pvt_Extensions/
143 | ModelManifest.xml
144 |
145 | # =========================
146 | # Windows detritus
147 | # =========================
148 |
149 | # Windows image file caches
150 | Thumbs.db
151 | ehthumbs.db
152 |
153 | # Folder config file
154 | Desktop.ini
155 |
156 | # Recycle Bin used on file shares
157 | $RECYCLE.BIN/
158 |
159 | # Mac desktop service store files
160 | .DS_Store
161 |
162 | #Nuget Packages
163 | packages/
164 | !packages/repositories.config
165 |
166 | GitHubExtension/ViewModel/LocalMachine/
167 | README.html
168 |
--------------------------------------------------------------------------------
/GitHubIssues/Model/AuthenticationHelpers.cs:
--------------------------------------------------------------------------------
1 | // **********************************************************************************
2 | // The MIT License (MIT)
3 | //
4 | // Copyright (c) 2015 Rob Prouse
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy of
7 | // this software and associated documentation files (the "Software"), to deal in
8 | // the Software without restriction, including without limitation the rights to
9 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
10 | // the Software, and to permit persons to whom the Software is furnished to do so,
11 | // subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in all
14 | // copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 | //
23 | // **********************************************************************************
24 |
25 | #region Using Directives
26 |
27 | using System;
28 | using System.Globalization;
29 | using System.Linq;
30 | using System.Net;
31 | using System.Net.NetworkInformation;
32 | using System.Security.Cryptography;
33 | using System.Text;
34 |
35 | #endregion
36 |
37 | namespace Alteridem.GitHub.Model
38 | {
39 | public static class AuthenticationHelpers
40 | {
41 | public static string GetFingerprint()
42 | {
43 | return Sha256Hash(GetNetworkInterface());
44 | }
45 |
46 | public static string GetMachineName()
47 | {
48 | try
49 | {
50 | return Dns.GetHostName();
51 | }
52 | catch (Exception)
53 | {
54 | try
55 | {
56 | return Environment.MachineName;
57 | }
58 | catch (Exception)
59 | {
60 | return "--unknown--";
61 | }
62 | }
63 | }
64 |
65 | public static string Sha256Hash(string input)
66 | {
67 | using (SHA256 shA256 = SHA256.Create())
68 | {
69 | byte[] bytes = Encoding.UTF8.GetBytes(input);
70 | var hash = from b in shA256.ComputeHash(bytes) select b.ToString("x2", CultureInfo.InvariantCulture);
71 | return string.Join("", hash);
72 | }
73 | }
74 |
75 | public static string GetNetworkInterface()
76 | {
77 | var nics = from nic in NetworkInterface.GetAllNetworkInterfaces()
78 | where nic.OperationalStatus == OperationalStatus.Up
79 | orderby nic.Speed
80 | select nic.GetPhysicalAddress().ToString();
81 | return nics.FirstOrDefault(addr => addr.Length > 12) ?? GetMachineName();
82 | }
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/GitHubExtension/View/LightTheme.xaml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
23 |
24 |
27 |
28 |
34 |
35 |
42 |
43 |
52 |
53 |
56 |
57 |
62 |
63 |
69 |
70 |
--------------------------------------------------------------------------------
/GitHubExtension/IssueListToolWindow.cs:
--------------------------------------------------------------------------------
1 | // **********************************************************************************
2 | // The MIT License (MIT)
3 | //
4 | // Copyright (c) 2014 Rob Prouse
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy of
7 | // this software and associated documentation files (the "Software"), to deal in
8 | // the Software without restriction, including without limitation the rights to
9 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
10 | // the Software, and to permit persons to whom the Software is furnished to do so,
11 | // subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in all
14 | // copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 | //
23 | // **********************************************************************************
24 |
25 | #region Using Directives
26 |
27 | using System.Runtime.InteropServices;
28 | using Alteridem.GitHub.Extension.View;
29 | using Microsoft.VisualStudio.Shell;
30 |
31 | #endregion
32 |
33 | namespace Alteridem.GitHub.Extension
34 | {
35 | ///
36 | /// This class implements the tool window exposed by this package and hosts a user control.
37 | ///
38 | /// In Visual Studio tool windows are composed of a frame (implemented by the shell) and a pane,
39 | /// usually implemented by the package implementer.
40 | ///
41 | /// This class derives from the ToolWindowPane class provided from the MPF in order to use its
42 | /// implementation of the IVsUIElementPane interface.
43 | ///
44 | [Guid("04baf945-0cc3-4594-87ca-1656d83fdcfe")]
45 | public class IssueListToolWindow : ToolWindowPane
46 | {
47 | ///
48 | /// Standard constructor for the tool window.
49 | ///
50 | public IssueListToolWindow() :
51 | base(null)
52 | {
53 | // Set the window title reading it from the resources.
54 | Caption = Resources.IssueListWindowTitle;
55 | // Set the image that will appear on the tab of the window frame
56 | // when docked with an other window
57 | // The resource ID correspond to the one defined in the resx file
58 | // while the Index is the offset in the bitmap strip. Each image in
59 | // the strip being 16x16.
60 | BitmapResourceID = 301;
61 | BitmapIndex = 1;
62 |
63 | // This is the user control hosted by the tool window; Note that, even if this class implements IDisposable,
64 | // we are not calling Dispose on this object. This is because ToolWindowPane calls Dispose on
65 | // the object returned by the Content property.
66 | base.Content = new IssueList();
67 | }
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/GitHubExtension/View/Avatar.xaml.cs:
--------------------------------------------------------------------------------
1 | // **********************************************************************************
2 | // The MIT License (MIT)
3 | //
4 | // Copyright (c) 2014 Rob Prouse
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy of
7 | // this software and associated documentation files (the "Software"), to deal in
8 | // the Software without restriction, including without limitation the rights to
9 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
10 | // the Software, and to permit persons to whom the Software is furnished to do so,
11 | // subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in all
14 | // copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 | //
23 | // **********************************************************************************
24 |
25 | #region Using Directives
26 |
27 | using System;
28 | using System.ComponentModel;
29 | using System.Runtime.CompilerServices;
30 | using System.Windows;
31 | using System.Windows.Controls;
32 | using Alteridem.GitHub.Annotations;
33 | using Alteridem.GitHub.Extension.Interfaces;
34 | using Alteridem.GitHub.Extension.ViewModel;
35 |
36 | #endregion
37 |
38 | namespace Alteridem.GitHub.Extension.View
39 | {
40 | ///
41 | /// Interaction logic for Avatar.xaml
42 | ///
43 | public partial class Avatar
44 | {
45 | private readonly IAvatar _avatar;
46 |
47 | public Avatar()
48 | {
49 | InitializeComponent();
50 | _avatar = Factory.Get();
51 | Image.DataContext = _avatar;
52 | }
53 |
54 | internal IAvatar AvatarViewModel
55 | {
56 | get { return _avatar; }
57 | }
58 |
59 | public double Size
60 | {
61 | get { return _avatar != null ? _avatar.Size : Width; }
62 | set
63 | {
64 | if ( _avatar != null ) _avatar.Size = value;
65 | Width = value;
66 | Height = value;
67 | }
68 | }
69 |
70 | public string AvatarUrl
71 | {
72 | get { return GetValue(AvatarUrlProperty) as string; }
73 | set { SetValue(AvatarUrlProperty, value); }
74 | }
75 |
76 | public static readonly DependencyProperty AvatarUrlProperty =
77 | DependencyProperty.Register(
78 | "AvatarUrl",
79 | typeof (string),
80 | typeof (Avatar),
81 | new FrameworkPropertyMetadata(OnAvatarUrlChanged));
82 |
83 | private static void OnAvatarUrlChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
84 | {
85 | var avatar = d as Avatar;
86 | if (avatar == null || avatar.AvatarViewModel == null)
87 | return;
88 |
89 | avatar.AvatarViewModel.AvatarUrl = e.NewValue as string;
90 | }
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/GitHubExtension/ViewModel/AddCommentViewModel.cs:
--------------------------------------------------------------------------------
1 | // **********************************************************************************
2 | // The MIT License (MIT)
3 | //
4 | // Copyright (c) 2014 Rob Prouse
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy of
7 | // this software and associated documentation files (the "Software"), to deal in
8 | // the Software without restriction, including without limitation the rights to
9 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
10 | // the Software, and to permit persons to whom the Software is furnished to do so,
11 | // subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in all
14 | // copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 | //
23 | // **********************************************************************************
24 |
25 | #region Using Directives
26 |
27 | using System.Windows.Input;
28 | using Alteridem.GitHub.Extension.Interfaces;
29 | using Alteridem.GitHub.Extension.View;
30 | using Octokit;
31 | using Issue = Octokit.Issue;
32 |
33 | #endregion
34 |
35 | namespace Alteridem.GitHub.Extension.ViewModel
36 | {
37 | public class AddCommentViewModel : BaseGitHubViewModel
38 | {
39 | private readonly Issue _issue;
40 | private string _comment;
41 |
42 | public AddCommentViewModel()
43 | {
44 | _issue = GitHubApi.Issue;
45 |
46 | CloseIssueCommand = new RelayCommand(OnCloseIssue, p => CanCloseIssue());
47 | CommentCommand = new RelayCommand(OnCommentOnIssue, p => CanCommentOnIssue());
48 | }
49 |
50 | public Issue Issue
51 | {
52 | get { return _issue; }
53 | }
54 |
55 | public string Comment
56 | {
57 | get { return _comment; }
58 | set
59 | {
60 | if (value == _comment) return;
61 | _comment = value;
62 | OnPropertyChanged();
63 | }
64 | }
65 |
66 | public ICommand CloseIssueCommand { get; private set; }
67 | public ICommand CommentCommand { get; private set; }
68 |
69 | public void OnCloseIssue(object o)
70 | {
71 | GitHubApi.CloseIssue(GitHubApi.Issue, Comment);
72 | var closable = o as IClosable;
73 | if ( closable != null )
74 | closable.Close();
75 | }
76 |
77 | public bool CanCloseIssue()
78 | {
79 | return _issue != null;
80 | }
81 |
82 | public void OnCommentOnIssue(object o)
83 | {
84 | GitHubApi.AddComment(GitHubApi.Issue, Comment);
85 | var closable = o as IClosable;
86 | if (closable != null)
87 | closable.Close();
88 | }
89 |
90 | public bool CanCommentOnIssue()
91 | {
92 | return _issue != null && !string.IsNullOrWhiteSpace(Comment);
93 | }
94 | }
95 | }
--------------------------------------------------------------------------------
/GitHubIssues/Converters/StringToInverseColorConverter.cs:
--------------------------------------------------------------------------------
1 | // **********************************************************************************
2 | // The MIT License (MIT)
3 | //
4 | // Copyright (c) 2014 Rob Prouse
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy of
7 | // this software and associated documentation files (the "Software"), to deal in
8 | // the Software without restriction, including without limitation the rights to
9 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
10 | // the Software, and to permit persons to whom the Software is furnished to do so,
11 | // subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in all
14 | // copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 | //
23 | // **********************************************************************************
24 |
25 | #region Using Directives
26 |
27 | using System;
28 | using System.Globalization;
29 | using System.Windows.Data;
30 | using System.Windows.Media;
31 |
32 | #endregion
33 |
34 | namespace Alteridem.GitHub.Converters
35 | {
36 | public class StringToInverseColorConverter : IValueConverter
37 | {
38 | ///
39 | /// Converts a value.
40 | ///
41 | ///
42 | /// A converted value. If the method returns null, the valid null value is used.
43 | ///
44 | /// The value produced by the binding source.The type of the binding target property.The converter parameter to use.The culture to use in the converter.
45 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
46 | {
47 | var colorString = value as string;
48 | var background = colorString.ParseColor();
49 | var hsb = background.ToHsb();
50 | var foreground = Colors.White;
51 |
52 | if ( (hsb.B > 0.6 && hsb.S < 0.4) || (hsb.B > 0.7 && hsb.H > 40 && hsb.H < 200))
53 | {
54 | hsb.B = 0.4F;
55 | foreground = hsb.ToRgb();
56 | }
57 | return new SolidColorBrush(foreground);
58 | }
59 |
60 | ///
61 | /// Converts a value.
62 | ///
63 | ///
64 | /// A converted value. If the method returns null, the valid null value is used.
65 | ///
66 | /// The value that is produced by the binding target.The type to convert to.The converter parameter to use.The culture to use in the converter.
67 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
68 | {
69 | return null;
70 | }
71 | }
72 | }
--------------------------------------------------------------------------------
/GitHubExtension/View/RelayCommand.cs:
--------------------------------------------------------------------------------
1 | // **********************************************************************************
2 | // The MIT License (MIT)
3 | //
4 | // Copyright (c) 2014 Rob Prouse
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy of
7 | // this software and associated documentation files (the "Software"), to deal in
8 | // the Software without restriction, including without limitation the rights to
9 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
10 | // the Software, and to permit persons to whom the Software is furnished to do so,
11 | // subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in all
14 | // copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 | //
23 | // **********************************************************************************
24 |
25 | using System;
26 | using System.Diagnostics;
27 | using System.Windows.Input;
28 |
29 | namespace Alteridem.GitHub.Extension.View
30 | {
31 | //
32 | /// A command whose sole purpose is to
33 | /// relay its functionality to other
34 | /// objects by invoking delegates. The
35 | /// default return value for the CanExecute
36 | /// method is 'true'.
37 | ///
38 | public class RelayCommand : ICommand
39 | {
40 | #region Fields
41 |
42 | readonly Action