CoursesCollection.cs :  » Network-Clients » iReaper » IReaper » CourseData » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Network Clients » iReaper 
iReaper » IReaper » CourseData » CoursesCollection.cs
/*
 * 2006.6.27
 *  getKeydList
 */
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.ComponentModel;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Runtime.CompilerServices;
using IReaper.FileData;
using IReaper;

namespace IReaper.CourseData{
    public delegate void NotifyBindingListItemRemoveEventHandler(int index);

    public class CourseCollection : SortableBindingList<Course>
    {
        public event NotifyBindingListItemRemoveEventHandler NotifyRemove;
        static TimeComparer compare = new TimeComparer();
        CourseCollectionType type;
        Dictionary<string, Course> dic;
        bool isAutoAdded;

        /// <summary>
        /// 
        /// </summary>
        public CourseCollection(CourseCollectionType Type)
        {
            dic = new Dictionary<string, Course>();
            type = Type;
            isAutoAdded = true;
            CourseFileData.StatueChanged += new FileDataStatueChangedEventHandler(CourseFileData_StatueChange);
            Course.OnCourseUpdated += new CourseUpdatedEventHandler(Course_OnCourseUpdated);
        }
       

        /// <summary>
        /// CourseID
        /// </summary>
        /// <returns></returns>
        public Dictionary<string, Course> KeydList
        {
            get { return dic; }
        }

        /// <summary>
        ///  (Common)(Completed)
        /// </summary>
        public CourseCollectionType Type
        {
            get { return type; }
            set { type = value; }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="course"></param>
        public new void Add(Course course)
        {
            if (this.Contains(course))
                return;
            dic.Add(course.Id, course);
            base.Add(course);
        }

        /// <summary>
        /// ID
        /// </summary>
        /// <param name="course"></param>
        /// <returns></returns>
        public new bool Contains(Course course)
        {
            if (base.Contains(course))
                return true;
            return dic.ContainsKey(course.Id);
        }

        /// <summary>
        /// CoursesCollection
        /// </summary>
        /// <returns></returns>
        public virtual CourseCollection GetTypedCoursesCollection()
        {
            CourseCollection courses = new CourseCollection(this.type);
            courses.isAutoAdded = false;
            return courses;
        }

        /// <summary>
        /// Course
        /// </summary>
        public new void Clear()
        {
            base.Clear();
            base.OnListChanged(new ListChangedEventArgs(ListChangedType.ItemDeleted,-1));
            if (this.dic != null)
                this.dic.Clear();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="index"></param>
        protected override void RemoveItem(int index)
        {
            if (NotifyRemove != null)
                NotifyRemove(index);
            Course c = this[index];
            dic.Remove(c.Id);
            base.RemoveItem(index);
        }

        [MethodImpl(MethodImplOptions.Synchronized)]
        private void Course_OnCourseUpdated(Course course)
        {
            int index = -1;
            if ((index = this.IndexOf(course)) >= 0)
            {
                this.ResetItem(index);
            }
        }

        /// <summary>
        /// CourseFileData
        /// </summary>
        /// <param name="Data"></param>
        [MethodImpl(MethodImplOptions.Synchronized)]
        private void CourseFileData_StatueChange(CourseFileData Data)
        {
            int index = this.IndexOf(Data.Owner);
            bool ppt, video, code, qa, wmv, mp3, mp4,completed, idle;
            ppt = CourseFileData.IsCourseFileFinished(Data.Owner.PPT);
            video = CourseFileData.IsCourseFileFinished(Data.Owner.Video);
            code = CourseFileData.IsCourseFileFinished(Data.Owner.Code);
            qa = CourseFileData.IsCourseFileFinished(Data.Owner.QA);
            wmv = CourseFileData.IsCourseFileFinished(Data.Owner.WMV);
            mp3 = CourseFileData.IsCourseFileFinished(Data.Owner.MP3);
            mp4 = CourseFileData.IsCourseFileFinished(Data.Owner.MP4);
            completed = CourseFileData.IsCourseFileFinished(Data);
            idle = Data.RunState == RunningStatue.Created;
            if (index >= 0)//
            {
                if (!ppt && !video && !code && !qa && !mp3 && !mp4 && !wmv && type == CourseCollectionType.Completed) //
                {
                    this.RemoveItem(index);
                    return;
                }
                //
                else if (completed || idle)//
                {
                    this.ResetItem(index);
                    return;
                }
            }
            else if (isAutoAdded && completed && type == CourseCollectionType.Completed)
            {
                this.Add(Data.Owner);//
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public void SortByTime()
        {
            List<Course> list = this.Items as List<Course>;
            list.Sort(compare);
            base.OnListChanged(new ListChangedEventArgs(ListChangedType.Reset,-1));
        }
    }

    class TimeComparer : IComparer<Course>
    {
        #region IComparer<Course> 

        public int Compare(Course x, Course y)
        {
            if (x.Time < y.Time)
                return 1;
            else if (x.Time == y.Time)
                return 0;
            else
                return -1;
        }
        #endregion
    }

    /// <summary>
    /// CourseCollection
    /// CourseCollection
    /// 
    /// </summary>
    public enum CourseCollectionType
    {
        /// <summary>
        /// 
        /// </summary>
        Completed,
        /// <summary>
        /// 
        /// </summary>
        Common,
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.