#pragma warning restore 1998

        public async Task PushtoDicomEventLoop(int taskID)
        {
            var taskInfo = $"task: {taskID} connection: {Connection.name}";

            var profile = _profileStorage.Current;

            _logger.Log(LogLevel.Debug, $"{taskInfo} Beginning PushtoDicom");

            try
            {
                await PushtoDicom(taskID);

                bool success = await toDicomSignal.WaitAsync(profile.KickOffInterval, LITETask.cts.Token).ConfigureAwait(false);

                //toDicomSignal.Release();
                // toDicomSignal.Dispose();
                // toDicomSignal = new SemaphoreSlim(0, 1);
            }
            catch (TaskCanceledException)
            {
                _logger.Log(LogLevel.Information, $"Task was canceled.");
            }
            catch (Exception e)
            {
                _logger.LogFullException(e, taskInfo);
            }
            finally
            {
                LITETask.Stop($"{Connection.name}.PushtoDicomEventLoop");
            }

            _logger.Log(LogLevel.Debug, $"{taskInfo} Ending PushtoDicomEventLoop");
        }
        public async Task ProcessHubMessages(int taskID)
        {
            var taskInfo = $"task: {taskID} connection: {Connection.name}";
            var profile  = _profileStorage.Current;

            _logger.Log(LogLevel.Debug, $"{taskInfo} Entering ProcessHubMessages");

            try
            {
                do
                {
                    bool success = await HubMessagesSignal.WaitAsync(profile.KickOffInterval, LITETask.cts.Token).ConfigureAwait(false);

                    // HubMessagesSignal.Dispose();
                    // HubMessagesSignal = new SemaphoreSlim(0, 1);
                } while (Connection.responsive);
            }
            catch (TaskCanceledException)
            {
                _logger.Log(LogLevel.Information, $"Task was canceled.");
            }
            catch (OperationCanceledException)
            {
                _logger.Log(LogLevel.Warning, $"Wait Operation Canceled. Exiting ProcessHubMessages");
            }
            catch (Exception e)
            {
                _logger.LogFullException(e, taskInfo);
                _logger.Log(LogLevel.Critical, $"{taskInfo} Exiting ProcessHubMessages");
            }
            finally
            {
                LITETask.Stop($"{Connection.name}.ProcessHubMessages");
            }
        }
        public override async Task Kickoff(int taskID)
        {
            var taskInfo = $"task: {taskID} connection: {Connection.name}";

            try
            {
                _logger.Log(LogLevel.Debug, $"{taskInfo} Check for scanpaths");

                if (Connection.scanpaths?.Count > 0 && (LITETask.CanStart($"{Connection.name}.scan")))
                {
                    _logger.Log(LogLevel.Debug, $"{taskInfo} scanpaths.count: {Connection.scanpaths.Count}");
                    var  newTaskID = LITETask.NewTaskID();
                    Task task      = new Task(new Action(async() => await Scan(newTaskID)));
                    await LITETask.Start(newTaskID, task, $"{Connection.name}.scan", isLongRunning : false);
                }

                await Task.Yield(); //bogus await to make the sync go away
            }
            catch (TaskCanceledException)
            {
                _logger.Log(LogLevel.Information, $"Task was canceled.");
            }
            catch (Exception e)
            {
                _logger.LogFullException(e, taskInfo);

                //throw e;
                throw;
            }
            finally
            {
                LITETask.Stop($"{Connection.name}.Kickoff");
            }
        }
        public async Task Read(TcpClient client, int taskID)
        {
            await _hl7ReaderService.Read(client, taskID, Connection);

            Clean();   // cleanup the connection, remove from list

            LITETask.Stop($"{Connection.name}.read");
        }
        public override async Task Kickoff(int taskID)
        {
            var taskInfo = $"task: {taskID} connection: {Connection.name}";

            try
            {
                if (Connection.enabled == true && (Connection.inout == InOut.inbound || Connection.inout == InOut.both))
                {
                    await Start();  //starts the inbound connection if for some reason it is not started already.
                }
                else
                {
                    _logger.Log(LogLevel.Information, $"{Connection.name} Cannot start listener: enabled: {Connection.enabled} inout: {Connection.inout}");
                }

                //connections
                _logger.Log(LogLevel.Debug, $"{Connection.name} Total Connections: {clients.Count}");
                _logger.Log(LogLevel.Debug, $"{Connection.name} Cleaning Connections...");

                Clean();

                _logger.Log(LogLevel.Debug, $"{Connection.name} Active Connections: {clients.Count}");

                if (LITETask.CanStart($"{Connection.name}.SendToRules"))
                {
                    var  newTaskID = LITETask.NewTaskID();
                    Task task      = new Task(new Action(async() => await SendToRules(newTaskID, Connection.responsive)));
                    await LITETask.Start(newTaskID, task, $"{Connection.name}.SendToRules", isLongRunning : true);
                }

                if (Connection.inout == InOut.both || Connection.inout == InOut.outbound)
                {
                    if (LITETask.CanStart($"{Connection.name}.Upload"))
                    {
                        var  newTaskID = LITETask.NewTaskID();
                        Task task      = new Task(new Action(async() => await Upload(newTaskID)));
                        await LITETask.Start(newTaskID, task, $"{Connection.name}.Upload", isLongRunning : false);
                    }
                }
            }
            catch (TaskCanceledException)
            {
                _logger.Log(LogLevel.Information, $"Task was canceled.");
            }
            catch (Exception e)
            {
                _logger.LogFullException(e, taskInfo);
                //throw e;
                throw;
            }
            finally
            {
                LITETask.Stop($"{Connection.name}.Kickoff");
            }
        }
        public override async Task Kickoff(int taskID)
        {
            var taskInfo = $"task: {taskID} connection: {Connection.name}";

            try
            {
                if (Connection.enabled == true && Connection.localPort != 0)
                {
                    CreateListener();
                }

                if (dicomClient == null)
                {
                    Init();
                }

                _logger.Log(LogLevel.Information, $"{taskInfo} toDicom: {Connection.toDicom.Count} toRules: {Connection.toRules.Count}");

                if (LITETask.CanStart($"{Connection.name}.SendToDicom"))
                {
                    var  newTaskID = LITETask.NewTaskID();
                    Task task      = new Task(new Action(async() => await SendToDicom(taskID)));
                    await LITETask.Start(newTaskID, task, $"{Connection.name}.SendToDicom", isLongRunning : false);
                }

                if (LITETask.CanStart($"{Connection.name}.SendToRules"))
                {
                    var  newTaskID = LITETask.NewTaskID();
                    Task task      = new Task(new Action(async() => await SendToRules(newTaskID, Connection.responsive)));
                    await LITETask.Start(newTaskID, task, $"{Connection.name}.SendToRules", isLongRunning : true);
                }
            }
            catch (TaskCanceledException)
            {
                _logger.Log(LogLevel.Information, $"Task was canceled.");
            }
            catch (OperationCanceledException)
            {
                _logger.Log(LogLevel.Warning, $"Wait Operation Canceled.");
            }
            catch (Exception e)
            {
                _logger.LogFullException(e);
            }
            finally
            {
                LITETask.Stop($"{Connection.name}.Kickoff");
            }
        }
        public async Task Upload(int taskID)
        {
            var taskInfo = $"task: {taskID} connection: {Connection.name}";

            _logger.Log(LogLevel.Debug, $"{taskInfo} Entering Upload");

            try
            {
                do
                {
                    if (Connection.ToHL7.Count == 0)
                    {
                        bool success = await ToHL7Signal.WaitAsync(_profileStorage.Current.KickOffInterval, LITETask.cts.Token).ConfigureAwait(false);
                    }
                    await Task.Delay(1000).ConfigureAwait(false);  //to allow for some accumulation for efficient batching.

                    if (Connection.ToHL7.Count > 0)
                    {
                        await SendToHL7(taskID);
                    }
                } while (Connection.responsive);
            }
            catch (TaskCanceledException)
            {
                _logger.Log(LogLevel.Information, $"Task was canceled.");
            }
            catch (OperationCanceledException)
            {
                _logger.Log(LogLevel.Warning, $"Wait Operation Canceled. Exiting Upload");
            }
            catch (Exception e)
            {
                _logger.LogFullException(e, taskInfo);
                _logger.Log(LogLevel.Critical, $"{taskInfo} Exiting Upload");
            }
            finally
            {
                LITETask.Stop($"{Connection.name}.Upload");
            }
        }
        private async Task Purge(int taskID)
        {
            var taskInfo = $"task: {taskID}";

            try
            {
                await Task.Run(() =>
                {
                    _purgeService.Purge(taskID, Connection);
                });
            }
            catch (TaskCanceledException)
            {
                _logger.Log(LogLevel.Information, $"Task was canceled.");
            }
            catch (Exception e)
            {
                _logger.LogFullException(e);
            }
            finally
            {
                LITETask.Stop($"{Connection.name}.Purge");
            }
        }
        public override async Task Kickoff(int taskID)
        {
            var taskInfo = $"task: {taskID} connection: {Connection.name}";

            _logger.Log(LogLevel.Debug, $"{taskInfo} Beginning Tasks");
            var profile = _profileStorage.Current;

            try
            {
                if (Connection.TestConnection)
                {
                    if (LITETask.CanStart($"{Connection.name}.echoscu") && (Connection.inout == InOut.outbound | Connection.inout == InOut.both))
                    {
                        var  newTaskID = LITETask.NewTaskID();
                        Task task      = new Task(new Action(async() => await EchoSCU(newTaskID)));
                        await LITETask.Start(newTaskID, task, $"{Connection.name}.echoscu", isLongRunning : true);
                    }
                }

                if (LITETask.CanStart($"{Connection.name}.PushtoDicomEventLoop"))
                {
                    var  newTaskID = LITETask.NewTaskID();
                    Task task      = new Task(new Action(async() => await PushtoDicomEventLoop(newTaskID)));
                    await LITETask.Start(newTaskID, task, $"{Connection.name}.PushtoDicomEventLoop", isLongRunning : false);
                }

                if (LITETask.CanStart($"{Connection.name}.storescp") && (Connection.inout == InOut.inbound | Connection.inout == InOut.both))
                {
                    var  newTaskID = LITETask.NewTaskID();
                    Task task      = new Task(new Action(async() => await StoreScp(newTaskID)));
                    await LITETask.Start(newTaskID, task, $"{Connection.name}.storescp", isLongRunning : true);
                }

                if (LITETask.CanStart($"{Connection.name}.SendToRules"))
                {
                    var  newTaskID = LITETask.NewTaskID();
                    Task task      = new Task(new Action(async() => await SendToRules(newTaskID, Connection.responsive)));
                    await LITETask.Start(newTaskID, task, $"{Connection.name}.SendToRules", isLongRunning : true);
                }

                if (LITETask.CanStart($"{Connection.name}.Scanner"))
                {
                    var  newTaskID = LITETask.NewTaskID();
                    Task task      = new Task(new Action(async() => await Scanner(newTaskID)));
                    await LITETask.Start(newTaskID, task, $"{Connection.name}.Scanner", isLongRunning : false);
                }

                await Task.Delay(profile.KickOffInterval, LITETask.cts.Token).ConfigureAwait(false);
            }
            catch (TaskCanceledException)
            {
                _logger.Log(LogLevel.Information, $"Task was canceled.");
            }
            catch (Exception e)
            {
                _logger.LogFullException(e, taskInfo);
            }
            finally
            {
                LITETask.Stop($"{Connection.name}.Kickoff");
            }

            _logger.Log(LogLevel.Debug, $"{taskInfo} Ending Tasks");
        }
示例#10
0
        public override void Init()
        {
            if (Connection.Boxes.Count == 0)
            {
                //add sample box
                ShareDestinations shareDestinations = new ShareDestinations
                {
                    boxUuid = "19db62ba-128d-412c-8c4f-df28351e8ae0",
                    boxName = "LITESample"
                };
                Connection.Boxes.Add(shareDestinations);
            }

            List <string> fileEntries;

            string dir;

            lock (InitLock)
            {
                LITETask.Register($"{Connection.name}.Wado", Connection.maxWadoTasks);
                LITETask.Register($"{Connection.name}.Stow", Connection.maxStowTasks);
                LITETask.Register($"{Connection.name}.downloadStudy", Connection.maxStudyDownloadTasks);
                LITETask.Register($"{Connection.name}.putHL7", Connection.maxHL7UploadTasks);
                LITETask.Register($"{Connection.name}.PostResponse", Connection.maxPostResponseTasks);

                if (loginNeeded)
                {
                    base.Init();
                    int newTaskID = LITETask.NewTaskID();


                    // Register is a one-time operation.  Once you have your tenantID, don't call this again, but populate the tenantID upon class instantiation.
                    if (Connection.tenantID == null)
                    {
                        register(newTaskID).Wait();
                    }

                    // if you tried to register and you still don't have a tenantID, we're done.
                    if (Connection.tenantID == null)
                    {
                        _logger.Log(LogLevel.Warning, $"Account is not registered.");
                        return;
                    }

                    // //login
                    // newTaskID = LITETask.newTaskID();
                    // var result = login(newTaskID).Result;
                    // if (result != "OK")
                    // {
                    //     return;  //this is to prevent reading in work below if we don't login.
                    // }
                }

                //read the persisted RoutedItems bound for Cloud

                dir = _profileStorage.Current.tempPath +
                      Path.DirectorySeparatorChar +
                      Connection.name +
                      Path.DirectorySeparatorChar +
                      Constants.Dirs.ToCloud +
                      Path.DirectorySeparatorChar +
                      Constants.Dirs.Meta;

                Directory.CreateDirectory(dir);
                fileEntries = _util.DirSearch(dir, Constants.Extensions.MetaExt.ToSearchPattern());

                foreach (string file in fileEntries)
                {
                    var st = _routedItemLoader.LoadFromFile(file);
                    if (st == null)
                    {
                        continue;
                    }

                    st.fromConnection = Connection.name;

                    if (!Connection.toCloud.Contains(st))
                    {
                        Connection.toCloud.Add(st);
                    }
                }
            }

            //read the persisted RoutedItems bound for Rules

            dir = _profileStorage.Current.tempPath +
                  Path.DirectorySeparatorChar +
                  Connection.name +
                  Path.DirectorySeparatorChar +
                  Constants.Dirs.ToRules +
                  Path.DirectorySeparatorChar +
                  Constants.Dirs.Meta;

            Directory.CreateDirectory(dir);
            fileEntries = _util.DirSearch(dir, Constants.Extensions.MetaExt.ToSearchPattern());

            foreach (string file in fileEntries)
            {
                RoutedItem ri = _routedItemLoader.LoadFromFile(file);
                if (ri == null)
                {
                    continue;
                }

                ri.fromConnection = Connection.name;

                if (!toRules.Contains(ri))
                {
                    toRules.Add(ri);
                }
            }

            Connection.started = true;
        }
示例#11
0
        public override async Task Kickoff(int taskID)
        {
            var taskInfo = $"task: {taskID} connection: {Connection.name}";

            _logger.Log(LogLevel.Debug, $"{taskInfo} Entering Kickoff");

            try
            {
                if (Connection.isPrimary && LITETask.CanStart($"{Connection.name}.ExpireCache"))
                {
                    var  newTaskID = LITETask.NewTaskID();
                    Task task      = new Task(new Action(async() => await ExpireCache(newTaskID)), LITETask.cts.Token);
                    LITETask.Start(newTaskID, task, $"{Connection.name}.ExpireCache", isLongRunning: true).Wait();
                }

                if (Connection.TestConnection)
                {
                    if (LITETask.CanStart($"{Connection.name}.PingCert"))
                    {
                        var  newTaskID = LITETask.NewTaskID();
                        Task task      = new Task(new Action(async() => await PingCert(Connection.URL, newTaskID)));
                        await LITETask.Start(newTaskID, task, $"{Connection.name}.PingCert", isLongRunning : false);
                    }
                }

                if (loginNeeded)
                {
                    await login(taskID);
                }

                if (LITETask.CanStart($"{Connection.name}.KeepAlive"))
                {
                    var  newTaskID = LITETask.NewTaskID();
                    Task task      = new Task(new Action(async() => await KeepAlive()));
                    await LITETask.Start(newTaskID, task, $"{Connection.name}.KeepAlive", isLongRunning : false);
                }

                if (LITETask.CanStart($"{Connection.name}.SendToRules"))
                {
                    var  newTaskID = LITETask.NewTaskID();
                    Task task      = new Task(new Action(async() => await SendToRules(newTaskID, Connection.responsive)),
                                              LITETask.cts.Token);
                    await LITETask.Start(newTaskID, task, $"{Connection.name}.SendToRules", isLongRunning : true);
                }

                var currentProfile = _profileStorage.Current;
                var rules          = currentProfile.rules;

                _rulesManager.Init(rules);

                if (_rulesManager.DoesRouteDestinationExistForSource(Connection.name))
                {
                    if (LITETask.CanStart($"{Connection.name}.Download"))
                    {
                        var  newTaskID = LITETask.NewTaskID();
                        Task task      = new Task(new Action(async() => await Download(newTaskID)), LITETask.cts.Token);
                        await LITETask.Start(newTaskID, task, $"{Connection.name}.Download", isLongRunning : false);
                    }

                    if (LITETask.CanStart($"{Connection.name}.markDownloadComplete"))
                    {
                        var  newTaskID = LITETask.NewTaskID();
                        Task task      = new Task(new Action(async() => await markDownloadComplete(taskID)), LITETask.cts.Token);
                        await LITETask.Start(newTaskID, task, $"{Connection.name}.markDownloadComplete", isLongRunning : false);
                    }
                }

                if (LITETask.CanStart($"{Connection.name}.Upload"))
                {
                    var  newTaskID = LITETask.NewTaskID();
                    Task task      = new Task(new Action(async() => await Upload(newTaskID)));
                    await LITETask.Start(newTaskID, task, $"{Connection.name}.Upload", isLongRunning : false);
                }


                if (LITETask.CanStart($"{Connection.name}.getShareDestinations"))
                {
                    var  newTaskID = LITETask.NewTaskID();
                    Task task      = new Task(new Action(async() => await getShareDestinations(newTaskID)));
                    await LITETask.Start(newTaskID, task, $"{Connection.name}.getShareDestinations", isLongRunning : false);
                }
            }
            catch (TaskCanceledException)
            {
                _logger.Log(LogLevel.Information, $"{taskInfo} Task was canceled.");
            }
            catch (Exception e)
            {
                _logger.LogFullException(e, $"{taskInfo} Exiting Kickoff Due to Exception");
            }
            finally
            {
                LITETask.Stop($"{Connection.name}.Kickoff");
            }
        }
示例#12
0
        // Keep session alive to avoid timeouts etc
        public async Task KeepAlive()
        {
            await _keepAliveService.KeepAlive(Connection, GetHttpManager());

            LITETask.Stop($"{Connection.name}.KeepAlive");
        }
        //public static IWebHostBuilder CreateWebHostBuilder(string[] args)
        //{

        //    return WebHost.CreateDefaultBuilder(args).UseStartup<Startup>();
        //    // return BlazorWebAssemblyHost.CreateDefaultBuilder()
        //    //     .UseBlazorStartup<Startup>();

        //}

        public override async Task Kickoff(int taskID)
        {
            var taskInfo = $"task: {taskID} connection: {Connection.name}";

            _logger.Log(LogLevel.Debug, $"{taskInfo} Entering Kickoff");

            try
            {
                var profile = _profileStorage.Current;

                LiteProfileUtils liteProfileUtils = new LiteProfileUtils(profile);

                Connection.boxes = liteProfileUtils.GetBoxes();

                Connection.shareDestinations = liteProfileUtils.GetShareDestinations();

                if (Connection.inout == InOut.inbound | Connection.inout == InOut.both)
                {
                    if (Connection.egs)
                    {
                        if ((LiteEngine.kickOffCount + 9) % 10 == 0)
                        {
                            if (LITETask.CanStart($"{Connection.name}.Purge"))
                            {
                                var  newTaskID = LITETask.NewTaskID();
                                Task task      = new Task(new Action(async() => await Purge(newTaskID)), LITETask.cts.Token);
                                await LITETask.Start(newTaskID, task, $"{Connection.name}.Purge", isLongRunning : false);
                            }
                        }

                        //EGS http Listening port
                        if (LITETask.CanStart($"{Connection.name}.EGS"))
                        {
                            string[] args      = { $"name={Connection.name}" };
                            var      newTaskID = LITETask.NewTaskID();

                            // todo: migrate later
//                            Task task = new Task(new Action(async () => await CreateWebHostBuilder(args).Build().RunAsync()), LITETask.cts.Token);

//#pragma warning disable 4014

//                            //task.ContinueWith(x => LITETask.Stop($"{name}.EGS"), ct);

//#pragma warning restore 4014

//                            await LITETask.Start(newTaskID, task, $"{Connection.name}.EGS", $"{Connection.name}.EGS", isLongRunning: true);
//                            var stopWatch = new Stopwatch();
//                            stopWatch.Start();

//                            do
//                            {
//                                await Task.Delay(10000).ConfigureAwait(false); //loop until server is started

//                            } while (!await ping());
//                            stopWatch.Stop();
//                            _logger.Log(LogLevel.Information, $"{taskInfo} EGS Server Started elapsed: {stopWatch.Elapsed}");
                            OpenBrowser();
                        }
                    }

                    await ConnectToHubs();
                    await RegisterWithEGS(taskID);

                    if (LITETask.CanStart($"{Connection.name}.Download"))
                    {
                        var  newTaskID = LITETask.NewTaskID();
                        Task task      = new Task(new Action(async() => await Download(newTaskID)), LITETask.cts.Token);
                        await LITETask.Start(newTaskID, task, $"{Connection.name}.Download", isLongRunning : false);
                    }
                }

                if (Connection.inout == InOut.outbound | Connection.inout == InOut.both)
                {
                    if (Connection.TestConnection)
                    {
                        if (LITETask.CanStart($"{Connection.name}.PingCert"))
                        {
                            var  newTaskID = LITETask.NewTaskID();
                            Task task      = new Task(new Action(async() => await PingCert(Connection.URL, newTaskID)));
                            await LITETask.Start(newTaskID, task, $"{Connection.name}.PingCert", isLongRunning : false);
                        }
                    }

                    if (LITETask.CanStart($"{Connection.name}.Upload"))
                    {
                        var  newTaskID = LITETask.NewTaskID();
                        Task task      = new Task(new Action(async() => await Upload(newTaskID)));
                        await LITETask.Start(newTaskID, task, $"{Connection.name}.Upload", isLongRunning : false);
                    }
                }

                if (LITETask.CanStart($"{Connection.name}.SendToRules"))
                {
                    var  newTaskID = LITETask.NewTaskID();
                    Task task      = new Task(new Action(async() => await SendToRules(newTaskID, Connection.responsive)), LITETask.cts.Token);
                    await LITETask.Start(newTaskID, task, $"{Connection.name}.SendToRules", isLongRunning : true);
                }

                if (LITETask.CanStart($"{Connection.name}.ProcessHubMessages"))
                {
                    var  newTaskID = LITETask.NewTaskID();
                    Task task      = new Task(new Action(async() => await ProcessHubMessages(newTaskID)), LITETask.cts.Token);
                    await LITETask.Start(newTaskID, task, $"{Connection.name}.ProcessHubMessages", isLongRunning : false);
                }
            }
            catch (TaskCanceledException)
            {
                _logger.Log(LogLevel.Information, $"Task was canceled.");
            }
            catch (Exception e)
            {
                _logger.LogFullException(e, $"{taskInfo} Exiting Kickoff Due to Exception ");
            }
            finally
            {
                LITETask.Stop($"{Connection.name}.Kickoff");
            }
        }
        public override void Init()
        {
            LITETask.Register($"{Connection.name}.DownloadViaHttp", Connection.maxDownloadViaHttpTasks);
            LITETask.Register($"{Connection.name}.Store", Connection.maxStoreTasks);
            List <string> fileEntries;

            var profile = _profileStorage.Current;

            lock (InitLock)
            {
                base.Init();

                //read the persisted RoutedItems bound for EGS

                string dir = profile.tempPath + Path.DirectorySeparatorChar + Connection.name + Path.DirectorySeparatorChar + "toEGS" + Path.DirectorySeparatorChar + Constants.Dirs.Meta;
                Directory.CreateDirectory(dir);
                fileEntries = _util.DirSearch(dir, Constants.Extensions.MetaExt.ToSearchPattern());

                foreach (string file in fileEntries)
                {
                    RoutedItem st = _routedItemLoader.LoadFromFile(file);
                    if (st == null)
                    {
                        continue;
                    }

                    st.fromConnection = Connection.name;

                    if (!Connection.toEGS.Contains(st))
                    {
                        Connection.toEGS.Add(st);
                    }
                }

                //read the persisted RoutedItems bound for Rules

                dir = profile.tempPath + Path.DirectorySeparatorChar + Connection.name + Path.DirectorySeparatorChar + Constants.Dirs.ToRules + Path.DirectorySeparatorChar + Constants.Dirs.Meta;
                Directory.CreateDirectory(dir);
                fileEntries = _util.DirSearch(dir, Constants.Extensions.MetaExt.ToSearchPattern());

                foreach (string file in fileEntries)
                {
                    RoutedItem ri = _routedItemLoader.LoadFromFile(file);
                    if (ri == null)
                    {
                        continue;
                    }
                    ri.fromConnection = Connection.name;

                    if (!toRules.Contains(ri))
                    {
                        toRules.Add(ri);
                    }
                }

                //read the persisted RoutedItems inbound from EGS
                dir = profile.tempPath + Path.DirectorySeparatorChar + Connection.name + Path.DirectorySeparatorChar + "fromEGS" + Path.DirectorySeparatorChar + Constants.Dirs.Meta;
                Directory.CreateDirectory(dir);
                fileEntries = _util.DirSearch(dir, Constants.Extensions.MetaExt.ToSearchPattern());

                foreach (string file in fileEntries)
                {
                    RoutedItem ri = _routedItemLoader.LoadFromFile(file);
                    if (ri == null)
                    {
                        continue;
                    }

                    ri.fromConnection = Connection.name;

                    if (!Connection.fromEGS.Contains(ri))
                    {
                        Connection.fromEGS.Add(ri);
                    }
                }
            }

            Connection.started = true;
        }
        public override void Init()
        {
            _logger.Log(LogLevel.Debug, $"{Connection.name} entering init.");

            base.Init();

            //register semaphore limits
            LITETask.Register($"{Connection.name}.read", Connection.maxInboundConnections);

            //2019-04-05 shb BOUR-934 old code was for conn.accept semaphore (without ip:port) which caused more than one accept per ip:port
            //in situations where multiple addresses were returned but say ipv6 was disabled.  Now we don't need to specify
            //so that when we create the task the type is specific to the ip and port which will register a semaphore of 1

            // var addressList = Dns.GetHostEntry(localHostname).AddressList;
            // foreach( var address in addressList){
            //     LITETask.Register($"{name}.accept: {address}:{localPort}", 1);
            // }

            //read the persisted RoutedItems bound for Rules

            string dir = _profileStorage.Current.tempPath + Path.DirectorySeparatorChar + Connection.name + Path.DirectorySeparatorChar + Constants.Dirs.ToRules + Path.DirectorySeparatorChar + Constants.Dirs.Meta;

            Directory.CreateDirectory(dir);
            var fileEntries = _util.DirSearch(dir, Constants.Extensions.MetaExt.ToSearchPattern());

            foreach (string file in fileEntries)
            {
                RoutedItem ri = _routedItemLoader.LoadFromFile(file);
                if (ri == null)
                {
                    continue;
                }

                ri.fromConnection = Connection.name;

                if (!toRules.Contains(ri))
                {
                    toRules.Add(ri);
                }
            }

            //read the persisted RoutedItems bound for HL7

            dir = _profileStorage.Current.tempPath + Path.DirectorySeparatorChar + Connection.name + Path.DirectorySeparatorChar + "toHL7" + Path.DirectorySeparatorChar + Constants.Dirs.Meta;
            Directory.CreateDirectory(dir);
            fileEntries = _util.DirSearch(dir, Constants.Extensions.MetaExt.ToSearchPattern());

            foreach (string file in fileEntries)
            {
                RoutedItem ri = _routedItemLoader.LoadFromFile(file);
                if (ri == null)
                {
                    continue;
                }

                ri.fromConnection = Connection.name;

                if (!Connection.ToHL7.Contains(ri))
                {
                    Connection.ToHL7.Add(ri);
                }
            }

            Connection.started = true;
        }