public RunViaUnityEditorStrategy(ISolution solution,
                                         IUnitTestResultManager unitTestResultManager,
                                         UnityEditorProtocol editorProtocol,
                                         NUnitTestProvider unitTestProvider,
                                         IUnitTestElementIdFactory idFactory,
                                         ISolutionSaver riderSolutionSaver,
                                         UnityRefresher unityRefresher,
                                         NotificationsModel notificationsModel,
                                         UnityHost unityHost,
                                         ILogger logger,
                                         Lifetime lifetime,
                                         PackageValidator packageValidator
                                         )
        {
            mySolution = solution;
            myUnitTestResultManager = unitTestResultManager;
            myEditorProtocol        = editorProtocol;
            myUnitTestProvider      = unitTestProvider;
            myIDFactory             = idFactory;
            myRiderSolutionSaver    = riderSolutionSaver;
            myUnityRefresher        = unityRefresher;
            myNotificationsModel    = notificationsModel;
            myUnityHost             = unityHost;
            myLogger           = logger;
            myLifetime         = lifetime;
            myPackageValidator = packageValidator;
            myElements         = new WeakToWeakDictionary <UnitTestElementId, IUnitTestElement>();

            myUnityProcessId = new Property <int?>(lifetime, "RunViaUnityEditorStrategy.UnityProcessId");

            myUnityProcessId.ForEachValue_NotNull(lifetime, (lt, processId) =>
            {
                var process = myLogger.CatchIgnore(() => Process.GetProcessById(processId.NotNull()));
                if (process == null)
                {
                    myUnityProcessId.Value = null;
                    return;
                }

                process.EnableRaisingEvents = true;

                void OnProcessExited(object sender, EventArgs a) => myUnityProcessId.Value = null;
                lt.Bracket(() => process.Exited += OnProcessExited, () => process.Exited -= OnProcessExited);

                if (process.HasExited)
                {
                    myUnityProcessId.Value = null;
                }
            });

            myEditorProtocol.UnityModel.ViewNotNull(lifetime, (lt, model) =>
            {
                if (model.UnityProcessId.HasValue())
                {
                    myUnityProcessId.Value = model.UnityProcessId.Value;
                }

                model.UnityProcessId.FlowInto(lt, myUnityProcessId, id => id);
            });
        }
        public RunViaUnityEditorStrategy(ISolution solution,
                                         IUnitTestResultManager unitTestResultManager,
                                         BackendUnityHost backendUnityHost,
                                         NUnitTestProvider unitTestProvider,
                                         IUnitTestElementIdFactory idFactory,
                                         ISolutionSaver riderSolutionSaver,
                                         UnityRefresher unityRefresher,
                                         NotificationsModel notificationsModel,
                                         FrontendBackendHost frontendBackendHost,
                                         ILogger logger,
                                         Lifetime lifetime,
                                         PackageValidator packageValidator,
                                         JetBrains.Application.ActivityTrackingNew.UsageStatistics usageStatistics)
        {
            mySolution = solution;
            myUnitTestResultManager = unitTestResultManager;
            myBackendUnityHost      = backendUnityHost;
            myUnitTestProvider      = unitTestProvider;
            myIDFactory             = idFactory;
            myRiderSolutionSaver    = riderSolutionSaver;
            myUnityRefresher        = unityRefresher;
            myNotificationsModel    = notificationsModel;
            myFrontendBackendHost   = frontendBackendHost;
            myLogger           = logger;
            myLifetime         = lifetime;
            myPackageValidator = packageValidator;
            myUsageStatistics  = usageStatistics;

            myUnityProcessId = new Property <int?>(lifetime, "RunViaUnityEditorStrategy.UnityProcessId");

            myUnityProcessId.ForEachValue_NotNull(lifetime, (lt, processId) =>
            {
                var process = myLogger.CatchIgnore(() => Process.GetProcessById(processId.NotNull()));
                if (process == null)
                {
                    myUnityProcessId.Value = null;
                    return;
                }

                process.EnableRaisingEvents = true;

                void OnProcessExited(object sender, EventArgs a) => myUnityProcessId.Value = null;
                lt.Bracket(() => process.Exited += OnProcessExited, () => process.Exited -= OnProcessExited);

                if (process.HasExited)
                {
                    myUnityProcessId.Value = null;
                }
            });

            myBackendUnityHost.BackendUnityModel.ViewNotNull(lifetime, (lt, model) =>
            {
                // This will set the current value, if it exists
                model.UnityApplicationData.FlowInto(lt, myUnityProcessId, data => data.UnityProcessId);
            });
        }
 public RunViaUnityEditorStrategy(ISolution solution,
                                  IUnitTestResultManager unitTestResultManager,
                                  UnityEditorProtocol editorProtocol,
                                  NUnitTestProvider unitTestProvider,
                                  IUnitTestElementIdFactory idFactory,
                                  ISolutionSaver riderSolutionSaver,
                                  UnityRefresher unityRefresher,
                                  NotificationsModel notificationsModel,
                                  UnityHost unityHost,
                                  ILogger logger
                                  )
 {
     mySolution = solution;
     myUnitTestResultManager = unitTestResultManager;
     myEditorProtocol        = editorProtocol;
     myUnitTestProvider      = unitTestProvider;
     myIDFactory             = idFactory;
     myRiderSolutionSaver    = riderSolutionSaver;
     myUnityRefresher        = unityRefresher;
     myNotificationsModel    = notificationsModel;
     myUnityHost             = unityHost;
     myLogger   = logger;
     myElements = new WeakToWeakDictionary <UnitTestElementId, IUnitTestElement>();
 }