Esempio n. 1
0
        private static void CheckFileOnStart()
        { 
             string methodName = MethodBase.GetCurrentMethod().Name;
            logger.InfoFormat("BEGIN: {0}()", methodName);
            try
            {
             
                 FileInfo[] fileInfos = FileOperation.GetFilesByWildCard(_config.FolderPath,
                                                                                                          _config.FileFilter);
                foreach (FileInfo file in fileInfos)
                {
                    DataHandle handle = new DataHandle();

                    XmlDocument  xml= CheckWellFormedXML(file.FullName);
                     handle.fullPath = file.FullName;
                     handle.Name = file.Name;
                     handle.eventType = WatcherChangeTypes.Created;
                     handle.content =System.IO.File.ReadAllText(file.FullName);
                    if (xml!=null)
                    {
                        handle.Xml = xml;
                        logger.Info(handle.ToString());
                        queue.Enqueue(handle);
                    }
                    else 
                    {
                        string badfolder = _config.BadXmlFolder + DateTime.Now.ToString(dateFormat) + "\\";
                        if (!Directory.Exists(badfolder))
                        {
                            Directory.CreateDirectory(badfolder);
                        }
                        File.Move(file.FullName, badfolder + file.Name + "." + DateTime.Now.ToString(TimeFormat));
                        logger.Error(handle.ToString());
                    }
                    
                }
            }
            catch(Exception ex)
            {
                
                logger.Error(methodName, ex);
               
            }
            finally
            {
                logger.InfoFormat("END: {0}()", methodName);
            }

        }
Esempio n. 2
0
 private static void OnChanged(object sender, FileSystemEventArgs e)
 {
    string methodName = MethodBase.GetCurrentMethod().Name;
     logger.InfoFormat("BEGIN: {0}()", methodName);
     DataHandle handle = new DataHandle();
     handle.fullPath = e.FullPath;
     handle.Name = e.Name;
     handle.eventType = e.ChangeType;
     try
     {
         if (File.Exists(e.FullPath))
         {
             
             DateTime lastWriteTime = File.GetLastWriteTime(e.FullPath);
             //if (lastWriteTime != lastRead)
             if (!cacheManager.Contains(e.FullPath) ||
                  (DateTime)cacheManager[e.FullPath] != lastWriteTime)
             {
                 logger.Info(handle.ToString());
                 queue.Enqueue(handle);
                 addCache(e.FullPath, lastWriteTime);
             }
             else    //discard the (duplicated) OnChanged event
             {
                 logger.Info(" discard the (duplicated) OnChanged event  => " + e.FullPath);
             }
         }
         else
         {
             logger.Error(" File not exists => " + e.FullPath);
         }
      }
     catch(Exception ex)
     {               
         logger.Error(methodName, ex);             
         
     }
     finally
     {
         logger.InfoFormat("END: {0}()", methodName);
     }
 }