A Swiss Army knife for developers.
C# blazorcross-platformcsharpdesktopdesktop-appdesktop-applicationdeveloper-toolsextensiblefluentfluent-designlinuxmacosmicasyntax-highlightingtypescriptwindowswindows-10windows-11winui
feat: add cron parser tool (#535)
Nerijus73d2b7818b93
diff --git a/THIRD-PARTY-NOTICES.md b/THIRD-PARTY-NOTICES.mdindex 679cdd59e..8a859dede 100644--- a/THIRD-PARTY-NOTICES.md+++ b/THIRD-PARTY-NOTICES.md@@ -16,6 +16,7 @@ This project incorporates components from the projects listed below. The origina12. Efficient Compression Tool (https://github.com/fhanau/Efficient-Compression-Tool)13. NLipsum (https://github.com/alexcpendleton/NLipsum)14. SQL Formatter (https://github.com/zeroturnaround/sql-formatter)+15. Cronos (https://github.com/HangfireIO/Cronos)Newtonsoft.Json NOTICES AND INFORMATION BEGIN HERE=========================================@@ -485,3 +486,27 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHERLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THESOFTWARE.++Cronos NOTICES AND INFORMATION BEGIN HERE+=========================================+The MIT License (MIT)++Copyright (c) 2017 Hangfire OÜ++Permission is hereby granted, free of charge, to any person obtaining a copy+of this software and associated documentation files (the "Software"), to deal+in the Software without restriction, including without limitation the rights+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell+copies of the Software, and to permit persons to whom the Software is+furnished to do so, subject to the following conditions:++The above copyright notice and this permission notice shall be included in all+copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE+SOFTWARE.\ No newline at end of filediff --git a/src/Directory.Build.props b/src/Directory.Build.propsindex 743a1cb83..16c049513 100644--- a/src/Directory.Build.props+++ b/src/Directory.Build.props@@ -17,6 +17,7 @@</PropertyGroup><PropertyGroup>+ <Nuget_Cronos>0.7.1</Nuget_Cronos><NuGet_DotNet>6.0.0</NuGet_DotNet><Nuget_GitInfo>2.2.0</Nuget_GitInfo><Nuget_Markdig>0.26.0</Nuget_Markdig>diff --git a/src/dev/impl/DevToys/Assets/Icons/Cron.svg b/src/dev/impl/DevToys/Assets/Icons/Cron.svgnew file mode 100644index 000000000..e45588e43--- /dev/null+++ b/src/dev/impl/DevToys/Assets/Icons/Cron.svg@@ -0,0 +1,16 @@+<?xml version="1.0" encoding="UTF-8" standalone="no"?>+<svg+ version="1.1"+ viewBox="0.008 0.008 31.984 31.984"+ id="svg22"+ xmlns="http://www.w3.org/2000/svg"+ xmlns:svg="http://www.w3.org/2000/svg">+ <defs+ id="defs26" />+ <path+ d="m 16.141993,4.3697013 c -6.3858498,0 -11.570761,5.1850276 -11.570761,11.5707607 0,6.386436 5.1850279,11.571348 11.570761,11.571348 6.386436,0 11.571348,-5.185029 11.571348,-11.571348 0,-6.3858496 -5.18503,-11.5707607 -11.571348,-11.5707607 z m 0,2.3142109 c 5.108738,0 9.256842,4.1482808 9.256842,9.2568418 0,5.108739 -4.148279,9.256845 -9.256842,9.256845 -5.108504,0 -9.2568438,-4.148282 -9.2568438,-9.256845 0,-5.108503 4.1482808,-9.2568418 9.2568438,-9.2568418 z m -1.156959,3.4714038 v 5.785381 c 0,0.438653 0.247617,0.839074 0.639758,1.034461 l 4.62842,2.314209 c 0.570592,0.285869 1.267145,0.05452 1.551898,-0.517218 0.285638,-0.570363 0.05429,-1.266908 -0.517219,-1.551662 l -3.988664,-1.994683 v -5.070506 c 0,-0.638878 -0.518362,-1.1571932 -1.157194,-1.1571932 -0.638643,0 -1.156958,0.5183622 -1.156958,1.1571932 z"+ fill-rule="evenodd"+ id="path20"+ fill="#000000"+ style="stroke-width:0.0586395" />+</svg>diff --git a/src/dev/impl/DevToys/DevToys.csproj b/src/dev/impl/DevToys/DevToys.csprojindex 660b1d535..21c90eade 100644--- a/src/dev/impl/DevToys/DevToys.csproj+++ b/src/dev/impl/DevToys/DevToys.csproj@@ -90,6 +90,8 @@<Compile Include="ViewModels\Tools\AllTools\AllToolsToolProvider.cs" /><Compile Include="ViewModels\Tools\AllTools\AllToolsToolViewModel.cs" /><Compile Include="ViewModels\Tools\Converters\ConvertersGroupToolProvider.cs" />+ <Compile Include="ViewModels\Tools\Converters\CronParser\CronParserToolProvider.cs" />+ <Compile Include="ViewModels\Tools\Converters\CronParser\CronParserToolViewModel.cs" /><Compile Include="ViewModels\Tools\Converters\NumberBaseConverter\AdvancedNumberBaseConverterControlViewModel.cs" /><Compile Include="ViewModels\Tools\Converters\NumberBaseConverter\BasicNumberBaseConverterControlViewModel.cs" /><Compile Include="ViewModels\Tools\Converters\NumberBaseConverter\Exceptions\InvalidBaseNumberException.cs" />@@ -134,17 +136,20 @@<Compile Include="ViewModels\Tools\Text\StringEscapeUnescape\StringEscapeUnescapeToolProvider.cs" /><Compile Include="ViewModels\Tools\Text\StringEscapeUnescape\StringEscapeUnescapeToolViewModel.cs" /><Compile Include="ViewModels\Tools\Text\TextGroupToolProvider.cs" />- <Compile Include="ViewModels\Tools\Text\XmlValidator\Parsing\ParserBase.cs"/>- <Compile Include="ViewModels\Tools\Text\XmlValidator\Parsing\ParsingResultBase.cs"/>- <Compile Include="ViewModels\Tools\Text\XmlValidator\Parsing\XmlParser.cs"/>- <Compile Include="ViewModels\Tools\Text\XmlValidator\Parsing\XmlParsingResult.cs"/>- <Compile Include="ViewModels\Tools\Text\XmlValidator\Parsing\XsdParser.cs"/>- <Compile Include="ViewModels\Tools\Text\XmlValidator\Parsing\XsdParsingResult.cs"/>- <Compile Include="ViewModels\Tools\Text\XmlValidator\XmlValidatorToolProvider.cs"/>- <Compile Include="ViewModels\Tools\Text\XmlValidator\XmlValidatorToolViewModel.cs"/>+ <Compile Include="ViewModels\Tools\Text\XmlValidator\Parsing\ParserBase.cs" />+ <Compile Include="ViewModels\Tools\Text\XmlValidator\Parsing\ParsingResultBase.cs" />+ <Compile Include="ViewModels\Tools\Text\XmlValidator\Parsing\XmlParser.cs" />+ <Compile Include="ViewModels\Tools\Text\XmlValidator\Parsing\XmlParsingResult.cs" />+ <Compile Include="ViewModels\Tools\Text\XmlValidator\Parsing\XsdParser.cs" />+ <Compile Include="ViewModels\Tools\Text\XmlValidator\Parsing\XsdParsingResult.cs" />+ <Compile Include="ViewModels\Tools\Text\XmlValidator\XmlValidatorToolProvider.cs" />+ <Compile Include="ViewModels\Tools\Text\XmlValidator\XmlValidatorToolViewModel.cs" /><Compile Include="Views\Tools\AllTools\AllToolsToolPage.xaml.cs"><DependentUpon>AllToolsToolPage.xaml</DependentUpon></Compile>+ <Compile Include="Views\Tools\Converters\CronParser\CronParserToolPage.xaml.cs">+ <DependentUpon>CronParserToolPage.xaml</DependentUpon>+ </Compile><Compile Include="Views\Tools\Converters\NumberBaseConverter\AdvancedNumberBaseConverterControl.xaml.cs"><DependentUpon>AdvancedNumberBaseConverterControl.xaml</DependentUpon></Compile>@@ -326,7 +331,10 @@<Content Include="Assets\GitHubMarkdownCss\index.html" /><Content Include="Assets\Icons\Base64Image.svg" /><Content Include="Assets\Icons\ColorBlindnessSimulator.svg" />- <Content Include="Assets\Icons\XmlValidator.svg"/>+ <Content Include="Assets\Icons\Cron.svg">+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>+ </Content>+ <Content Include="Assets\Icons\XmlValidator.svg" /><Content Include="Assets\Icons\EncodersDecoders.svg"><CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory></Content>@@ -579,7 +587,7 @@<Generator>MSBuild:Compile</Generator><SubType>Designer</SubType></Page>- <PRIResource Include="Strings\*\*.resw"/>+ <PRIResource Include="Strings\*\*.resw" /><Page Include="Themes\Custom.xaml"><Generator>MSBuild:Compile</Generator><SubType>Designer</SubType>@@ -624,6 +632,10 @@<SubType>Designer</SubType><Generator>MSBuild:Compile</Generator></Page>+ <Page Include="Views\Tools\Converters\CronParser\CronParserToolPage.xaml">+ <Generator>MSBuild:Compile</Generator>+ <SubType>Designer</SubType>+ </Page><Page Include="Views\Tools\Converters\NumberBaseConverter\AdvancedNumberBaseConverterControl.xaml"><SubType>Designer</SubType><Generator>MSBuild:Compile</Generator>@@ -746,6 +758,7 @@</Page></ItemGroup><ItemGroup>+ <PackageReference Include="Cronos" Version="$(Nuget_Cronos)" /><PackageReference Include="GitInfo" Version="$(Nuget_GitInfo)" /><PackageReference Include="Markdig" Version="$(Nuget_Markdig)" /><PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform" Version="$(NuGet_MicrosoftNETCoreUniversalWindowsPlatform)" />diff --git a/src/dev/impl/DevToys/LanguageManager.cs b/src/dev/impl/DevToys/LanguageManager.csindex 8accdd2ca..930bee340 100644--- a/src/dev/impl/DevToys/LanguageManager.cs+++ b/src/dev/impl/DevToys/LanguageManager.cs@@ -30,6 +30,7 @@ namespace DevToysprivate readonly CheckSumGeneratorStrings _checksumgenerator = new CheckSumGeneratorStrings();private readonly ColorBlindnessSimulatorStrings _colorblindnesssimulator = new ColorBlindnessSimulatorStrings();private readonly CommonStrings _common = new CommonStrings();+ private readonly CRONParserStrings _cronparser = new CRONParserStrings();private readonly GuidGeneratorStrings _guidgenerator = new GuidGeneratorStrings();private readonly GZipEncoderDecoderStrings _gzipencoderdecoder = new GZipEncoderDecoderStrings();private readonly HashGeneratorStrings _hashgenerator = new HashGeneratorStrings();@@ -96,6 +97,11 @@ namespace DevToys/// </summary>public CommonStrings Common => _common;+ /// <summary>+ /// Gets the <see cref="CRONParserStrings"/>.+ /// </summary>+ public CRONParserStrings CRONParser => _cronparser;+/// <summary>/// Gets the <see cref="GuidGeneratorStrings"/>./// </summary>@@ -730,6 +736,101 @@ namespace DevToyspublic string ViewImage => _resources.GetString("ViewImage");}+ public class CRONParserStrings : ObservableObject+ {+ private readonly ResourceLoader _resources = ResourceLoader.GetForViewIndependentUse("CRONParser");++ /// <summary>+ /// Gets the resource AccessibleName.+ /// </summary>+ public string AccessibleName => _resources.GetString("AccessibleName");++ /// <summary>+ /// Gets the resource Configuration.+ /// </summary>+ public string Configuration => _resources.GetString("Configuration");++ /// <summary>+ /// Gets the resource UseSecondsDescription.+ /// </summary>+ public string UseSecondsDescription => _resources.GetString("UseSecondsDescription");++ /// <summary>+ /// Gets the resource UseSecondsTitle.+ /// </summary>+ public string UseSecondsTitle => _resources.GetString("UseSecondsTitle");++ /// <summary>+ /// Gets the resource MenuDisplayName.+ /// </summary>+ public string MenuDisplayName => _resources.GetString("MenuDisplayName");++ /// <summary>+ /// Gets the resource Description.+ /// </summary>+ public string Description => _resources.GetString("Description");++ /// <summary>+ /// Gets the resource SearchDisplayName.+ /// </summary>+ public string SearchDisplayName => _resources.GetString("SearchDisplayName");++ /// <summary>+ /// Gets the resource SearchKeywords.+ /// </summary>+ public string SearchKeywords => _resources.GetString("SearchKeywords");++ /// <summary>+ /// Gets the resource CronErrorMessage.+ /// </summary>+ public string CronErrorMessage => _resources.GetString("CronErrorMessage");++ /// <summary>+ /// Gets the resource InputTitle.+ /// </summary>+ public string InputTitle => _resources.GetString("InputTitle");++ /// <summary>+ /// Gets the resource OutputDateTimeDescription.+ /// </summary>+ public string OutputDateTimeDescription => _resources.GetString("OutputDateTimeDescription");++ /// <summary>+ /// Gets the resource OutputDateTimeTitle.+ /// </summary>+ public string OutputDateTimeTitle => _resources.GetString("OutputDateTimeTitle");++ /// <summary>+ /// Gets the resource OutputFormatErrorMessage.+ /// </summary>+ public string OutputFormatErrorMessage => _resources.GetString("OutputFormatErrorMessage");++ /// <summary>+ /// Gets the resource OutputLimitDescription.+ /// </summary>+ public string OutputLimitDescription => _resources.GetString("OutputLimitDescription");++ /// <summary>+ /// Gets the resource OutputLimitTitle.+ /// </summary>+ public string OutputLimitTitle => _resources.GetString("OutputLimitTitle");++ /// <summary>+ /// Gets the resource OutputTitle.+ /// </summary>+ public string OutputTitle => _resources.GetString("OutputTitle");++ /// <summary>+ /// Gets the resource SecondsExcludedMode.+ /// </summary>+ public string SecondsExcludedMode => _resources.GetString("SecondsExcludedMode");++ /// <summary>+ /// Gets the resource SecondsIncludedMode.+ /// </summary>+ public string SecondsIncludedMode => _resources.GetString("SecondsIncludedMode");+ }+public class GuidGeneratorStrings : ObservableObject{private readonly ResourceLoader _resources = ResourceLoader.GetForViewIndependentUse("GuidGenerator");diff --git a/src/dev/impl/DevToys/Strings/en-US/CRONParser.resw b/src/dev/impl/DevToys/Strings/en-US/CRONParser.reswnew file mode 100644index 000000000..fecae801d--- /dev/null+++ b/src/dev/impl/DevToys/Strings/en-US/CRONParser.resw@@ -0,0 +1,174 @@+<?xml version="1.0" encoding="utf-8"?>+<root>+ <!--+ Microsoft ResX Schema++ Version 2.0++ The primary goals of this format is to allow a simple XML format+ that is mostly human readable. The generation and parsing of the+ various data types are done through the TypeConverter classes+ associated with the data types.++ Example:++ ... ado.net/XML headers & schema ...+ <resheader name="resmimetype">text/microsoft-resx</resheader>+ <resheader name="version">2.0</resheader>+ <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>+ <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>+ <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>+ <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>+ <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">+ <value>[base64 mime encoded serialized .NET Framework object]</value>+ </data>+ <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">+ <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>+ <comment>This is a comment</comment>+ </data>++ There are any number of "resheader" rows that contain simple+ name/value pairs.++ Each data row contains a name, and value. The row also contains a+ type or mimetype. Type corresponds to a .NET class that support+ text/value conversion through the TypeConverter architecture.+ Classes that don't support this are serialized and stored with the+ mimetype set.++ The mimetype is used for serialized objects, and tells the+ ResXResourceReader how to depersist the object. This is currently not+ extensible. For a given mimetype the value must be set accordingly:++ Note - application/x-microsoft.net.object.binary.base64 is the format+ that the ResXResourceWriter will generate, however the reader can+ read any of the formats listed below.++ mimetype: application/x-microsoft.net.object.binary.base64+ value : The object must be serialized with+ : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter+ : and then encoded with base64 encoding.++ mimetype: application/x-microsoft.net.object.soap.base64+ value : The object must be serialized with+ : System.Runtime.Serialization.Formatters.Soap.SoapFormatter+ : and then encoded with base64 encoding.++ mimetype: application/x-microsoft.net.object.bytearray.base64+ value : The object must be serialized into a byte array+ : using a System.ComponentModel.TypeConverter+ : and then encoded with base64 encoding.+ -->+ <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">+ <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />+ <xsd:element name="root" msdata:IsDataSet="true">+ <xsd:complexType>+ <xsd:choice maxOccurs="unbounded">+ <xsd:element name="metadata">+ <xsd:complexType>+ <xsd:sequence>+ <xsd:element name="value" type="xsd:string" minOccurs="0" />+ </xsd:sequence>+ <xsd:attribute name="name" use="required" type="xsd:string" />+ <xsd:attribute name="type" type="xsd:string" />+ <xsd:attribute name="mimetype" type="xsd:string" />+ <xsd:attribute ref="xml:space" />+ </xsd:complexType>+ </xsd:element>+ <xsd:element name="assembly">+ <xsd:complexType>+ <xsd:attribute name="alias" type="xsd:string" />+ <xsd:attribute name="name" type="xsd:string" />+ </xsd:complexType>+ </xsd:element>+ <xsd:element name="data">+ <xsd:complexType>+ <xsd:sequence>+ <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />+ <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />+ </xsd:sequence>+ <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />+ <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />+ <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />+ <xsd:attribute ref="xml:space" />+ </xsd:complexType>+ </xsd:element>+ <xsd:element name="resheader">+ <xsd:complexType>+ <xsd:sequence>+ <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />+ </xsd:sequence>+ <xsd:attribute name="name" type="xsd:string" use="required" />+ </xsd:complexType>+ </xsd:element>+ </xsd:choice>+ </xsd:complexType>+ </xsd:element>+ </xsd:schema>+ <resheader name="resmimetype">+ <value>text/microsoft-resx</value>+ </resheader>+ <resheader name="version">+ <value>2.0</value>+ </resheader>+ <resheader name="reader">+ <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>+ </resheader>+ <resheader name="writer">+ <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>+ </resheader>+ <data name="AccessibleName" xml:space="preserve">+ <value>Cron parsing tool</value>+ </data>+ <data name="Configuration" xml:space="preserve">+ <value>Configuration</value>+ </data>+ <data name="UseSecondsDescription" xml:space="preserve">+ <value>Choose whatever Cron expression should includes seconds in its definition</value>+ </data>+ <data name="UseSecondsTitle" xml:space="preserve">+ <value>Cron Mode</value>+ </data>+ <data name="MenuDisplayName" xml:space="preserve">+ <value>Cron parser</value>+ </data>+ <data name="Description" xml:space="preserve">+ <value>Parse Cron expression to get scheduled dates</value>+ </data>+ <data name="SearchDisplayName" xml:space="preserve">+ <value>Cron expression parser</value>+ </data>+ <data name="SearchKeywords" xml:space="preserve">+ <value>Cron</value>+ </data>+ <data name="CronErrorMessage" xml:space="preserve">+ <value>Cron expression is not valid</value>+ </data>+ <data name="InputTitle" xml:space="preserve">+ <value>Cron expression to parse</value>+ </data>+ <data name="OutputDateTimeDescription" xml:space="preserve">+ <value>Date time fomat of upcoming dates</value>+ </data>+ <data name="OutputDateTimeTitle" xml:space="preserve">+ <value>Output format</value>+ </data>+ <data name="OutputFormatErrorMessage" xml:space="preserve">+ <value>Output date time format is not valid</value>+ </data>+ <data name="OutputLimitDescription" xml:space="preserve">+ <value>How many scheduled dates needs to be generated</value>+ </data>+ <data name="OutputLimitTitle" xml:space="preserve">+ <value>Next scheduled dates</value>+ </data>+ <data name="OutputTitle" xml:space="preserve">+ <value>Next scheduled dates</value>+ </data>+ <data name="SecondsExcludedMode" xml:space="preserve">+ <value>Standard mode (5 - segment Cron)</value>+ </data>+ <data name="SecondsIncludedMode" xml:space="preserve">+ <value>Seconds included (6 - segment Cron)</value>+ </data>+</root>\ No newline at end of filediff --git a/src/dev/impl/DevToys/ViewModels/Tools/Converters/CronParser/CronParserToolProvider.cs b/src/dev/impl/DevToys/ViewModels/Tools/Converters/CronParser/CronParserToolProvider.csnew file mode 100644index 000000000..39542583d--- /dev/null+++ b/src/dev/impl/DevToys/ViewModels/Tools/Converters/CronParser/CronParserToolProvider.cs@@ -0,0 +1,48 @@+#nullable enable++using System.Composition;+using DevToys.Api.Tools;+using DevToys.Core.Threading;+using DevToys.Shared.Api.Core;+using Windows.UI.Xaml.Controls;++namespace DevToys.ViewModels.Tools.CronParser+{+ [Export(typeof(IToolProvider))]+ [Name("CronParser")]+ [Parent(ConvertersGroupToolProvider.InternalName)]+ [ProtocolName("cronparser")]+ [Order(4)]+ internal sealed class CronParserToolProvider : ToolProviderBase, IToolProvider+ {+ private readonly IMefProvider _mefProvider;++ public string MenuDisplayName => LanguageManager.Instance.CRONParser.MenuDisplayName;++ public string? SearchDisplayName => LanguageManager.Instance.CRONParser.SearchDisplayName;++ public string? Description => LanguageManager.Instance.CRONParser.Description;++ public string AccessibleName => LanguageManager.Instance.CRONParser.AccessibleName;++ public string? SearchKeywords => LanguageManager.Instance.CRONParser.SearchKeywords;++ public TaskCompletionNotifier<IconElement> IconSource => CreateSvgIcon("Cron.svg");++ [ImportingConstructor]+ public CronParserToolProvider(IMefProvider mefProvider)+ {+ _mefProvider = mefProvider;+ }++ public bool CanBeTreatedByTool(string data)+ {+ return false;+ }++ public IToolViewModel CreateTool()+ {+ return _mefProvider.Import<CronParserToolViewModel>();+ }+ }+}diff --git a/src/dev/impl/DevToys/ViewModels/Tools/Converters/CronParser/CronParserToolViewModel.cs b/src/dev/impl/DevToys/ViewModels/Tools/Converters/CronParser/CronParserToolViewModel.csnew file mode 100644index 000000000..47dcfa505--- /dev/null+++ b/src/dev/impl/DevToys/ViewModels/Tools/Converters/CronParser/CronParserToolViewModel.cs@@ -0,0 +1,257 @@+#nullable enable++using System;+using System.Collections.Generic;+using System.Composition;+using System.Globalization;+using Cronos;+using DevToys.Api.Core.Settings;+using DevToys.Api.Tools;+using DevToys.Shared.Core;+using DevToys.Views.Tools.CronParser;+using Microsoft.Toolkit.Mvvm.ComponentModel;+using Microsoft.Toolkit.Mvvm.Input;+using Windows.ApplicationModel.DataTransfer;++namespace DevToys.ViewModels.Tools.CronParser+{+ [Export(typeof(CronParserToolViewModel))]+ public sealed class CronParserToolViewModel : ObservableRecipient, IToolViewModel+ {+ private readonly ISettingsProvider _settingsProvider;++ private bool _isInputInvalid;+ private bool _isOutputFormatInvalid;+ private string _cronExpression;+ private bool _setPropertyInProgress;+ private string? _outputValue;++ private const string DefaultCronWithSeconds = "* * * * * *";+ private const string DefaultCronWithoutSeconds = "* * * * *";+ private const string DefaultTimestampFormat = "yyyy-MM-dd ddd HH:mm:ss";+ private const string DefaultOutputLimit = "5";++ /// <summary>+ /// Whether the tool should include seconds in cron definition+ /// </summary>+ private static readonly SettingDefinition<bool> IncludeSeconds+ = new(+ name: $"{nameof(CronParserToolViewModel)}.{nameof(IncludeSeconds)}",+ isRoaming: true,+ defaultValue: true);++ /// <summary>+ /// Whether datetime format tool should use for output+ /// </summary>+ private static readonly SettingDefinition<string> OutputDateTime+ = new(+ name: $"{nameof(CronParserToolViewModel)}.{nameof(OutputDateTime)}",+ isRoaming: true,+ defaultValue: DefaultTimestampFormat);++ /// <summary>+ /// How many lines of next occurencies the tool should generate+ /// </summary>+ private static readonly SettingDefinition<string> OutputLimit+ = new(+ name: $"{nameof(CronParserToolViewModel)}.{nameof(OutputLimit)}",+ isRoaming: true,+ defaultValue: DefaultOutputLimit);++ public Type View => typeof(CronParserToolPage);++ internal CRONParserStrings Strings => LanguageManager.Instance.CRONParser;++ internal bool IsInputInvalid+ {+ get => _isInputInvalid;+ set => SetProperty(ref _isInputInvalid, value);+ }++ internal bool IsOutputFormatInvalid+ {+ get => _isOutputFormatInvalid;+ set => SetProperty(ref _isOutputFormatInvalid, value);+ }++ /// <summary>+ /// Gets or sets Cron expression+ /// </summary>+ internal string UserCronExpression+ {+ get => _cronExpression;+ set+ {+ SetProperty(ref _cronExpression, value);+ ParseCronExpression();+ }+ }++ /// <summary>+ /// Gets or sets whatever Cron should include settings+ /// </summary>+ internal bool IncludeSecondsMode+ {+ get => _settingsProvider.GetSetting(IncludeSeconds);+ set+ {+ if (!_setPropertyInProgress)+ {+ _setPropertyInProgress = true;++ if (_settingsProvider.GetSetting(IncludeSeconds) != value)+ {+ _settingsProvider.SetSetting(IncludeSeconds, value);+ OnPropertyChanged();+ ParseCronExpression();+ }++ _setPropertyInProgress = false;+ }+ }+ }++ /// <summary>+ /// Gets or sets number of output lines.+ /// </summary>+ internal string OutputLimitMode+ {+ get => _settingsProvider.GetSetting(OutputLimit);+ set+ {+ if (!_setPropertyInProgress)+ {+ _setPropertyInProgress = true;++ if (_settingsProvider.GetSetting(OutputLimit) != value)+ {+ _settingsProvider.SetSetting(OutputLimit, value);+ OnPropertyChanged();+ ParseCronExpression();+ }++ _setPropertyInProgress = false;+ }+ }+ }++ /// <summary>+ /// Gets or sets the output format+ /// </summary>+ internal string OutputDateTimeFormat+ {+ get => _settingsProvider.GetSetting(OutputDateTime);+ set+ {+ if (!_setPropertyInProgress)+ {+ _setPropertyInProgress = true;++ if (_settingsProvider.GetSetting(OutputDateTime) != value)+ {+ _settingsProvider.SetSetting(OutputDateTime, value);+ OnPropertyChanged();+ ParseCronExpression();+ }++ _setPropertyInProgress = false;+ }+ }+ }++ internal string? OutputValue+ {+ get => _outputValue;+ private set => SetProperty(ref _outputValue, value);+ }+++ [ImportingConstructor]+ public CronParserToolViewModel(ISettingsProvider settingsProvider)+ {+ _settingsProvider = settingsProvider;++ _cronExpression = string.Empty;++ IsInputInvalid = false;+ IsOutputFormatInvalid = false;++ if (IncludeSecondsMode)+ {+ UserCronExpression = DefaultCronWithSeconds;+ }+ else+ {+ UserCronExpression = DefaultCronWithoutSeconds;+ }+ }++ private void ParseCronExpression()+ {+ IsInputInvalid = false;+ IsOutputFormatInvalid = false;++ if (!ValidateDateTimeFormat(OutputDateTimeFormat))+ {+ IsOutputFormatInvalid = true;++ return;+ }++ var output = new List<string>();++ try+ {+ if (string.IsNullOrEmpty(UserCronExpression))+ {+ return;+ }++ var expression = CronExpression.Parse(UserCronExpression, IncludeSecondsMode ? CronFormat.IncludeSeconds : CronFormat.Standard);++ Assumes.NotNull(expression, nameof(expression));++ DateTimeOffset? nextOccurence = expression.GetNextOccurrence(DateTimeOffset.Now, TimeZoneInfo.Local, true);++ if (nextOccurence == null)+ {+ return;+ }++ output.Add(nextOccurence.Value.ToString(OutputDateTimeFormat));++ for (int i = 0; i <= int.Parse(OutputLimitMode); i++)+ {+ nextOccurence = expression.GetNextOccurrence(nextOccurence.Value, TimeZoneInfo.Local, false);++ if (nextOccurence == null)+ {+ break;+ }++ output.Add(nextOccurence.Value.ToString(OutputDateTimeFormat));+ }++ OutputValue = string.Join(Environment.NewLine, output);+ }+ catch (CronFormatException)+ {+ IsInputInvalid = true;+ }+ }++ private bool ValidateDateTimeFormat(string dateFormat)+ {+ try+ {+ string s = DateTime.Now.ToString(dateFormat, CultureInfo.InvariantCulture);+ DateTime.Parse(s, CultureInfo.InvariantCulture);+ return true;+ }+ catch+ {+ return false;+ }+ }+ }+}diff --git a/src/dev/impl/DevToys/ViewModels/Tools/Converters/NumberBaseConverter/NumberBaseConverterToolViewModel.cs b/src/dev/impl/DevToys/ViewModels/Tools/Converters/NumberBaseConverter/NumberBaseConverterToolViewModel.csindex 8ecfebf66..a58256f53 100644--- a/src/dev/impl/DevToys/ViewModels/Tools/Converters/NumberBaseConverter/NumberBaseConverterToolViewModel.cs+++ b/src/dev/impl/DevToys/ViewModels/Tools/Converters/NumberBaseConverter/NumberBaseConverterToolViewModel.cs@@ -91,7 +91,7 @@ namespace DevToys.ViewModels.Tools.NumberBaseConverterAdvancedViewModel = advnacedViewModel;BasicViewModel = basicViewModel;IsActive = true;- }+ }public void Receive(ChangeInfoBarStatusMessage message){diff --git a/src/dev/impl/DevToys/Views/Tools/Converters/CronParser/CronParserToolPage.xaml b/src/dev/impl/DevToys/Views/Tools/Converters/CronParser/CronParserToolPage.xamlnew file mode 100644index 000000000..b34eabd48--- /dev/null+++ b/src/dev/impl/DevToys/Views/Tools/Converters/CronParser/CronParserToolPage.xaml@@ -0,0 +1,113 @@+<Page+ x:Class="DevToys.Views.Tools.CronParser.CronParserToolPage"+ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"+ xmlns:d="http://schemas.microsoft.com/expression/blend/2008"+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"+ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"+ xmlns:muxc="using:Microsoft.UI.Xaml.Controls"+ xmlns:controls="using:DevToys.UI.Controls"+ xmlns:ex="using:DevToys.UI.Extensions"+ mc:Ignorable="d"+ d:DesignHeight="400"+ d:DesignWidth="600">++ <Grid Margin="0,0,0,16" RowSpacing="12">+ <VisualStateManager.VisualStateGroups>+ <VisualStateGroup>+ <VisualState>+ <VisualState.StateTriggers>+ <ex:IsCompactOverlayModeTrigger TargetElement="{x:Bind}" />+ </VisualState.StateTriggers>+ <VisualState.Setters>+ <Setter Target="SubTitleTextBlock.Visibility" Value="Collapsed"/>+ <Setter Target="CronMode.Visibility" Value="Collapsed"/>+ <Setter Target="OutputLimit.Visibility" Value="Collapsed"/>+ <Setter Target="OutputDateTimeSetting.Visibility" Value="Collapsed"/>+ </VisualState.Setters>+ </VisualState>+ </VisualStateGroup>+ </VisualStateManager.VisualStateGroups>+ <Grid.ChildrenTransitions>+ <TransitionCollection>+ <EntranceThemeTransition IsStaggeringEnabled="True" FromVerticalOffset="50"/>+ </TransitionCollection>+ </Grid.ChildrenTransitions>++ <Grid.RowDefinitions>+ <RowDefinition Height="Auto"/>+ <RowDefinition Height="Auto"/>+ <RowDefinition Height="*"/>+ </Grid.RowDefinitions>++ <StackPanel Grid.Row="0" Spacing="4" >++ <muxc:InfoBar+ Severity="Warning"+ Message="{x:Bind ViewModel.Strings.CronErrorMessage}"+ IsOpen="{x:Bind ViewModel.IsInputInvalid, Mode=OneWay}"+ IsClosable="False"/>++ <muxc:InfoBar+ Severity="Warning"+ Message="{x:Bind ViewModel.Strings.OutputFormatErrorMessage}"+ IsOpen="{x:Bind ViewModel.IsOutputFormatInvalid, Mode=OneWay}"+ IsClosable="False"/>++ <TextBlock x:Name="SubTitleTextBlock" Style="{StaticResource SubTitleTextBlock}" Text="{x:Bind ViewModel.Strings.Configuration}" />++ <controls:ExpandableSettingControl+ x:Name="CronMode"+ Title="{x:Bind ViewModel.Strings.UseSecondsTitle}"+ Description="{x:Bind ViewModel.Strings.UseSecondsDescription}">+ <controls:ExpandableSettingControl.Icon>+ <FontIcon Glyph="" />+ </controls:ExpandableSettingControl.Icon>+ <ToggleSwitch+ Style="{StaticResource RightAlignedToggleSwitchStyle}"+ OnContent="{x:Bind ViewModel.Strings.SecondsIncludedMode}" OffContent="{x:Bind ViewModel.Strings.SecondsExcludedMode}"+ IsOn="{x:Bind ViewModel.IncludeSecondsMode, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />+ </controls:ExpandableSettingControl>+ <controls:ExpandableSettingControl+ x:Name="OutputLimit"+ Title="{x:Bind ViewModel.Strings.OutputLimitTitle}"+ Description="{x:Bind ViewModel.Strings.OutputLimitDescription}">+ <controls:ExpandableSettingControl.Icon>+ <FontIcon Glyph="" />+ </controls:ExpandableSettingControl.Icon>+ <ComboBox+ SelectedValuePath="Tag"+ SelectedValue="{x:Bind ViewModel.OutputLimitMode, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">+ <ComboBoxItem Tag="5" Content="5" />+ <ComboBoxItem Tag="10" Content="10" />+ <ComboBoxItem Tag="25" Content="25" />+ <ComboBoxItem Tag="50" Content="50" />+ <ComboBoxItem Tag="100" Content="100" />+ </ComboBox>+ </controls:ExpandableSettingControl>+ <controls:ExpandableSettingControl+ x:Name="OutputDateTimeSetting"+ Title="{x:Bind ViewModel.Strings.OutputDateTimeTitle}"+ Description="{x:Bind ViewModel.Strings.OutputDateTimeDescription}">+ <controls:ExpandableSettingControl.Icon>+ <FontIcon Glyph="" />+ </controls:ExpandableSettingControl.Icon>+ <TextBox MinWidth="150" Text="{x:Bind ViewModel.OutputDateTimeFormat, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"></TextBox>+ </controls:ExpandableSettingControl>+ </StackPanel>++ <controls:CustomTextBox+ Grid.Row="1"+ Header="{x:Bind ViewModel.Strings.InputTitle}"+ Text="{x:Bind ViewModel.UserCronExpression, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"+ Tag="UserCronExpression"/>++ <controls:CustomTextBox+ Grid.Row="2"+ MinHeight="250"+ IsReadOnly="True"+ AcceptsReturn="True"+ IsRichTextEdit="False"+ Header="{x:Bind ViewModel.Strings.OutputTitle}"+ Text="{x:Bind ViewModel.OutputValue, Mode=OneWay}"/>+ </Grid>+</Page>diff --git a/src/dev/impl/DevToys/Views/Tools/Converters/CronParser/CronParserToolPage.xaml.cs b/src/dev/impl/DevToys/Views/Tools/Converters/CronParser/CronParserToolPage.xaml.csnew file mode 100644index 000000000..f363d4213--- /dev/null+++ b/src/dev/impl/DevToys/Views/Tools/Converters/CronParser/CronParserToolPage.xaml.cs@@ -0,0 +1,50 @@+#nullable enable++using DevToys.Api.Core.Navigation;+using DevToys.Shared.Core;+using DevToys.ViewModels.Tools.CronParser;+using Windows.UI.Xaml;+using Windows.UI.Xaml.Controls;+using Windows.UI.Xaml.Navigation;++namespace DevToys.Views.Tools.CronParser+{+ public sealed partial class CronParserToolPage : Page+ {+ public static readonly DependencyProperty ViewModelProperty+ = DependencyProperty.Register(+ nameof(ViewModel),+ typeof(CronParserToolViewModel),+ typeof(CronParserToolPage),+ new PropertyMetadata(null));++ /// <summary>+ /// Gets the page's view model.+ /// </summary>+ public CronParserToolViewModel ViewModel+ {+ get => (CronParserToolViewModel)GetValue(ViewModelProperty);+ set => SetValue(ViewModelProperty, value);+ }++ public CronParserToolPage()+ {+ InitializeComponent();+ }++ protected override void OnNavigatedTo(NavigationEventArgs e)+ {+ var parameters = (NavigationParameter)e.Parameter;++ if (ViewModel is null)+ {+ // Set the view model+ Assumes.NotNull(parameters.ViewModel, nameof(parameters.ViewModel));+ ViewModel = (CronParserToolViewModel)parameters.ViewModel!;+ DataContext = ViewModel;+ }++ base.OnNavigatedTo(e);+ }+ }+}diff --git a/src/tests/DevToys.Tests/Providers/Tools/HashGeneratorTests.cs b/src/tests/DevToys.Tests/Providers/Tools/HashGeneratorTests.csindex 58cb9cf45..04ade87b2 100644--- a/src/tests/DevToys.Tests/Providers/Tools/HashGeneratorTests.cs+++ b/src/tests/DevToys.Tests/Providers/Tools/HashGeneratorTests.cs@@ -19,6 +19,7 @@ namespace DevToys.Tests.Providers.Toolsawait ThreadHelper.RunOnUIThreadAsync(() =>{+ viewModel.IsHmacMode = false;viewModel.IsUppercase = false;viewModel.Input = input;});@@ -39,6 +40,7 @@ namespace DevToys.Tests.Providers.Toolsawait ThreadHelper.RunOnUIThreadAsync(() =>{+ viewModel.IsHmacMode = false;viewModel.IsUppercase = true;viewModel.Input = input;});