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
}
}
|