You are viewing limited content. For full access, please sign in.

Question

Question

Import agent notifications

asked on October 13, 2017

Hi,

We use Import Agent a lot in our organisation to get documents into our LF repository.  90% of the time this works flawlessly, however there are times when meta data in a LST file isn't correct or missing and the import process fails.  If this isn't being monitored, it can be some time before someone notices that there are a few documents in the import error folders (along with the relevant LST file).

 

Is there a way of having someone notified by email or similar the moment an import LST fails for some reason?

Also, when files are moved to the error folder, they aren't contained in their initial folder before import.  Is it possible to maintain the folder structure of the initial images (with associated LST file) when they are moved to the Import Error folder?

 

Anthony 

0 0

Answer

SELECTED ANSWER
replied on October 14, 2017

What I did for the notification piece is to write a Windows Service that spawns numerous FileWatcher objects (based on a configuration file), so any time an .xml file is created in any of the IAError folders, it sends me a message.  You're welcome to the code, if you want.

0 0
replied on October 31, 2017

Hi,

Would be great to see the code - thank you!

Anthony

0 0
replied on October 31, 2017

 I would have upload a .zip with the project, but since I can't ... hope this helps and let me know if you have any questions.  Hopefully you'll be able to decipher this.

 

protected override void OnStart(string[] args)
        {
            this.AutoLog = true;
           
            List<DirectoryInfo> dirs = (new DirectoryManager()).GetDirectoryList();
            FileSystemWatcher fsw;
            foreach (DirectoryInfo info in dirs)
            {
                EventLogMgr.Write("Adding watcher to: " + info.FullName);
                fsw = new FileSystemWatcher(info.FullName);
                fsw.Created += fsw_Created; 
                fsw.EnableRaisingEvents = true;
                _watchers.Add(fsw);
            }
        }

 

 

 protected void fsw_Created(object sender, FileSystemEventArgs e)
        {
            try
            {
                SmtpClient smtp = new SmtpClient(ConfigurationManager.AppSettings["SMTPServer"]);
                System.Net.Mail.MailMessage msg = new MailMessage();
                msg.From = new MailAddress(ConfigurationManager.AppSettings["MailFrom"]);
                msg.To.Add(new MailAddress(ConfigurationManager.AppSettings["MailTo"]));
                msg.Subject = ConfigurationManager.AppSettings["MailSubject"];
                msg.IsBodyHtml = false;
                msg.Body = "The following file failed to be imported by the Laserfiche Import Agent: " + Environment.NewLine + Environment.NewLine + e.FullPath;
                smtp.Send(msg);
                EventLogMgr.Write("Import Failed: " + e.FullPath);
            }
            catch (Exception ex)
            {
                EventLogMgr.Write("Error! " + ex.Message);
            }
        }

 

  public static class EventLogMgr
    {
        public static void Write(string Message)
        {
            string source = ConfigurationManager.AppSettings["EventLogSource"];
            string log = ConfigurationManager.AppSettings["EventLogName"];
            if (!System.Diagnostics.EventLog.SourceExists(source))
            {
                System.Diagnostics.EventLog.CreateEventSource(
                    source, log);
                Thread.Sleep(5000);
            }

            EventLog eLog = new EventLog();
            eLog.Source = source;
            eLog.Log = log;
            eLog.WriteEntry(Message);
        }
    }

 class DirectoryManager
    {
        private XmlDocument _xDoc = new XmlDocument();

        public DirectoryManager()
        {
            _xDoc.Load(ConfigurationManager.AppSettings["DirectoryConfigFile"]);
        }

        public List<DirectoryInfo> GetDirectoryList()
        {
            List<DirectoryInfo> result = new List<DirectoryInfo>();
            DirectoryInfo dInfo;
            XmlNodeList nodes = _xDoc.SelectNodes("directories/directory");
            XmlAttribute attr;
            foreach (XmlNode node in nodes)
            {
                attr = node.Attributes["value"];
                if (attr != null)
                {
                    dInfo = new DirectoryInfo(attr.Value);
                    if (dInfo.Exists)
                    {
                        string[] directories = Directory.GetDirectories(attr.Value.ToString(), "IAError", SearchOption.AllDirectories);
                        foreach (string s in directories)
                        {
                            dInfo = new DirectoryInfo(s);
                            result.Add(dInfo);
                        }
                    }
                    else { 
                    
                    }
                }
            }
            return result;
        }
    }

 

==== DirectoryList.xml ===========

 

<?xml version="1.0" encoding="utf-8" ?>
<!--Add the ROOT directory only.  The service will traverse subdirectories and any \IAError directory will be monitored-->
<directories>
  <directory value="E:\DMS_Queue\Input\"></directory>
  <directory value="E:\DMS_Queue\Test\"></directory>
</directories>

1 0
replied on November 3, 2017

This is very kind of you.  I will look over this.

Anthony

0 0
replied on March 4, 2024

Hey @████████, would you willing to send me a copy of that project/zip by uploading it here? (Upload link valid through 4/4/2024). Thank you!

https://ftp.laserfiche.com/public/folder/1m9xpz-cu06fciwxdaqybw/ImportAgentWatcher

0 0

Replies

replied on October 15, 2017

Hi Anthony,

Import Agent doesn't support notification and it doesn't maintain the folder structure of initial images referenced by LST. I don't think Import Agent will support notification (Rich gives a good alternative), but it is a good request for Import Agent to maintain folder structure referenced by LST. 

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.