Ejemplo n.º 1
0
        private static void TestHl7FileStream()
        {
            Console.WriteLine("\n==============================================\nTesting filestreams.");
            var path = _basePath + "\\TestApp\\TestMessages";

            var di = new DirectoryInfo(path);

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

            var mfs = new MultipleFilesStream(di);

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

            using (var stream = new HL7InputStreamMessageStringEnumerator(mfs))
            {
                var x = 0;
                Console.WriteLine("\nReading files from: '{0}'.", path);
                while (stream.MoveNext())
                {
                    var message = stream.Current;
                    if (message != null)
                    {
                        _messages.Add(message);
                        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);
                }
            }
        }
Ejemplo n.º 2
0
        private static void TestHL7FileStream()
        {
            Console.WriteLine("\n==============================================\nTesting filestreams.");
            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 (HL7InputStreamMessageStringEnumerator stream = new HL7InputStreamMessageStringEnumerator(mfs))
            {
                int x = 0;
                Console.WriteLine("\nReading files from: '{0}'.", path);
                while (stream.MoveNext())
                {
                    string message = stream.Current;
                    if (message != null)
                    {
                        messages.Add(message);
                        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);
                }
            }
        }
Ejemplo n.º 3
0
        public void MoveNext_EnumeratesAllMessagesFromFilesInDirectory()
        {
            Console.WriteLine("\n==============================================\nTesting filestreams.");

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

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

            var multipleFilesStream = new MultipleFilesStream(directoryInfo);

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

            var actualMessageCount = 0;

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

                    if (message != null)
                    {
                        Console.WriteLine("Message read.");
                        actualMessageCount++;
                    }
                    else
                    {
                        Console.WriteLine("Message not read.");
                    }
                }

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

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

            // Assert
            Assert.AreEqual(expectedFilesRead, actualFilesRead);
            Assert.AreEqual(expectedMessageLength, actualMessageCount);
        }
Ejemplo n.º 4
0
        private IEnumerable <string> GetHl7Strings()
        {
            var directoryInfo       = new DirectoryInfo(TestMessageDirectory);
            var multipleFilesStream = new MultipleFilesStream(directoryInfo);

            multipleFilesStream.FileEndMarker = '\n';

            var messages = new List <string>();

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

            return(messages);
        }
Ejemplo n.º 5
0
        private static void TestHL7FileStream()
        {
            Console.WriteLine("\n==============================================\nTesting filestreams.");
            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 (HL7InputStreamMessageStringEnumerator stream = new HL7InputStreamMessageStringEnumerator(mfs))
            {
                int x = 0;
                Console.WriteLine("\nReading files from: '{0}'.", path);        
                while (stream.MoveNext())
                {
                    string message = stream.Current;
                    if (message != null)
                    {
                        messages.Add(message);
                        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);
                }
            }
        }