Fixed issue in GUI tool that action dropdown and api dropdown not auto reload when config file changed

Alternate request/response output color
Allow GUI tool to be maximize
bug fixes.
This commit is contained in:
Xiaomin Wu 2015-02-03 18:22:11 -08:00
Родитель 93889494f7
Коммит 90aa2bf1f8
6 изменённых файлов: 209 добавлений и 55 удалений

Просмотреть файл

@ -2,13 +2,49 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:System="clr-namespace:System;assembly=mscorlib" x:Class="ArmGuiClient.MainWindow"
Title="ARM GUI Client" Height="665.5" Width="809" ResizeMode="NoResize">
Title="ARM GUI Client" Height="665.5" Width="809" MinWidth="809" MinHeight="665.5">
<Grid>
<ComboBox x:Name="SubscriptionCB" HorizontalAlignment="Left" Margin="201,10,0,0" VerticalAlignment="Top" Width="298" Height="22" SelectionChanged="SubscriptionCB_SelectionChanged"/>
<Button x:Name="LoginBtn" Content="Login" HorizontalAlignment="Left" Margin="651,10,0,0" VerticalAlignment="Top" Width="67" Click="LoginBtn_Click" Height="22"/>
<Button x:Name="LogoutBtn" Content="Logout" HorizontalAlignment="Left" Margin="723,10,0,0" VerticalAlignment="Top" Width="67" Click="LogoutBtn_Click" Height="22"/>
<RichTextBox x:Name="OutputRTB" IsReadOnly="True" HorizontalAlignment="Left" Height="534" Margin="201,39,0,0"
VerticalAlignment="Top" Width="589" ScrollViewer.VerticalScrollBarVisibility="Auto" Padding="0">
<Grid.RowDefinitions>
<RowDefinition Height="27"></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition Height="60"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="210"></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<ComboBox x:Name="TenantCB" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Width="Auto" Height="Auto" SelectionChanged="TenantCB_SelectionChanged" Margin="2" Grid.Column="0" Grid.Row="0"/>
<Grid Grid.Column="1" Grid.Row="0">
<Grid.RowDefinitions>
<RowDefinition Height="27"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition Width="150"></ColumnDefinition>
<ColumnDefinition Width="25"></ColumnDefinition>
<ColumnDefinition Width="60"></ColumnDefinition>
<ColumnDefinition Width="60"></ColumnDefinition>
</Grid.ColumnDefinitions>
<ComboBox x:Name="SubscriptionCB" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Width="Auto" Height="Auto" SelectionChanged="SubscriptionCB_SelectionChanged" Margin="2" Grid.Column="0" Grid.Row="0"/>
<ComboBox x:Name="ApiVersionCB" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Width="Auto" Height="Auto" SelectedIndex="0" SelectionChanged="ApiVersionCB_SelectionChanged" Margin="2" Grid.Column="1" Grid.Row="0"/>
<Button Content="?" x:Name="HelpBtn" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Width="Auto" Height="Auto" Click="HelpBtn_Click" Margin="2" Grid.Column="2" Grid.Row="0"/>
<Button x:Name="LoginBtn" Content="Login" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Width="Auto" Height="Auto" Click="LoginBtn_Click" Margin="2" Grid.Column="3" Grid.Row="0"/>
<Button x:Name="LogoutBtn" Content="Logout" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Width="Auto" Height="Auto" Click="LogoutBtn_Click" Margin="2" Grid.Column="4" Grid.Row="0"/>
</Grid>
<ComboBox x:Name="ActionCB" HorizontalAlignment="Left" VerticalAlignment="Top" Width="210" Height="25" SelectionChanged="ActionCB_SelectionChanged" Grid.Column="0" Grid.Row="1"/>
<ListView x:Name="ParamLV" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Width="Auto" Height="Auto" Margin="0,26,0,0" Grid.Column="0" Grid.Row="1">
<ListView.View>
<GridView>
<GridViewColumn/>
</GridView>
</ListView.View>
</ListView>
<RichTextBox x:Name="OutputRTB" IsReadOnly="True" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Width="Auto" Height="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto" Grid.Column="1" Grid.Row="1">
<FlowDocument>
<FlowDocument.Resources>
<Style TargetType="{x:Type Paragraph}">
@ -21,25 +57,22 @@
</Paragraph>
</FlowDocument>
</RichTextBox>
<TextBox x:Name="CmdText" HorizontalAlignment="Left" Height="46" Margin="0,579,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="694"/>
<Button x:Name="ExecuteBtn" Margin="710,579,0,0" VerticalAlignment="Top" Height="46" HorizontalAlignment="Left" Width="80" Click="ExecuteBtn_Click">
<StackPanel>
<TextBlock Text="Execute" HorizontalAlignment="Center"/>
<TextBlock Text="(Ctrl + Enter)" HorizontalAlignment="Center"/>
</StackPanel>
</Button>
<ComboBox x:Name="ApiVersionCB" HorizontalAlignment="Left" Margin="504,10,0,0" VerticalAlignment="Top" Width="100" Height="22" SelectedIndex="0" SelectionChanged="ApiVersionCB_SelectionChanged">
<System:String>2014-11-01</System:String>
</ComboBox>
<ComboBox x:Name="TenantCB" HorizontalAlignment="Left" Margin="6,10,0,0" VerticalAlignment="Top" Width="190" SelectionChanged="TenantCB_SelectionChanged"/>
<ComboBox x:Name="ActionCB" HorizontalAlignment="Left" Margin="6,39,0,0" VerticalAlignment="Top" Width="190" SelectionChanged="ActionCB_SelectionChanged"/>
<ListView x:Name="ParamLV" HorizontalAlignment="Left" Height="507" Margin="0,66,0,0" VerticalAlignment="Top" Width="201">
<ListView.View>
<GridView>
<GridViewColumn/>
</GridView>
</ListView.View>
</ListView>
<Button Content="?" x:Name="HelpBtn" HorizontalAlignment="Left" Margin="615,10,0,0" VerticalAlignment="Top" Width="27" Height="22" Click="HelpBtn_Click" />
<Grid Grid.Column="0" Grid.Row="2" Grid.ColumnSpan="2">
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition Width="100"></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBox x:Name="CmdText" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Width="Auto" Height="Auto" TextWrapping="Wrap" Text="TextBox" Grid.Column="0" Grid.Row="0"/>
<Button x:Name="ExecuteBtn" VerticalAlignment="Stretch" Width="Auto" Height="Auto" Click="ExecuteBtn_Click" Margin="10, 5, 10, 5" Grid.Column="1" Grid.Row="0">
<StackPanel>
<TextBlock Text="Execute" HorizontalAlignment="Center"/>
<TextBlock Text="(Ctrl + Enter)" HorizontalAlignment="Center"/>
</StackPanel>
</Button>
</Grid>
</Grid>
</Window>

Просмотреть файл

@ -21,7 +21,7 @@ namespace ArmGuiClient
/// </summary>
public partial class MainWindow : Window
{
private static readonly string _tmpPayloadFile = System.IO.Path.Combine(Environment.CurrentDirectory, "ArmGuiClient.Payload.json");
private static readonly string _tmpPayloadFile = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ArmGuiClient.Payload.json");
private GuiPersistentAuthHelper _authHelper;
public MainWindow()
@ -36,9 +36,24 @@ namespace ArmGuiClient
this._authHelper = new GuiPersistentAuthHelper();
this.InitUI();
this.InitKeyboardBindings();
ConfigSettingFactory.RegisterOnChangedEvent(() =>
{
Application.Current.Dispatcher.Invoke(() =>
{
this.InitUI();
});
});
if (this.CheckIsLogin())
{
this.PopulateTenant();
if (this._authHelper.AzureEnvironments != ConfigSettingFactory.ConfigSettings.GetAzureEnvironments())
{
Logger.WarnLn("Your login session enviroment is '{0}', it is different from your config.json '{1}'",
ConfigSettingFactory.ConfigSettings.TargetEnvironment, this._authHelper.AzureEnvironments);
}
}
}
catch (Exception ex)
@ -84,8 +99,12 @@ namespace ArmGuiClient
});
}
this.ActionCB.SelectedIndex = 0;
this.OutputRTB.Document.Blocks.Clear();
this.HelpBtn_Click(null, null);
}
private void InitKeyboardBindings()
{
// bind keyboard short cuts
var editPayloadCommand = new RoutedCommand();
editPayloadCommand.InputGestures.Add(new KeyGesture(Key.W, ModifierKeys.Control, "Ctrl + E"));
@ -112,6 +131,13 @@ namespace ArmGuiClient
{
this.HelpBtn_Click(null, null);
}));
var actionFocusCommand = new RoutedCommand();
actionFocusCommand.InputGestures.Add(new KeyGesture(Key.D, ModifierKeys.Control, "Ctrl + R"));
this.CommandBindings.Add(new CommandBinding(actionFocusCommand, (object sender, ExecutedRoutedEventArgs e) =>
{
this.ActionCB.IsDropDownOpen = true;
}));
}
private void PopulateParamsUI(ConfigActioin action)
@ -154,7 +180,8 @@ namespace ArmGuiClient
private bool CheckIsLogin()
{
if (this._authHelper != null && this._authHelper.IsCacheValid())
if (this._authHelper != null
&& this._authHelper.IsCacheValid())
{
this.LoginBtn.IsEnabled = false;
this.LogoutBtn.IsEnabled = true;
@ -196,7 +223,10 @@ namespace ArmGuiClient
// api version
ComboBoxItem apiItem = this.ApiVersionCB.SelectedValue as ComboBoxItem;
cmd = cmd.Replace("{apiVersion}", apiItem.Content as string);
if (apiItem != null)
{
cmd = cmd.Replace("{apiVersion}", apiItem.Content as string);
}
// subscription
string subscriptionId = this.SubscriptionCB.SelectedValue as string;
@ -275,8 +305,9 @@ namespace ArmGuiClient
try
{
ConfigActioin action = this.GetSelectedAction();
if (string.Equals("get", action.HttpMethod, StringComparison.OrdinalIgnoreCase) ||
string.Equals("delete", action.HttpMethod, StringComparison.OrdinalIgnoreCase))
if (action == null
|| string.Equals("get", action.HttpMethod, StringComparison.OrdinalIgnoreCase)
|| string.Equals("delete", action.HttpMethod, StringComparison.OrdinalIgnoreCase))
{
return;
}
@ -293,6 +324,7 @@ namespace ArmGuiClient
catch (Exception ex)
{
Logger.ErrorLn("Editor: '{0}'", ConfigSettingFactory.ConfigSettings.Editor);
Logger.ErrorLn("Payload file: '{0}'", _tmpPayloadFile);
Logger.ErrorLn("{0} {1}", ex.Message, ex.StackTrace);
}
}
@ -410,16 +442,17 @@ namespace ArmGuiClient
private void HelpBtn_Click(object sender, RoutedEventArgs e)
{
Logger.InfoLn(string.Empty);
Logger.InfoLn("*******************************************************************************************************************");
Logger.InfoLn("**************************************************************************************************************");
Logger.InfoLn("> Ctrl + D to open action dropdown");
Logger.InfoLn("> Ctrl + H to print help content");
Logger.InfoLn("> Ctrl + P to edit config.json");
Logger.InfoLn("> Ctrl + P to edit config.json, ArmGuiClient will auto-reload config.json if there is any chagnes.");
Logger.InfoLn("> Ctrl + W to edit payload");
Logger.InfoLn("> Ctrl + F8 to clear console");
Logger.InfoLn("> Ctrl + Enter to run command");
Logger.InfoLn(@"> For more information, please visit: https://github.com/projectkudu/ARMClient");
Logger.InfoLn("*******************************************************************************************************************");
Logger.InfoLn(@"> For more information, please visit: https://github.com/projectkudu/ARMClient/wiki/ArmGuiClient");
Logger.InfoLn(@"> Command promte version: https://github.com/projectkudu/ARMClient");
Logger.InfoLn("**************************************************************************************************************");
Logger.InfoLn(string.Empty);
}
}
}

Просмотреть файл

@ -4,15 +4,16 @@ using System;
using System.IO;
using System.Timers;
using System.Web.Script.Serialization;
using System.Windows;
namespace ArmGuiClient.Models
{
internal class ConfigSettingFactory
{
public static readonly string ConfigFilePath = System.IO.Path.Combine(Environment.CurrentDirectory, "config.json");
public static readonly string ConfigFilePath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "config.json");
private static ConfigSettings _settingInstance;
private static FileSystemWatcher _configWatcher;
private static Timer _refreshTimer;
private static Action _externalEventWhenConfigChanged;
public static void Init()
{
@ -34,15 +35,28 @@ namespace ArmGuiClient.Models
try
{
_settingInstance = GetConfigSettings();
try
{
_externalEventWhenConfigChanged();
}
catch (Exception ex)
{
Logger.ErrorLn("{0} {1}", ex.Message, ex.StackTrace);
}
Logger.InfoLn("Changes are detected from config.json. Setting updated.");
}
catch (Exception ex)
{
Logger.ErrorLn("Changes are detected from config.json. {0} {1}", ex.Message, ex.StackTrace);
Logger.ErrorLn("{0} {1}\nChanges are detected from config.json but failed to read.", ex.Message, ex.StackTrace);
}
};
}
public static void RegisterOnChangedEvent(Action action)
{
_externalEventWhenConfigChanged = action;
}
public static void Shutdown()
{
if (_configWatcher != null)

Просмотреть файл

@ -6,27 +6,29 @@ using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Media;
namespace ArmGuiClient.Utils
{
class HttpLoggingHandler : DelegatingHandler
{
private readonly bool _verbose;
private static Brush _infoBrush = Brushes.SpringGreen;
public HttpLoggingHandler(HttpMessageHandler innerHandler, bool verbose)
: base(innerHandler)
{
this._verbose = verbose;
_verbose = verbose;
}
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
if (_verbose)
{
Logger.InfoLn("---------- Request -----------------------");
LogInfoLn("---------- Request -----------------------");
Logger.InfoLn("{0} {1} HTTP/{2}", request.Method, request.RequestUri.PathAndQuery, request.Version);
Logger.InfoLn("Host: {0}", request.RequestUri.Host);
LogInfoLn("{0} {1} HTTP/{2}", request.Method, request.RequestUri.PathAndQuery, request.Version);
LogInfoLn("Host: {0}", request.RequestUri.Host);
foreach (var header in request.Headers)
{
@ -39,7 +41,7 @@ namespace ArmGuiClient.Utils
{
headerVal = String.Join("; ", header.Value);
}
Logger.InfoLn("{0}: {1}", header.Key, headerVal);
LogInfoLn("{0}: {1}", header.Key, headerVal);
}
await DumpContent(request.Content);
@ -54,15 +56,16 @@ namespace ArmGuiClient.Utils
if (_verbose)
{
Logger.InfoLn("---------- Response ({0} ms) ------------", watch.ElapsedMilliseconds);
Logger.InfoLn("HTTP/{0} {1} {2}", response.Version, responseStatusCocde, response.StatusCode);
LogInfoLn("---------- Response ({0} ms) ------------", watch.ElapsedMilliseconds);
LogInfoLn("HTTP/{0} {1} {2}", response.Version, responseStatusCocde, response.StatusCode);
foreach (var header in response.Headers)
{
Logger.InfoLn("{0}: {1}", header.Key, String.Join("; ", header.Value));
LogInfoLn("{0}: {1}", header.Key, String.Join("; ", header.Value));
}
}
await DumpContent(response.Content, this.isErrorRequest(responseStatusCocde));
await DumpContent(response.Content, isErrorRequest(responseStatusCocde));
AlternateInfoBrush();
return response;
}
@ -74,13 +77,13 @@ namespace ArmGuiClient.Utils
}
var result = await content.ReadAsStringAsync();
Logger.InfoLn(string.Empty);
LogInfoLn(string.Empty);
if (!string.IsNullOrWhiteSpace(result))
{
dynamic parsedJson = JsonConvert.DeserializeObject(result);
string indentedResult = JsonConvert.SerializeObject(parsedJson, Formatting.Indented);
Logger.WriteLn(indentedResult, isErrorContent ? Logger.ErrorBrush : Logger.InfoBrush);
Logger.WriteLn(indentedResult, isErrorContent ? Logger.ErrorBrush : _infoBrush);
}
}
@ -88,5 +91,15 @@ namespace ArmGuiClient.Utils
{
return responseStatusCode >= 400 && responseStatusCode < 600;
}
private static void LogInfoLn(string format, params object[] args)
{
Logger.WriteLn(string.Format(format, args), _infoBrush);
}
private static void AlternateInfoBrush()
{
_infoBrush = ((_infoBrush == Brushes.SpringGreen) ? Brushes.MediumSpringGreen : Brushes.SpringGreen);
}
}
}

Просмотреть файл

@ -18,6 +18,7 @@ namespace ArmGuiClient.Utils
{
_outputRTB = textBox;
_flowDoc = _outputRTB.Document;
Clear();
}
public static void Clear()

Просмотреть файл

@ -5,8 +5,7 @@
"Editor": "%windir%\\system32\\notepad.exe",
"AutoPromptEditor": "true",
"DefaultValues": {
"resourceGroup": "tryag",
"location": "westus"
"placeholderFromParamsOrPayload": "default value for params or payload"
},
"Actioins": [
{
@ -105,6 +104,23 @@
}
}
},
{
"httpMethod": "DELETE",
"name": "Delete Website",
"template": "/subscriptions/{subscription}/resourceGroups/{resourceGroup}/providers/Microsoft.Web/sites/{siteName}?api-version={apiVersion}",
"params": [
{
"name": "Resource Group Name",
"placeHolder": "resourceGroup",
"required": "true"
},
{
"name": "Website Name",
"placeHolder": "siteName",
"required": "true"
}
]
},
{
"httpMethod": "GET",
"name": "List Site Extensions",
@ -125,7 +141,7 @@
{
"httpMethod": "PUT",
"name": "Install Site Extensions",
"template": "/subscriptions/{subscription}/resourceGroups/{resourceGroup}/providers/Microsoft.Web/sites/{siteName}/siteextensions/{extensionName}?api-version={apiVersion}",
"template": "/subscriptions/{subscription}/resourceGroups/{resourceGroup}/providers/Microsoft.Web/sites/{siteName}/siteextensions/{siteExtensionName}?api-version={apiVersion}",
"params": [
{
"name": "Resource Group Name",
@ -139,7 +155,7 @@
},
{
"name": "Extension Name",
"placeHolder": "extensionName",
"placeHolder": "siteExtensionName",
"required": "true"
}
],
@ -147,6 +163,50 @@
"properties": {
}
}
},
{
"httpMethod": "GET",
"name": "Get Site Extension",
"template": "/subscriptions/{subscription}/resourceGroups/{resourceGroup}/providers/Microsoft.Web/sites/{siteName}/siteextensions/{siteExtensionName}?api-version={apiVersion}",
"params": [
{
"name": "Resource Group Name",
"placeHolder": "resourceGroup",
"required": "true"
},
{
"name": "Website Name",
"placeHolder": "siteName",
"required": "true"
},
{
"name": "Extension Name",
"placeHolder": "siteExtensionName",
"required": "true"
}
]
},
{
"httpMethod": "DELETE",
"name": "Delete Site Extension",
"template": "/subscriptions/{subscription}/resourceGroups/{resourceGroup}/providers/Microsoft.Web/sites/{siteName}/siteextensions/{siteExtensionName}?api-version={apiVersion}",
"params": [
{
"name": "Resource Group Name",
"placeHolder": "resourceGroup",
"required": "true"
},
{
"name": "Website Name",
"placeHolder": "siteName",
"required": "true"
},
{
"name": "Extension Name",
"placeHolder": "siteExtensionName",
"required": "true"
}
]
}
]
}