Skip to content

Commit

Permalink
Show description for cron expressions (#839)
Browse files Browse the repository at this point in the history
* Show description for cron expressions

* Remove PostBuildEvent
  • Loading branch information
micahmo authored Jun 9, 2023
1 parent 0f09e48 commit e2a46f8
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 1 deletion.
21 changes: 21 additions & 0 deletions THIRD-PARTY-NOTICES.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ This project incorporates components from the projects listed below. The origina
15. [Cronos](#cronos) (<https://github.com/HangfireIO/Cronos>)
16. [BouncyCastle](#bouncy-castle) (<https://www.bouncycastle.org/>)
17. [SVG Repo](#svg-repo) (<https://www.svgrepo.com/>)
18. [Cron Expression Descriptor](#cron-expression-descriptor) (<https://github.com/bradymholt/cron-expression-descriptor/>)

Newtonsoft.Json
=========================================
Expand Down Expand Up @@ -564,3 +565,23 @@ 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.

Cron Expression Descriptor
=========================================

Copyright (c) 2017 Brady Holt

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.
1 change: 1 addition & 0 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
</PropertyGroup>

<PropertyGroup>
<Nuget_CronExpressionDescriptor>2.20.0</Nuget_CronExpressionDescriptor>
<Nuget_Cronos>0.7.1</Nuget_Cronos>
<NuGet_DotNet>6.0.0</NuGet_DotNet>
<Nuget_GitInfo>2.2.0</Nuget_GitInfo>
Expand Down
1 change: 1 addition & 0 deletions src/dev/impl/DevToys/DevToys.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,7 @@
</Page>
</ItemGroup>
<ItemGroup>
<PackageReference Include="CronExpressionDescriptor" Version="$(Nuget_CronExpressionDescriptor)" />
<PackageReference Include="Cronos" Version="$(Nuget_Cronos)" />
<PackageReference Include="GitInfo" Version="$(Nuget_GitInfo)" />
<PackageReference Include="Markdig" Version="$(Nuget_Markdig)" />
Expand Down
10 changes: 10 additions & 0 deletions src/dev/impl/DevToys/LanguageManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1006,6 +1006,16 @@ public class CRONParserStrings : ObservableObject
/// Gets the resource SecondsIncludedMode.
/// </summary>
public string SecondsIncludedMode => _resources.GetString("SecondsIncludedMode");

/// <summary>
/// Gets the resource DescriptionTitle.
/// </summary>
public string DescriptionTitle => _resources.GetString("DescriptionTitle");

/// <summary>
/// Gets the resource DescriptionErrorMessage.
/// </summary>
public string DescriptionErrorMessage => _resources.GetString("DescriptionErrorMessage");
}

public class GuidGeneratorStrings : ObservableObject
Expand Down
6 changes: 6 additions & 0 deletions src/dev/impl/DevToys/Strings/en-US/CRONParser.resw
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,10 @@
<data name="SecondsIncludedMode" xml:space="preserve">
<value>Seconds included (6 - segment Cron)</value>
</data>
<data name="DescriptionTitle" xml:space="preserve">
<value>Description</value>
</data>
<data name="DescriptionErrorMessage" xml:space="preserve">
<value>Unable to generate description</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
using Microsoft.Toolkit.Mvvm.ComponentModel;
using Microsoft.Toolkit.Mvvm.Input;
using Windows.ApplicationModel.DataTransfer;
using CronExpressionDescriptor;
using DevToys.Core;

namespace DevToys.ViewModels.Tools.CronParser
{
Expand All @@ -25,6 +27,7 @@ public sealed class CronParserToolViewModel : ObservableRecipient, IToolViewMode
private string _cronExpression;
private bool _setPropertyInProgress;
private string? _outputValue;
private string? _cronDescription;

private const string DefaultCronWithSeconds = "* * * * * *";
private const string DefaultCronWithoutSeconds = "* * * * *";
Expand Down Expand Up @@ -165,6 +168,14 @@ internal string? OutputValue
private set => SetProperty(ref _outputValue, value);
}

/// <summary>
/// A human-readable description of the cron expression
/// </summary>
internal string? CronDescription
{
get => _cronDescription;
set => SetProperty(ref _cronDescription, value);
}

[ImportingConstructor]
public CronParserToolViewModel(ISettingsProvider settingsProvider)
Expand Down Expand Up @@ -218,6 +229,17 @@ private void ParseCronExpression()
return;
}

// Attempt to generate a description
try
{
CronDescription = ExpressionDescriptor.GetDescription(UserCronExpression);
}
catch (Exception ex)
{
CronDescription = Strings.DescriptionErrorMessage;
Logger.LogFault($"Error generating description from cron expression: '{UserCronExpression}'", ex);
}

output.Add(nextOccurence.Value.ToString(OutputDateTimeFormat));

for (int i = 0; i <= int.Parse(OutputLimitMode); i++)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
</Grid.ChildrenTransitions>

<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
Expand Down Expand Up @@ -102,7 +103,15 @@
Tag="UserCronExpression"/>

<controls:CustomTextBox
Grid.Row="2"
Grid.Row="2"
IsReadOnly="True"
AcceptsReturn="True"
IsRichTextEdit="False"
Header="{x:Bind ViewModel.Strings.DescriptionTitle}"
Text="{x:Bind ViewModel.CronDescription, Mode=OneWay}"/>

<controls:CustomTextBox
Grid.Row="3"
MinHeight="250"
IsReadOnly="True"
AcceptsReturn="True"
Expand Down

0 comments on commit e2a46f8

Please sign in to comment.