Пример #1
0
 /// <summary>
 /// 读取
 /// </summary>
 public static void Read(DatabaseEntity model)
 {
     model.MasterFile.Database = model;
     //读主文件
     DataFileManage.Read(model.MasterFile);
     //读数据库信息
     DataPageEntity modelD = new DataPageEntity { DataFile = model.MasterFile, ID = Config.DATABASE_PAGE_ID };
     DataPageManage.Read(modelD);
     model.FromBytes(modelD.Content);
 }
Пример #2
0
 /// <summary>
 /// 删除
 /// </summary>
 public static void Delete(DataColumnEntity modelDC)
 {
     //清空列的内容页
     long ContentPageID = modelDC.ContentPageID;
     while (ContentPageID > 0)
     {
         DataPageEntity modelDP = new DataPageEntity { DataFile = modelDC.Table.DataFile, ID = ContentPageID };
         ContentPageID = DataContentManage.ReadNextPageID(modelDP);
         DataPageManage.Clear(modelDP);
     }
     modelDC.ColumnPage.Columns.Remove(modelDC);
     modelDC.Table.UserColumns.Remove(modelDC);
     modelDC.ColumnPage.DataPage.Content = modelDC.ColumnPage.ToBytes();
     DataPageManage.Write(modelDC.ColumnPage.DataPage);
     modelDC = null;
 }
Пример #3
0
 /// <summary>
 /// 创建文件
 /// </summary>
 public static void Create(DataFileEntity model)
 {
     FileStream fs = new FileStream(model.FilePath, FileMode.CreateNew);
     model.FileStream = fs;
     model.MaxPageID = 2;
     //写入0页
     DataPageManage.Write(new DataPageEntity { DataFile = model, ID = Config.DATABASE_PAGE_ID, Content = model.Database.ToBytes() });
     //写入1页
     DataPageManage.Write(new DataPageEntity { DataFile = model, ID = Config.DATAFILE_PAGE_ID, Content = model.ToBytes() });
     //写入2页
     TablePageEntity modelTP = new TablePageEntity { Tables = new List<DataTable.DataTableEntity>() };
     DataPageEntity modelDP= new DataPageEntity { DataFile = model, ID = Config.DATATABLE_PAGE_ID, Content = modelTP.ToBytes() };
     DataPageManage.Write(modelDP);
     //赋值
     modelTP.DataPage = modelDP;
     model.TablePage = modelTP;
 }
Пример #4
0
 /// <summary>
 /// 创建
 /// </summary>
 public static void Create(DatabaseEntity modelD,DataTableEntity modelDT)
 {
     modelDT.TablePage = modelD.MasterFile.TablePage;
     modelDT.ID = modelD.Tables.Count == 0 ? 1 : modelD.Tables.Max(info => info.ID) + 1;
     //列信息编号
     modelDT.ColumnPageID = DataFileManage.GetEmptyPageID(modelD.MasterFile);
     //写入表
     modelDT.TablePage.Tables.Add(modelDT);
     modelDT.TablePage.DataPage.Content = modelDT.TablePage.ToBytes();
     DataPageManage.Write(modelDT.TablePage.DataPage);
     //创建列分页
     ColumnPageEntity modelCP = new ColumnPageEntity { Columns = new List<DataColumnEntity>(),  Table = modelDT };
     DataPageEntity modelDP = new DataPageEntity { DataFile = modelD.MasterFile, ID = modelDT.ColumnPageID ,Content = modelCP.ToBytes()};
     DataPageManage.Write(modelDP);
     //赋值
     modelCP.DataPage = modelDP;
     modelDT.ColumnPage = modelCP;
     modelDT.UserColumns = new List<DataColumnEntity>();
     //创建系统列
     DataColumnEntity modelDC = new DataColumnEntity { Name = EColumnType.RowIndex.ToString(), Type = EColumnType.RowIndex, DataType = EContentType.Byte, DataLength = Config.ROWINDEX_LENGTH };
     DataColumnManage.Create(modelDT, modelDC);
 }
Пример #5
0
 /// <summary>
 /// 写下一页编号
 /// </summary>
 /// <param name="modelDP"></param>
 /// <returns></returns>
 public static void WriteNextPageID(DataPageEntity modelDP, long NextPageID)
 {
     modelDP.Content = BitConverter.GetBytes(NextPageID);
     DataPageManage.Write(modelDP, ContentPageEntity.NEXTPAGEID_START, sizeof(Int64));
 }
Пример #6
0
 /// <summary>
 /// 读取下一页编号
 /// </summary>
 /// <param name="modelDP"></param>
 /// <returns></returns>
 public static long ReadNextPageID(DataPageEntity modelDP)
 {
     DataPageManage.Read(modelDP, ContentPageEntity.NEXTPAGEID_START, sizeof(Int64));
     return BitConverter.ToInt64(modelDP.Content, 0);
 }
Пример #7
0
 /// <summary>
 /// 读取内容页
 /// </summary>
 /// <param name="modelDP"></param>
 /// <returns></returns>
 public static ContentPageEntity ReadContentPage(DataPageEntity modelDP,ContentPageEntity modelCP)
 {
     DataPageManage.Read(modelDP);
     modelCP.DataPage = modelDP;
     modelCP.FromBytes(modelDP.Content);
     modelDP.Content = null;
     return modelCP;
 }
Пример #8
0
 /// <summary>
 /// 新建内容页
 /// </summary>
 /// <param name="modelDC">所在列</param>
 /// <param name="PageID">前一页页编号</param>
 /// <param name="PageIndex">页号</param>
 /// <returns></returns>
 public static ContentPageEntity NewContentPage(DataColumnEntity modelDC, long PageID, int PageIndex)
 {
     long NextPageID = DataFileManage.GetEmptyPageID(modelDC.Table.DataFile);
     //修改前一页
     WriteNextPageID(new DataPageEntity { DataFile = modelDC.Table.DataFile, ID = PageID }, NextPageID);
     //创建数据分页
     byte[] array = new byte[Config.PAGE_SIZE];
     array[0] = Convert.ToByte(EPageType.DataContent);
     DataPageEntity modelDP = new DataPageEntity { DataFile = modelDC.Table.DataFile, ID = NextPageID, Content = array };
     DataPageManage.Write(modelDP);
     modelDP.Content = null;
     //创建实体
     ContentPageEntity modelCP = new ContentPageEntity { Column = modelDC, DataPage=modelDP, PageIndex = PageIndex, Contents = new List<DataContentEntity>() };
     return modelCP;
 }
Пример #9
0
 /// <summary>
 /// 读文件
 /// </summary>
 /// <param name="modelDF"></param>
 public static void Read(DataFileEntity model)
 {
     model.FileStream = new FileStream(model.FilePath, FileMode.Open);
     //读文件信息
     DataPageEntity modelDP = new DataPageEntity { DataFile = model, ID = Config.DATAFILE_PAGE_ID };
     DataPageManage.Read(modelDP);
     model.FromBytes(modelDP.Content);
     //读表信息
     DataPageEntity modelDPT = new DataPageEntity { DataFile = model, ID = Config.DATATABLE_PAGE_ID };
     DataPageManage.Read(modelDPT);
     model.TablePage = new TablePageEntity();
     model.TablePage.DataPage = modelDPT;
     model.TablePage.FromBytes(modelDPT.Content);
     //读取列
     foreach (DataTableEntity modelDT in model.TablePage.Tables)
     {
         DataPageEntity modelDPTemp = new DataPageEntity { DataFile = model, ID = modelDT.ColumnPageID };
         DataPageManage.Read(modelDPTemp);
         modelDT.ColumnPage = new ColumnPageEntity();
         modelDT.ColumnPage.DataPage = modelDPTemp;
         modelDT.ColumnPage.Table = modelDT;
         modelDT.ColumnPage.FromBytes(modelDPTemp.Content);
         //表用户列
         modelDT.UserColumns = new List<DataColumnEntity>();
         modelDT.UserColumns.AddRange(modelDT.ColumnPage.Columns.Where(info => info.Type == EColumnType.User));
     }
 }
Пример #10
0
 /// <summary>
 /// 写入
 /// </summary>
 /// <param name="model">页实体</param>
 /// <param name="start">页中起始位置</param>
 /// <param name="length">长度</param>
 public static void Write(DataPageEntity model,int start=0, int length=Config.PAGE_SIZE)
 {
     model.DataFile.FileStream.Seek(model.ID * Config.PAGE_SIZE + start, SeekOrigin.Begin);
     model.DataFile.FileStream.Write(model.Content, 0, length);
 }
Пример #11
0
 /// <summary>
 /// 清空页
 /// </summary>
 /// <param name="model"></param>
 public static void Clear(DataPageEntity model)
 {
     model.Content = new byte[] { Convert.ToByte(EPageType.Empty) };
     Write(model, 0, 1);
 }
Пример #12
0
 /// <summary>
 /// 修改
 /// </summary>
 public static void Update(DataColumnEntity modelDC,DataColumnEntity newDC)
 {
     if (modelDC.DataLength!= newDC.DataLength || modelDC.DataType!=newDC.DataType)//改变列类型或长度
     {
         List<DataContentEntity> listDC = DataContentManage.Read(modelDC, info => true);
         //清空列的内容页
         long ContentPageID = modelDC.ContentPageID;
         while (ContentPageID > 0)
         {
             DataPageEntity modelDP = new DataPageEntity { DataFile = modelDC.Table.DataFile, ID = ContentPageID };
             ContentPageID = DataContentManage.ReadNextPageID(modelDP);
             DataPageManage.Clear(modelDP);
         }
         //创建数据分页
         byte[] array = new byte[Config.PAGE_SIZE];
         array[0] = Convert.ToByte(EPageType.DataContent);
         DataPageManage.Write(new DataPageEntity { DataFile = modelDC.Table.DataFile, ID = modelDC.ContentPageID, Content = array });
         //改变列
         modelDC.Name = newDC.Name;
         modelDC.DataType = newDC.DataType;
         modelDC.DataLength = newDC.DataLength;
         modelDC.ColumnPage.DataPage.Content = modelDC.ColumnPage.ToBytes();
         DataPageManage.Write(modelDC.ColumnPage.DataPage);
         //写入数据
         for (int i = 0; i < listDC.Count; i++)
         {
             DataContentManage.Create(modelDC, listDC[i], i);
         }
     }
     else if (modelDC.Name != newDC.Name)//只改变列名
     {
         modelDC.Name = newDC.Name;
         modelDC.ColumnPage.DataPage.Content = modelDC.ColumnPage.ToBytes();
         DataPageManage.Write(modelDC.ColumnPage.DataPage);
     }
 }