コード例 #1
0
        public async Task SaveProfile(Profile profile)
        {
            Throw.IfNull(profile);

            var taskInfo = "";

            try
            {
                await SyncWithCloud(profile);
            }
            catch (TaskCanceledException)
            {
                _logger.Log(LogLevel.Information, $"{taskInfo} Task Canceled");
            }
            catch (System.Net.Http.HttpRequestException e)
            {
                _logger.Log(LogLevel.Critical, $"{taskInfo} HttpRequestException: {e.Message} {e.StackTrace}");
            }
            catch (NullReferenceException)
            {
                _logger.Log(LogLevel.Critical, $"{taskInfo} no putCloudProfile arg. Remote Monitoring Disabled!!");
            }
            catch (InvalidOperationException e)
            {
                _logger.Log(LogLevel.Warning, $"{taskInfo} unable to putCloudProfile due to concurrent Profile modification. {e.Message} {e.StackTrace}");
            }
            catch (Exception e)
            {
                _logger.Log(LogLevel.Critical, $"{taskInfo} unable to putCloudProfile due to concurrent Profile modification. {e.Message} {e.StackTrace}");
                if (e.InnerException != null)
                {
                    _logger.Log(LogLevel.Critical, $"Inner Exception: {e.InnerException}");
                }
            }

            try
            {
                if (profile.startupParams.saveProfilePath != null)
                {
                    _fileProfileWriter.Save(profile, profile.startupParams.saveProfilePath);

                    // During write set modified date to now so it doesn't go back around and reload
                    Profile.modifiedDate = DateTime.Now;
                }
            }
            catch (NullReferenceException)
            {
                _logger.Log(LogLevel.Critical, $"{taskInfo} no saveProfileFile arg. Agent startup may not include latest config!!  Set saveProfileFile to the same value as loadProfileFile.");
            }
        }
コード例 #2
0
        public bool ConfigureDcmtk(bool install, Profile profile, string currentProfile)
        {
            var stopWatch = new Stopwatch();

            stopWatch.Start();
            profile.version++;

            //determine platform
            var platform = Environment.OSVersion.Platform;

            Console.WriteLine($"OSVersion is {Environment.OSVersion}");
            Console.WriteLine($"{RuntimeInformation.OSDescription}");
            Console.WriteLine($"Processor:{System.Runtime.InteropServices.RuntimeInformation.ProcessArchitecture} OS Arch:{System.Runtime.InteropServices.RuntimeInformation.OSArchitecture}");
            Console.WriteLine($"{System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription}");
            Console.WriteLine($"Current Profile is {currentProfile}");


            if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
            {
                Console.WriteLine($"Platform is Linux");
                if (install)
                {
                    Console.WriteLine("Linux: dcmtk-3.6.3-linux-x86_64.tar.bz2 will be uncompressed ../LITE/tools/dcmtk/dcmtk-3.6.3-linux-x86_64");

                    //tar -xjvf tools/dcmtk/dcmtk-3.6.3-linux-x86_64.tar.bz2
                    var proc = new Process();
                    ProcessStartInfo procinfo = new ProcessStartInfo
                    {
                        WindowStyle            = ProcessWindowStyle.Hidden,
                        CreateNoWindow         = true,
                        RedirectStandardError  = true,
                        RedirectStandardOutput = true,
                        Verb = "runas",

                        //Directory.CreateDirectory("tools/dcmtk/dcmtk-3.6.3-linux-x86_64");
                        Arguments = $"-xjvf tools/dcmtk/dcmtk-3.6.3-linux-x86_64.tar.bz2 -C tools/dcmtk",
                        FileName  = "tar"
                    };
                    proc.StartInfo = procinfo;


                    proc.Start();
                    proc.OutputDataReceived += (object sendingProcess,
                                                DataReceivedEventArgs outLine) =>
                    {
                        try
                        {
                            if (!string.IsNullOrEmpty(outLine.Data))
                            {
                                Console.WriteLine($"{outLine.Data}");
                            }
                        }

                        catch (Exception e)
                        {
                            _logger.Log(LogLevel.Information, $"{e.Message}{e.StackTrace}");
                        }
                    };
                    proc.ErrorDataReceived += (object sendingProcess, DataReceivedEventArgs outLine) =>
                    {
                        try
                        {
                            if (!String.IsNullOrEmpty(outLine.Data))
                            {
                                Console.WriteLine($"{outLine.Data}");
                            }
                        }

                        catch (Exception e)
                        {
                            _logger.Log(LogLevel.Information, $"{e.Message}{e.StackTrace}");
                        }
                    };
                    proc.EnableRaisingEvents = true;
                    proc.Exited += (object sender, EventArgs e) =>
                    {
                        Process p = (Process)sender;
                        if (p.ExitCode != 0)
                        {
                            Console.WriteLine($"{((Process)sender).StartInfo.FileName} Proc ExitCode:{proc.ExitCode}");
                        }
                        ;
                    };

                    while (!proc.HasExited)
                    {
                        Console.WriteLine($"{procinfo.FileName} is running...");
                        Task.Delay(1000, _taskManager.cts.Token).Wait();
                    }

                    if (proc.ExitCode != 0)
                    {
                        Console.WriteLine($"Not updating dcmtkLibPath due to extraction error.");
                        return(false);
                    }
                    else
                    {
                        Console.WriteLine($"Updating dcmtkLibPath.");
                        profile.dcmtkLibPath = "tools/dcmtk/dcmtk-3.6.3-linux-x86_64";
                        //profile.Save(currentProfile);
                        _fileProfileWriter.Save(profile, currentProfile);
                    }
                }

                else
                {
                    if (profile.dcmtkLibPath != null)
                    {
                        Console.WriteLine($"Clearing dcmtkLibPath.");
                        Directory.Delete(profile.dcmtkLibPath, true);
                        profile.dcmtkLibPath = null;
                        //profile.Save(currentProfile);
                        _profileWriter.SaveProfile(profile).Wait();
                    }
                }
            }

            if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
            {
                Console.WriteLine($"Platform is OSX");
                if (install)
                {
                    Console.WriteLine("Mac: dcmtk-3.6.3-macosx-x86_64.tar.bz2 will be uncompressed to tools/dcmtk/dcmtk-3.6.3-macosx-x86_64");

                    //tar -xjvf tools/dcmtk/dcmtk-3.6.3-macosx-x86_64.tar.bz2
                    var proc = new Process();
                    ProcessStartInfo procinfo = new ProcessStartInfo
                    {
                        WindowStyle            = ProcessWindowStyle.Hidden,
                        CreateNoWindow         = true,
                        RedirectStandardError  = true,
                        RedirectStandardOutput = true,

                        Verb = "runas",

                        //Directory.CreateDirectory("tools/dcmtk/dcmtk-3.6.3-macosx-x86_64");
                        Arguments = $"-xjvf tools/dcmtk/dcmtk-3.6.3-macosx-x86_64.tar.bz2 -C tools/dcmtk",
                        FileName  = "tar"
                    };

                    proc.StartInfo           = procinfo;
                    proc.OutputDataReceived += (object sendingProcess, DataReceivedEventArgs outLine) =>
                    {
                        try
                        {
                            if (!String.IsNullOrEmpty(outLine.Data))
                            {
                                Console.WriteLine($"{outLine.Data}");
                            }
                        }

                        catch (Exception e)
                        {
                            _logger.Log(LogLevel.Information, $"{e.Message}{e.StackTrace}");
                        }
                    };
                    proc.ErrorDataReceived += (object sendingProcess, DataReceivedEventArgs outLine) =>
                    {
                        try
                        {
                            if (!string.IsNullOrEmpty(outLine.Data))
                            {
                                Console.WriteLine($"{outLine.Data}");
                            }
                        }

                        catch (Exception e)
                        {
                            _logger.Log(LogLevel.Information, $"{e.Message}{e.StackTrace}");
                        }
                    };
                    proc.EnableRaisingEvents = true;
                    proc.Exited += (object sender, EventArgs e) =>
                    {
                        Process p = (Process)sender;
                        if (p.ExitCode != 0)
                        {
                            Console.WriteLine($"{((Process)sender).StartInfo.FileName} Proc ExitCode:{proc.ExitCode}");
                        }
                        ;
                    };

                    proc.Start();
                    proc.BeginOutputReadLine();
                    proc.BeginErrorReadLine();

                    while (!proc.HasExited)
                    {
                        Console.WriteLine($"{procinfo.FileName} is running...");
                        Task.Delay(1000, _taskManager.cts.Token).Wait();
                    }

                    if (proc.ExitCode != 0)
                    {
                        return(false);
                    }
                    else
                    {
                        profile.dcmtkLibPath = "tools/dcmtk/dcmtk-3.6.3-maxosx-x86_64";
                        //profile.Save(currentProfile);
                        _fileProfileWriter.Save(profile, currentProfile);
                    }
                }
                else
                {
                    if (profile.dcmtkLibPath != null)
                    {
                        Console.WriteLine($"Clearing dcmtkLibPath.");
                        Directory.Delete(profile.dcmtkLibPath, true);
                        profile.dcmtkLibPath = null;
                        //profile.Save(currentProfile);
                        _fileProfileWriter.Save(profile, currentProfile);
                    }
                }
            }

            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                Console.WriteLine($"Platform is Windows");
                Console.WriteLine($"Windows: dcmtk-3.6.3-win64-dynamic.zip will be uncompressed to ../LITE/tools/dcmtk/dcmtk-3.6.3-win64-dynamic");

                if (install)
                {
                    ZipFile.ExtractToDirectory("tools/dcmtk/dcmtk-3.6.3-win64-dynamic.zip", "tools/dcmtk");
                    profile.dcmtkLibPath = "tools" + Path.DirectorySeparatorChar + Constants.Dirs.dcmtk + Path.DirectorySeparatorChar + "dcmtk-3.6.3-win64-dynamic";
                    //profile.Save(currentProfile);
                    _fileProfileWriter.Save(profile, currentProfile);
                }
                else
                {
                    if (profile.dcmtkLibPath != null)
                    {
                        Console.WriteLine($"Clearing dcmtkLibPath.");
                        Directory.Delete(profile.dcmtkLibPath, true);
                        profile.dcmtkLibPath = null;
                        //profile.Save(currentProfile);
                        _fileProfileWriter.Save(profile, currentProfile);
                    }
                }
            }

            return(true);
        }
コード例 #3
0
        public ConfigurationLoaderPackage LoadConfiguration(string[] args, List <string> argsList)
        {
            System.Reflection.Assembly assembly = System.Reflection.Assembly.GetEntryAssembly();
            FileVersionInfo            fvi      = FileVersionInfo.GetVersionInfo(assembly.Location);
            var version = fvi.FileVersion;

            SaveInRegistry(version);

            var newCurrentDir = assembly.Location.Substring(0, assembly.Location.LastIndexOf(Path.DirectorySeparatorChar));

            Directory.SetCurrentDirectory(newCurrentDir);

            _logger.LogInformation($"LiTE current directory = {newCurrentDir}");

            var currentDir = Directory.GetCurrentDirectory();

            _logger.Log(LogLevel.Information, $"Life Image Transfer Exchange v{version} Started");

            var stopWatch = new Stopwatch();

            var taskInfo = $"";

            stopWatch.Start();

            ExtractWindowsDCMTK();
            var platform = DetectPlatform();

            string startupConfigFilePath = _liteConfigService.GetDefaults().StartupConfigFilePath;

            _logger.Log(LogLevel.Warning, $"startupConfigFilePath: {startupConfigFilePath} Profiles: {_util.GetTempFolder(Constants.Dirs.Profiles)}");

            //2019-05-22 shb copy profile files to working folder.  Needed for read-only installs such as OSX .app bundle and docker/kubernetes
            if (!Directory.Exists(_util.GetTempFolder(Constants.Dirs.Profiles)))
            {
                _logger.Log(LogLevel.Warning, $"{_util.GetTempFolder(Constants.Dirs.Profiles)} does not exist.");
                _logger.Log(LogLevel.Warning, $"Current Directory: {Directory.GetCurrentDirectory()}");

                //TODO check legacy folder locations for existing profile and copy to new location
                if (Directory.Exists(Constants.ProgramDataDir + Path.DirectorySeparatorChar + Constants.Dirs.Profiles))
                {
                    _logger.Log(LogLevel.Warning, $"Copying legacy profiles {Constants.ProgramDataDir + Path.DirectorySeparatorChar + Constants.Dirs.Profiles}");

                    Directory.CreateDirectory(_util.GetTempFolder(Constants.Dirs.Profiles));
                    foreach (string filename in Directory.EnumerateFiles(Constants.ProgramDataDir + Path.DirectorySeparatorChar + Constants.Dirs.Profiles))
                    {
                        var destfile = _util.GetTempFolder(Constants.Dirs.Profiles) + Path.DirectorySeparatorChar + filename.Substring(filename.LastIndexOf(Path.DirectorySeparatorChar));
                        _logger.Log(LogLevel.Information, $"Copying {filename} to {destfile}");

                        using FileStream SourceStream      = File.Open(filename, FileMode.Open, FileAccess.Read);
                        using FileStream DestinationStream = File.Create(destfile);
                        SourceStream.CopyTo(DestinationStream);
                    }
                }
                else if (Directory.Exists(Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + Constants.Dirs.Profiles))
                {
                    _logger.Log(LogLevel.Warning, $"Copying default profiles {Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + Constants.Dirs.Profiles}");

                    Directory.CreateDirectory(_util.GetTempFolder(Constants.Dirs.Profiles));
                    foreach (string filename in Directory.EnumerateFiles(Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + Constants.Dirs.Profiles))
                    {
                        var destfile = _util.GetTempFolder(Constants.Dirs.Profiles) + Path.DirectorySeparatorChar + filename.Substring(filename.LastIndexOf(Path.DirectorySeparatorChar));
                        _logger.Log(LogLevel.Information, $"Copying {filename} to {destfile}");

                        using FileStream SourceStream      = File.Open(filename, FileMode.Open, FileAccess.Read);
                        using FileStream DestinationStream = File.Create(destfile);
                        SourceStream.CopyTo(DestinationStream);
                    }
                }
                else
                {
                    _logger.Log(LogLevel.Warning, $"{Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + Constants.Dirs.Profiles} does not exist.");
                }
            }

            var startupProfile = _profileLoaderService.LoadStartupConfiguration(startupConfigFilePath);

            if (startupProfile.startupParams.localProfilePath != _util.GetTempFolder(startupProfile.startupParams.localProfilePath))
            {
                _logger.Log(LogLevel.Warning, $"Changing startupProfile.startupParams.localProfilePath: {startupProfile.startupParams.localProfilePath} to {_util.GetTempFolder(startupProfile.startupParams.localProfilePath)}");

                startupProfile.startupParams.localProfilePath = _util.GetTempFolder(startupProfile.startupParams.localProfilePath);
                startupProfile.startupParams.saveProfilePath  = _util.GetTempFolder(startupProfile.startupParams.saveProfilePath);
                _profileFileWriter.Save(startupProfile, startupConfigFilePath);
            }

            // ulong installedMemory;
            // MEMORYSTATUSEX memStatus = new MEMORYSTATUSEX();
            // if (GlobalMemoryStatusEx(memStatus))
            // {
            //     installedMemory = memStatus.ullTotalPhys;
            // }


            //ShowGreetings();

            // load the logger
            //var profile = new Profile(Logger.logger);
            var profile = new Profile();

            //profile.logger

            // todo: load logger

            // check for setup
            // if (args.Length != 0 && args[0].ToLower() != "setup")
            // {
            //     profile = loadArgs(args, profile);   // re-assign, can be replaced

            //     LITE.SaveToStartupConfigration(profile);
            // }
            // else
            // {
            //startupProfile = Profile.LoadStartupConfiguration();
            startupProfile = _profileLoaderService.LoadStartupConfiguration(startupConfigFilePath);
            profile        = startupProfile;
            //                    }

            //                    _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;

            _logger.Log(LogLevel.Debug, $"Startup Configuration: {profile}");

            //setup
            if (args != null && args.Length > 0 && args[0] != null && args[0] == "setup")
            {
                bool exitCode = false;

                if (args.Length == 1)
                {
                    Setup.EnterSetup(profile);
                }
                else
                {
                    var arg = argsList.Find(x => x.Contains("register="));
                    if (arg != null)
                    {
                        var regParamList = argsList.Find(x => x.Contains("register=")).Substring(9);

                        var regParams = regParamList.Split(',');
                        if (regParams.Length == 4)
                        {
                            exitCode = Setup.Register(regParams, profile);
                            _util.ConfigureService(true);
                        }
                        else
                        {
                            _logger.Log(LogLevel.Information, "Lite Registration: Lite register=\"username,password,orgcode,servicename\"");
                        }
                    }
                    else
                    {
                        var argUninstall = argsList.Find(x => x.Contains("uninstall"));
                        if (argUninstall != null)
                        {
                            _util.ConfigureService(false);
                        }
                    }
                }

                Environment.Exit((exitCode == false) ? 0 : 1);
            }

            // recovery loop
            _logger.Log(LogLevel.Information, "Life Image Transfer Exchange - Starting Processing");
            profile.lastStartup = DateTime.Now;

            //instantiate the class instance

            //var lite = new LITE(profile);

            profile.runningCodeVersion = version;
            //LITE.profile.runningCodeVersion = version;

            _logger.Log(LogLevel.Information, $"{taskInfo} Running time: {stopWatch.Elapsed}");

            return(new ConfigurationLoaderPackage(profile, platform, version));
        }