ファイルを移動してアーカイブし、空の *.cnf ファイルを生成して、これらのファイルを処理してもよいことを別のアプリケーションに知らせるプロセスを IIS で実行しています。どういうわけか、IIS は *.cnf ファイルを解放していません。以下にコードを貼り付けました。それが私のコードにあるのか、それともIISだけなのか、誰かが指摘してくれることを願っています。
public void Run()
{
try
{
// Log start of job
_log.Info("GL file copy job started ...");
// Check if today's date is not a holiday before processing these GL files
if (!_prov.IsGlHoliday())
{
// Get tmp directory
string glTempDirPath = GLConstants.Directories.GLTmp;
// Copy files from tmp to production drop off directory
if (Directory.Exists(glTempDirPath))
{
// Get tmp directory information
DirectoryInfo glTempDirInfo = new DirectoryInfo(glTempDirPath);
// Get all files at directory root level only
FileInfo[] glTempFiles = glTempDirInfo.GetFiles("*", SearchOption.TopDirectoryOnly);
// Check if any error files were generated during validation process
bool errorsFound = false;
foreach (FileInfo f in glTempFiles)
{
if (!f.Attributes.HasFlag(FileAttributes.Hidden) && f.Name.ToLower().IndexOf("error") != -1)
{
errorsFound = true;
break;
}
}
if (!errorsFound)
{
// Get GL data and confirmation files
List<FileInfo> glFiles = new List<FileInfo>();
foreach (FileInfo f in glTempFiles)
{
if (!f.Attributes.HasFlag(FileAttributes.Hidden) && f.Name.ToLower().IndexOf("error") == -1)
{
glFiles.Add(f);
}
}
_log.Info(string.Format("Copy and archiving {0} GL file{1} ...", glFiles.Count.ToString(), (glFiles.Count > 0) ? "s" : string.Empty));
// Archive Data files only
// 1. Create archive directory if it does not exist
// 2. Move files from temporary directory to archive directory
string glArchiveDirPath = Path.Combine(GLConstants.Directories.GLArchive, DateTime.Now.ToString("MMddyyyy"));
DirectoryInfo glArchiveDirInfo = new DirectoryInfo(glArchiveDirPath);
if (!(glArchiveDirInfo.Exists)) { glArchiveDirInfo.Create(); }
foreach (FileInfo f in glFiles)
{
string srcDestination = f.FullName;
string archiveDestination = Path.Combine(glArchiveDirPath, f.Name);
f.CopyTo(archiveDestination, true);
_log.Info(string.Format("GL file archived from {0} to {1} ...", srcDestination, f.FullName));
}
// (1) Move data files
foreach (FileInfo f in glFiles)
{
string moveToDestination = Path.Combine(GLConstants.Directories.GL, f.Name);
f.MoveTo(moveToDestination);
_log.Info(string.Format("GL file moved from {0} to {1} ...", f.FullName, moveToDestination));
}
// (2) Create confirmation files (.cnf) for these data files (TIF, BIOS, INPAXRF)
List<string> cnfFiles = new List<string>();
foreach (FileInfo f in glFiles)
{
if (
(f.Name.IndexOf("TIF", StringComparison.OrdinalIgnoreCase) != -1)
||
(f.Name.IndexOf("BIOS", StringComparison.OrdinalIgnoreCase) != -1)
||
(f.Name.IndexOf("INPAXRF", StringComparison.OrdinalIgnoreCase) != -1)
)
{
cnfFiles.Add(f.Name);
}
}
foreach (string f in cnfFiles)
{
string cnfFile = Path.Combine(GLConstants.Directories.GL, string.Format("{0}{1}", f, ".cnf"));
File.CreateText(cnfFile);
}
NotifyGLJobStatus.Send(new GLJobStatus { subject = "GL file copy", msg = "GL file copy process completed." });
}
else
{
_log.Info("One or more error files detected, GL file copy process terminated ...");
NotifyGLJobStatus.Send(new GLJobStatus { subject = "GL file copy", msg = "One or more error files detected, GL file copy process terminated." });
}
}
else
{
_log.Info(string.Format("{0} path does not exist, GL file copy process terminated ...", glTempDirPath));
NotifyGLJobStatus.Send(new GLJobStatus { subject = "GL file copy", msg = string.Format("{0} path does not exist, GL file copy process terminated.", glTempDirPath) });
}
}
else
{
_log.Info(string.Format("{0} is a holiday, GL file copy process terminated ...", DateTime.Now.ToString("d")));
NotifyGLJobStatus.Send(new GLJobStatus { subject = "GL file copy", msg = string.Format("{0} is a holiday, GL file copy process terminated.", DateTime.Now.ToString("d")) });
}
// Log end of job
_log.Info("GL file copy job ended ...");
}
catch (Exception ex)
{
_log.Fatal(string.Format("{0} : {1} ({2})", ex.Source, ex.Message, ex.ToString()));
NotifyGLJobStatus.Send(new GLJobStatus { subject = "GL file copy (ERROR)", msg = ex.Message });
}
}