Exemple #1
0
        /// <summary>
        ///     <c>Startup</c>
        ///     The method caled by Topshelf to start the service running
        /// </summary>
        public void Start()
        {
            try
            {
                if (WatchSocket)
                {
                    SocketListener = new Hl7SocketListener(ListenerPort, Parse)
                    {
                        RunAsService = true, AllowZeroTQ = AllowZeroTQ, DebugMode = DebugMode
                    };
                    SocketListener.Go();
                }

                if (WatchFileSystem)
                {
                    FilesystemListener = new FilesystemListener(GetPlatformOs.Current == PlatformOs.Windows ? WinMonitorDirectory : NixMonitorDirectory, Parse)
                    {
                        RunAsService = true,
                        Listening    = true,
                        DebugMode    = DebugMode
                    };
                    FilesystemListener.Go();
                }

                EventLogger.Info("Service started");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                EventLogger.Error($"Failed to start service: {ex.Message}");
                throw;
            }
        }
Exemple #2
0
        /// <summary>
        ///     <c>Restart</c>
        ///     Method called by Topshellf to restart the service
        /// </summary>
        public void Restart()
        {
            if (WatchSocket)
            {
                SocketListener.ShutDown();
                SocketListener.Go();
            }

            if (WatchFileSystem)
            {
                FilesystemListener.ShutDown();
                FilesystemListener.Go();
            }

            EventLogger.Info("Service restarted");
        }
        public void Construct()
        {
            var _path = GetPlatformOs.Current == PlatformOs.Windows ? $@"\motNext\io" : "~/Project/Tests/ListenerTests/io";

            try
            {
                using (var hl7Listener = new Hl7SocketListener(24045, callback))
                {
                    hl7Listener.Go();
                }
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }

            try
            {
                using (var fsListener = new FilesystemListener(_path, callback))
                {
                    fsListener.Go();
                }

                using (var fsListener = new FilesystemListener(_path, callback, true))
                {
                    fsListener.Go();
                }
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }

            // Force failures
            try
            {
                using (var hl7Listener = new Hl7SocketListener(0, callback))
                {
                    hl7Listener.Go();
                }

                Assert.Fail("Did not trap illegal socket address");
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Illegal aocket address {ex.Message}");
            }

            try
            {
                using (var hl7Listener = new Hl7SocketListener(24045, null))
                {
                    hl7Listener.Go();
                }

                Assert.Fail("Did not trap null callback");
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Null callback {ex.Message}");
            }


            try
            {
                using (var fsListener = new FilesystemListener(null, callback))
                {
                    fsListener.Go();
                }

                Assert.Fail("Allowed null path parameter");
            }
            catch
            {
                Console.WriteLine("Trapped null path parameter");
            }

            try
            {
                using (var fsListener = new FilesystemListener(_path, null))
                {
                    fsListener.Go();
                }

                Assert.Fail("Allowed null callback parameter");
            }
            catch
            {
                Console.WriteLine("Trapped null callback parameter");
            }
        }