public static DeploymentStatusFile Open(string id, IEnvironment environment, IAnalytics analytics, IOperationLock statusLock)
{
return statusLock.LockOperation(() =>
{
string path = Path.Combine(environment.DeploymentsPath, id, StatusFile);
if (!FileSystemHelpers.FileExists(path))
{
return null;
}
try
{
XDocument document = null;
using (var stream = FileSystemHelpers.OpenRead(path))
{
document = XDocument.Load(stream);
}
return new DeploymentStatusFile(id, environment, statusLock, document);
}
catch (Exception ex)
{
// in the scenario where w3wp is abruptly terminated while xml is being written,
// we may end up with corrupted xml. we will handle the error and remove the problematic directory.
analytics.UnexpectedException(ex);
FileSystemHelpers.DeleteDirectorySafe(Path.GetDirectoryName(path), ignoreErrors: true);
// it is ok to return null as callers already handle null.
return null;
}
}, "Getting deployment status", DeploymentStatusManager.LockTimeout);
}