private static string GetDataFilePath(string applicationKey, string sessionId)
{
var basePath = SiteConfig.DataStoragePath;
var dataRootPath = Path.Combine(basePath, applicationKey);
if (!dataRootPath.StartsWith(basePath)) // block malicious application keys
throw new ArgumentException(dataRootPath);
if (!Directory.Exists(dataRootPath))
Directory.CreateDirectory(dataRootPath);
var filesMask = string.Format("*.{0}.txt", sessionId);
var files = Directory.GetFiles(dataRootPath, filesMask);
if (files.Length > 0)
{
if (files.Length != 1)
throw new ApplicationException(string.Format("Too much data files for session {0}", sessionId));
return files[0];
}
else
{
var time = DateTime.UtcNow;
var filePath = Const.FormatFilePath(dataRootPath, sessionId, time);
return filePath;
}
}