代码改变世界

继续学习IReaper(3)

2011-07-24 23:16  symphony2010  阅读(150)  评论(0编辑  收藏  举报

在GlobalInit()这个函数里:

   1: private static void GlobalInit()
   2:        {
   3:            LocalAppFolder = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "iReaper");
   4:            Control.CheckForIllegalCrossThreadCalls = false;
   5:            //init browser
   7:            //check for upgrade
   6:            IReaper.CommonGui.ButtonStatuMonitor.Init();
   8:            if (Properties.Settings.Default.CallUpgrade)
   9:            {
  10:                Settings.Default.Upgrade();
  11:                Settings.Default.CallUpgrade = false;
  12:                Settings.Default.Save();
  13:            }
  14:            //create runningCourseFile
  15:            Core.CoreData[CoreDataType.CurrentViewedFiles] = new FileData.RunningCourseFileDataCollection(true);//得先搞清后面这个类
  16:            //ToolStripManager.Renderer = new iReaperToolStripRender();
  17:            IReaper.Utils.SetCulture(Application.CurrentCulture);
  18:           
  19:  
  20:        }

Control.CheckForIllegalCrossThreadCalls,比较有用,往往在我们需要在另一个线程调用Windows控件时,避免对编译安全的错误提示.

剩下的:if语句块暂时先放一放.下面来看:new FileData.RunningCourseFileDataCollection这个类:

 

   1: public class RunningCourseFileDataCollection : CourseFileDataCollection
   2:    {
   3:        #region static region
   4:  
   5:        #endregion
   6:  
   7:        bool _isHook;
   8:        /// <summary>
   9:        /// 
  10:        /// </summary>
  11:        /// <param name="isHook">是否邦定</param>
  12:        public RunningCourseFileDataCollection(bool isHook)
  13:            : base()
  14:        {
  15:            if (!isHook)
  16:            {
  17:                this.RemoveHook();
  18:            }
  19:            this._isHook = isHook;
  20:  
  21:        }
  22:  
  23:        /// <summary>
  24:        /// 根据下载运行体状态的变化,将非创建的,结束的数据都加进来
  25:        /// </summary>
  26:        /// <param name="Data"></param>
  27:        [MethodImpl(MethodImplOptions.Synchronized)]
  28:        protected override void CourseFileData_StatueChange(CourseFileData Data)
  29:        {
  30:            int index = -1;
  31:            if (Data.RunState == RunningStatue.Created ||
  32:                Data.RunState == RunningStatue.Finished)
  33:            {
  34:                lock (this)//删除对象需要上锁
  35:                {
  36:                    if (this.Contains(Data))
  37:                    {
  38:                        this.Remove(Data);
  39:                    }
  40:                }
  41:            }
  42:            else if ((index = this.IndexOf(Data)) >= 0)
  43:            {
  44:                this.ResetItem(index);
  45:            }
  46:            else if (Data.RunState == RunningStatue.RunRequest ||
  47:                    Data.RunState == RunningStatue.Running)
  48:            {
  49:                this.Add(Data);
  50:                this.ResetItem(this.Count - 1);
  51:            }
  52:        }
  53:        /// <summary>
  54:        /// <seealso cref="BindingList"/>
  55:        /// </summary>
  56:        /// <param name="Data"></param>
  57:        public new void Add(CourseFileData Data)
  58:        {
  59:            if (this.Contains(Data))
  60:            {
  61:                return;
  62:            }
  63:            base.Add(Data);
  64:        }
  65:    }

 

CourseFileData为 用来存储某个文件所代表的数据,将支持下载初始化、开始下载、暂停、启动、结束、运行完成任务等功能的数据 .

继续学习之前,我想把事件的使用方法在分析一下.

事件本身是代理的实例化(微软提供的例子)

分析后明白事件的声明其实在调用者本身,事件的处理是在另一个类里.能否在同一个类里呢?我觉得也可以

显然这么做没什么意义.实现代理是为了更方便的编写程序.