Skip to content

Commit

Permalink
Created CommonExtensions project. Moved files around
Browse files Browse the repository at this point in the history
  • Loading branch information
benrhughes committed Nov 12, 2012
1 parent ae886bd commit 0109e71
Show file tree
Hide file tree
Showing 24 changed files with 217 additions and 93 deletions.
30 changes: 17 additions & 13 deletions Client/Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -74,26 +74,27 @@
<Reference Include="PresentationFramework" />
</ItemGroup>
<ItemGroup>
<ApplicationDefinition Include="App.xaml">
<ApplicationDefinition Include="Controls\App.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="ExceptionExtensions.cs" />
<Compile Include="SortType.cs" />
<Compile Include="UpdateChecker.cs" />
<Compile Include="MainWindowViewModel.cs" />
<Compile Include="PostponeDialog.xaml.cs">
<Compile Include="Controls\PostponeDialog.xaml.cs">
<DependentUpon>PostponeDialog.xaml</DependentUpon>
</Compile>
<Compile Include="FilterDialog.xaml.cs">
<Compile Include="Controls\FilterDialog.xaml.cs">
<DependentUpon>FilterDialog.xaml</DependentUpon>
</Compile>
<Compile Include="Help.xaml.cs">
<Compile Include="Controls\Help.xaml.cs">
<DependentUpon>Help.xaml</DependentUpon>
</Compile>
<Compile Include="HotKey.cs" />
<Compile Include="HotKeyMainWindows.cs" />
<Compile Include="ObserverChangeFile.cs" />
<Compile Include="Options.xaml.cs">
<Compile Include="Controls\Options.xaml.cs">
<DependentUpon>Options.xaml</DependentUpon>
</Compile>
<Compile Include="Properties\SharedAssemblyInfo.cs" />
Expand All @@ -110,33 +111,32 @@
<DesignTimeSharedInput>True</DesignTimeSharedInput>
<DependentUpon>User.settings</DependentUpon>
</Compile>
<Compile Include="Utilities.cs" />
<Compile Include="WindowLocation.cs" />
<Page Include="PostponeDialog.xaml">
<Page Include="Controls\PostponeDialog.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="FilterDialog.xaml">
<Page Include="Controls\FilterDialog.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Help.xaml">
<Page Include="Controls\Help.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="MainWindow.xaml">
<Page Include="Controls\MainWindow.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Compile Include="App.xaml.cs">
<Compile Include="Controls\App.xaml.cs">
<DependentUpon>App.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="MainWindow.xaml.cs">
<Compile Include="Controls\MainWindow.xaml.cs">
<DependentUpon>MainWindow.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Page Include="Options.xaml">
<Page Include="Controls\Options.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
Expand All @@ -157,6 +157,10 @@
<Project>{C51DEEDA-B581-401B-870B-DBB7D10119BF}</Project>
<Name>ColorFont</Name>
</ProjectReference>
<ProjectReference Include="..\CommonExtensions\CommonExtensions.csproj">
<Project>{5CE19CC1-833A-4950-B86E-CBF59FA00D6F}</Project>
<Name>CommonExtensions</Name>
</ProjectReference>
<ProjectReference Include="..\ToDoLib\ToDoLib.csproj">
<Project>{07AA9CEA-4EF0-4B47-AFBD-6F74AD9C4653}</Project>
<Name>ToDoLib</Name>
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public MainWindow()
{
Application.Current.DispatcherUnhandledException += (o, e) =>
{
HandleException("An unexpected error occurred", e.Exception);
Helper.HandleException("An unexpected error occurred", e.Exception);
e.Handled = true;
};

Expand Down Expand Up @@ -450,7 +450,7 @@ private void lbTasks_PreviewKeyUp(object sender, KeyEventArgs e)
ViewModel.KeyboardShortcut(e.Key, e.KeyboardDevice.Modifiers);
}

//this is just for j and k - the nav keys. Using KeyDown allows for holding the key to navigate
// Using KeyDown allows for holding the key to navigate
private void lbTasks_PreviewKeyDown(object sender, KeyEventArgs e)
{
if (Keyboard.Modifiers.HasFlag(ModifierKeys.Alt) && lbTasks.HasItems)
Expand Down Expand Up @@ -513,7 +513,7 @@ private void lbTasks_PreviewKeyDown(object sender, KeyEventArgs e)
private void lbTasks_PreviewMouseDoubleClick(object sender, MouseButtonEventArgs e)
{
e.Handled = true;
KeyboardShortcut(Key.U);
ViewModel.KeyboardShortcut(Key.U);
}

#endregion
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
16 changes: 2 additions & 14 deletions Client/Utilities.cs → Client/ExceptionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,9 @@

namespace Client
{
public class Utilities
public static class ExceptionExtensions
{
public void Try(Action action, string errorMessage)
{
try
{
action();
}
catch (Exception ex)
{
HandleException(errorMessage, ex);
}
}

public void HandleException(string errorMessage, Exception ex)
public static void Handle(this Exception ex, string errorMessage)
{
Log.Error(errorMessage, ex);
MessageBox.Show(errorMessage + Environment.NewLine + ex.Message + Environment.NewLine + "Please see Help -> Show Error Log for more details",
Expand Down
34 changes: 25 additions & 9 deletions Client/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Windows.Input;
using System.IO;
using ColorFont;
using CommonExtensions;

namespace Client
{
Expand All @@ -31,7 +32,7 @@ public MainWindowViewModel(MainWindow window)
UpdateDisplayedTasks();
}

public SortType SortType
public SortType SortType
{
get { return _sortType; }
set
Expand Down Expand Up @@ -60,7 +61,7 @@ public void LoadTasks(string filePath)
}
catch (Exception ex)
{
HandleException("An error occurred while opening " + filePath, ex);
ex.Handle("An error occurred while opening " + filePath);
}
}

Expand Down Expand Up @@ -172,7 +173,15 @@ public void KeyboardShortcut(Key key, ModifierKeys modifierKeys = ModifierKeys.N

if (res == MessageBoxResult.Yes)
{
Try(() => _taskList.Delete((Task)_window.lbTasks.SelectedItem), "Error deleting task");
try
{
_taskList.Delete((Task)_window.lbTasks.SelectedItem);
}
catch (Exception ex)
{
ex.Handle("Error deleting task");
}

UpdateDisplayedTasks();
}
}
Expand Down Expand Up @@ -245,7 +254,7 @@ public void UpdateDisplayedTasks()
}
catch (Exception ex)
{
HandleException("Error while sorting tasks", ex);
ex.Handle("Error while sorting tasks");
}

if (selected == null)
Expand Down Expand Up @@ -288,7 +297,14 @@ private void Refresh()

private void Reload()
{
Try(() => _taskList.ReloadTasks(), "Error loading tasks");
try
{
_taskList.ReloadTasks();
}
catch (Exception ex)
{
ex.Handle("Error loading tasks");
}
}

public void ShowFilterDialog()
Expand All @@ -300,7 +316,7 @@ public void ShowFilterDialog()
f.FilterTextPreset1 = User.Default.FilterTextPreset1;
f.FilterTextPreset2 = User.Default.FilterTextPreset2;
f.FilterTextPreset3 = User.Default.FilterTextPreset3;

if (f.ShowDialog().Value)
{
User.Default.FilterText = f.FilterText.Trim();
Expand All @@ -317,7 +333,7 @@ public static IEnumerable<Task> FilterList(IEnumerable<Task> tasks)
{
var filters = User.Default.FilterText;
var comparer = User.Default.FilterCaseSensitive ? StringComparison.InvariantCulture : StringComparison.InvariantCultureIgnoreCase;

if (String.IsNullOrEmpty(filters))
return tasks;

Expand All @@ -334,7 +350,7 @@ public static IEnumerable<Task> FilterList(IEnumerable<Task> tasks)
else if (filter.Equals("due:future", StringComparison.OrdinalIgnoreCase)
&& task.DueDate.IsDateGreaterThan(DateTime.Now))
continue;
else if (filter.Equals("due:past", StringComparison.OrdinalIgnoreCase)
else if (filter.Equals("due:past", StringComparison.OrdinalIgnoreCase)
&& task.DueDate.IsDateLessThan(DateTime.Now))
continue;
else if (filter.Equals("due:active", StringComparison.OrdinalIgnoreCase)
Expand Down Expand Up @@ -452,7 +468,7 @@ private void ToggleComplete(Task task)
}
catch (Exception ex)
{
HandleException("An error occurred while updating the task's completed status", ex);
ex.Handle("An error occurred while updating the task's completed status");
}
}

Expand Down
55 changes: 55 additions & 0 deletions CommonExtensions/CommonExtensions.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{5CE19CC1-833A-4950-B86E-CBF59FA00D6F}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>CommonExtensions</RootNamespace>
<AssemblyName>CommonExtensions</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="IEnumerableExtensions.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="StringExtensions.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
25 changes: 25 additions & 0 deletions CommonExtensions/IEnumerableExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CommonExtensions
{
public static class IEnumerableExtensions
{
public static void Each<T>(this IEnumerable<T> items, Action<T> action)
{
if (!items.IsNullOrEmpty())
{
foreach (var item in items)
if (item != null)
action(item);
}
}

public static bool IsNullOrEmpty<T>(this IEnumerable<T> items)
{
return items == null || items.Count() == 0;
}
}
}
36 changes: 36 additions & 0 deletions CommonExtensions/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("CommonExtensions")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("CommonExtensions")]
[assembly: AssemblyCopyright("Copyright © 2012")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("c667f573-1652-4a43-9b87-c6f3a662af4f")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
34 changes: 34 additions & 0 deletions CommonExtensions/StringExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CommonExtensions
{
public static class StringExtensions
{
public static bool IsDateGreaterThan(this string dateString, DateTime date)
{
if (dateString.IsNullOrEmpty())
return false;

DateTime comparisonDate;
if (!DateTime.TryParse(dateString, out comparisonDate))
return false;

return comparisonDate.Date > date.Date;
}

public static bool IsDateLessThan(this string dateString, DateTime date)
{
if (dateString.IsNullOrEmpty())
return false;

DateTime comparisonDate;
if (!DateTime.TryParse(dateString, out comparisonDate))
return false;

return comparisonDate.Date < date.Date;
}
}
}
Loading

0 comments on commit 0109e71

Please sign in to comment.