private void DoPackage(byte[] pack)
{
ulong fileNumber = pack.Substring(0, 8).To_UInt64_BigEndian();
byte type = pack.Substring(8, 1)[0];
string filename = BackupFNP.ParseFilenameBack(fileNumber);
long offset = 0;
byte[] data = null;
//Console.WriteLine("t: {0}", type);
//types description
// 0 - table file, 1 - rollback file, 2 - rollbackhelper, 3 - recreate table file (only table file), 4 - recreate rollback file (only rollback file), 5 - removing complete table
FileStream lfs = null;
bool contains = false;
string tfn = String.Empty;
switch (type)
{
case 0:
//Write into table file
lfs = this.GetFileStream(filename);
//if (lfs == null)
//{
// Console.WriteLine("Backup lfs = null");
// return;
//}
offset = pack.Substring(9, 8).To_Int64_BigEndian();
data = pack.Substring(17);
lfs.Position = offset;
lfs.Write(data, 0, data.Length);
lfs.Flush();
break;
case 1:
//write into rollback file
lfs = this.GetFileStream(filename + ".rol");
if (lfs == null)
{
System.Diagnostics.Debug.WriteLine("Backup lfs = null");
return;
}
offset = pack.Substring(9, 8).To_Int64_BigEndian();
data = pack.Substring(17);
lfs.Position = offset;
lfs.Write(data, 0, data.Length);
lfs.Flush();
break;
case 2:
//write into rollbackhelper
lfs = this.GetFileStream(filename + ".rhp");
if (lfs == null)
{
System.Diagnostics.Debug.WriteLine("Backup lfs = null");
return;
}
offset = pack.Substring(9, 8).To_Int64_BigEndian();
data = pack.Substring(17);
lfs.Position = offset;
lfs.Write(data, 0, data.Length);
lfs.Flush();
break;
case 3:
//3 - recreate table file (only table file)
contains = ds.ContainsKey(filename);
if (contains)
{
ds[filename].Dispose();
}
tfn = Path.Combine(this.DataBaseFolder, filename);
File.Delete(tfn);
if (!contains)
ds.Add(filename, null);
ds[filename] = new FileStream(tfn, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None);
break;
case 4:
//4 - recreate rollback file (only rollback file)
contains = ds.ContainsKey(filename + ".rol");
if (contains)
{
ds[filename + ".rol"].Dispose();
}
tfn = Path.Combine(this.DataBaseFolder, filename + ".rol");
File.Delete(tfn);
if (!contains)
ds.Add(filename + ".rol", null);
ds[filename + ".rol"] = new FileStream(tfn, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None);
break;
case 5:
//5 - removing complete table
if (ds.ContainsKey(filename))
{
ds[filename].Dispose();
}
ds.Remove(filename);
if (ds.ContainsKey(filename + ".rol"))
{
ds[filename + ".rol"].Dispose();
}
ds.Remove(filename + ".rol");
if (ds.ContainsKey(filename + ".rhp"))
{
ds[filename + ".rhp"].Dispose();
}
ds.Remove(filename + ".rhp");
break;
}
}