Ejemplo n.º 1
0
        public void Cleanup_AutoDeleteOn_DeletesCompletedFiles()
        {
            FileTriggerAttribute attribute      = new FileTriggerAttribute(attributeSubPath, "*.dat", autoDelete: true);
            FileProcessor        localProcessor = CreateTestProcessor(attribute);

            // create a completed file set
            string          completedFile       = WriteTestFile("dat");
            string          completedStatusFile = localProcessor.GetStatusFile(completedFile);
            StatusFileEntry status = new StatusFileEntry
            {
                State      = ProcessingState.Processing,
                Timestamp  = DateTime.UtcNow,
                ChangeType = WatcherChangeTypes.Created,
                InstanceId = "1"
            };
            StringWriter sw = new StringWriter();

            _serializer.Serialize(sw, status);
            sw.WriteLine();
            status.State     = ProcessingState.Processed;
            status.Timestamp = status.Timestamp + TimeSpan.FromSeconds(15);
            _serializer.Serialize(sw, status);
            sw.WriteLine();
            sw.Flush();
            File.WriteAllText(completedStatusFile, sw.ToString());

            // include an additional companion metadata file
            string completedAdditionalFile = completedFile + ".metadata";

            File.WriteAllText(completedAdditionalFile, "Data");

            // write a file that SHOULDN'T be deleted
            string dontDeleteFile = Path.ChangeExtension(completedFile, "json");

            File.WriteAllText(dontDeleteFile, "Data");

            // create an incomplete file set
            string incompleteFile       = WriteTestFile("dat");
            string incompleteStatusFile = localProcessor.GetStatusFile(incompleteFile);

            status = new StatusFileEntry
            {
                State      = ProcessingState.Processing,
                Timestamp  = DateTime.UtcNow,
                ChangeType = WatcherChangeTypes.Created,
                InstanceId = "1"
            };
            sw = new StringWriter();
            _serializer.Serialize(sw, status);
            sw.WriteLine();
            File.WriteAllText(incompleteStatusFile, sw.ToString());

            localProcessor.Cleanup();

            // expect the completed set to be deleted
            Assert.False(File.Exists(completedFile));
            Assert.False(File.Exists(completedAdditionalFile));
            Assert.False(File.Exists(completedStatusFile));
            Assert.True(File.Exists(dontDeleteFile));

            // expect the incomplete set to remain
            Assert.False(File.Exists(completedFile));
            Assert.False(File.Exists(completedStatusFile));
        }
Ejemplo n.º 2
0
 private void OnCleanupTimer(object sender, ElapsedEventArgs e)
 {
     _processor.Cleanup();
 }