Exemple #1
0
        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");
        }
Exemple #2
0
        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);
                }
            }
        }
Exemple #3
0
        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...
            }
        }
Exemple #4
0
        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();
        }
Exemple #5
0
        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();
        }
Exemple #6
0
        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();
        }
Exemple #7
0
        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);
        }
Exemple #8
0
        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);
            }
        }