public void StartRestoration()
{
try
{
//holder of filenames and filestreams
ds.Clear();
DirectoryInfo diDB = new DirectoryInfo(DataBaseFolder);
DirectoryInfo diBP = new DirectoryInfo(BackupFolder);
if (!diDB.Exists)
diDB.Create();
if (!diBP.Exists)
diBP.Create();
long totalBackupFileLength = 0;
long processed = 0;
foreach (var file in diBP.GetFiles())
{
totalBackupFileLength += file.Length;
}
if (totalBackupFileLength == processed)
{
OnRestore(new BackupRestorationProcess()
{
ReadinessInProcent = 100,
Finished = true
});
return;
}
int readinessInProcent = Convert.ToInt32((processed * 100) / totalBackupFileLength);
int prevReadinessInProcent = 0;
OnRestore(new BackupRestorationProcess()
{
ReadinessInProcent = readinessInProcent,
Finished = false
});
byte[] readOut = new byte[100000];
int cnt = 0;
byte[] pack = null;
uint packSize = 0;
foreach (var file in diBP.GetFiles().Where(r => r.Name.StartsWith("dbreeze_ibp_")).OrderBy(r => r.Name))
{
using (var bfs = new FileStream(file.FullName, FileMode.Open, FileAccess.Read, FileShare.None))
{
while ((cnt = bfs.Read(readOut, 0, readOut.Length)) > 0)
{
processed += cnt;
readinessInProcent = Convert.ToInt32((processed * 100) / totalBackupFileLength);
pack = pack.Concat(readOut.Substring(0, cnt));
while (true)
{
if (pack == null || pack.Length < 4)
break;
packSize = pack.Substring(0, 4).To_UInt32_BigEndian();
if (pack.Length >= 4 + packSize)
{
this.DoPackage(pack.Substring(4, (int)packSize));
pack = pack.Substring(4 + (int)packSize);
}
else
break;
}
if (prevReadinessInProcent != readinessInProcent)
{
prevReadinessInProcent = readinessInProcent;
OnRestore(new BackupRestorationProcess()
{
ReadinessInProcent = readinessInProcent,
Finished = false
});
}
}
if (prevReadinessInProcent != readinessInProcent)
{
prevReadinessInProcent = readinessInProcent;
OnRestore(new BackupRestorationProcess()
{
ReadinessInProcent = readinessInProcent,
Finished = false
});
}
bfs.Dispose();
}
}
this.CloseHandels();
OnRestore(new BackupRestorationProcess()
{
ReadinessInProcent = 100,
Finished = true
});
}
catch (Exception ex)
{
throw ex;
}
}