void fileUpload_FileUploadCompleted(object sender, FileUploadCompletedEventArgs args)
{
string id = ctx.Request.QueryString["id"];
string user = Membership.GetUser().UserName;
uint st;
uint et;
using (var FileEntities = new FileEntities())
{
try
{
var fileName = args.FileName;
var macAddress = fileName.Substring(0, fileName.IndexOf('-'));
File File = FileEntities.Files.FirstOrDefault((File c) => F.MACAddress == macAddress && F.FileType != -1);
if (File == null)
{
File = CreateFile(macAddress);
IsFileCreated = true;
log4net.GlobalContext.Properties["source"] = "SERVER";
Log.Info(string.Format("File created for offline import: {0}", File.FileName));
File.HTTP = 80;
string groupName = DefaultNames.DefaultGroup.ToString();
var group = FileEntities.Groups.FirstOrDefault((Group g) => g.GroupName == groupName);
if (args.GroupId == 0)
File.GroupId = group.GroupId;
else
File.GroupId = args.GroupId;
FileEntities.Files.AddObject(File);
}
else
{
IsFileCreated = false;
log4net.GlobalContext.Properties["source"] = "SERVER";
log4net.ThreadContext.Properties["Fileid"] = File.FileId;
Log.Info(string.Format("File Upload Completed for offline import: {0}", File.FileName));
}
var targetFilePath = Helper.LocalFilePath(File, fileName);
CustomLogger.LogUserUploadRequest(user, fileName, File.FileName);
try
{
EventFile eventFile = FileEntities.EventFiles.FirstOrDefault((EventFile ef) => ef.FilePath == fileName && ef.File.FileType!=-1);
if (eventFile != null)
{
log4net.GlobalContext.Properties["source"] = "SERVER";
Log.Info(string.Format("Deleting the data corresponding to eventFile: {0}", eventFile.FilePath));
FileEntities.usp_DeleteEventData(eventFile.EventFileId, true, File.FileId);
}
else
{
Log.Info(string.Format("There is no event file entry with that file path: {0}", args.FilePath));
}
}
catch (InvalidOperationException e)
{
log4net.GlobalContext.Properties["source"] = "SERVER";
}
if (File.Exists(targetFilePath))
{
File.Delete(targetFilePath);
}
FileInfo fi = new FileInfo(args.FilePath);
fi.MoveTo(targetFilePath);
EventFile newEventFile = new EventFile();
newEventFile.FilePath = fileName;
newEventFile.File = File;
newEventFile.DownloadStatus = (int)DownloadStatus.Downloaded;
newEventFile.DateOfDownloadStart = DateTime.Now;
newEventFile.DateOfDownload = DateTime.Now;
newEventFile.ModeOfDownload = (int)DownloadMode.FileUpload;
newEventFile.EventFileDate = Helper.GetDateTimeFromFilePath(fileName).Value;
newEventFile.EventFileSize = (int)fi.Length;
FileEntities.EventFiles.AddObject(newEventFile);
FileEntities.SaveChanges();
CustomLogger.LogUploadFileCompleted(fileName, File.FileName,File.FileId);
log4net.GlobalContext.Properties["source"] = "SERVER";
log4net.ThreadContext.Properties["Fileid"] = File.FileId;
Log.Info(string.Format("Offline import started: {0}", File.FileName));
if (args.IsOffline)
{
using (SqlConnection conn = new SqlConnection(Db.ConnectionString))
{
conn.Open();
Helper.ImportFile(FileEntities, newEventFile, ImportMode.ManualMode, false, conn,IsFileCreated);
if (newEventFile.RecordsCount!=0)
{
DBLogger.Log.DebugFormat("Offline Import Process Start");
var min = newEventFile.StartTime;
var max = newEventFile.EndTime;
st = Convert.ToUInt32(min);
et = Convert.ToUInt32(max);
Db.CreateHourData(conn, st, et, File.FileId);
Db.CreateDayData(conn, st, et, File.FileId);
DBLogger.Log.DebugFormat("Offline Import Process End");
}
}
}
}
catch (InvalidOperationException e)
{
log4net.GlobalContext.Properties["source"] = "SERVER";
Log.Error(string.Format("Unable to find File corresponding to uploaded file: {0}, {1}", args.FileName, e.ToString()), e);
}
catch (Exception e)
{
log4net.GlobalContext.Properties["source"] = "SERVER";
Log.Error(string.Format("Unable to process uploaded file: {0}, {1}", args.FileName, e.ToString()), e);
}
}
}
The above code is import file for offline mode. It's working fine.
In this method i import 5 files(different file Id) ,the import process method (Filehelper.ImportFile) called
for every file.this also good.
Now the chanllenge is,
In my code, This code is calling each file,
if (newEventFile.RecordsCount!=0)
{
DBLogger.Log.DebugFormat("Offline Import Process Start");
DBLogger.Log.DebugFormat("Insert Daily and Hourly Summary Starting Time : {0}", DateTime.Now);
var min = newEventFile.StartTime;
var max = newEventFile.EndTime;
st = Convert.ToUInt32(min);
et = Convert.ToUInt32(max);
DbApi.CreateHourlySummaryData(conn, st, et, cell.CellId);
DbApi.CreateDailySummaryData(conn, st, et, cell.CellId);
DBLogger.Log.DebugFormat("Insert Daily and Hourly Summary Ending Time : {0},{1},{2}", DateTime.Now, st, et);
DBLogger.Log.DebugFormat("Offline Import Process End");
}
Now i want call only one time for above code( for all files) (after completeing import process method (Filehelper.ImportFile)for all files) based on fileId, Please help me...