コード例 #1
0
        static void Main(string[] args)
        {
            Log.NewEntry("BeganIMSFileCopier");
            while (true)
            {
                if (!Directory.Exists(dir.destinationDirectory))
                {
                    Log.NewEntry("Can't find Destination Directory", dir.destinationDirectory);
                    fileWatcher.DisableWatcher();
                    fileWatcherEnabled = false;
                    allFilesCopied     = false;
                    try
                    {
                        Directory.CreateDirectory(dir.destinationDirectory);
                        Log.NewEntry("Destination Directory created", dir.destinationDirectory);
                    }
                    catch (Exception)
                    {
                        Log.NewEntry("Destination Directory could not be created", dir.destinationDirectory);
                        Thread.Sleep(5000);
                        continue;
                    }
                }
                if (!allFilesCopied)
                {
                    ThreadPool.QueueUserWorkItem(_ => FileCopier.CopyAllFiles(dir.sourceDirectory, dir.destinationDirectory));
                    allFilesCopied = true;
                }
                if (!fileWatcherEnabled)
                {
                    fileWatcher.EnableWatcher();
                    fileWatcherEnabled = true;
                }
                Thread.Sleep(100);
            }

            ////Console.WriteLine("High Speed File Copier \n\r");
            //EstablishConnectionsToDirectories();
            //ThreadPool.QueueUserWorkItem(_ => FileCopier.CopyAllFiles(dir.sourceDirectory, dir.destinationDirectory));
            //fileWatcher.EnableWatcher();
            //new Thread(delegate ()
            //{
            //    MaintainConnectionsToDirectories();
            //}).Start();
            //// Hold main thread indefinitely. End program with Red X.
            //while (true)
            //{
            //    Thread.Sleep(10000);
            //}
        }
コード例 #2
0
 /// <summary>
 /// Copies all files the FileWatcher catches as Created
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 /// <param name="src">Source Directory</param>
 /// <param name="dest">Destination Directory</param>
 private void OnCreated(object sender, FileSystemEventArgs e, string src, string dest)
 {
     ThreadPool.QueueUserWorkItem(_ => FileCopier.CopyFile(e.FullPath, src, dest));
 }