예제 #1
0
        public async Task Process()
        {
            var taskInfo = $"";
            var profile  = _profileStorage.Current;

            _logger.Log(LogLevel.Information, "Life Image Transfer Exchange Loop");

            try
            {
                try
                {
                    lock (ProfileLocker)
                    {
                        _profileManager.LoadProfile(profile, profile.startupParams.localProfilePath);
                        //Profile.LoadProfile(profile, profile.startupParams.localProfilePath);
                        if (profile.duplicatesDetectionUpload)
                        {
                            string message = "Duplicates detection and elimination process is active for upload process.";
                            _logger.Log(LogLevel.Information, $"{message}");
                        }
                        else
                        {
                            string message = "Duplicates detection and elimination process is not active for upload process.";
                            _logger.Log(LogLevel.Information, $"{message}");
                        }
                        if (profile.duplicatesDetectionDownload)
                        {
                            string message = "Duplicates detection and elimination process is active for download process.";
                            _logger.Log(LogLevel.Information, $"{message}");
                        }
                        else
                        {
                            string message = "Duplicates detection and elimination process is not active for download process.";
                            _logger.Log(LogLevel.Information, $"{message}");
                        }
                        //var primaryConnection = profile.GetPrimaryLifeImageConnection();
                        var primaryConnection = _connectionFinder.GetPrimaryLifeImageConnection(profile);
                        if (primaryConnection == null)
                        {
                            throw new Exception($"Primary Connection Missing out of {profile.connections.Capacity} total connections.");
                        }

                        if (platform.Equals("win") && string.IsNullOrEmpty(profile.dcmtkLibPath))
                        {
                            Console.WriteLine(profile.name);
                            profile.dcmtkLibPath = "tools" + Path.DirectorySeparatorChar + Constants.Dirs.dcmtk + Path.DirectorySeparatorChar + "dcmtk-3.6.3-win64-dynamic";
                            //profile.SaveProfile();
                            _profileWriter.SaveProfile(profile).Wait();
                        }

                        if (!primaryConnection.loginNeeded)
                        {
                            _cloudProfileLoaderService.LoadProfile(profile, primaryConnection).Wait();
                            //profile.LoadProfile(primaryConnection).Wait();
                        }

                        //profile.SaveProfile();
                        _profileWriter.SaveProfile(profile).Wait();

                        bool isEnabled = false;
                        AppContext.TryGetSwitch("System.Net.Http.useSocketsHttpHandler", out isEnabled);

                        if (isEnabled != profile.useSocketsHttpHandler)
                        {
                            _logger.Log(LogLevel.Debug, $"{taskInfo} Calling AppContext.SetSwitch(\"System.Net.Http.useSocketsHttpHandler\", {profile.useSocketsHttpHandler})"); AppContext.SetSwitch("System.Net.Http.useSocketsHttpHandler", profile.useSocketsHttpHandler);
                        }
                    }
                }
                catch (Exception e)
                {
                    if (e.Message.Contains("Replacement Strategy Needs Full LITE.init()"))
                    {
                        _logger.Log(LogLevel.Critical, $"{taskInfo} Configuration changed received.");
                    }
                    else
                    {
                        _logger.LogFullException(e, $"{taskInfo} Profile Operations Problem: {e.Message}");
                    }

                    throw e;
                }

                //adjust loglevel if necessary
                //                                    _logger.LogLevel = profile.logger.logLevel;
                Logger.logger.ConsoleTraceLevel = profile.logger.ConsoleTraceLevel;
                Logger.logger.FileTraceLevel    = profile.logger.FileTraceLevel;
                Logger.logger.SplunkTraceLevel  = profile.logger.SplunkTraceLevel;
                Logger.logger.TracePattern      = profile.logger.TracePattern;

                //compile the scripts as needed
                foreach (var myscript in profile.rules.scripts)
                {
                    if (myscript.script == null)
                    {
                        _logger.Log(LogLevel.Debug, $"compiling {myscript.name}");
                        _scriptService.Compile(myscript);
                    }
                }


                //let's queue up some work
                _logger.Log(LogLevel.Information, "Life Image Transfer Exchange kickoff start");

                var newTaskID = _taskManager.NewTaskID();
                await kickOff(newTaskID);

                _logger.Log(LogLevel.Information, "Life Image Transfer Exchange kickoff end");

                if (profile.backlogDetection)
                {
                    foreach (var conn in profile.connections)
                    {
                        if (conn.toRules.Count > 0)
                        {
                            profile.backlog = true;
                        }
                    }

                    if (profile.backlog)
                    {
                        _logger.Log(LogLevel.Debug, $"{taskInfo} Detected Backlog, skipping kickoffInterval");
                        await Task.Delay(profile.backlogInterval, _taskManager.cts.Token);

                        profile.backlog = false;
                    }
                    else
                    {
                        await Task.Delay(profile.KickOffInterval, _taskManager.cts.Token);
                    }
                }
                else
                {
                    await Task.Delay(profile.KickOffInterval, _taskManager.cts.Token);
                }

                RecoveryCount = 0;
            }
            catch (Exception e)
            {
                if (LITETask._shutdown)
                {
                    throw new Exception("Application is terminated");
                }
                ;

                if (e.Message.Contains("Replacement Strategy Needs Full LITE.init()"))
                {
                }
                else
                {
                    _logger.Log(LogLevel.Critical, $"{taskInfo} Life Image Transfer Exchange Loop Exception: breaking out of run loop due to unrecoverable exception. {e.Message}");
                    if (e.InnerException != null)
                    {
                        _logger.Log(LogLevel.Critical, $"Inner Exception: {e.InnerException}");
                    }
                }
            }
        }