예제 #1
0
        private void OnCreated(object sender, FileSystemEventArgs e)
        {
            log($"FileSystemWatcher.OnCreated: File creation detected: {e.FullPath}");

            // Make a FileInfo object out of it.
            FileInfo f = null;

            try
            {
                f = new FileInfo(e.FullPath);
            }
            catch (Exception exception)
            {
                // Well, guess we won't be handling this file.... Ignore.
                log($"FileSystemWatcher.OnCreated: Exception creating FileInfo object: {exception.Message}");
                return;
            }

            // File's not ready yet. Ignore.
            while (!isFileUnlocked(f))
            {
                // This log entry is a partial duplicate with the one in isFileUnlocked. Both are commented because they SPAM LIKE CRAZY when files are transferred from slow media.
                // log($"FileSystemWatcher.OnCreated: Ignoring locked file: {e.FullPath}");
                Thread.Sleep(threadSleepTime);

                // TODO Detect issues that aren't going to resolve themselves and cancel. Maybe have isFileUnlocked rethrow if the exception is not an in-use file?
            }

            // File is READY!
            log($"FileSystemWatcher.OnCreated: Giving file to ImageReviewer module: {e.FullPath}");
            Outputs.GetOutput(NextModule)?.Give(f);
        }
예제 #2
0
 // Sends the file under review to the Reject module, if any, then moves on to the next image and returns a bitmap of it.
 public void Reject()
 {
     if (fileUnderReview == null)
     {
         return;
     }
     Outputs.GetOutput(RejectOutput)?.Give(fileUnderReview);
     fileUnderReview = null;
 }
예제 #3
0
 // Sends the file under review to the Accept module, if any, then moves on to the next image and returns a bitmap of it.
 public void Accept()
 {
     if (fileUnderReview == null)
     {
         return;
     }
     Outputs.GetOutput(AcceptOutput)?.Give(fileUnderReview);
     fileUnderReview = null;
 }
예제 #4
0
        private void moveAndGiveFile(FileInfo file)
        {
            if (file == null)
            {
                return;
            }

            // If we have nowhere to put the file, pass it along (or let it disappear from the pipeline, if there's nowhere to go).
            if (DestinationFolder == null)
            {
                log($"FileMover.Give: Nowhere to move file and nowhere to Give file: {file.FullName}");
                Outputs.GetOutput(NextModule)?.Give(file);
                return;
            }

            try
            {
                string destinationPath = DestinationFolder + "/" + file.Name;

                try
                {
                    // Remove the file if it exists.
                    if (File.Exists(destinationPath))
                    {
                        File.Delete(destinationPath);
                    }
                    log($"FileMover.moveAndGiveFile: Deleted existing file: {destinationPath}");
                }
                catch (Exception)
                {
                    log($"FileMover.moveAndGiveFile: Could not delete existing file: {destinationPath}");
                }

                // Attempt the move. Note that MoveTo updates the fullName on successful move, so we don't have to worry about that.
                file.MoveTo(destinationPath);
                log($"FileMover.moveAndGiveFile: Moved file: {file.FullName}");
            }
            catch (Exception e)
            {
                log($"FileMover.Give: file.MoveTo threw exception: {e.Message}");

                // And we DON'T return here, because we don't want to break the pipeline if there's a chance it could still work.
            }

            // Now we pass it on.
            Outputs.GetOutput(NextModule)?.Give(file);
        }
예제 #5
0
        private void backgroundPrint(FileInfo file)
        {
            // Keep trying to print every second until it goes through.
            while (!printers.TryPrint(file))
            {
                Thread.Sleep(retryDelayMS);
            }

            // Make sure we don't need the file anymore...
            bool gotLock = false;

            while (!gotLock)
            {
                qLock.Enter(ref gotLock);
            }
            if (!files.Contains(file))
            {
                // Then give the file to the next module.
                Outputs.GetOutput(NextModule).Give(file);
            }
            qLock.Exit();
        }