Example #1
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));
                });
            });
        }
 public UnityInstallationSynchronizer(Lifetime lifetime,
                                      UnityHost host, UnityVersion unityVersion,
                                      UnityEditorProtocol unityEditorProtocol)
 {
     myUnityEditorProtocol = unityEditorProtocol;
     unityVersion.ActualVersionForSolution.Advise(lifetime, version => NotifyFrontend(host, unityVersion, version));
 }
Example #3
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));
                });
            });
        }
Example #4
0
        public UnityRefreshTracker(Lifetime lifetime, ISolution solution, UnityRefresher refresher,
                                   UnityEditorProtocol protocolController, DocumentTransactionManager documentTransactionManager, IShellLocks locks,
                                   ILogger logger)
        {
            myLogger = logger;

            if (solution.GetData(ProjectModelExtensions.ProtocolSolutionKey) == null)
            {
                return;
            }

            var groupingEvent = solution.Locks.GroupingEvents.CreateEvent(lifetime, "UnityRefresherOnSaveEvent", TimeSpan.FromMilliseconds(500),
                                                                          Rgc.Invariant, () => refresher.Refresh(false));

            var protocolSolution = solution.GetProtocolSolution();

            protocolSolution.Editors.AfterDocumentInEditorSaved.Advise(lifetime, _ =>
            {
                if (protocolController.UnityModel.Value == null)
                {
                    return;
                }

                myLogger.Verbose("protocolSolution.Editors.AfterDocumentInEditorSaved");
                groupingEvent.FireIncoming();
            });
        }
        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));
            });
        }
Example #6
0
        public ConnectionTracker(Lifetime lifetime, ILogger logger, UnityHost host, UnityEditorProtocol editorProtocol,
                                 IThreading locks, UnitySolutionTracker unitySolutionTracker)
        {
            State = new Property <UnityEditorState>(lifetime, "UnityEditorPlugin::ConnectionState", UnityEditorState.Disconnected);

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

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

                //check connection between backend and unity editor
                locks.QueueRecurring(lifetime, "PeriodicallyCheck", TimeSpan.FromSeconds(1), () =>
                {
                    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 one second. 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));
                });
            });
        }
Example #7
0
 public UnityUsagesAsyncFinderCallback(LifetimeDefinition progressBarLifetimeDefinition, Lifetime componentLifetime, UnityUsagesFinderConsumer consumer, UnityHost unityHost, UnityEditorProtocol editorProtocol, IShellLocks shellLocks,
                                       string displayName, FindUsageResultElement selected, bool focusUnity)
 {
     myProgressBarLifetimeDefinition = progressBarLifetimeDefinition;
     myComponentLifetime             = componentLifetime;
     myConsumer       = consumer;
     myUnityHost      = unityHost;
     myEditorProtocol = editorProtocol;
     myShellLocks     = shellLocks;
     myDisplayName    = displayName;
     mySelected       = selected;
 }
        public UnityRefresher(IShellLocks locks, Lifetime lifetime, ISolution solution, UnityEditorProtocol pluginProtocolController)
        {
            myLocks    = locks;
            myLifetime = lifetime;
            mySolution = solution;
            myPluginProtocolController = pluginProtocolController;

            if (solution.GetData(ProjectModelExtensions.ProtocolSolutionKey) == null)
            {
                return;
            }

            myPluginProtocolController.Refresh.Advise(lifetime, Refresh);
        }
Example #9
0
        public UnityController(UnityEditorProtocol unityEditorProtocol, ISolution solution,
                               Lifetime lifetime, UnitySolutionTracker solutionTracker)
        {
            if (solution.GetData(ProjectModelExtensions.ProtocolSolutionKey) == null)
            {
                return;
            }

            myUnityEditorProtocol = unityEditorProtocol;
            mySolution            = solution;
            myLifetime            = lifetime;
            mySolutionTracker     = solutionTracker;
            myRdUnityModel        = solution.GetProtocolSolution().GetRdUnityModel();
        }
Example #10
0
 public UnityEditorFindUsageResultCreator(Lifetime lifetime, ISolution solution, SearchDomainFactory searchDomainFactory, IShellLocks locks,
                                          UnitySceneDataLocalCache sceneDataCache, UnityHost unityHost, UnityExternalFilesModuleFactory externalFilesModuleFactory,
                                          UnityEditorProtocol editorProtocol,
                                          [CanBeNull] RiderBackgroundTaskHost backgroundTaskHost = null)
 {
     myLifetime = lifetime;
     mySolution = solution;
     myLocks    = locks;
     myUnitySceneDataLocalCache = sceneDataCache;
     myBackgroundTaskHost       = backgroundTaskHost;
     myYamlSearchDomain         = searchDomainFactory.CreateSearchDomain(externalFilesModuleFactory.PsiModule);
     myUnityHost             = unityHost;
     myEditorProtocol        = editorProtocol;
     mySolutionDirectoryPath = solution.SolutionDirectory;
 }
        public UnityRiderAlternateProjectOutputProvider(Lifetime lifetime, UnityEditorProtocol editorProtocol, IShellLocks shellLocks) : base(lifetime)
        {
            myShellLocks = shellLocks;

            myProjectNameToOutputFilePathMap = new ConcurrentDictionary <string, FileSystemPath>();

            editorProtocol.UnityModel.ViewNotNull(lifetime, (modelLifetime, model) =>
            {
                model.CompiledAssemblies.AdviseNotNull(modelLifetime, compiledAssemblies =>
                {
                    myProjectNameToOutputFilePathMap = compiledAssemblies.ToDictionary(a => a.Name, a => FileSystemPath.TryParse(a.OutputPath));
                    PathsChanged.Fire();
                });
            });
        }
Example #12
0
        public ConnectionTracker(Lifetime lifetime, ILogger logger, UnityHost host, UnityEditorProtocol editorProtocol,
                                 IThreading locks, UnitySolutionTracker unitySolutionTracker)
        {
            State = new Property <UnityEditorState>(lifetime, "UnityEditorPlugin::ConnectionState", UnityEditorState.Disconnected);

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

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

                //check connection between backend and unity editor
                locks.QueueRecurring(lifetime, "PeriodicallyCheck", TimeSpan.FromSeconds(1), () =>
                {
                    var model = editorProtocol.UnityModel.Value;
                    if (model == null)
                    {
                        State.SetValue(UnityEditorState.Disconnected);
                    }
                    else
                    {
                        try
                        {
                            var rdTask = model.GetUnityEditorState.Start(Unit.Instance);
                            rdTask?.Result.Advise(lifetime, result =>
                            {
                                State.SetValue(result.Result);
                                logger.Trace($"myIsConnected = {State.Value}");
                            });
                        }
                        catch (Exception e)
                        {
                            e.Data.Add("UnityModel", editorProtocol.UnityModel.Value);
                            throw;
                        }
                    }

                    logger.Trace($"Sending connection state. State: {State.Value}");
                    host.PerformModelAction(m => m.EditorState.Value = Wrap(State.Value));
                });
            });
        }
 public UnityEditorFindUsageResultCreator(Lifetime lifetime, ISolution solution, SearchDomainFactory searchDomainFactory, IShellLocks locks,
                                          AssetHierarchyProcessor assetHierarchyProcessor, UnityHost unityHost, UnityExternalFilesModuleFactory externalFilesModuleFactory,
                                          UnityEditorProtocol editorProtocol, IPersistentIndexManager persistentIndexManager,
                                          [CanBeNull] RiderBackgroundTaskHost backgroundTaskHost = null)
 {
     myLifetime = lifetime;
     mySolution = solution;
     myLocks    = locks;
     myAssetHierarchyProcessor = assetHierarchyProcessor;
     myBackgroundTaskHost      = backgroundTaskHost;
     myYamlSearchDomain        = searchDomainFactory.CreateSearchDomain(externalFilesModuleFactory.PsiModule);
     myUnityHost              = unityHost;
     myEditorProtocol         = editorProtocol;
     myPersistentIndexManager = persistentIndexManager;
     mySolutionDirectoryPath  = solution.SolutionDirectory;
 }
Example #14
0
        public static void CreateRequestAndShow([NotNull]  UnityEditorProtocol editor, UnityHost host, Lifetime lifetime, [NotNull] FileSystemPath solutionDirPath, [NotNull] UnitySceneDataLocalCache unitySceneDataLocalCache,
                                                [NotNull] string anchor, IPsiSourceFile sourceFile, bool needExpand = false)
        {
            FindUsageResultElement request;

            using (ReadLockCookie.Create())
            {
                request = CreateRequest(solutionDirPath, unitySceneDataLocalCache, anchor, sourceFile, needExpand);
            }

            host.PerformModelAction(a => a.AllowSetForegroundWindow.Start(Unit.Instance).Result.Advise(lifetime,
                                                                                                       result =>
            {
                editor.UnityModel.Value.ShowGameObjectOnScene.Fire(request.ConvertToUnityModel());
            }));
        }
Example #15
0
        public UnityRefresher(IShellLocks locks, Lifetime lifetime, ISolution solution, UnityEditorProtocol pluginProtocolController, ISettingsStore settingsStore)
        {
            myLocks    = locks;
            myLifetime = lifetime;
            mySolution = solution;
            myPluginProtocolController = pluginProtocolController;

            if (solution.GetData(ProjectModelExtensions.ProtocolSolutionKey) == null)
            {
                return;
            }

            myBoundSettingsStore = settingsStore.BindToContextLive(myLifetime, ContextRange.Smart(solution.ToDataContext()));

            myPluginProtocolController.Refresh.Advise(lifetime, Refresh);
        }
Example #16
0
        public ConnectionTracker(Lifetime lifetime, ILogger logger, UnityHost host, UnityEditorProtocol editorProtocol,
                                 IThreading locks, UnitySolutionTracker unitySolutionTracker)
        {
            State = new Property <UnityEditorState>(lifetime, "UnityEditorPlugin::ConnectionState", UnityEditorState.Disconnected);

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

            unitySolutionTracker.IsUnityProject.AdviseOnce(lifetime, args =>
            {
                //periodically check connection between backend and unity editor
                lifetime.StartMainUnguardedAsync(async() =>
                {
                    while (lifetime.IsAlive)
                    {
                        var model = editorProtocol.UnityModel.Value;
                        if (model == null)
                        {
                            State.SetValue(UnityEditorState.Disconnected);
                        }
                        else
                        {
                            try
                            {
                                var rdTask = model.GetUnityEditorState.Start(Unit.Instance);
                                rdTask?.Result.Advise(lifetime, result =>
                                {
                                    State.SetValue(result.Result);
                                    logger.Trace($"myIsConnected = {State.Value}");
                                });
                            }
                            catch (Exception e)
                            {
                                e.Data.Add("UnityModel", editorProtocol.UnityModel.Value);
                                throw;
                            }
                        }

                        logger.Trace($"Sending connection state. State: {State.Value}");
                        host.PerformModelAction(m => m.EditorState.Value = Wrap(State.Value));
                        await Task.Delay(1000, lifetime);
                    }
                });
            });
        }
Example #17
0
        public UnityRefresher(IShellLocks locks, Lifetime lifetime, ISolution solution,
                              UnityEditorProtocol editorProtocol, ISettingsStore settingsStore,
                              ILogger logger)
        {
            myLocks          = locks;
            myLifetime       = lifetime;
            mySolution       = solution;
            myEditorProtocol = editorProtocol;
            myLogger         = logger;

            if (solution.GetData(ProjectModelExtensions.ProtocolSolutionKey) == null)
            {
                return;
            }

            myBoundSettingsStore = settingsStore.BindToContextLive(myLifetime, ContextRange.Smart(solution.ToDataContext()));
        }
        public UnityInstallationSynchronizer(Lifetime lifetime, UnitySolutionTracker solutionTracker,
                                             UnityHost host, UnityVersion unityVersion, UnityReferencesTracker referencesTracker,
                                             UnityEditorProtocol unityEditorProtocol)
        {
            myUnityEditorProtocol = unityEditorProtocol;
            solutionTracker.IsUnityProjectFolder.Advise(lifetime, res =>
            {
                if (!res)
                {
                    return;
                }
                NotifyFrontend(host, unityVersion);
            });

            referencesTracker.HasUnityReference.Advise(lifetime, res =>
            {
                if (!res)
                {
                    return;
                }
                NotifyFrontend(host, unityVersion);
            });
        }
        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);
                    }
                });
            });
        }
Example #20
0
        public UnityRefreshTracker(Lifetime lifetime, ISolution solution, UnityRefresher refresher, ChangeManager changeManager, UnityEditorProtocol protocolController)
        {
            if (solution.GetData(ProjectModelExtensions.ProtocolSolutionKey) == null)
            {
                return;
            }

            var groupingEvent = solution.Locks.GroupingEvents.CreateEvent(lifetime, "UnityRefresherOnSaveEvent", TimeSpan.FromMilliseconds(500),
                                                                          Rgc.Invariant, () => refresher.Refresh(false));

            var protocolSolution = solution.GetProtocolSolution();

            protocolSolution.Editors.AfterDocumentInEditorSaved.Advise(lifetime, _ =>
            {
                if (refresher.IsRefreshing)
                {
                    return;
                }

                if (protocolController.UnityModel.Value == null)
                {
                    return;
                }

                groupingEvent.FireIncoming();
            });

            changeManager.Changed2.Advise(lifetime, args =>
            {
                var changes = args.ChangeMap.GetChanges <ProjectModelChange>();
                if (changes == null)
                {
                    return;
                }

                if (refresher.IsRefreshing)
                {
                    return;
                }

                var hasChange = changes.Any(HasAnyFileChangeRec);
                if (!hasChange)
                {
                    return;
                }

                groupingEvent.FireIncoming();
            });
        }