Click here to Skip to main content
15,886,258 members
Articles / Desktop Programming / WPF

GoalBook - A Hybrid Smart Client

Rate me:
Please Sign up or sign in to vote.
4.86/5 (24 votes)
25 Sep 2009CPOL10 min read 79.1K   834   69  
A WPF hybrid smart client that synchronises your goals with the Toodledo online To-do service.
// <copyright file="FolderComparer.cs" company="GoalBook"> 
//    Copyright © 2009 Mark Brownsword. All rights reserved.
//    This source code and supporting files are licensed under The Code Project  
//    Open License (CPOL) as detailed at http://www.codeproject.com/info/cpol10.aspx. 
// </copyright>
namespace GoalBook.Infrastructure.Comparers
{
    using System;
    using System.Collections;
    using GoalBook.Infrastructure.ObjectModel;

    /// <summary>
    /// Folder Comparer.
    /// </summary>
    public class FolderComparer : IComparer
    {        
        /// <summary>
        /// Declaration for FolderList.
        /// </summary>
        private FolderList folders;

        /// <summary>
        /// Initializes a new instance of the FolderComparer class.
        /// </summary>
        /// <param name="folders">list of folders</param>
        public FolderComparer(FolderList folders)
        {
            this.folders = folders;
        }

        /// <summary>
        /// Compare implementation.
        /// </summary>
        /// <param name="x">x parameter</param>
        /// <param name="y">y parameter</param>
        /// <returns>        
        /// Value               Condition                
        /// Less than zero      x is less than y
        /// Zero                x equals y
        /// Greater than zero   x is greater than y
        /// </returns>
        public int Compare(object x, object y)
        {
            if (x == y)
            {
                return 0;
            }

            if (x == null)
            {
                return -1;
            }

            if (y == null)
            {
                return 1;
            }

            Folder t1 = this.GetFolder(x.ToString());
            Folder t2 = this.GetFolder(y.ToString());

            if (t1 == null)
            {
                return -1;
            }            
            else if (t2 == null)
            {
                return 1;
            }

            if (t1.Order < t2.Order)
            {
                return -1;
            }            
            else if (t1.Order > t2.Order)
            {
                return 1;
            }

            return 0;
        }
        
        /// <summary>
        /// Get Folder.
        /// </summary>
        /// <param name="title">title parameter</param>
        /// <returns>Folder instance</returns>
        private Folder GetFolder(string title)
        {
            foreach (Folder folder in this.folders)
            {
                if (folder.Title == title)
                {
                    return folder;
                }
            }

            return null;
        }            
    }
}

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)


Written By
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.

Comments and Discussions