public IXApplication StartApplication(AppVersionInfo vers, StartupOptions_e opts, CancellationToken cancellationToken) { var args = new List <string>(); if (opts.HasFlag(StartupOptions_e.Safe)) { args.Add(SwApplication.CommandLineArguments.SafeMode); } if (opts.HasFlag(StartupOptions_e.Background)) { args.Add(SwApplication.CommandLineArguments.BackgroundMode); } if (opts.HasFlag(StartupOptions_e.Silent)) { args.Add(SwApplication.CommandLineArguments.SilentMode); } var app = SwApplication.Start(((SwAppVersionInfo)vers).Version, string.Join(" ", args), cancellationToken); app.Sw.CommandInProgress = true; return(app); }
public IXApplication StartApplication(IXVersion vers, StartupOptions_e opts, CancellationToken cancellationToken) { var app = SwApplicationFactory.PreCreate(); app.State = ApplicationState_e.Default; app.Version = (ISwVersion)vers; app.CustomServices = m_CustomServices; List <string> forceDisabledAddIns = null; if (opts.HasFlag(StartupOptions_e.Safe)) { app.State |= ApplicationState_e.Safe; TryDisableAddIns(out forceDisabledAddIns); } if (opts.HasFlag(StartupOptions_e.Background)) { app.State |= ApplicationState_e.Background; } if (opts.HasFlag(StartupOptions_e.Silent)) { app.State |= ApplicationState_e.Silent; } if (opts.HasFlag(StartupOptions_e.Hidden)) { app.State |= ApplicationState_e.Hidden; } try { app.Commit(cancellationToken); } finally { if (forceDisabledAddIns != null) { TryEnableAddIns(forceDisabledAddIns); } } app.Sw.UserControlBackground = true; app.Sw.CommandInProgress = true; //Note. By some reasons the process from IXApplication::Process does not fire exited event var prc = Process.GetProcessById(app.Process.Id); prc.EnableRaisingEvents = true; prc.Exited += OnProcessExited; m_ForceDisabledAddIns.Add(prc, forceDisabledAddIns); return(app); }
private IXApplication AttemptStartApplication(IXVersion versionInfo, StartupOptions_e opts, CancellationToken cancellationToken, TimeSpan?timeout) { int curAttempt = 1; CancellationTokenSource appStartCancellationTokenSrc = null; while (curAttempt <= MAX_ATTEMPTS) { try { var appStartTimeout = timeout.HasValue ? timeout.Value : TimeSpan.FromMinutes(5); if (cancellationToken != default) { appStartCancellationTokenSrc = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken); } else { appStartCancellationTokenSrc = new CancellationTokenSource(); } appStartCancellationTokenSrc.CancelAfter(appStartTimeout); m_UserLogger.WriteLine($"Starting host application: {versionInfo.DisplayName}"); var app = m_AppProvider.StartApplication(versionInfo, opts, appStartCancellationTokenSrc.Token); TryAddProcessToJob(app); return(app); } catch { if (cancellationToken.IsCancellationRequested) { throw new JobCancelledException(); } m_UserLogger.WriteLine($"Failed to start application from attempt {curAttempt}"); curAttempt++; } finally { appStartCancellationTokenSrc?.Dispose(); } } throw new UserMessageException("Failed to start application. Operation is aborted"); }
private IXApplication StartApplication(IXVersion versionInfo, StartupOptions_e opts, CancellationToken cancellationToken) { m_JournalWriter.WriteLine($"Starting host application: {versionInfo.DisplayName}"); IXApplication app; try { app = m_AppProvider.StartApplication(versionInfo, opts, p => TryAddProcessToJob(p), cancellationToken); if (opts.HasFlag(StartupOptions_e.Silent)) { m_PopupKiller.Start(app.Process, TimeSpan.FromSeconds(POPUP_KILLER_PING_SECS)); } } catch (Exception ex) { throw new UserException("Failed to start host application", ex); } return(app); }