CourseFileData.cs :  » Network-Clients » iReaper » IReaper » FileData » 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 » FileData » CourseFileData.cs
/*
 * 2006.6.29
 *  FileType setStorage.BasePath storage.BasePath
 * 
 */

using System;
using System.Runtime.Serialization;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Threading;
using System.IO;
using IReaper.CourseData;
using IReaper.Running;
using IReaper.Properties;

namespace IReaper.FileData{
    public delegate void FileDataStatueChangedEventHandler(CourseFileData Data);
    /// <summary>
    /// 
    /// </summary>
    public class CourseFileData
    {
        #region static
        public static event EventHandler RLChanged;
        public static event FileDataStatueChangedEventHandler StatueChanged;
        public static AsyncOperation async;
        /// <summary>
        /// async
        /// </summary>
        public static void InitlizeAsyncObject()
        {
            if (async == null)
            {
                async = AsyncOperationManager.CreateOperation("Global");
            }
        }

        /// <summary>
        /// CourseFile
        /// </summary>
        /// <param name="Data"></param>
        /// <returns></returns>
        public static bool IsCourseFileFinished(CourseFileData Data)
        {
            if (Data == null)
                return false;
            else if (Data.LifetimeStatue != LifetimePosition.DownloadProcessed)
                return false;
            //else if (!File.Exists(Data.FilePath))
            //    return false;
            return true;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="course"></param>
        /// <returns></returns>
        public static bool IsCourseFileAvailable(CourseFileData data)
        {
            if (data == null)//,
            {
                return false;
            }
            return true;
        }


        /// <summary>
        /// 
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public static bool IsCourseFileRunnable(CourseFileData data)
        {
            if (!IsCourseFileAvailable(data)) //
                return false;
            if (data.RunState != RunningStatue.Running && data.LifetimeStatue != LifetimePosition.DownloadProcessed)
                return true;
            else
                return false;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public static bool IsCourseFileRemovable(CourseFileData data)
        {
            return CourseFileData.IsCourseFileFinished(data);
        }

        /// <summary>
        /// CourseFileData
        /// CourseFileData
        /// True
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public static bool IsCourseFileExist(CourseFileData data)
        {
            if (!IsCourseFileAvailable(data))
                return false;
            if (string.IsNullOrEmpty(data.FileName))
                return false;
            try
            {
                if (File.Exists(data.FilePath))
                    return true;
                else
                    return false;
            }
            catch
            {
                return false;
            }
        }
        #endregion

        #region fields
        public CourseFileDataStorage Storage;
        SendOrPostCallback changeStatue;
        LifetimePosition tpLifetime;/* DownloadCreated
                                     * DownloadCreated
                                     * 
                                     */

        CourseFileWorker worker;
        Course course;
        string message;
        string filename;
        string remotepath;
        FileDataStatueWrapper statue;
        string rootpath;
        double speed;
        #endregion

        #region constructor
        /// <summary>
        /// 
        /// </summary>
        /// <param name="RelativeCourse"></param>
        public CourseFileData(Course RelativeCourse)
        {
            this.filename = null;
            this.remotepath = null;
            this.rootpath = null;
            
            this.Storage = new CourseFileDataStorage();
            this.Storage.Init(RelativeCourse.Id);
            this.Storage.Index = -1;//set the index as minus 1.
            this.course = RelativeCourse;
            if (course == null)//
                throw new ArgumentNullException();
            this.changeStatue = new SendOrPostCallback(OnStatueChange);
            this.tpLifetime = LifetimePosition.TaskCreated;
            statue = new FileDataStatueWrapper();
        }
        #endregion

        #region Attributes
        public double Speed
        {
            get { return speed; }
            set { speed = value; }
        }
        /// <summary>
        /// 
        /// </summary>
        public CourseFileWorker RunningWorker
        {
            set { worker = value; }
            get { return worker; }
        }

        public Course Owner
        {
            get { return course; }
        }

        /// <summary>
        /// 
        /// </summary>
        public string Message
        {
            get { return message; }
            set { this.message = value; }
        }

        /// <summary>
        /// The complete path of the local file
        /// </summary>
        public string FilePath
        {
            get 
            { 
                if(!string.IsNullOrEmpty(this.FileName))
                    return Path.Combine(this.RootPath,this.FileName);
                return string.Empty;
            }
        }

        /*
         * CourseFileData
         * 1. 
         *      RootPath
         * 2. 
         *      RootPath
         * 
         * 3. 
         *      
         */
        /// <summary>
        /// 
        /// </summary>
        public string RootPath
        {
            get
            {
                string stPath = Storage.RootPath;
                //1
                if (string.IsNullOrEmpty(stPath))
                {
                    Storage.RootPath = PathManager.Manager.GetRelativePath(this);
                }
                //21
                if (string.IsNullOrEmpty(this.rootpath))
                {
                    this.rootpath = Path.Combine(Settings.Default.RootPath, Storage.RootPath);   
                }
                //3
                return this.rootpath;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public string FileName
        {
            get 
            {
                if (string.IsNullOrEmpty(this.filename))
                {
                    this.filename = Storage.FileName;
                }
                return this.filename;
            }
            set
            {
                this.filename = value;
                Storage.FileName = value;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public string RemotePath
        {
            get 
            {
                if (string.IsNullOrEmpty(this.remotepath))
                {
                    this.remotepath = Storage.RemotePath;
                }
                return this.remotepath;
            }
            set 
            {
                this.remotepath = value;
                Storage.RemotePath = value;
                Storage.Flush();
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public long TotalSize
        {
            get { return Storage.Length; }
            set { Storage.Length = value;}
        }

        /// <summary>
        /// 
        /// </summary>
        public long ReadSize
        {
            get { return Storage.Read;}
            set { Storage.Read = value;}
        }

        /// <summary>
        /// ppt,video,code
        /// </summary>
        public FileType FileType
        {
            get { return Storage.Type; }
            set { Storage.Type = value; }
        }

        /// <summary>
        /// 
        /// </summary>
        public RunningStatue RunState
        {
            get { return Storage.RunState;}
            set 
            {
                Storage.RunState = value;
                this.FlushToScreen();
                if (RLChanged != null)
                {
                    RLChanged(this, EventArgs.Empty);
                }
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public FileDataStatueWrapper Statue
        {
            get
            {
                statue.position = this.LifetimeStatue;
                statue.runstatue = this.RunState;
                return this.statue;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public LifetimePosition LifetimeStatue
        {
            get 
            {
                if (tpLifetime == LifetimePosition.DownloadCreated)
                    return tpLifetime;
                else
                    return Storage.LifetimeStatue; 
            }
            set 
            {
                if (value == LifetimePosition.DownloadCreated)
                    tpLifetime = LifetimePosition.DownloadCreated;
                else
                {
                    Storage.LifetimeStatue = value;
                    tpLifetime = value;
                }
                this.FlushToScreen();
                if (RLChanged != null)
                {
                    RLChanged(this, EventArgs.Empty);
                }
            }
        }

        /// <summary>
        /// ()
        /// </summary>
        public float Percentage
        {
            get 
            {
                if (this.TotalSize == 0)
                    return 0;
                else 
                    return this.ReadSize * 100.0f / this.TotalSize; 
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public void FlushToScreen()
        {
            async.Post(this.changeStatue, null);
            //this.changeStatue(null);
        }

        /// <summary>
        /// Storage
        /// </summary>
        public void ReloadPathFromStorage()
        {
            //FileName
            this.filename = Storage.FileName;   
            //root Path
            this.rootpath = Path.Combine(Settings.Default.RootPath, Storage.RootPath);
        }

        #endregion

        private void OnStatueChange(object obj)
        {
            if (StatueChanged != null)
            { StatueChanged(this); }
        }
       
    }
    
    /// <summary>
    /// 
    /// </summary>
    public class FileDataStatueWrapper
    {
        public LifetimePosition position;
        public RunningStatue runstatue;
    }
    

    /// <summary>
    /// 
    /// </summary>
    public enum LifetimePosition:byte
    {
        TaskCreated = 0x0,//CourseFileData
        DownloadCreated = 0x01,//ServicePoint
        LocalFileCreated = 0x02,//
        Downloading = 0x03,//
        DownloadFinished = 0x04,//
        ExtensionChange = 0x05,//
        UnCompressing = 0x06,//
        DownloadProcessed = 0x07//
    }

    /// <summary>
    /// 
    /// </summary>
    public enum RunningStatue:byte
    { 
        Created = 0x0,
        RunRequest = 0x01,
        RunQueued = 0x02,
        Running = 0x03,
        StopRequest = 0x04,
        Stopped = 0x05,
        Error = 0x06,
        Finished = 0x07
    }


}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.