# HG changeset patch # User Steven Hollidge # Date 1334784526 -3600 # Node ID 64f19743cfd695ba9aa4162972a2c552f1d8bd59 # Parent 502f5f365649101b2cc4622a873c6737aad5b3f8 Initial load for Silverlight Validation diff -r 502f5f365649 -r 64f19743cfd6 SilverlightValidation/Libs/FluentValidation.dll Binary file SilverlightValidation/Libs/FluentValidation.dll has changed diff -r 502f5f365649 -r 64f19743cfd6 SilverlightValidation/Libs/System.Windows.Controls.Data.Input.dll Binary file SilverlightValidation/Libs/System.Windows.Controls.Data.Input.dll has changed diff -r 502f5f365649 -r 64f19743cfd6 SilverlightValidation/Libs/System.Windows.Controls.dll Binary file SilverlightValidation/Libs/System.Windows.Controls.dll has changed diff -r 502f5f365649 -r 64f19743cfd6 SilverlightValidation/SilverlightValidation.sln --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SilverlightValidation/SilverlightValidation.sln Wed Apr 18 22:28:46 2012 +0100 @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual Studio 2010 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SilverlightValidation", "SilverlightValidation\SilverlightValidation.csproj", "{0C1CC1FC-915A-4428-8952-CDC79EABC3F4}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {0C1CC1FC-915A-4428-8952-CDC79EABC3F4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0C1CC1FC-915A-4428-8952-CDC79EABC3F4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0C1CC1FC-915A-4428-8952-CDC79EABC3F4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0C1CC1FC-915A-4428-8952-CDC79EABC3F4}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff -r 502f5f365649 -r 64f19743cfd6 SilverlightValidation/SilverlightValidation/App.xaml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SilverlightValidation/SilverlightValidation/App.xaml Wed Apr 18 22:28:46 2012 +0100 @@ -0,0 +1,3 @@ + diff -r 502f5f365649 -r 64f19743cfd6 SilverlightValidation/SilverlightValidation/App.xaml.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SilverlightValidation/SilverlightValidation/App.xaml.cs Wed Apr 18 22:28:46 2012 +0100 @@ -0,0 +1,59 @@ +using System; +using System.Windows; + +namespace SilverlightValidation +{ + public partial class App : Application + { + + public App() + { + this.Startup += this.Application_Startup; + this.Exit += this.Application_Exit; + this.UnhandledException += this.Application_UnhandledException; + + InitializeComponent(); + } + + private void Application_Startup(object sender, StartupEventArgs e) + { + this.RootVisual = new UserView(); + } + + private void Application_Exit(object sender, EventArgs e) + { + + } + + private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e) + { + // If the app is running outside of the debugger then report the exception using + // the browser's exception mechanism. On IE this will display it a yellow alert + // icon in the status bar and Firefox will display a script error. + if (!System.Diagnostics.Debugger.IsAttached) + { + + // NOTE: This will allow the application to continue running after an exception has been thrown + // but not handled. + // For production applications this error handling should be replaced with something that will + // report the error to the website and stop the application. + e.Handled = true; + Deployment.Current.Dispatcher.BeginInvoke(delegate { ReportErrorToDOM(e); }); + } + } + + private void ReportErrorToDOM(ApplicationUnhandledExceptionEventArgs e) + { + try + { + string errorMsg = e.ExceptionObject.Message + e.ExceptionObject.StackTrace; + errorMsg = errorMsg.Replace('"', '\'').Replace("\r\n", @"\n"); + + System.Windows.Browser.HtmlPage.Window.Eval("throw new Error(\"Unhandled Error in Silverlight Application " + errorMsg + "\");"); + } + catch (Exception) + { + } + } + } +} diff -r 502f5f365649 -r 64f19743cfd6 SilverlightValidation/SilverlightValidation/Properties/AppManifest.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SilverlightValidation/SilverlightValidation/Properties/AppManifest.xml Wed Apr 18 22:28:46 2012 +0100 @@ -0,0 +1,6 @@ + + + + diff -r 502f5f365649 -r 64f19743cfd6 SilverlightValidation/SilverlightValidation/Properties/AssemblyInfo.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SilverlightValidation/SilverlightValidation/Properties/AssemblyInfo.cs Wed Apr 18 22:28:46 2012 +0100 @@ -0,0 +1,35 @@ +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("SilverlightValidation")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("SilverlightValidation")] +[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("3f5a4c47-8fbd-4568-8728-e26ee6a51945")] + +// 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 Revision and Build Numbers +// by using the '*' as shown below: +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff -r 502f5f365649 -r 64f19743cfd6 SilverlightValidation/SilverlightValidation/RelayCommand.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SilverlightValidation/SilverlightValidation/RelayCommand.cs Wed Apr 18 22:28:46 2012 +0100 @@ -0,0 +1,41 @@ +using System; +using System.Windows.Input; + +namespace SilverlightValidation +{ + public class RelayCommand : ICommand + { + public event EventHandler CanExecuteChanged; + + readonly Action _execute; + readonly Predicate _canExecute; + + public RelayCommand(Action execute, + Predicate canExecute = null) + { + if (execute == null) throw new ArgumentNullException("execute"); + + _execute = execute; + _canExecute = canExecute; + } + + + public void UpdateCanExecuteCommand() + { + if (CanExecuteChanged != null) + CanExecuteChanged(this, new EventArgs()); + } + + + public bool CanExecute(object parameter) + { + return _canExecute == null || _canExecute(parameter); + } + + + public void Execute(object parameter) + { + _execute(parameter); + } + } +} diff -r 502f5f365649 -r 64f19743cfd6 SilverlightValidation/SilverlightValidation/SilverlightValidation.csproj --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SilverlightValidation/SilverlightValidation/SilverlightValidation.csproj Wed Apr 18 22:28:46 2012 +0100 @@ -0,0 +1,122 @@ + + + + Debug + AnyCPU + 8.0.50727 + 2.0 + {0C1CC1FC-915A-4428-8952-CDC79EABC3F4} + {A1591282-1198-4647-A2B1-27E5FF5F6F3B};{fae04ec0-301f-11d3-bf4b-00c04f79efbc} + Library + Properties + SilverlightValidation + SilverlightValidation + Silverlight + v5.0 + $(TargetFrameworkVersion) + true + + + true + true + SilverlightValidation.xap + Properties\AppManifest.xml + SilverlightValidation.App + SilverlightValidationTestPage.html + true + true + false + Properties\OutOfBrowserSettings.xml + false + true + + + + + + v3.5 + + + true + full + false + Bin\Debug + DEBUG;TRACE;SILVERLIGHT + true + true + prompt + 4 + + + pdbonly + true + Bin\Release + TRACE;SILVERLIGHT + true + true + prompt + 4 + + + + ..\Libs\FluentValidation.dll + + + + + + + ..\Libs\System.Windows.Controls.dll + + + ..\Libs\System.Windows.Controls.Data.Input.dll + + + + + + + App.xaml + + + + + + + + + UserView.xaml + + + + + Designer + MSBuild:Compile + + + Designer + MSBuild:Compile + + + + + + + + + + + + + + + + \ No newline at end of file diff -r 502f5f365649 -r 64f19743cfd6 SilverlightValidation/SilverlightValidation/UserModel.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SilverlightValidation/SilverlightValidation/UserModel.cs Wed Apr 18 22:28:46 2012 +0100 @@ -0,0 +1,23 @@ +using System; + +namespace SilverlightValidation +{ + public interface ICloneable + { + T Clone(); + } + + public class UserModel : IUserModel, ICloneable + { + public string Username { get; set; } + public string Email { get; set; } + public string Password { get; set; } + public DateTime DateOfBirth { get; set; } + public string Description { get; set; } + + public UserModel Clone() + { + return (UserModel) this.MemberwiseClone(); + } + } +} diff -r 502f5f365649 -r 64f19743cfd6 SilverlightValidation/SilverlightValidation/UserModelValidator.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SilverlightValidation/SilverlightValidation/UserModelValidator.cs Wed Apr 18 22:28:46 2012 +0100 @@ -0,0 +1,32 @@ +using System; +using FluentValidation; + +namespace SilverlightValidation +{ + public class UserModelValidator : AbstractValidator + { + public UserModelValidator() + { + RuleFor(x => x.Username) + .NotEmpty() + .WithMessage("Username cannot be blank."); + + RuleFor(x => x.Password) + .NotEmpty() + .WithMessage("Password cannot be blank."); + + RuleFor(x => x.Email) + .EmailAddress() + .WithMessage("Email is required."); + + RuleFor(x => x.DateOfBirth) + .Must(BeAValidDateOfBirth) + .WithMessage("Date of birth must be within the last 100 years."); + } + + private bool BeAValidDateOfBirth(DateTime dateOfBirth) + { + return (dateOfBirth < DateTime.Today) && (dateOfBirth > DateTime.Today.AddYears(-100)); + } + } +} diff -r 502f5f365649 -r 64f19743cfd6 SilverlightValidation/SilverlightValidation/UserView.xaml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SilverlightValidation/SilverlightValidation/UserView.xaml Wed Apr 18 22:28:46 2012 +0100 @@ -0,0 +1,109 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +