Example #1
0
        private bool RunSam(Run.RunOptions options)
        {
            if (options.SetDbDate)
            {
                using (var pr = new ProcessRunner())
                {
                    int exitCode = pr.ExecuteProcess("setdbdat", "today force", _appSettings.TempDir, true);
                    if (exitCode != 0)
                    {
                        this.ShowError(string.Format("\"setdbdat today force\" returned exit code {0}.\n\n" +
                                                     "(The SAM will still start, but the dbdate may be incorrect)", exitCode));
                    }
                }
            }

            var args = options.CreateSamArgsString();

            using (Process proc = new Process())
            {
                var platformPath = _appSettings.PlatformPath;
                if (string.IsNullOrEmpty(platformPath))
                {
                    this.ShowError(Res.Err_DkPlatformDirUnknown);
                    return(false);
                }

                var exePathName = Path.Combine(platformPath, "SAM.exe");
                if (!File.Exists(exePathName))
                {
                    this.ShowError("SAM.exe not found in path.");
                    return(false);
                }

                ProcessStartInfo info = new ProcessStartInfo(exePathName, args);
                info.UseShellExecute        = false;
                info.RedirectStandardOutput = false;
                info.RedirectStandardError  = false;
                info.CreateNoWindow         = false;
                info.WorkingDirectory       = _appSettings.ExeDirs.FirstOrDefault();
                proc.StartInfo = info;
                if (!proc.Start())
                {
                    this.ShowError("Unable to start the SAM.");
                    return(false);
                }
            }

            if (options.LoadSam && !options.Diags)
            {
                RunLoadSam(options);
            }

            return(true);
        }