- goalbook.zip
- GoalBook
- Dependencies
- CAG WPF 2
- Microsoft.Practices.Composite.dll
- Microsoft.Practices.Composite.Presentation.dll
- Microsoft.Practices.Composite.UnityExtensions.dll
- Microsoft.Practices.ObjectBuilder2.dll
- Microsoft.Practices.ServiceLocation.dll
- Microsoft.Practices.Unity.dll
- vssver2.scc
- CSLA
- Csla.dll
- Csla.XmlSerializers.dll
- vssver2.scc
- Infragistics
- Infragistics3.Wpf.DataPresenter.v9.1.Express.dll
- Infragistics3.Wpf.Editors.v9.1.Express.dll
- Infragistics3.Wpf.v9.1.Express.dll
- vssver2.scc
- WPFToolkit
- vssver2.scc
- WPFToolkit.dll
- GoalBook.Controls
- GoalBook.Goals
- GoalBook.Infrastructure
- GoalBook.Notes
- GoalBook.Public
- GoalBook.Shell
- App.ico
- App.xaml
- App.xaml.cs
- Bootstrapper.cs
- Commands
- GoalBook.Shell.csproj
- GoalBook.Shell.csproj.user
- Journal.ico
- Journal48.ico
- Misc
- Modules
- Properties
- Resources
- arrow_refresh.png
- arrow_undo.png
- checked.gif
- cross.png
- disk.png
- email.png
- erase.png
- error.png
- exclamation.png
- flag_red.png
- group.png
- help.png
- information.png
- magnifier.png
- page_red.png
- pencil.png
- printer.png
- user.png
- vssver2.scc
- Wave.jpg
- world.png
- world_link.png
- Services
- Splash.png
- Views
- vssver2.scc
- Windows
- GoalBook.sln
- GoalBook.snk
- GoalBook.Synchronisation
- GoalBook.Tasks
- License.txt
- ReadMe.txt
- SolutionInfo.cs
- vssver2.scc
|
//===============================================================================
// Goal Book.
// Copyright © 2009 Mark Brownsword.
//===============================================================================
#region Using Statements
using System;
using System.Runtime.Serialization;
using System.Text.RegularExpressions;
using System.Xml;
using System.Xml.Schema;
using System.Xml.Serialization;
using Csla;
using Csla.Validation;
using GoalBook.Infrastructure.Properties;
using GoalBook.Public.Encryption;
#endregion
namespace GoalBook.Infrastructure
{
/// <summary>
/// Credentials type.
/// </summary>
[Serializable]
public class Credentials : BusinessBase<Credentials>, IXmlSerializable
{
#region Constants and Enums
#endregion
#region Inner Classes and Structures
#endregion
#region Delegates and Events
#endregion
#region Instance and Shared Fields
#endregion
#region Constructors
/// <summary>
/// Constructor.
/// </summary>
public Credentials()
{
MarkAsChild();
ValidationRules.CheckRules();
}
/// <summary>
/// Constructor.
/// </summary>
public Credentials(string email, string userID, string password) : this()
{
Email = email;
UserID = userID;
Password = password;
base.MarkOld();
}
#endregion
#region Properties
private static PropertyInfo<string> EmailProperty = RegisterProperty(typeof(Credentials), new PropertyInfo<string>("Email"));
private static PropertyInfo<string> UserIDProperty = RegisterProperty(typeof(Credentials), new PropertyInfo<string>("UserID"));
private static PropertyInfo<string> PasswordProperty = RegisterProperty(typeof(Credentials), new PropertyInfo<string>("Password"));
/// <summary>
/// Reference to Email.
/// </summary>
public string Email
{
get
{
CanReadProperty(EmailProperty.Name, true);
return GetProperty(EmailProperty);
}
set
{
CanWriteProperty(EmailProperty.Name, true);
if (!GetProperty(EmailProperty).Equals(value))
{
SetProperty(EmailProperty, value);
PropertyHasChanged(EmailProperty.Name);
}
}
}
/// <summary>
/// Reference to UserID.
/// </summary>
public string UserID
{
get
{
CanReadProperty(UserIDProperty.Name, true);
return GetProperty(UserIDProperty);
}
set
{
CanWriteProperty(UserIDProperty.Name, true);
if (!GetProperty(UserIDProperty).Equals(value))
{
SetProperty(UserIDProperty, value);
PropertyHasChanged(UserIDProperty.Name);
}
}
}
/// <summary>
/// Reference to Password.
/// </summary>
public string Password
{
get
{
CanReadProperty(PasswordProperty.Name, true);
return GetProperty(PasswordProperty);
}
set
{
CanWriteProperty(PasswordProperty.Name, true);
if (!GetProperty(PasswordProperty).Equals(value))
{
SetProperty(PasswordProperty, value);
PropertyHasChanged(PasswordProperty.Name);
}
}
}
#endregion
#region Private and Protected Methods
#endregion
#region Public and internal Methods
/// <summary>
/// Clear all data.
/// </summary>
public void Clear()
{
this.Email =
this.UserID =
this.Password = null;
ValidationRules.CheckRules();
}
/// <summary>
/// MapFields.
/// </summary>
public void MapFields(Credentials credentials)
{
this.Email = credentials.Email;
this.UserID = credentials.UserID;
this.Password = credentials.Password;
ValidationRules.CheckRules();
}
/// <summary>
/// EmailValidator.
/// Called by BusinessBase RulesEngine.
/// </summary>
public static bool EmailValidator<T>(T target, RuleArgs e) where T : Credentials
{
//Validate Email.
const string emailRegex = @"^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$";
if (Regex.IsMatch(target.Email, emailRegex)) { return true; }
else { e.Description = Resources.ValidationEmailMessage; }
return false;
}
#endregion
#region Event Handlers
/// <summary>
/// OnDeserialized Handler.
/// </summary>
[OnDeserialized()]
private void OnDeserializedHandler(StreamingContext context)
{
base.OnDeserialized(context);
//Execute business rules against each property
//when the item is deserialized.
//ValidationRules.SuppressRuleChecking = true;
ValidationRules.CheckRules();
}
#endregion
#region Base Class Overrides
/// <summary>
/// PropertyHasChanged event.
/// </summary>
/// <param name="propertyName">propertyName parameter</param>
protected override void PropertyHasChanged(string propertyName)
{
base.PropertyHasChanged(propertyName);
}
/// <summary>
/// Add Business Rules. Defines basic validation rules to execute against specified fields.
/// </summary>
protected override void AddBusinessRules()
{
//Email.
ValidationRules.AddRule(CommonRules.StringMaxLength, new CommonRules.MaxLengthRuleArgs(EmailProperty, 255));
ValidationRules.AddRule<Credentials>(EmailValidator, EmailProperty);
//Password
ValidationRules.AddRule(CommonRules.StringMaxLength, new CommonRules.MaxLengthRuleArgs(PasswordProperty, 255));
ValidationRules.AddRule(CommonRules.StringMinLength, new CommonRules.MinLengthRuleArgs(PasswordProperty, 6));
}
/// <summary>
/// Override for GetIdValue.
/// </summary>
protected override object GetIdValue()
{
return GetProperty(EmailProperty);
}
#endregion
#region IXmlSerializable Members
public XmlSchema GetSchema()
{
return null;
}
public void ReadXml(XmlReader reader)
{
Email = reader.GetAttribute(EmailProperty.Name);
UserID = reader.GetAttribute(UserIDProperty.Name);
Password = DPAPI.Decrypt(reader.GetAttribute(PasswordProperty.Name));
base.MarkOld();
}
public void WriteXml(XmlWriter writer)
{
writer.WriteAttributeString(EmailProperty.Name, Email);
writer.WriteAttributeString(UserIDProperty.Name, UserID);
writer.WriteAttributeString(PasswordProperty.Name, DPAPI.Encrypt(DPAPI.KeyType.UserKey, Password));
}
#endregion
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I've been working as a software developer since 2000 and hold a Bachelor of Business degree from The Open Polytechnic of New Zealand. Computers are for people and I aim to build applications for people that they would want to use.