CourseFileDataStorage.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 » CourseFileDataStorage.cs
using System;
using System.Runtime.InteropServices;
using System.Collections.Generic;
using System.Text;
using System.IO;
using Microsoft.Win32.SafeHandles;
using System.Threading;
using IReaper;
using IReaper.Running;
using IReaper.CourseData;
using IReaper.Properties;

namespace IReaper.FileData{

    /// <summary>
    /// 
    /// </summary>
    [StructLayout(LayoutKind.Sequential, Pack = 4)]
    public unsafe struct CourseFileDataStorage
    {
        public void Init(string courseId)
        {
            ID = courseId;
            RunState = RunningStatue.Created;
            LifetimeStatue = LifetimePosition.TaskCreated;
        }
        #region Fields
        /// <summary>
        /// ID
        /// </summary>
        fixed char id[16];
        /// <summary>
        /// 
        /// </summary>
        long length;
        /// <summary>
        /// 
        /// </summary>
        long read;
        /// <summary>
        /// 
        /// </summary>
        long index;
        /// <summary>
        /// NTFS261
        /// </summary>
        fixed char rootpath[261];
        /// <summary>
        /// 
        /// </summary>
        fixed char filename[256];
        /// <summary>
        /// 
        /// </summary>
        fixed char url[512];
        /// <summary>
        /// 
        /// </summary>
        byte type;
        /// <summary>
        /// 
        /// </summary>
        byte runstate;
        /// <summary>
        /// 
        /// </summary>
        byte lifetime;
        #endregion

        #region Attributes
        /// <summary>
        /// ID
        /// </summary>
        public string ID
        {
            get
            {
                fixed (char* tpID = id)
                {
                    return new string(tpID);
                }
            }
            set
            {
                fixed (char* tpID = id)
                {
                    Utils.StringCopy(tpID, 16, value);
                }
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public long Length
        {
            get { return length; }
            set
            {
                length = value;
                this.Flush();
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public long Read
        {
            get { return read; }
            set
            {
                read = value;
                this.Flush();
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public long Index
        {
            get { return index; }
            set { index = value; }
        }

        /// <summary>
        /// 
        /// </summary>
        public string RootPath
        {
            get
            {
                string path = null;
                //2006.6.29 
                fixed (char* tpPath = rootpath)
                {
                    path = new string(tpPath);
                }
                return path;
            }
            set
            {
                fixed (char* tpPath = rootpath)
                {
                    Utils.StringCopy(tpPath, 261, value);
                }
                this.Flush();
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public string FileName
        {
            get
            {
                fixed (char* tpName = filename)
                {
                    return new string(tpName);
                }
            }
            set
            {
                
                fixed (char* tpName = filename)
                {
                    Utils.StringCopy(tpName, 256, value);
                }
                this.Flush();
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public string FilePath
        {
            get { return System.IO.Path.Combine(this.RootPath, this.FileName); }
        }

        public string RemotePath
        {
            get
            {
                fixed (char* tpurl = url)
                {
                    return new string(tpurl);
                }
            }
            set
            {
                fixed (char* tpurl = url)
                {
                    Utils.StringCopy(tpurl, 512, value);
                }
            }
        }
        /// <summary>
        /// PPT,Video,Code
        /// </summary>
        public FileType Type
        {
            get
            {
                return (FileType)this.type;
            }
            set
            {
                this.type = (byte)value;
                this.Flush();
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public RunningStatue RunState
        {
            get{ return (RunningStatue)this.runstate;}
            set
            {
                this.runstate = (byte)value;
                this.Flush();
            }
        }
        /// <summary>
        /// 
        /// </summary>
        public LifetimePosition LifetimeStatue
        {
            get
            {
                return (LifetimePosition)this.lifetime;
            }
            set
            {
                this.lifetime = (byte)value;
                this.Flush();
            }

      
        }
        /// <summary>
        /// 
        /// </summary>
        public void Flush()
        {
            CourseFileDataManager.UpdateCourseFileDataStorage(this);
        }

        #endregion

        #region static
      

        /// <summary>
        /// CourseFileDataStoragebyte[]
        /// </summary>
        /// <param name="source"></param>
        /// <param name="destination"></param>
        internal unsafe static void Copy(CourseFileDataStorage* source, ref byte[] destination)
        {
            if (destination == null || destination.Length != sizeof(CourseFileDataStorage))
                throw new ApplicationException();
            fixed (byte* buffer = &(destination[0]))
            {
                CourseFileDataStorage* des = (CourseFileDataStorage*)buffer;
                *des = *source;
            }
            
            //byte* src = (byte*)source->id;
            //for (int i = 0; i < destination.Length; i++)
            //{
            //    destination[i] = *src;
            //    src++;
            //}
            //return;
        }

        /// <summary>
        /// CourseFileDataStoragebyte[]
        /// </summary>
        /// <param name="source"></param>
        /// <param name="destination"></param>
        internal unsafe static void Copy(byte[] source, CourseFileDataStorage * destination)
        {
            if (source == null || source.Length != sizeof(CourseFileDataStorage))
                throw new ApplicationException();
            fixed (byte* buffer = &(source[0]))
            {
                CourseFileDataStorage* src = (CourseFileDataStorage*)buffer;
                *destination = *src;
            }
        }

        static CourseFileDataStorage empty = new CourseFileDataStorage();
        /// <summary>
        /// CourseFileDataStorage
        /// </summary>
        internal static CourseFileDataStorage Empty
        {
            get { return empty; }
        }
        #endregion

        #region override
        /// <summary>
        /// CourseFileDataStorage
        /// ID
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public override bool Equals(object obj)
        {
            CourseFileDataStorage Storage1 = (CourseFileDataStorage)obj;
            if (Storage1.ID == this.ID &&
                Storage1.Type == this.Type)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// CourseFileDataStorageHashCodeID.GetHashCode() ^ Type.GetHashCode()
        /// </summary>
        /// <returns></returns>
        public override int GetHashCode()
        {
            return this.ID.GetHashCode() << this.Type.GetHashCode();
        }
        #endregion
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.