예제 #1
0
 public JetPopupMenusInteractivePatched(
     [NotNull] Lifetime lifetime,
     [NotNull] IIsApplicationActiveState isApplicationActiveState,
     [NotNull] IUIApplicationSimple uiapp,
     [NotNull] IAutomationViewsRegistry automationViewsRegistry,
     [CanBeNull, Optional] ITooltipManager tooltipman,
     [CanBeNull, Optional] IWin32Window ownerwin,
     [CanBeNull, Optional] IWindowsHookManager windowsHookManager,
     [CanBeNull, Optional] ISettingsStore settstore,
     [CanBeNull, Optional] PopupWindowManager popupWindowManager)
     : base(lifetime, isApplicationActiveState, uiapp, automationViewsRegistry, tooltipman, ownerwin, windowsHookManager, settstore, popupWindowManager)
 {
 }
        private void StartPollingUnityEditorState(BackendUnityModel backendUnityModel, Lifetime modelLifetime,
                                                  FrontendBackendHost frontendBackendHost,
                                                  IThreading threading,
                                                  IIsApplicationActiveState isApplicationActiveState,
                                                  ILogger logger)
        {
            modelLifetime.StartAsync(threading.Tasks.GuardedMainThreadScheduler, async() =>
            {
                // TODO: This would be much easier with a property
                // Would have to reset the property when the connection drops
                while (modelLifetime.IsAlive)
                {
                    if (isApplicationActiveState.IsApplicationActive.Value ||
                        frontendBackendHost.Model?.RiderFrontendTests.HasTrueValue() == true)
                    {
                        PollEditorState(backendUnityModel, frontendBackendHost, modelLifetime, threading, logger);
                    }

                    await Task.Delay(1000, modelLifetime);
                }
            });
        }
        // TODO: Remove FrontendBackendHost. It's too easy to get circular dependencies
        public BackendUnityHost(Lifetime lifetime, ILogger logger,
                                FrontendBackendHost frontendBackendHost,
                                IThreading threading,
                                IIsApplicationActiveState isApplicationActiveState,
                                PackageManager packageManager,
                                JetBrains.Application.ActivityTrackingNew.UsageStatistics usageStatistics)
        {
            myUsageStatistics = usageStatistics;

            myEditorState = UnityEditorState.Disconnected;

            BackendUnityModel.ViewNotNull(lifetime, (modelLifetime, backendUnityModel) =>
            {
                InitialiseModel(backendUnityModel);
                AdviseModel(backendUnityModel, modelLifetime, packageManager);
                StartPollingUnityEditorState(backendUnityModel, modelLifetime, frontendBackendHost, threading,
                                             isApplicationActiveState, logger);
            });
            BackendUnityModel.ViewNull(lifetime, _ =>
            {
                myEditorState = UnityEditorState.Disconnected;
                if (frontendBackendHost.IsAvailable)
                {
                    UpdateFrontendEditorState(frontendBackendHost, logger);
                }
            });

            // Are we testing?
            if (frontendBackendHost.IsAvailable)
            {
                // Tell the frontend if the backend/Unity connection is available
                // (not actually passthrough)
                var frontendBackendModel = frontendBackendHost.Model.NotNull("frontendBackendHost.Model != null");
                BackendUnityModel.FlowIntoRdSafe(lifetime,
                                                 backendUnityModel => backendUnityModel != null,
                                                 frontendBackendModel.UnityEditorConnected);
            }
        }
예제 #4
0
        public ConnectionTracker(Lifetime lifetime, ILogger logger, UnityHost host, UnityEditorProtocol editorProtocol,
                                 IThreading locks, UnitySolutionTracker unitySolutionTracker,
                                 IIsApplicationActiveState isApplicationActiveState)
        {
            State = new Property <UnityEditorState>(lifetime, "UnityEditorPlugin::ConnectionState",
                                                    UnityEditorState.Disconnected);

            if (locks.Dispatcher.IsAsyncBehaviorProhibited)
            {
                return;
            }

            unitySolutionTracker.IsUnityProject.AdviseOnce(lifetime, args =>
            {
                if (!args)
                {
                    return;
                }

                var updateConnectionAction = new Action(() =>
                {
                    var model = editorProtocol.UnityModel.Value;
                    if (model == null)
                    {
                        State.SetValue(UnityEditorState.Disconnected);
                    }
                    else
                    {
                        if (!model.IsBound)
                        {
                            State.SetValue(UnityEditorState.Disconnected);
                        }

                        var rdTask = model.GetUnityEditorState.Start(Unit.Instance);
                        rdTask?.Result.Advise(lifetime, result =>
                        {
                            State.SetValue(result.Result);
                            logger.Trace($"Inside Result. Sending connection state. State: {State.Value}");
                            host.PerformModelAction(m => m.EditorState.Value = Wrap(State.Value));
                        });

                        var waitTask = Task.Delay(TimeSpan.FromSeconds(2));
                        waitTask.ContinueWith(_ =>
                        {
                            if (rdTask != null && !rdTask.AsTask().IsCompleted)
                            {
                                logger.Trace("There were no response from Unity in two seconds. Set connection state to Disconnected.");
                                State.SetValue(UnityEditorState.Disconnected);
                            }
                        }, locks.Tasks.GuardedMainThreadScheduler);
                    }

                    logger.Trace($"Sending connection state. State: {State.Value}");
                    host.PerformModelAction(m => m.EditorState.Value = Wrap(State.Value));
                });

                lifetime.StartMainUnguardedAsync(async() =>
                {
                    while (lifetime.IsAlive)
                    {
                        if (isApplicationActiveState.IsApplicationActive.Value ||
                            host.GetValue(rdUnityModel => rdUnityModel.RiderFrontendTests).HasTrueValue())
                        {
                            updateConnectionAction();
                        }

                        await Task.Delay(1000, lifetime);
                    }
                });
            });
        }