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");
            }
        }
#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 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 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");
            }
        }
Пример #11
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");
            }
        }