Skip to content

Commit

Permalink
added refresh button, auto annotations, fixed bugs with regex parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobias Kiertscher committed Apr 26, 2018
1 parent d073ecf commit 421b248
Show file tree
Hide file tree
Showing 15 changed files with 609 additions and 203 deletions.
60 changes: 60 additions & 0 deletions src/DashOps/ActionMatcher.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Mastersign.DashOps.Model
{
partial class ActionMatcher
{
private bool MatchString(string value)
=> !string.IsNullOrWhiteSpace(value) &&
(Regex != null
? System.Text.RegularExpressions.Regex.IsMatch(value, Regex)
: string.Equals(value, Value));

private string NormalizedFacette
{
get
{
if (string.Equals(
Facette, nameof(CommandAction.Verb),
StringComparison.InvariantCultureIgnoreCase))
{
return nameof(CommandAction.Verb);
}
if (string.Equals(
Facette, nameof(CommandAction.Service),
StringComparison.InvariantCultureIgnoreCase))
{
return nameof(CommandAction.Service);
}
if (string.Equals(
Facette, nameof(CommandAction.Host),
StringComparison.InvariantCultureIgnoreCase))
{
return nameof(CommandAction.Host);
}
return Facette;
}
}

public bool Match(ActionView actionView)
{
switch (Mode)
{
case ActionMatchMode.Description:
return MatchString(actionView.Description);
case ActionMatchMode.Command:
return MatchString(actionView.ExpandedCommand);
case ActionMatchMode.Facette:
return MatchString(actionView.GetFacetteValue(NormalizedFacette));
case ActionMatchMode.Tag:
return actionView.Tags.Any(MatchString);
default:
throw new ArgumentOutOfRangeException();
}
}
}
}
15 changes: 7 additions & 8 deletions src/DashOps/ActionView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,20 @@ namespace Mastersign.DashOps
{
partial class ActionView
{
private static MD5 md5 = MD5.Create();
private static readonly MD5 Md5 = MD5.Create();

public bool HasFacette(string name)
=> this.Facettes?.ContainsKey(name) ?? false;
=> Facettes?.ContainsKey(name) ?? false;

public string[] GetFacettes()
=> this.Facettes?.Keys.ToArray() ?? Array.Empty<string>();
=> Facettes?.Keys.ToArray() ?? Array.Empty<string>();

public bool HasFacetteValue(string name, string value)
=> this.Facettes?.ContainsKey(name) ?? false
&& string.Equals(this.Facettes[name], value);
=> string.Equals(GetFacetteValue(name), value);

public string GetFacetteValue(string name)
=> this.Facettes != null
? this.Facettes.TryGetValue(name, out string value) ? value : null
=> Facettes != null
? Facettes.TryGetValue(name, out var value) ? value : null
: null;

public string CommandLabel => ExpandedCommand
Expand All @@ -42,7 +41,7 @@ public string ActionId
{
var str = Command + " " + CommandLine.FormatArgumentList(Arguments);
var data = Encoding.UTF8.GetBytes(str);
var hash = md5.ComputeHash(data);
var hash = Md5.ComputeHash(data);
return BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant();
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/DashOps/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
StartupUri="MainWindow.xaml"
Startup="Application_Startup">
<Application.Resources>

<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Icons.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
2 changes: 1 addition & 1 deletion src/DashOps/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public partial class App : Application

private void Application_Startup(object sender, StartupEventArgs e)
{
var projectFile = default(string);
string projectFile;
if (e.Args.Length == 1)
{
if (File.Exists(e.Args[0]))
Expand Down
41 changes: 41 additions & 0 deletions src/DashOps/AutoAnnotation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Mastersign.DashOps.Model
{
partial class AutoAnnotation
{
public bool Match(ActionView action)
{
if (Include != null && Include.Any(m => !m.Match(action))) return false;
if (Exclude != null && Exclude.Any(m => m.Match(action))) return false;
return true;
}

public void Apply(ActionView action)
{
if (Tags != null)
{
action.Tags = action.Tags
.Union(Tags)
.ToArray();
}

if (Facettes != null)
{
foreach (var facetteName in Facettes.Keys)
{
if (!action.Facettes.ContainsKey(facetteName))
{
action.Facettes[facetteName] = Facettes[facetteName];
}
}
}

action.Reassure = action.Reassure || Reassure;
}
}
}
6 changes: 6 additions & 0 deletions src/DashOps/DashOps.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="ActionMatcher.cs" />
<Compile Include="ActionSubset.cs" />
<Compile Include="AutoAnnotation.cs" />
<Compile Include="CommandLine.cs" />
<Compile Include="DashOpsCommands.cs" />
<Compile Include="DesignTimeProjectView.cs" />
Expand All @@ -76,6 +78,10 @@
<DesignTime>True</DesignTime>
<DependentUpon>ViewModel.xml</DependentUpon>
</Compile>
<Page Include="Icons.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="MainWindow.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
Expand Down
3 changes: 3 additions & 0 deletions src/DashOps/DashOpsCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ namespace Mastersign.DashOps
{
public static class DashOpsCommands
{
public static readonly RoutedUICommand RefreshProject
= new RoutedUICommand("Refresh Project", "Refresh Project", typeof(MainWindow));

public static readonly RoutedUICommand ExecuteAction
= new RoutedUICommand("Execute Action", "Execute Action", typeof(MainWindow));

Expand Down
21 changes: 21 additions & 0 deletions src/DashOps/Icons.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Viewbox x:Key="IconRefresh"
Width="16" Height="16">
<Rectangle Width="16" Height="16">
<Rectangle.Fill>
<DrawingBrush>
<DrawingBrush.Drawing>
<DrawingGroup>
<DrawingGroup.Children>
<GeometryDrawing Brush="#00FFFFFF" Geometry="F1M16,16L0,16 0,0 16,0z" />
<GeometryDrawing Brush="#FFF6F6F6" Geometry="F1M16,8C16,12.411 12.411,16 8,16 3.589,16 0,12.411 0,8 0,6.597 0.384,5.212 1.088,4L0,4 0,0 8,0 8,8 4,8C4,10.206 5.794,12 8,12 10.206,12 12,10.206 12,8 12,6.656 11.331,5.41 10.21,4.666L9.377,4.112 11.592,0.78 12.425,1.333C14.663,2.822,16,5.314,16,8" />
<GeometryDrawing Brush="#FF00529C" Geometry="F1M15,8C15,11.859 11.859,15 8,15 4.14,15 1,11.859 1,8 1,6.076 1.801,4.292 3.121,3L1,3 1,1 7,1 7,7 5,7 5,4.002C3.766,4.931 3,6.401 3,8 3,10.757 5.243,13 8,13 10.757,13 13,10.757 13,8 13,6.321 12.164,4.763 10.764,3.833L11.871,2.167C13.83,3.469,15,5.649,15,8" />
</DrawingGroup.Children>
</DrawingGroup>
</DrawingBrush.Drawing>
</DrawingBrush>
</Rectangle.Fill>
</Rectangle>
</Viewbox>
</ResourceDictionary>
15 changes: 12 additions & 3 deletions src/DashOps/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@
<CommandBinding Command="NavigationCommands.GoToPage"
CanExecute="GoToPageCommandCheck"
Executed="GoToPageCommandHandler" />
<CommandBinding Command="local:DashOpsCommands.RefreshProject"
CanExecute="RefreshProjectCommandCheck"
Executed="RefreshProjectCommandHandler" />
<CommandBinding Command="local:DashOpsCommands.ExecuteAction"
CanExecute="ExecuteActionCommandCheck"
Executed="ExecuteActionCommandHandler" />
Expand All @@ -66,6 +69,7 @@
<Grid.ColumnDefinitions>
<ColumnDefinition Width="200"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<ItemsControl x:Name="Perspectives"
Grid.ColumnSpan="2"
Expand All @@ -86,16 +90,21 @@
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<Button Content="{StaticResource IconRefresh}"
Grid.Row="0" Grid.Column="2" Padding="4" Margin="20,0"
HorizontalAlignment="Center" VerticalAlignment="Center"
Command="local:DashOpsCommands.RefreshProject" />
<ListBox x:Name="ActionSubsets"
Grid.Column="0" Grid.Row="1"
Margin="20,0,0,20"
BorderThickness="0"
Padding="0"
ItemsSource="{Binding CurrentPerspective.Subsets}">
ItemsSource="{Binding CurrentPerspective.Subsets}"
SelectedItem="{Binding CurrentPerspective.CurrentSubset}">
</ListBox>
<ScrollViewer Grid.Row="1" Grid.Column="1" Margin="10,0,20,20">
<ScrollViewer Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="2" Margin="10,0,20,20">
<ItemsControl x:Name="Actions"
ItemsSource="{Binding ElementName=ActionSubsets, Path=SelectedItem.Actions}" Padding="0,0,10,0">
ItemsSource="{Binding CurrentPerspective.CurrentSubset.Actions}" Padding="0,0,10,0">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Vertical" />
Expand Down
10 changes: 10 additions & 0 deletions src/DashOps/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ private void GoToPageCommandCheck(object sender, CanExecuteRoutedEventArgs e)
e.CanExecute = e.Parameter != ProjectView.CurrentPerspective;
}

private void RefreshProjectCommandHandler(object sender, ExecutedRoutedEventArgs e)
{
App.ProjectLoader.ReloadProjectAndProjectView();
}

private void RefreshProjectCommandCheck(object sender, CanExecuteRoutedEventArgs e)
{
e.CanExecute = true;
}

private void ExecuteActionCommandHandler(object sender, ExecutedRoutedEventArgs e)
{
if (!(e.Parameter is ActionView action)) return;
Expand Down
Loading

0 comments on commit 421b248

Please sign in to comment.