Exemple #1
0
        private static void TestHl7FileMessageStream()
        {
            Console.WriteLine("\n==============================================\nTesting message stream.");
            var path = _basePath + "\\TestApp\\TestMessages";

            var di = new DirectoryInfo(path);

            Console.WriteLine("{0} files found.", di.GetFiles().Length);

            var mfs = new MultipleFilesStream(di)
            {
                FileEndMarker = '\n'
            };

            mfs.FileCompleted += mfs_FileCompleted;

            using (var stream = new HL7InputStreamMessageEnumerator(mfs))
            {
                var x = 0;
                Console.WriteLine("\nReading files from: '{0}'.", path);
                while (stream.MoveNext())
                {
                    var message = stream.Current;
                    if (message != null)
                    {
                        Console.WriteLine("Message read.");
                        x++;
                    }
                    else
                    {
                        Console.WriteLine("Message not read.");
                    }

                    stream.MoveNext();
                }
                Console.WriteLine("{0} files read.\n", x);

                var allFiles =
                    Directory.GetFiles(path + "\\Done")
                    .Select(file => new FileInfo(file))
                    .ToList();

                Console.WriteLine("Moving {0} files back.\n", allFiles.Count);
                foreach (var file in allFiles)
                {
                    file.MoveTo(path + "\\" + file.Name);
                }
            }
        }
Exemple #2
0
        private IList <IMessage> GetHl7IMessages()
        {
            var currentDirectory     = Path.GetDirectoryName(GetType().Assembly.Location);
            var testMessageDirectory = Path.Combine(currentDirectory, "TestMessages");

            var directoryInfo       = new DirectoryInfo(testMessageDirectory);
            var multipleFilesStream = new MultipleFilesStream(directoryInfo);

            multipleFilesStream.FileEndMarker = '\n';

            var messages = new List <IMessage>();

            using (var enumerator = new HL7InputStreamMessageEnumerator(multipleFilesStream))
            {
                while (enumerator.MoveNext())
                {
                    var message = enumerator.Current;
                    if (message != null)
                    {
                        messages.Add(message);
                    }
                }
            }

            return(messages);
        }
Exemple #3
0
        private static void TestHL7FileMessageStream()
        {
            Console.WriteLine("\n==============================================\nTesting message stream.");
            string path = basePath + "\\TestApp\\TestMessages";

            DirectoryInfo di = new DirectoryInfo(path);

            Console.WriteLine("{0} files found.", di.GetFiles().Count());

            MultipleFilesStream mfs = new MultipleFilesStream(di);

            mfs.FileEndMarker  = '\n';
            mfs.FileCompleted += mfs_FileCompleted;

            using (HL7InputStreamMessageEnumerator stream = new HL7InputStreamMessageEnumerator(mfs))
            {
                int x = 0;
                Console.WriteLine("\nReading files from: '{0}'.", path);
                while (stream.MoveNext())
                {
                    IMessage message = stream.Current;
                    if (message != null)
                    {
                        Console.WriteLine("Message read.");
                        x++;
                    }
                    else
                    {
                        Console.WriteLine("Message not read.");
                    }

                    stream.MoveNext();
                }
                Console.WriteLine("{0} files read.\n", x);

                List <String> allFiles = Directory.GetFiles(path + "\\Done").ToList();
                Console.WriteLine("Moving {0} files back.\n", allFiles.Count());
                foreach (string file in allFiles)
                {
                    FileInfo mFile = new FileInfo(file);
                    mFile.MoveTo(path + "\\" + mFile.Name);
                }
            }
        }
        public void MoveNext_ParsesAllHl7MessagesFromAllFilesInDirectory()
        {
            Output.WriteLine("\n==============================================\nTesting filestreams.");

            // Arrange
            var directoryInfo         = new DirectoryInfo(TestMessageDirectory);
            var expectedFilesRead     = directoryInfo.GetFiles().Length;
            var expectedMessageLength = 6;
            var actualFilesRead       = 0;

            Output.WriteLine("{0} files found.", expectedFilesRead);

            var multipleFilesStream = new MultipleFilesStream(directoryInfo);

            multipleFilesStream.FileEndMarker  = '\n';
            multipleFilesStream.FileCompleted += (o, e) =>
            {
                Output.WriteLine("\nMessages Read from {0}", Path.GetFileName(e.FileName));
                actualFilesRead++;
            };

            var actualMessageCount = 0;

            // Act
            using (var sut = new HL7InputStreamMessageEnumerator(multipleFilesStream))
            {
                Output.WriteLine("\nReading files from: '{0}'.", TestMessageDirectory);
                while (sut.MoveNext())
                {
                    var message = sut.Current;

                    if (message != null)
                    {
                        Output.WriteLine("{0} Message read.", message.GetType().Name);
                        actualMessageCount++;
                    }
                    else
                    {
                        Output.WriteLine("Message not read.");
                    }
                }

                Output.WriteLine("\n{0} messages read.", actualMessageCount);
            }

            Output.WriteLine("{0} files read.\n", actualFilesRead);

            // Assert
            Assert.Equal(expectedFilesRead, actualFilesRead);
            Assert.Equal(expectedMessageLength, actualMessageCount);
        }
Exemple #5
0
        private static void TestHL7FileMessageStream()
        {
            Console.WriteLine("\n==============================================\nTesting message stream.");
            string path = basePath + "\\TestApp\\TestMessages";

            DirectoryInfo di = new DirectoryInfo(path);
            Console.WriteLine("{0} files found.", di.GetFiles().Count());

            MultipleFilesStream mfs = new MultipleFilesStream(di);
            mfs.FileEndMarker = '\n';
            mfs.FileCompleted += mfs_FileCompleted;

            using (HL7InputStreamMessageEnumerator stream = new HL7InputStreamMessageEnumerator(mfs))
            {
                int x = 0;
                Console.WriteLine("\nReading files from: '{0}'.", path);
                while (stream.MoveNext())
                {
                    IMessage message = stream.Current;
                    if (message != null)
                    {
                        Console.WriteLine("Message read.");
                        x++;
                    }
                    else
                        Console.WriteLine("Message not read.");

                    stream.MoveNext();
                }
                Console.WriteLine("{0} files read.\n", x);

                List<String> allFiles = Directory.GetFiles(path + "\\Done").ToList();
                Console.WriteLine("Moving {0} files back.\n", allFiles.Count());
                foreach (string file in allFiles)
                {
                    FileInfo mFile = new FileInfo(file);
                    mFile.MoveTo(path + "\\" + mFile.Name);
                }
            }
        }