Exemplo n.º 1
0
        public static void Run(string[] args, ref int success)
        {
            try
            {
                string FilePath, FileName, Destination = "";
                int    PollingIntervalMilliSec = 0;
                object resourceLock            = new object();

                if (args.Length > 0)
                {
                    FilePath                = args[0].Trim();
                    FileName                = args[1].Trim();
                    Destination             = args[2].Trim();
                    PollingIntervalMilliSec = Convert.ToInt32(args[3].Trim());
                }
                else
                {
                    FilePath = ConfigurationManager.AppSettings.Get("path");
                    FileName = ConfigurationManager.AppSettings.Get("fileName");
                    FileName = ConfigurationManager.AppSettings.Get("Destination");
                    PollingIntervalMilliSec = Convert.ToInt32(ConfigurationManager.AppSettings.Get("PollingIntervalMilliSec"));
                }

                StringBuilder sb = new StringBuilder();
                sb.AppendLine("Path - " + FilePath);
                sb.AppendLine("Name - " + FileName);
                sb.AppendLine("Destination - " + Destination);
                sb.AppendLine("PollingIntervalMilliSec - " + PollingIntervalMilliSec);

                Console.Write(sb.ToString());
                Trace.TraceInformation(sb.ToString());

                if (Directory.Exists(FilePath))
                {
                    Trace.TraceInformation("Path exists - starting file watcher");
                    Console.WriteLine("Path exists - starting file watcher");

                    FileWatcher fw = new FileWatcher(FilePath, FileName, Destination, resourceLock);


                    while (fw.success == (int)ApplicationResponseTypes.FAILNOTFOUND)
                    {
                        lock (resourceLock)
                        {
                            Thread.Sleep(PollingIntervalMilliSec);
                            string logThis = ($"Watching for input file/ Waiting for file to be moved - {DateTime.Now}");
                            Console.WriteLine(logThis);
                            Trace.TraceInformation(logThis);
                        }
                    }

                    success = fw.success;
                }
                else
                {
                    Console.WriteLine("Path does not exist");
                    Trace.TraceInformation("Path does not exist");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                Trace.TraceError(ex.ToString());
            }
        }
Exemplo n.º 2
0
 protected override void OnStart(string[] args)
 {
     FileWatcher few = new FileWatcher();
 }