-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from TimVinkemeier/bugfix/find-and-replace
Bug fixes, added minimal start page
- Loading branch information
Showing
11 changed files
with
190 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
41 changes: 41 additions & 0 deletions
41
TimVinkemeier.AzureDevOpsToolkit/Extensions/HyperlinkExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using System.Diagnostics; | ||
using System.Windows; | ||
using System.Windows.Documents; | ||
|
||
namespace TimVinkemeier.AzureDevOpsToolkit.Extensions | ||
{ | ||
public static class HyperlinkExtensions | ||
{ | ||
public static readonly DependencyProperty IsExternalProperty = | ||
DependencyProperty.RegisterAttached("IsExternal", typeof(bool), typeof(HyperlinkExtensions), new UIPropertyMetadata(false, OnIsExternalChanged)); | ||
|
||
public static bool GetIsExternal(DependencyObject obj) | ||
{ | ||
return (bool)obj.GetValue(IsExternalProperty); | ||
} | ||
|
||
public static void SetIsExternal(DependencyObject obj, bool value) | ||
{ | ||
obj.SetValue(IsExternalProperty, value); | ||
} | ||
|
||
private static void Hyperlink_RequestNavigate(object sender, System.Windows.Navigation.RequestNavigateEventArgs e) | ||
{ | ||
Process.Start(new ProcessStartInfo(e.Uri.AbsoluteUri) | ||
{ | ||
UseShellExecute = true | ||
}); | ||
e.Handled = true; | ||
} | ||
|
||
private static void OnIsExternalChanged(object sender, DependencyPropertyChangedEventArgs args) | ||
{ | ||
var hyperlink = sender as Hyperlink; | ||
|
||
if ((bool)args.NewValue) | ||
hyperlink.RequestNavigate += Hyperlink_RequestNavigate; | ||
else | ||
hyperlink.RequestNavigate -= Hyperlink_RequestNavigate; | ||
} | ||
} | ||
} |
75 changes: 48 additions & 27 deletions
75
TimVinkemeier.AzureDevOpsToolkit/Services/SettingsService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,71 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Microsoft.VisualStudio.Services.Common; | ||
|
||
using Newtonsoft.Json; | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Threading.Tasks; | ||
|
||
using TimVinkemeier.AzureDevOpsToolkit.Core.Services; | ||
|
||
namespace TimVinkemeier.AzureDevOpsToolkit.Services | ||
{ | ||
public class SettingsService : ISettingsService | ||
{ | ||
public Task<T> GetSettingAsync<T>(Setting setting) | ||
private IDictionary<string, string> _allSettings; | ||
|
||
public async Task<T> GetSettingAsync<T>(Setting setting) | ||
{ | ||
var value = setting switch | ||
if (_allSettings is null) | ||
{ | ||
Setting.AzureDevOpsToken => Properties.Settings.Default.AzureDevOpsToken, | ||
Setting.OrganisationBaseUrl => Properties.Settings.Default.OrganisationBaseUrl, | ||
Setting.ProjectName => Properties.Settings.Default.ProjectName, | ||
_ => throw new ArgumentException(null, nameof(setting)) | ||
}; | ||
await ReadSettingsAsync().ConfigureAwait(false); | ||
} | ||
|
||
return Task.FromResult(JsonConvert.DeserializeObject<T>(value)); | ||
var key = Enum.GetName(setting); | ||
return _allSettings.TryGetValue(key, out var value) | ||
? JsonConvert.DeserializeObject<T>(value) | ||
: default; | ||
} | ||
|
||
public Task SetSettingAsync<T>(Setting setting, T value) | ||
public async Task SetSettingAsync<T>(Setting setting, T value) | ||
{ | ||
switch (setting) | ||
{ | ||
case Setting.AzureDevOpsToken: | ||
Properties.Settings.Default.AzureDevOpsToken = JsonConvert.SerializeObject(value); | ||
break; | ||
await ReadSettingsAsync().ConfigureAwait(false); | ||
|
||
var key = Enum.GetName(setting); | ||
var json = JsonConvert.SerializeObject(value); | ||
_allSettings.AddOrUpdate(key, json, (_, _) => json); | ||
|
||
await SaveSettingsAsync().ConfigureAwait(false); | ||
await ReadSettingsAsync().ConfigureAwait(false); | ||
} | ||
|
||
private static FileInfo GetSettingsFileInfo() | ||
=> new FileInfo(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "TimVinkemeier.AzureDevOps", "settings.json")); | ||
|
||
case Setting.OrganisationBaseUrl: | ||
Properties.Settings.Default.OrganisationBaseUrl = JsonConvert.SerializeObject(value); | ||
break; | ||
private async Task ReadSettingsAsync() | ||
{ | ||
var file = GetSettingsFileInfo(); | ||
|
||
case Setting.ProjectName: | ||
Properties.Settings.Default.ProjectName = JsonConvert.SerializeObject(value); | ||
break; | ||
if (!file.Exists) | ||
{ | ||
_allSettings = new Dictionary<string, string>(); | ||
await SaveSettingsAsync().ConfigureAwait(false); | ||
return; | ||
} | ||
|
||
default: | ||
throw new ArgumentException(null, nameof(setting)); | ||
}; | ||
var fullJson = await File.ReadAllTextAsync(file.FullName).ConfigureAwait(false); | ||
_allSettings = JsonConvert.DeserializeObject<IDictionary<string, string>>(fullJson); | ||
} | ||
|
||
private async Task SaveSettingsAsync() | ||
{ | ||
var file = GetSettingsFileInfo(); | ||
|
||
Properties.Settings.Default.Save(); | ||
Directory.CreateDirectory(file.DirectoryName); | ||
|
||
return Task.CompletedTask; | ||
var fullJson = JsonConvert.SerializeObject(_allSettings); | ||
await File.WriteAllTextAsync(file.FullName, fullJson).ConfigureAwait(false); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.