Merge pull request #386 from wangcai0124/VolumeDockerFileWindowsRS5
Handle the case that dataFile content is empty or non-number
This commit is contained in:
Коммит
caf39e7788
|
@ -27,17 +27,38 @@ namespace AzureFilesVolumeTestApp
|
||||||
Directory.CreateDirectory(dataFolderFullPath);
|
Directory.CreateDirectory(dataFolderFullPath);
|
||||||
|
|
||||||
var dataFileFullPath = Path.Combine(dataFolderFullPath, DataFileName);
|
var dataFileFullPath = Path.Combine(dataFolderFullPath, DataFileName);
|
||||||
|
var sequenceNumber = 0;
|
||||||
|
string fileContent = "";
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (File.Exists(dataFileFullPath))
|
||||||
|
{
|
||||||
|
// The content may be empty or non-number, catch the exception to avoid crash
|
||||||
|
fileContent = File.ReadAllText(dataFileFullPath);
|
||||||
|
sequenceNumber = Int32.Parse(fileContent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Exception {e.ToString()}");
|
||||||
|
Console.WriteLine($"Invalid file content {fileContent}");
|
||||||
|
}
|
||||||
|
|
||||||
var sequenceNumber = File.Exists(dataFileFullPath) ? Int32.Parse(File.ReadAllText(dataFileFullPath)) : 0;
|
|
||||||
for(;;)
|
for(;;)
|
||||||
{
|
{
|
||||||
sequenceNumber++;
|
sequenceNumber++;
|
||||||
|
try
|
||||||
using (var file = new FileStream(dataFileFullPath, FileMode.OpenOrCreate, FileAccess.Write))
|
|
||||||
{
|
{
|
||||||
var bytes = Encoding.ASCII.GetBytes(sequenceNumber.ToString());
|
using (var file = new FileStream(dataFileFullPath, FileMode.OpenOrCreate, FileAccess.Write))
|
||||||
file.Write(bytes, 0, bytes.Length);
|
{
|
||||||
file.Flush();
|
var bytes = Encoding.ASCII.GetBytes(sequenceNumber.ToString());
|
||||||
|
file.Write(bytes, 0, bytes.Length);
|
||||||
|
file.Flush();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Exception {e.ToString()}");
|
||||||
}
|
}
|
||||||
|
|
||||||
Thread.Sleep(PauseBetweenUpdatesMillisec);
|
Thread.Sleep(PauseBetweenUpdatesMillisec);
|
||||||
|
|
Загрузка…
Ссылка в новой задаче