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