Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

GoalBook - A Hybrid Smart Client

, 25 Sep 2009 CPOL
A WPF hybrid smart client that synchronises your goals with the Toodledo online To-do service.
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
CheckedList
vssver2.scc
Properties
vssver2.scc
vssver2.scc
GoalBook.Goals
GoalBook.Goals.csproj.user
Properties
vssver2.scc
Views
vssver2.scc
vssver2.scc
GoalBook.Infrastructure
Comparers
vssver2.scc
Constants
vssver2.scc
Controls
Converters
vssver2.scc
Enums
vssver2.scc
Events
vssver2.scc
GoalBook.Infrastructure.csproj.user
Helpers
vssver2.scc
Interfaces
vssver2.scc
ObjectModel
vssver2.scc
Printing
vssver2.scc
Properties
vssver2.scc
vssver2.scc
GoalBook.Notes
GoalBook.Notes.csproj.user
Properties
vssver2.scc
Resources
arrow_redo.png
arrow_undo.png
cut.png
page_copy.png
paste_plain.png
text_bold.png
text_indent.png
text_indent_remove.png
text_italic.png
text_list_bullets.png
text_list_numbers.png
vssver2.scc
world_link.png
Views
vssver2.scc
vssver2.scc
GoalBook.Public
Encryption
vssver2.scc
HtmlConverter
vssver2.scc
HtmlParser
vssver2.scc
Misc
vssver2.scc
Properties
vssver2.scc
vssver2.scc
GoalBook.Shell
App.ico
Commands
vssver2.scc
GoalBook.Shell.csproj.user
Journal.ico
Journal48.ico
Misc
vssver2.scc
Modules
vssver2.scc
Properties
licenses.licx
vssver2.scc
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
vssver2.scc
Splash.png
Views
vssver2.scc
vssver2.scc
Windows
vssver2.scc
GoalBook.snk
GoalBook.Synchronisation
Events
vssver2.scc
Properties
vssver2.scc
ToodleDo
vssver2.scc
vssver2.scc
GoalBook.Tasks
Controls
vssver2.scc
Properties
vssver2.scc
Views
vssver2.scc
vssver2.scc
vssver2.scc
//===============================================================================
// Goal Book.
// Copyright © 2009 Mark Brownsword. 
//===============================================================================

#region Using Statements
using System;
using System.Runtime.Serialization;
using System.Xml;
using System.Xml.Schema;
using System.Xml.Serialization;
using Csla;
using Csla.Validation;
using GoalBook.Infrastructure.Properties;
#endregion

namespace GoalBook.Infrastructure
{
    /// <summary>
    /// Proxy type.
    /// </summary>
    [Serializable]
    public class Proxy : BusinessBase<Proxy>, 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 Proxy()
        {
            MarkAsChild();

            ValidationRules.CheckRules();
        }
        /// <summary>
        /// Constructor.
        /// </summary>        
        public Proxy(string host, string port, bool enabled)
            : this()
        {
            Host = host;
            Port = port;
            Enabled = enabled;
            
            base.MarkOld();
        }
        #endregion

        #region Properties
        private static PropertyInfo<string> hostProperty = RegisterProperty(typeof(Proxy), new PropertyInfo<string>("Host"));
        private static PropertyInfo<string> portProperty = RegisterProperty(typeof(Proxy), new PropertyInfo<string>("Port"));
        private static PropertyInfo<bool> enabledProperty = RegisterProperty(typeof(Proxy), new PropertyInfo<bool>("Enabled"));

        /// <summary>
        /// Reference to Host.
        /// </summary>
        public string Host
        {
            get
            {
                CanReadProperty(hostProperty.Name, true);
                return GetProperty(hostProperty);
            }
            set
            {
                CanWriteProperty(hostProperty.Name, true);
                if (!GetProperty(hostProperty).Equals(value))
                {
                    SetProperty(hostProperty, value);
                    PropertyHasChanged(hostProperty.Name);
                }
            }
        }
        /// <summary>
        /// Reference to Port.
        /// </summary>
        public string Port
        {
            get
            {
                CanReadProperty(portProperty.Name, true);
                return GetProperty(portProperty);
            }
            set
            {
                CanWriteProperty(portProperty.Name, true);
                if (!GetProperty(portProperty).Equals(value))
                {
                    SetProperty(portProperty, value);
                    PropertyHasChanged(portProperty.Name);
                }
            }
        }
        /// <summary>
        /// Reference to Enabled.
        /// </summary>
        public bool Enabled
        {
            get
            {
                CanReadProperty(enabledProperty.Name, true);
                return GetProperty(enabledProperty);
            }
            set
            {
                CanWriteProperty(enabledProperty.Name, true);
                if (!GetProperty(enabledProperty).Equals(value))
                {
                    SetProperty(enabledProperty, value);
                    if (value.Equals(false))                    
                    {
                        SetProperty(hostProperty, string.Empty);
                        SetProperty(portProperty, 0);
                    }
                    ValidationRules.CheckRules();
                    PropertyHasChanged(enabledProperty.Name);
                }
            }
        }
        #endregion

        #region Private and Protected Methods
        
        private static bool IsValidPortNumber(string input)
        {            
            ushort result = 0;
            if (ushort.TryParse(input, out result))
            {
                if (result >= 1024 && result <= 65535)
                {
                    return true;
                }
            }
           
            return false;
        }

        #endregion

        #region Public and internal Methods
        /// <summary>
        /// MapFields. 
        /// </summary>        
        public void MapFields(Proxy proxy)
        {
            this.Host = proxy.Host;
            this.Port = proxy.Port;
            this.Enabled = proxy.Enabled;
            
            ValidationRules.CheckRules();
        }
        /// <summary>
        /// HostValidator.
        /// Called by BusinessBase RulesEngine.
        /// </summary>        
        public static bool HostValidator<T>(T target, RuleArgs e) where T : Proxy
        {
            if (target.Enabled)
            {                
                if (!string.IsNullOrEmpty(target.Host)) { return true; }
                else { e.Description = Resources.ValidationHostMessage; }
            }
            else
            {
                return true;
            }

            return false;
        }
        /// <summary>
        /// PortValidator.
        /// Called by BusinessBase RulesEngine.
        /// </summary>        
        public static bool PortValidator<T>(T target, RuleArgs e) where T : Proxy
        {
            if (target.Enabled)
            {                
                if (IsValidPortNumber(target.Port)) { return true; }
                else { e.Description = Resources.ValidationPortMessage; }
            }
            else
            {
                return true;
            }

            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>
        /// Add Business Rules. Defines basic validation rules to execute against specified fields.         
        /// </summary>
        protected override void AddBusinessRules()
        {
            //Host
            ValidationRules.AddRule(CommonRules.StringMaxLength, new CommonRules.MaxLengthRuleArgs(hostProperty, 255));
            ValidationRules.AddRule<Proxy>(HostValidator, hostProperty);

            //Port
            ValidationRules.AddRule(CommonRules.StringMaxLength, new CommonRules.MaxLengthRuleArgs(portProperty, 5));
            ValidationRules.AddRule<Proxy>(PortValidator, portProperty);
        }
        /// <summary>
        /// Override for GetIdValue.
        /// </summary>        
        protected override object GetIdValue()
        {
            return GetProperty(hostProperty);
        }
        #endregion

        #region IXmlSerializable Members
        public XmlSchema GetSchema()
        {
            return null;
        }
        public void ReadXml(XmlReader reader)
        {            
            Host = reader.GetAttribute(hostProperty.Name);
            Port = reader.GetAttribute(portProperty.Name);            
            bool enabled = false;
            if (bool.TryParse(reader.GetAttribute(enabledProperty.Name), out enabled))
            {
                Enabled = enabled;
            }

            base.MarkOld();
        }
        public void WriteXml(XmlWriter writer)
        {            
            writer.WriteAttributeString(hostProperty.Name, Host);
            writer.WriteAttributeString(portProperty.Name, Port);
            writer.WriteAttributeString(enabledProperty.Name, Enabled.ToString());
        }
        #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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Mark Brownsword
Software Developer (Senior)
Australia Australia
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.

| Advertise | Privacy | Mobile
Web03 | 2.8.141022.2 | Last Updated 25 Sep 2009
Article Copyright 2009 by Mark Brownsword
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid