private static Guid GetGuidFromFilename(string filepath)
{
string tmp = Path.GetFileNameWithoutExtension(filepath);
int index = Math.Max(tmp.LastIndexOf('_'), tmp.LastIndexOf(' '));
if (index == -1)
{
return new Guid(tmp);
}
Guid result;
string guidStr = tmp.Substring(index + 1);
if (!Guid.TryParse(guidStr, out result))
{
throw new InvalidOperationException("Failed to extract ID from file '{0}'".FormatWith(filepath));
}
return result;
}