private static string GetArchiveFileName(FileConfiguration configuration, string originalPath)
{
string archiveFormat = configuration.ArchiveFilePath;
if (string.IsNullOrWhiteSpace(archiveFormat))
{
archiveFormat = configuration.FilePath;
if (string.IsNullOrWhiteSpace(archiveFormat))
{
archiveFormat = string.Format(@"{{SOURCEPATH}}{0}{{SOURCENAME}}",Path.DirectorySeparatorChar);
}
}
string archiveFilePath = string.Empty;
foreach (var part in StringParser.GetParts(archiveFormat))
{
if (part.IsConst)
{
archiveFilePath += part.Value;
}
else
{
switch (part.Value.ToUpper())
{
case "BASEDIR":
archiveFilePath += System.AppDomain.CurrentDomain.BaseDirectory;
break;
case "WORKDIR":
archiveFilePath += Environment.CurrentDirectory;
break;
case "USERDIR":
archiveFilePath += Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
break;
case "DATE":
archiveFilePath += DateTime.Now.ToString("yyyy.MM.dd");
break;
case "DATETIME":
archiveFilePath += DateTime.Now.ToString("yyyy.MM.dd HH.mm.ss");
break;
case "SOURCENAME":
archiveFilePath += System.IO.Path.GetFileName(originalPath);
break;
case "SOURCEPATH":
archiveFilePath += System.IO.Path.GetDirectoryName(originalPath);
break;
}
}
}
return archiveFilePath;
}