Skip to content

Commit

Permalink
+ Added ErrorDialog
Browse files Browse the repository at this point in the history
+ A bit of deisgn change for MessageDialog too
  • Loading branch information
mhmd-azeez committed Nov 22, 2016
1 parent 96bbe11 commit 23e8fe7
Show file tree
Hide file tree
Showing 8 changed files with 206 additions and 33 deletions.
2 changes: 1 addition & 1 deletion RudeFox.FrontEnd/Mvvm/BindableBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace RudeFox.Mvvm
{
class BindableBase : INotifyPropertyChanged
public class BindableBase : INotifyPropertyChanged
{
public bool SetProperty<T>(ref T field, T value, [CallerMemberName] string propertyName = "")
{
Expand Down
8 changes: 8 additions & 0 deletions RudeFox.FrontEnd/RudeFox.FrontEnd.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,16 @@
<Compile Include="Services\DialogService.cs" />
<Compile Include="Services\ShredderService.cs" />
<Compile Include="ViewModels\AboutDialogVM.cs" />
<Compile Include="ViewModels\ErrorDialogVM.cs" />
<Compile Include="ViewModels\MainWindowVM.cs" />
<Compile Include="ViewModels\MessageDialogVM.cs" />
<Compile Include="ViewModels\WorkItemVM.cs" />
<Compile Include="Views\AboutDialog.xaml.cs">
<DependentUpon>AboutDialog.xaml</DependentUpon>
</Compile>
<Compile Include="Views\ErrorDialog.xaml.cs">
<DependentUpon>ErrorDialog.xaml</DependentUpon>
</Compile>
<Compile Include="Views\MainWindow.xaml.cs">
<DependentUpon>MainWindow.xaml</DependentUpon>
</Compile>
Expand Down Expand Up @@ -127,6 +131,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\ErrorDialog.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\MainWindow.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down
7 changes: 7 additions & 0 deletions RudeFox.FrontEnd/Services/DialogService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ public static DialogService Instance
#endregion

#region Methods
public ErrorDialog GetErrorDialog(string title, Exception exception)
{
var window = new ErrorDialog();
window.DataContext = new ErrorDialogVM(title, exception.Message, exception);
return window;
}

public AboutDialog GetAboutDialog()
{
var window = new AboutDialog();
Expand Down
87 changes: 87 additions & 0 deletions RudeFox.FrontEnd/ViewModels/ErrorDialogVM.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
using RudeFox.Models;
using RudeFox.Mvvm;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RudeFox.ViewModels
{
class ErrorDialogVM : BindableBase
{
#region Contructor
public ErrorDialogVM(string title, string message, Exception exception)
{
Title = title;
Message = message;
MessageIcon = MessageIcon.Error;
Details = GetExceptionInfo(exception);
OkButton = "Okay";
}
#endregion

#region Properties
private string _title;
public string Title
{
get { return _title; }
set { SetProperty(ref _title, value); }
}

private string _details;
public string Details
{
get { return _details; }
set { SetProperty(ref _details, value); }
}

private string _message;
public string Message
{
get { return _message; }
set { SetProperty(ref _message, value); }
}

private string _okButton;
public string OkButton
{
get { return _okButton; }
set { SetProperty(ref _okButton, value); }
}

private MessageIcon _messageIcon;
public MessageIcon MessageIcon
{
get { return _messageIcon; }
set
{
if (SetProperty(ref _messageIcon, value))
RaisePropertyChanged(nameof(Icon));
}
}

public string Icon
{
get { return "/Images/" + MessageIcon.ToString().ToLower() + ".png"; }
}
#endregion

#region Private Methods
private string GetExceptionInfo(Exception e)
{
string info = string.Empty;
info += e.ToString();

if (e.InnerException != null)
{
info += "\n\n";
info += "========== Inner Exception ========= \n";
info += GetExceptionInfo(e.InnerException);
}

return info;
}
#endregion
}
}
52 changes: 21 additions & 31 deletions RudeFox.FrontEnd/ViewModels/MainWindowVM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,52 +150,42 @@ on i.Path equals p
}
catch (AggregateException exc)
{
var failedTasks = tasks.Where(t => t.IsFaulted);
tasks.RemoveAll(t => failedTasks.Contains(t));

var failedItems = WorkItems.Where(item => item.Task.IsFaulted || item.Task.IsCanceled);

for (int i = 0; i < WorkItems.Count; i++)
{
if (failedItems.Contains(WorkItems[i]))
{
WorkItems.RemoveAt(i);
i--;
}
}

RemoveFailedTasks(tasks);
var exception = exc.Flatten();
MessageBox.Show(exception.ToString());

DialogService.Instance.GetErrorDialog("Could not delete item", exception).ShowDialog();
}
catch (Exception exc)
{
var failedTasks = tasks.Where(t => t.IsFaulted);
tasks.RemoveAll(t => failedTasks.Contains(t));

var failedItems = WorkItems.Where(item => item.Task.IsFaulted || item.Task.IsCanceled);
RemoveFailedTasks(tasks);
DialogService.Instance.GetErrorDialog("Could not delete item", exc).ShowDialog();
}

if (newItems.Count > 0)
{
for (int i = 0; i < WorkItems.Count; i++)
{
if (failedItems.Contains(WorkItems[i]))
if (newItems.Contains(WorkItems[i]))
{
WorkItems.RemoveAt(i);
i--;
}
}

MessageBox.Show(exc.ToString());
}

if (newItems.Count > 0)
}

private void RemoveFailedTasks(List<Task> tasks)
{
var failedTasks = tasks.Where(t => t.IsFaulted);
tasks.RemoveAll(t => failedTasks.Contains(t));

var failedItems = WorkItems.Where(item => item.Task.IsFaulted || item.Task.IsCanceled);

for (int i = 0; i < WorkItems.Count; i++)
{
for (int i = 0; i < WorkItems.Count; i++)
if (failedItems.Contains(WorkItems[i]))
{
if (newItems.Contains(WorkItems[i]))
{
WorkItems.RemoveAt(i);
i--;
}
WorkItems.RemoveAt(i);
i--;
}
}
}
Expand Down
41 changes: 41 additions & 0 deletions RudeFox.FrontEnd/Views/ErrorDialog.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<Window x:Class="RudeFox.Views.ErrorDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:RudeFox.Views"
xmlns:controls="clr-namespace:RudeFox.Controls"
mc:Ignorable="d"
WindowStartupLocation="CenterScreen" ResizeMode="NoResize"
Icon="/Images/icon_24.png"
Title="{Binding Title}" MinWidth="350" MinHeight="120" MaxHeight="350" MaxWidth="450"
SizeToContent="WidthAndHeight" Loaded="Window_Loaded" SnapsToDevicePixels="True">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="48" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="72"/>
<ColumnDefinition />
</Grid.ColumnDefinitions>

<Image VerticalAlignment="Center" Width="32" HorizontalAlignment="Center" Source="{Binding Icon}" />
<ScrollViewer Grid.Column="1" Margin="10" VerticalAlignment="Center" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto">
<TextBlock x:Name="txtMessage" FontSize="14" Text="{Binding Message}" TextWrapping="Wrap" />
</ScrollViewer>

<Expander Padding="5" FontWeight="SemiBold" Margin="0, 3" Header="Details" Grid.Row="1" Grid.Column="1">
<Grid Background="#FFE9ECEE">
<TextBox Text="{Binding Details}" VerticalScrollBarVisibility="Auto" MaxHeight="100" FontWeight="Normal" BorderThickness="0" IsReadOnly="True" Background="Transparent" TextWrapping="Wrap"/>
</Grid>
</Expander>

<Grid Background="#efefef" Grid.ColumnSpan="2" Grid.Row="2">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
<controls:FlatButton x:Name="okButton" Content="{Binding OkButton}" Margin="10,0,0,0" Padding="10,5" TabIndex="0" Click="okButton_Click" IsCancel="True"/>
</StackPanel>
</Grid>
</Grid>
</Window>
39 changes: 39 additions & 0 deletions RudeFox.FrontEnd/Views/ErrorDialog.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace RudeFox.Views
{
/// <summary>
/// Interaction logic for ErrorDialog.xaml
/// </summary>
public partial class ErrorDialog : Window
{
public ErrorDialog()
{
InitializeComponent();
}

private void Window_Loaded(object sender, RoutedEventArgs e)
{
okButton.Focus();
}

private void okButton_Click(object sender, RoutedEventArgs e)
{
DialogResult = true;
Close();
}

}
}
3 changes: 2 additions & 1 deletion RudeFox.FrontEnd/Views/MessageDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:RudeFox.Views" ShowInTaskbar="False"
xmlns:controls="clr-namespace:RudeFox.Controls"
Icon="/Images/icon_24.png"
mc:Ignorable="d" WindowStartupLocation="CenterScreen" ResizeMode="NoResize"
Title="{Binding Title}" MinWidth="350" MinHeight="120" MaxHeight="300" MaxWidth="600"
SizeToContent="WidthAndHeight" Loaded="Window_Loaded" SnapsToDevicePixels="True">
Expand All @@ -24,7 +25,7 @@
<TextBlock x:Name="txtMessage" FontSize="14" Text="{Binding Message}" TextWrapping="Wrap" />
</ScrollViewer>

<Grid Background="#eee" Grid.ColumnSpan="2" Grid.Row="1">
<Grid Background="#efefef" Grid.ColumnSpan="2" Grid.Row="1">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
<controls:FlatButton x:Name="okButton" IsDestructive="{Binding IsDestructive}" Content="{Binding OkButton}" IsDefault="True" Margin="10,0,0,0" Padding="10,5" TabIndex="0" Click="okButton_Click"/>
<controls:FlatButton x:Name="cancelButton" Content="{Binding CancelButton}" IsCancel="True" Margin="10,0,0,0" Padding="10,5" TabIndex="1" Click="cancelButton_Click"/>
Expand Down

0 comments on commit 23e8fe7

Please sign in to comment.