Пример #1
0
        public ConnectionTracker(Lifetime lifetime, ILogger logger, UnityHost host, UnityEditorProtocol editorProtocol, IShellLocks locks, UnitySolutionTracker unitySolutionTracker)
        {
            // TODO: this shouldn't be up in tests until we figure out how to test unity-editor requiring features
            if (locks.Dispatcher.IsAsyncBehaviorProhibited)
            {
                return;
            }

            unitySolutionTracker.IsUnityProjectFolder.AdviseOnce(lifetime, args =>
            {
                //check connection between backend and unity editor
                locks.QueueRecurring(lifetime, "PeriodicallyCheck", TimeSpan.FromSeconds(1), () =>
                {
                    if (editorProtocol.UnityModel.Value == null)
                    {
                        myLastCheckResult = UnityEditorState.Disconnected;
                    }
                    else
                    {
                        var rdTask = editorProtocol.UnityModel.Value.GetUnityEditorState.Start(RdVoid.Instance);
                        rdTask?.Result.Advise(lifetime, result =>
                        {
                            myLastCheckResult = result.Result;
                            logger.Trace($"myIsConnected = {myLastCheckResult}");
                        });
                    }

                    logger.Trace($"Sending connection state. State: {myLastCheckResult}");
                    host.PerformModelAction(m => m.EditorState.Value = Wrap(myLastCheckResult));
                });
            });
        }
        public ConnectionTracker(Lifetime lifetime, ILogger logger, UnityEditorProtocol unityEditorProtocolController, IShellLocks locks, ISolution solution)
        {
            // this shouldn't be up in tests until we figure out how to test unity-editor requiring features
            if (locks.Dispatcher.IsAsyncBehaviorProhibited)
            {
                return;
            }

            //check connection between backend and unity editor
            locks.QueueRecurring(lifetime, "PeriodicallyCheck", TimeSpan.FromSeconds(1), () =>
            {
                if (unityEditorProtocolController.UnityModel.Value == null)
                {
                    myLastCheckResult = UnityEditorState.Disconnected;
                }
                else
                {
                    var rdTask = unityEditorProtocolController.UnityModel.Value.GetUnityEditorState.Start(RdVoid.Instance);
                    rdTask?.Result.Advise(lifetime, result =>
                    {
                        myLastCheckResult = result.Result;
                        logger.Trace($"myIsConnected = {myLastCheckResult}");
                    });
                }

                logger.Trace($"Sending connection state. State: {myLastCheckResult}");
                solution.GetProtocolSolution().SetCustomData("UNITY_EditorState", Wrap(myLastCheckResult));
            });
        }
Пример #3
0
        public ConnectionTracker(Lifetime lifetime, ILogger logger, UnityHost host, UnityEditorProtocol editorProtocol, IShellLocks locks, UnitySolutionTracker unitySolutionTracker)
        {
            unitySolutionTracker.IsUnityProjectFolder.AdviseOnce(lifetime, args =>
            {
                //check connection between backend and unity editor
                locks.QueueRecurring(lifetime, "PeriodicallyCheck", TimeSpan.FromSeconds(1), () =>
                {
                    if (editorProtocol.UnityModel.Value == null)
                    {
                        myLastCheckResult = UnityEditorState.Disconnected;
                    }
                    else
                    {
                        var rdTask = editorProtocol.UnityModel.Value.GetUnityEditorState.Start(Unit.Instance);
                        rdTask?.Result.Advise(lifetime, result =>
                        {
                            myLastCheckResult = result.Result;
                            logger.Trace($"myIsConnected = {myLastCheckResult}");
                        });
                    }

                    logger.Trace($"Sending connection state. State: {myLastCheckResult}");
                    host.PerformModelAction(m => m.EditorState.Value = Wrap(myLastCheckResult));
                });
            });
        }
        private void PollEditorState(BackendUnityModel backendUnityModel, FrontendBackendHost frontendBackendHost,
                                     Lifetime modelLifetime, IThreading threading, ILogger logger)
        {
            if (!backendUnityModel.IsBound)
            {
                myEditorState = UnityEditorState.Disconnected;
                UpdateFrontendEditorState(frontendBackendHost, logger);
                return;
            }

            var task = backendUnityModel.GetUnityEditorState.Start(Unit.Instance);

            task?.Result.AdviseOnce(modelLifetime, result =>
            {
                logger.Trace($"Got poll result from Unity editor: {result.Result}");
                myEditorState = result.Result;
                UpdateFrontendEditorState(frontendBackendHost, logger);
            });

            Task.Delay(TimeSpan.FromSeconds(2), modelLifetime).ContinueWith(_ =>
            {
                if (task != null && !task.AsTask().IsCompleted)
                {
                    logger.Trace(
                        "There were no response from Unity in two seconds. Setting state to Disconnected.");
                    myEditorState = UnityEditorState.Disconnected;
                    UpdateFrontendEditorState(frontendBackendHost, logger);
                }
            }, threading.Tasks.GuardedMainThreadScheduler);
        }
Пример #5
0
        private EditorState Wrap(UnityEditorState state)
        {
            switch (state)
            {
            case UnityEditorState.Disconnected:
                return(EditorState.Disconnected);

            case UnityEditorState.Idle:
                return(EditorState.ConnectedIdle);

            case UnityEditorState.Play:
                return(EditorState.ConnectedPlay);

            case UnityEditorState.Refresh:
                return(EditorState.ConnectedRefresh);

            default:
                throw new ArgumentOutOfRangeException(nameof(state), state, null);
            }
        }
        // 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);
            }
        }