public static void RecordFileDetailsInDB(Dictionary <string, clsFileList> importFiles, string logProcessName) { uint count = 0; Utils.FileStatus status; WindART_SMIDataContext windARTDataContext = new WindART_SMIDataContext(); foreach (clsFileList readFile in importFiles.Values) { ProcessFile pf = new ProcessFile(); pf.ProcessDate = DateTime.Now; pf.OriginalName = readFile.OriginalFullFilepath; pf.Name = readFile.FullFilePath; pf.FileLocationId = readFile.FileLocationId; status = Utils.GetNextFileStatus(readFile); //status = Utils.FileStatus.UploadingToSharepoint; pf.FileStatus = (int)status; windARTDataContext.ProcessFiles.InsertOnSubmit(pf); windARTDataContext.SubmitChanges(); // Now we have the ProcessFile primary key readFile.ProcessFileId = pf.ProcessFileId; count++; } Utils.WriteToLog(Utils.LogSeverity.Info, logProcessName, count.ToString() + " file(s) marked as read"); }
public static void ReadProcessFileList(Dictionary <string, clsFileList> verifyFiles, Utils.FileStatus fileStatus) { WindART_SMIDataContext windARTDataContext = new WindART_SMIDataContext(); var processFilesCollection = from processFiles in windARTDataContext.ProcessFiles where processFiles.FileStatus == (int)fileStatus select processFiles; foreach (var pf in processFilesCollection) { clsFileList fl = new clsFileList(); fl.FullFilePath = pf.Name; fl.FileLocationId = (int)pf.FileLocationId; if (pf.FileFormatId != null) { fl.FileFormatId = (int)pf.FileFormatId; } //fl.Encrypted = pf.Encrypted.Equals('Y'); // should be a bool fl.ProcessFileId = pf.ProcessFileId; if (pf.SiteId != null) { fl.SiteId = (int)pf.SiteId; } // never add the same file twice if (!verifyFiles.Keys.Contains(fl.FullFilePath)) { verifyFiles.Add(fl.FullFilePath, fl); } } }
public static void WriteToLog(LogSeverity severity, string process, string message) { try { WindART_SMIDataContext windARTDataContext = new WindART_SMIDataContext(); Log newLog = new Log(); // field is varchar(4000) if (message.Length > 4000) { message = message.Substring(0, 4000); } newLog.Time = DateTime.Now; newLog.LogSeverityId = (byte)severity; newLog.Process = process; newLog.Message = message; windARTDataContext.Logs.InsertOnSubmit(newLog); windARTDataContext.SubmitChanges(); } catch (Exception) { // Hmmm, we cannot write to the log... } }
public static void UpdateStatusInDB(clsFileList updateFile, FileStatus newStatus) { WindART_SMIDataContext windARTDataContext = new WindART_SMIDataContext(); var ProcessedFilesQuery = from processedFiles in windARTDataContext.ProcessFiles where processedFiles.ProcessFileId == updateFile.ProcessFileId select processedFiles; // set db status // there should be only one, but do a foreach anyway foreach (ProcessFile pf in ProcessedFilesQuery) { pf.FileStatus = (int)newStatus; } windARTDataContext.SubmitChanges(); }
public static void DeleteMissingFileinDB(clsFileList updateFile) { WindART_SMIDataContext windARTDataContext = new WindART_SMIDataContext(); var ProcessedFilesQuery = from processedFiles in windARTDataContext.ProcessFiles where processedFiles.ProcessFileId == updateFile.ProcessFileId select processedFiles; // set db status // there should be only one, but do a foreach anyway foreach (ProcessFile pf in ProcessedFilesQuery) { windARTDataContext.ProcessFiles.DeleteOnSubmit(pf); } windARTDataContext.SubmitChanges(); }
public static void ReadProcessFileList(Dictionary <string, clsFileList> verifyFiles, Utils.FileStatus fileStatus) { WindART_SMIDataContext windARTDataContext = new WindART_SMIDataContext(); var processFilesCollection = from processFiles in windARTDataContext.ProcessFiles where processFiles.FileStatus == (int)fileStatus select processFiles; //Console.WriteLine("just before iterating results from processfile"); //Console.ReadLine(); foreach (var pf in processFilesCollection) { clsFileList fl = new clsFileList(); fl.FullFilePath = pf.Name; //****comment out for production // fl.FullFilePath = pf.Name.Replace(@"D:\", @"\\10.254.13.3\"); //*************************** fl.FileLocationId = (int)pf.FileLocationId; if (pf.FileFormatId != null) { fl.FileFormatId = (int)pf.FileFormatId; } //fl.Encrypted = pf.Encrypted.Equals('Y'); // should be a bool fl.ProcessFileId = pf.ProcessFileId; if (pf.SiteId != null) { fl.SiteId = (int)pf.SiteId; } // never add the same file twice if (!verifyFiles.Keys.Contains(fl.FullFilePath)) { verifyFiles.Add(fl.FullFilePath, fl); } fl.FullFilePath = pf.Name.Replace(@"\\10.254.13.3\", @"D:\"); } // Console.WriteLine("built list of files successfully"); //Console.ReadLine(); }
public void TestWriteToLog() { int before; int after; WindART_SMIDataContext windARTDataContext = new WindART_SMIDataContext(); var LogQuery = from logs in windARTDataContext.Logs select logs; before = LogQuery.Count(); Utils.WriteToLog(Utils.LogSeverity.Info, processName, "Testing writing to log"); after = LogQuery.Count(); // Something else might have logged at the same time // so we cannot assume after = before++ Assert.IsTrue(after > before); }
public static void WriteToLog(LogSeverity severity, string process, string message) { try { WindART_SMIDataContext windARTDataContext = new WindART_SMIDataContext(); Log newLog = new Log(); // field is varchar(4000) if (message.Length > 4000) { message = message.Substring(0, 4000); } newLog.Time = DateTime.Now; newLog.LogSeverityId = (byte)severity; newLog.Process = process; newLog.Message = message; windARTDataContext.Logs.InsertOnSubmit(newLog); windARTDataContext.SubmitChanges(); } catch (Exception e) { string sSource; string sLog; sSource = "Find File"; sLog = "Application"; if (!EventLog.SourceExists(sSource)) { EventLog.CreateEventSource(sSource, sLog); } EventLog.WriteEntry(sSource, e.Message, EventLogEntryType.Error); } }