Skip to content

A Swiss Army knife for developers.

updated localization, dynamic conversion mode and dynamic encoding mode

Benjamin Titeux9ee257e516a1
diff --git a/src/dev/impl/DevTools.Common/LanguageManager.cs b/src/dev/impl/DevTools.Common/LanguageManager.cs
index 464c6dc9e..7b1e2c42d 100644
--- a/src/dev/impl/DevTools.Common/LanguageManager.cs
+++ b/src/dev/impl/DevTools.Common/LanguageManager.cs
@@ -97,10 +97,55 @@ namespace DevTools.Common
{
private readonly ResourceLoader _resources = ResourceLoader.GetForViewIndependentUse("DevTools.Common/Base64EncoderDecoder");
+ /// <summary>
+ /// Gets the resource ConfigurationTitle.
+ /// </summary>
+ public string ConfigurationTitle => _resources.GetString("ConfigurationTitle");
+
+ /// <summary>
+ /// Gets the resource ConversionDecode.
+ /// </summary>
+ public string ConversionDecode => _resources.GetString("ConversionDecode");
+
+ /// <summary>
+ /// Gets the resource ConversionDescription.
+ /// </summary>
+ public string ConversionDescription => _resources.GetString("ConversionDescription");
+
+ /// <summary>
+ /// Gets the resource ConversionEncode.
+ /// </summary>
+ public string ConversionEncode => _resources.GetString("ConversionEncode");
+
+ /// <summary>
+ /// Gets the resource ConversionTitle.
+ /// </summary>
+ public string ConversionTitle => _resources.GetString("ConversionTitle");
+
/// <summary>
/// Gets the resource DisplayName.
/// </summary>
public string DisplayName => _resources.GetString("DisplayName");
+
+ /// <summary>
+ /// Gets the resource EncodingDescription.
+ /// </summary>
+ public string EncodingDescription => _resources.GetString("EncodingDescription");
+
+ /// <summary>
+ /// Gets the resource EncodingTitle.
+ /// </summary>
+ public string EncodingTitle => _resources.GetString("EncodingTitle");
+
+ /// <summary>
+ /// Gets the resource InputTitle.
+ /// </summary>
+ public string InputTitle => _resources.GetString("InputTitle");
+
+ /// <summary>
+ /// Gets the resource OutputTitle.
+ /// </summary>
+ public string OutputTitle => _resources.GetString("OutputTitle");
}
public class CommonStrings : ObservableObject
diff --git a/src/dev/impl/DevTools.Common/Strings/en/Base64EncoderDecoder.resw b/src/dev/impl/DevTools.Common/Strings/en/Base64EncoderDecoder.resw
index e7e695de7..a68f6994f 100644
--- a/src/dev/impl/DevTools.Common/Strings/en/Base64EncoderDecoder.resw
+++ b/src/dev/impl/DevTools.Common/Strings/en/Base64EncoderDecoder.resw
@@ -117,7 +117,34 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
+ <data name="ConfigurationTitle" xml:space="preserve">
+ <value>Configuration</value>
+ </data>
+ <data name="ConversionDecode" xml:space="preserve">
+ <value>Decode</value>
+ </data>
+ <data name="ConversionDescription" xml:space="preserve">
+ <value>Select which conversion mode you want to use</value>
+ </data>
+ <data name="ConversionEncode" xml:space="preserve">
+ <value>Encode</value>
+ </data>
+ <data name="ConversionTitle" xml:space="preserve">
+ <value>Conversion</value>
+ </data>
<data name="DisplayName" xml:space="preserve">
<value>Base 64 Encoder/Decoder</value>
</data>
+ <data name="EncodingDescription" xml:space="preserve">
+ <value>Select which encoding do you want to use</value>
+ </data>
+ <data name="EncodingTitle" xml:space="preserve">
+ <value>Encoding</value>
+ </data>
+ <data name="InputTitle" xml:space="preserve">
+ <value>Input</value>
+ </data>
+ <data name="OutputTitle" xml:space="preserve">
+ <value>Output</value>
+ </data>
</root>
\ No newline at end of file
diff --git a/src/dev/impl/DevTools.Providers.Impl/Tools/Base64EncoderDecoder/Base64EncoderDecoderToolPage.xaml b/src/dev/impl/DevTools.Providers.Impl/Tools/Base64EncoderDecoder/Base64EncoderDecoderToolPage.xaml
index 83348dd17..73fa72258 100644
--- a/src/dev/impl/DevTools.Providers.Impl/Tools/Base64EncoderDecoder/Base64EncoderDecoderToolPage.xaml
+++ b/src/dev/impl/DevTools.Providers.Impl/Tools/Base64EncoderDecoder/Base64EncoderDecoderToolPage.xaml
@@ -5,10 +5,76 @@
xmlns:local="using:DevTools.Providers.Impl.Tools.Base64EncoderDecoder"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+ xmlns:controls="using:DevTools.Common.UI.Controls"
+ xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
mc:Ignorable="d"
NavigationCacheMode="Required">
+ <Page.Resources>
+ <Style x:Key="SubTitleTextBlock" TargetType="TextBlock">
+ <Setter Property="FontSize" Value="14" />
+ <Setter Property="FontWeight" Value="Medium" />
+ <Setter Property="Margin" Value="0,12,0,0" />
+ </Style>
+ </Page.Resources>
+ <StackPanel Spacing="4">
+ <StackPanel.ChildrenTransitions>
+ <TransitionCollection>
+ <EntranceThemeTransition IsStaggeringEnabled="True" FromVerticalOffset="50"/>
+ </TransitionCollection>
+ </StackPanel.ChildrenTransitions>
- <Grid>
- <TextBlock Text="Base64EncoderDecoderToolPage" HorizontalAlignment="Center" VerticalAlignment="Center" />
- </Grid>
+ <TextBlock Style="{StaticResource SubTitleTextBlock}" Text="{x:Bind ViewModel.Strings.ConfigurationTitle}" />
+
+ <controls:ExpandableSettingControl
+ Title="{x:Bind ViewModel.Strings.ConversionTitle}"
+ Description="{x:Bind ViewModel.Strings.ConversionDescription}">
+ <controls:ExpandableSettingControl.Icon>
+ <FontIcon Glyph="&#x00CA;" />
+ </controls:ExpandableSettingControl.Icon>
+ <ComboBox
+ SelectedValuePath="Tag"
+ SelectedValue="{x:Bind ViewModel.ConversionMode, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
+ <ComboBoxItem Tag="Encode" Content="{x:Bind ViewModel.Strings.ConversionEncode}" IsSelected="True"/>
+ <ComboBoxItem Tag="Decode" Content="{x:Bind ViewModel.Strings.ConversionDecode}"/>
+ </ComboBox>
+ </controls:ExpandableSettingControl>
+
+ <controls:ExpandableSettingControl
+ Title="{x:Bind ViewModel.Strings.EncodingTitle}"
+ Description="{x:Bind ViewModel.Strings.EncodingDescription}">
+ <controls:ExpandableSettingControl.Icon>
+ <FontIcon Glyph="&#xF7E4;" />
+ </controls:ExpandableSettingControl.Icon>
+ <ComboBox
+ SelectedValuePath="Tag"
+ SelectedValue="{x:Bind ViewModel.EncodingMode, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
+ <ComboBoxItem Tag="UTF-8" Content="UTF-8" IsSelected="True"/>
+ <ComboBoxItem Tag="ASCII" Content="ASCII" />
+ </ComboBox>
+ </controls:ExpandableSettingControl>
+
+ <TextBlock Style="{StaticResource SubTitleTextBlock}" Text="{x:Bind ViewModel.Strings.InputTitle}" />
+
+ <TextBox x:Name="InputTextBox"
+ TextWrapping="Wrap"
+ AcceptsReturn="True"
+ IsSpellCheckEnabled="False"
+ MinWidth="400"
+ MinHeight="150"
+ Text="{x:Bind ViewModel.InputValue, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
+ />
+
+ <TextBlock Style="{StaticResource SubTitleTextBlock}" Text="{x:Bind ViewModel.Strings.OutputTitle}" />
+
+ <TextBox x:Name="OutputTextBox"
+ TextWrapping="Wrap"
+ AcceptsReturn="False"
+ IsSpellCheckEnabled="False"
+ MinWidth="400"
+ MinHeight="150"
+ IsReadOnly="True"
+ Text="{x:Bind ViewModel.OutputValue, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
+ />
+
+ </StackPanel>
</Page>
diff --git a/src/dev/impl/DevTools.Providers.Impl/Tools/Base64EncoderDecoder/Base64EncoderDecoderToolPage.xaml.cs b/src/dev/impl/DevTools.Providers.Impl/Tools/Base64EncoderDecoder/Base64EncoderDecoderToolPage.xaml.cs
index e6ef9c910..2d214c73a 100644
--- a/src/dev/impl/DevTools.Providers.Impl/Tools/Base64EncoderDecoder/Base64EncoderDecoderToolPage.xaml.cs
+++ b/src/dev/impl/DevTools.Providers.Impl/Tools/Base64EncoderDecoder/Base64EncoderDecoderToolPage.xaml.cs
@@ -1,8 +1,10 @@
#nullable enable
using DevTools.Core.Navigation;
+using Windows.System;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
+using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Navigation;
namespace DevTools.Providers.Impl.Tools.Base64EncoderDecoder
diff --git a/src/dev/impl/DevTools.Providers.Impl/Tools/Base64EncoderDecoder/Base64EncoderDecoderToolViewModel.cs b/src/dev/impl/DevTools.Providers.Impl/Tools/Base64EncoderDecoder/Base64EncoderDecoderToolViewModel.cs
index a6269d215..aa3a70d1b 100644
--- a/src/dev/impl/DevTools.Providers.Impl/Tools/Base64EncoderDecoder/Base64EncoderDecoderToolViewModel.cs
+++ b/src/dev/impl/DevTools.Providers.Impl/Tools/Base64EncoderDecoder/Base64EncoderDecoderToolViewModel.cs
@@ -1,14 +1,167 @@
#nullable enable
+using DevTools.Common;
+using DevTools.Core.Threading;
using Microsoft.Toolkit.Mvvm.ComponentModel;
using System;
using System.Composition;
+using System.Text;
+using Windows.UI.Xaml.Controls;
namespace DevTools.Providers.Impl.Tools.Base64EncoderDecoder
{
[Export(typeof(Base64EncoderDecoderToolViewModel))]
public class Base64EncoderDecoderToolViewModel : ObservableRecipient, IToolViewModel
{
+ private string? _inputValue;
+ private string? _outputValue;
+ private string? _encodingMode;
+ private string? _conversionMode;
+ private readonly IThread _thread;
+
public Type View { get; } = typeof(Base64EncoderDecoderToolPage);
+
+ internal Base64EncoderDecoderStrings Strings => LanguageManager.Instance.Base64EncoderDecoder;
+
+ /// <summary>
+ /// Gets or sets the input text.
+ /// </summary>
+ internal string? InputValue
+ {
+ get => _inputValue;
+ set
+ {
+ _thread.ThrowIfNotOnUIThread();
+ _inputValue = value;
+
+ if (ConversionMode == "Encode")
+ {
+ OutputValue = EncodeBase64Data(value);
+ }
+ else
+ {
+ OutputValue = DecodeBase64Data(value);
+ }
+ OnPropertyChanged();
+ }
+ }
+
+ /// <summary>
+ /// Gets or sets the output text.
+ /// </summary>
+ internal string? OutputValue
+ {
+ get => _outputValue;
+ set
+ {
+ _thread.ThrowIfNotOnUIThread();
+ _outputValue = value;
+ OnPropertyChanged();
+ }
+ }
+
+ /// <summary>
+ /// Gets or sets the conversion mode.
+ /// </summary>
+ internal string? ConversionMode
+ {
+ get
+ {
+ if (string.IsNullOrWhiteSpace(_conversionMode))
+ {
+ return "Encode";
+ }
+ return _conversionMode;
+ }
+ set
+ {
+ _thread.ThrowIfNotOnUIThread();
+ _conversionMode = value;
+ string? tmp = InputValue;
+ InputValue = OutputValue;
+ OutputValue = tmp;
+ }
+ }
+
+ /// <summary>
+ /// Gets or sets the encoding mode.
+ /// </summary>
+ internal string? EncodingMode
+ {
+ get
+ {
+ if (string.IsNullOrWhiteSpace(_encodingMode))
+ {
+ return "UTF-8";
+ }
+ return _encodingMode;
+ }
+ set
+ {
+ _thread.ThrowIfNotOnUIThread();
+ _encodingMode = value;
+ }
+ }
+
+ [ImportingConstructor]
+ public Base64EncoderDecoderToolViewModel(IThread thread)
+ {
+ _thread = thread;
+ }
+
+ public string EncodeBase64Data(string? data)
+ {
+ if (string.IsNullOrWhiteSpace(data))
+ {
+ return string.Empty;
+ }
+
+ string? encoded;
+
+ try
+ {
+ Encoding encoder = GetEncoder();
+ byte[] dataBytes = encoder.GetBytes(data);
+ encoded = Convert.ToBase64String(dataBytes);
+ }
+ catch (Exception)
+ {
+ return string.Empty;
+ }
+
+ return encoded;
+ }
+
+ public string DecodeBase64Data(string? data)
+ {
+ if (string.IsNullOrWhiteSpace(data))
+ {
+ return string.Empty;
+ }
+
+ string? decoded;
+
+ try
+ {
+ byte[] decodedData = Convert.FromBase64String(data);
+ Encoding encoder = GetEncoder();
+ decoded = encoder.GetString(decodedData);
+ }
+ catch (Exception)
+ {
+ return string.Empty;
+ }
+
+ return decoded;
+ }
+
+ private Encoding GetEncoder()
+ {
+ if (EncodingMode == "UTF-8")
+ {
+ return Encoding.UTF8;
+ }
+ return Encoding.ASCII;
+ }
}
}