コード例 #1
0
        public UnitySettingsSynchronizer(Lifetime lifetime, ISolution solution, UnityHost host,
                                         ISettingsStore settingsStore)
        {
            var boundStore = settingsStore.BindToContextLive(lifetime, ContextRange.Smart(solution.ToDataContext()));
            var entry      = boundStore.Schema.GetScalarEntry((UnitySettings s) => s.EnableShaderLabHippieCompletion);

            boundStore.GetValueProperty <bool>(lifetime, entry, null).Change.Advise_HasNew(lifetime, args =>
            {
                solution.Locks.ExecuteOrQueueEx(lifetime, "EnableShaderLabHippieCompletion", () =>
                                                host.PerformModelAction(rd => rd.EnableShaderLabHippieCompletion.Value = args.New));
            });

            var useYamlMergeSetting = boundStore.Schema.GetScalarEntry((UnitySettings s) => s.UseUnityYamlMerge);

            boundStore.GetValueProperty <bool>(lifetime, useYamlMergeSetting, null).Change.Advise_HasNew(lifetime, args =>
            {
                solution.Locks.ExecuteOrQueueEx(lifetime, "UseUnityYamlMerge", () =>
                                                host.PerformModelAction(rd => rd.UseUnityYamlMerge.Value = args.New));
            });

            var mergeParametersSetting = boundStore.Schema.GetScalarEntry((UnitySettings s) => s.MergeParameters);

            boundStore.GetValueProperty <string>(lifetime, mergeParametersSetting, null).Change.Advise_HasNew(lifetime, args =>
            {
                solution.Locks.ExecuteOrQueueEx(lifetime, "MergeParameters", () =>
                                                host.PerformModelAction(rd => rd.MergeParameters.Value = args.New));
            });
        }
コード例 #2
0
        private void AdviseModelData(Lifetime lifetime, Solution solution)
        {
            myHost.PerformModelAction(m => m.Play.Advise(lifetime, e =>
            {
                var model = UnityModel.Value;
                if (UnityModel.Value == null)
                {
                    return;
                }
                if (model.Play.Value == e)
                {
                    return;
                }

                myLogger.Info($"Play = {e} came from frontend.");
                model.Play.SetValue(e);
            }));

            myHost.PerformModelAction(m => m.Data.Advise(lifetime, e =>
            {
                var model = UnityModel.Value;
                if (e.NewValue == e.OldValue)
                {
                    return;
                }
                if (e.NewValue == null)
                {
                    return;
                }
                if (model == null)
                {
                    return;
                }

                switch (e.Key)
                {
                case "UNITY_Refresh":
                    myLogger.Info($"{e.Key} = {e.NewValue} came from frontend.");
                    var force = Convert.ToBoolean(e.NewValue);
                    Refresh.Fire(force);
                    solution.CustomData.Data.Remove("UNITY_Refresh");
                    break;

                case "UNITY_Step":
                    myLogger.Info($"{e.Key} = {e.NewValue} came from frontend.");
                    model.Step.Start(RdVoid.Instance);
                    solution.CustomData.Data.Remove("UNITY_Step");
                    break;

                case "UNITY_Pause":
                    myLogger.Info($"{e.Key} = {e.NewValue} came from frontend.");
                    model.Pause.SetValue(Convert.ToBoolean(e.NewValue));
                    break;
                }
            }));
        }
コード例 #3
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));
                });
            });
        }
コード例 #4
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));
                });
            });
        }
コード例 #5
0
            public void Complete()
            {
                myShellLocks.Tasks.StartNew(myComponentLifetime, Scheduling.MainGuard, () =>
                {
                    if (myConsumer.Result.Count != 0)
                    {
                        if (myEditorProtocol.UnityModel.Value == null)
                        {
                            return;
                        }

                        myUnityHost.PerformModelAction(a => a.AllowSetForegroundWindow.Start(Unit.Instance).Result
                                                       .Advise(myComponentLifetime,
                                                               result =>
                        {
                            var model = myEditorProtocol.UnityModel.Value;
                            if (mySelected != null)
                            {
                                model.ShowGameObjectOnScene.Fire(mySelected.ConvertToUnityModel());
                            }
                            // pass all references to Unity TODO temp workaround, replace with async api
                            model.FindUsageResults.Fire(new FindUsageResult(myDisplayName,
                                                                            myConsumer.Result.ToArray()).ConvertToUnityModel());
                        }));
                    }

                    myProgressBarLifetimeDefinition.Terminate();
                });
            }
コード例 #6
0
        private void NotifyFrontend(UnityHost host, UnityVersion unityVersion)
        {
            host.PerformModelAction(rd =>
            {
                // if model is there, then ApplicationPath was already set via UnityEditorProtocol, it would be more correct than any counted value
                if (myUnityEditorProtocol.UnityModel.Value != null)
                {
                    return;
                }

                var version = unityVersion.GetActualVersionForSolution();
                var info    = UnityInstallationFinder.GetApplicationInfo(version, unityVersion);
                if (info == null)
                {
                    return;
                }

                var contentsPath = UnityInstallationFinder.GetApplicationContentsPath(info.Path);
                rd.UnityApplicationData.SetValue(new UnityApplicationData(info.Path.FullPath,
                                                                          contentsPath.FullPath,
                                                                          UnityVersion.VersionToString(info.Version),
                                                                          UnityVersion.RequiresRiderPackage(info.Version)
                                                                          ));
            });
        }
コード例 #7
0
        private static void NotifyFrontend(UnityHost host, UnityVersion unityVersion)
        {
            var version = unityVersion.GetActualVersionForSolution();
            var info    = UnityInstallationFinder.GetApplicationInfo(version);

            if (info == null)
            {
                return;
            }

            host.PerformModelAction(rd =>
            {
                // ApplicationPath may be already set via UnityEditorProtocol, which is more accurate
                if (!rd.ApplicationPath.HasValue())
                {
                    rd.ApplicationPath.SetValue(info.Path.FullPath);
                }
                if (!rd.ApplicationContentsPath.HasValue())
                {
                    var contentsPath = UnityInstallationFinder.GetApplicationContentsPath(version);
                    if (contentsPath != null)
                    {
                        rd.ApplicationContentsPath.SetValue(contentsPath.FullPath);
                    }
                }
                if (!rd.ApplicationVersion.HasValue() && info.Version != null)
                {
                    rd.ApplicationVersion.SetValue(UnityVersion.VersionToString(info.Version));
                }
            });
        }
コード例 #8
0
 public UnityReferenceSynchronizer(Lifetime lifetime, UnityHost host, UnityReferencesTracker referencesTracker)
 {
     host.PerformModelAction(m =>
     {
         referencesTracker.HasUnityReference.Advise(lifetime, res => { m.HasUnityReference.SetValue(res); });
     });
 }
コード例 #9
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));
                });
            });
        }
コード例 #10
0
        public UnityInstallationSynchronizer(Lifetime lifetime, UnityReferencesTracker referencesTracker,
                                             UnityHost host, UnityInstallationFinder finder, UnityVersion unityVersion)
        {
            referencesTracker.HasUnityReference.Advise(lifetime, hasReference =>
            {
                if (!hasReference)
                {
                    return;
                }
                var version = unityVersion.GetActualVersionForSolution();
                var path    = finder.GetApplicationPath(version);
                if (path == null)
                {
                    return;
                }

                var contentPath = finder.GetApplicationContentsPath(version);

                host.PerformModelAction(rd =>
                {
                    // ApplicationPath may be already set via UnityEditorProtocol, which is more accurate
                    if (!rd.ApplicationPath.HasValue())
                    {
                        rd.ApplicationPath.SetValue(path.FullPath);
                    }
                    if (!rd.ApplicationContentsPath.HasValue())
                    {
                        rd.ApplicationContentsPath.SetValue(contentPath.FullPath);
                    }
                });
            });
        }
コード例 #11
0
        public UnityRefreshTracker(Lifetime lifetime, ISolution solution, UnityRefresher refresher,
                                   ILogger logger,
                                   IFileSystemTracker fileSystemTracker,
                                   UnityHost host,
                                   UnitySolutionTracker unitySolutionTracker)
        {
            myRefresher = refresher;
            myLogger    = logger;
            if (solution.GetData(ProjectModelExtensions.ProtocolSolutionKey) == null)
            {
                return;
            }

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

                // Rgc.Guarded - beware RIDER-15577
                myGroupingEvent = solution.Locks.GroupingEvents.CreateEvent(lifetime, "UnityRefresherGroupingEvent",
                                                                            TimeSpan.FromMilliseconds(500),
                                                                            Rgc.Guarded, () =>
                {
                    refresher.Refresh(RefreshType.Normal);
                });

                host.PerformModelAction(rd => rd.Refresh.Advise(lifetime, force =>
                {
                    if (force)
                    {
                        refresher.Refresh(RefreshType.ForceRequestScriptReload);
                    }
                    else
                    {
                        myGroupingEvent.FireIncoming();
                    }
                }));
            });

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

                var protocolSolution = solution.GetProtocolSolution();
                protocolSolution.Editors.AfterDocumentInEditorSaved.Advise(lifetime, _ =>
                {
                    logger.Verbose("protocolSolution.Editors.AfterDocumentInEditorSaved");
                    myGroupingEvent.FireIncoming();
                });

                fileSystemTracker.RegisterPrioritySink(lifetime, FileSystemChange, HandlingPriority.Other);
            });
        }
コード例 #12
0
 public static void CreateRequestAndShow([NotNull]  UnityHost unityHost, [NotNull] FileSystemPath solutionDirPath, [NotNull] UnitySceneDataLocalCache unitySceneDataLocalCache,
                                         [NotNull] string anchor, IPsiSourceFile sourceFile, bool needExpand = false)
 {
     using (ReadLockCookie.Create())
     {
         var request = CreateRequest(solutionDirPath, unitySceneDataLocalCache, anchor, sourceFile, needExpand);
         unityHost.PerformModelAction(t => t.ShowGameObjectOnScene.Fire(request));
     }
     UnityFocusUtil.FocusUnity(unityHost.GetValue(t => t.UnityProcessId.Value));
 }
コード例 #13
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
                    {
                        var rdTask = model.GetUnityEditorState.Start(Unit.Instance);
                        rdTask?.Result.Advise(lifetime, result =>
                        {
                            State.SetValue(result.Result);
                            logger.Trace($"myIsConnected = {State.Value}");
                            logger.Trace($"Inside Result. Sending connection state. State: {State.Value}");
                            host.PerformModelAction(m => m.EditorState.Value = Wrap(State.Value));
                        });
                    }

                    logger.Trace($"Sending connection state. State: {State.Value}");
                    host.PerformModelAction(m => m.EditorState.Value = Wrap(State.Value));
                });
            });
        }
コード例 #14
0
 public UnitySettingsSynchronizer(Lifetime lifetime, ISolution solution, UnityHost host,
                                  ISettingsStore settingsStore)
 {
     var boundStore = settingsStore.BindToContextLive(lifetime, ContextRange.Smart(solution.ToDataContext()));
     var entry = boundStore.Schema.GetScalarEntry((UnitySettings s) => s.EnableShaderLabHippieCompletion);
     boundStore.GetValueProperty<bool>(lifetime, entry, null).Change.Advise(lifetime, args =>
     {
         if (args.HasNew)
             host.PerformModelAction(rd => rd.EnableShaderLabHippieCompletion.Value = args.New);
     });
 }
コード例 #15
0
        public MonoInstallTrigger(Lifetime lifetime, ILogger logger, ISolutionLoadTasksScheduler scheduler,
                                  ISolution solution, UnitySolutionTracker unitySolutionTracker, UnityHost host)
        {
            if (PlatformUtil.RuntimePlatform != PlatformUtil.Platform.MacOsX)
            {
                return;
            }

            scheduler.EnqueueTask(new SolutionLoadTask("Check mono runtime", SolutionLoadTaskKinds.AfterDone, () =>
            {
                if (!unitySolutionTracker.IsUnityGeneratedProject.Value)
                {
                    return;
                }

                if (!HasModernUnityProjects(solution))
                {
                    return;
                }

                solution.Locks.Tasks.Queue(lifetime, () =>
                {
                    var wellKnownMonoRuntimes = MonoRuntimeDetector.DetectWellKnownMonoRuntimes();
                    var installedValidMono    = wellKnownMonoRuntimes
                                                .Any(runtime =>
                    {
                        var parsedVersion = string.Empty;
                        try
                        {
                            parsedVersion = ProcessOutputUtil.ExtractMonoVersion(runtime.ExePath);
                        }
                        catch (Exception e)
                        {
                            logger.Warn(e);
                        }

                        // if we fail to parse version - consider it is old
                        if (Version.TryParse(parsedVersion, out var version))
                        {
                            return(version.Major >= 5 && version.Minor >= 16);    // mono 5.16+ supports C# 7.3
                        }
                        logger.Warn("Failed to parse ProcessOutputUtil.ExtractMonoVersion output.");
                        return(false);
                    });

                    if (!installedValidMono)
                    {
                        solution.Locks.ExecuteOrQueue(lifetime, "Show install mono dialog",
                                                      () => { host.PerformModelAction(model => model.ShowInstallMonoDialog()); });
                    }
                });
            }));
        }
コード例 #16
0
        public UnityPluginInstaller(
            Lifetime lifetime,
            ILogger logger,
            ISolution solution,
            IShellLocks shellLocks,
            UnityPluginDetector detector,
            NotificationsModel notifications,
            ISettingsStore settingsStore,
            PluginPathsProvider pluginPathsProvider,
            UnityVersion unityVersion,
            UnityHost unityHost,
            UnitySolutionTracker unitySolutionTracker,
            UnityRefresher refresher)
        {
            myPluginInstallations = new JetHashSet <FileSystemPath>();

            myLifetime             = lifetime;
            myLogger               = logger;
            mySolution             = solution;
            myShellLocks           = shellLocks;
            myDetector             = detector;
            myNotifications        = notifications;
            myPluginPathsProvider  = pluginPathsProvider;
            myUnityVersion         = unityVersion;
            myUnitySolutionTracker = unitySolutionTracker;
            myRefresher            = refresher;

            myBoundSettingsStore = settingsStore.BindToContextLive(myLifetime, ContextRange.Smart(solution.ToDataContext()));
            myQueue = new ProcessingQueue(myShellLocks, myLifetime);

            unityHost.PerformModelAction(rdUnityModel =>
            {
                rdUnityModel.InstallEditorPlugin.AdviseNotNull(lifetime, x =>
                {
                    myShellLocks.ExecuteOrQueueReadLockEx(myLifetime, "UnityPluginInstaller.InstallEditorPlugin", () =>
                    {
                        var installationInfo = myDetector.GetInstallationInfo(myCurrentVersion);
                        QueueInstall(installationInfo, true);
                    });
                });
            });

            unitySolutionTracker.IsUnityProjectFolder.AdviseOnce(lifetime, args =>
            {
                if (!args)
                {
                    return;
                }
                myShellLocks.ExecuteOrQueueReadLockEx(myLifetime, "IsAbleToEstablishProtocolConnectionWithUnity", InstallPluginIfRequired);
                BindToInstallationSettingChange();
            });
        }
コード例 #17
0
            public void Complete()
            {
                myShellLocks.Tasks.StartNew(myLifetimeDef.Lifetime, Scheduling.MainGuard, () =>
                {
                    if (myConsumer.Result.Count != 0)
                    {
                        if (myFocusUnity)
                        {
                            UnityFocusUtil.FocusUnity(myUnityHost.GetValue(t => t.UnityProcessId.Value));
                        }

                        if (mySelected != null)
                        {
                            myUnityHost.PerformModelAction(t => t.ShowGameObjectOnScene.Fire(mySelected));
                        }
                        myUnityHost.PerformModelAction(t =>
                                                       t.FindUsageResults.Fire(new FindUsageResult(myDisplayName, myConsumer.Result.ToArray())));
                    }

                    myLifetimeDef.Terminate();
                });
            }
コード例 #18
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());
            }));
        }
コード例 #19
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);
                    }
                });
            });
        }
コード例 #20
0
        public UnityRefreshTracker(Lifetime lifetime, ISolution solution, UnityRefresher refresher,
                                   ILogger logger,
                                   IFileSystemTracker fileSystemTracker,
                                   UnityHost host,
                                   UnitySolutionTracker unitySolutionTracker)
        {
            myRefresher = refresher;
            myLogger    = logger;
            if (solution.GetData(ProjectModelExtensions.ProtocolSolutionKey) == null)
            {
                return;
            }

            unitySolutionTracker.IsUnityProjectFolder.AdviseOnce(lifetime, args =>
            {
                if (!args)
                {
                    return;
                }
                host.PerformModelAction(rd => rd.Refresh.Advise(lifetime, force =>
                {
                    refresher.Refresh(force ? RefreshType.ForceRequestScriptReload : RefreshType.Normal);
                }));
            });

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

                var protocolSolution = solution.GetProtocolSolution();
                protocolSolution.Editors.AfterDocumentInEditorSaved.Advise(lifetime, _ =>
                {
                    logger.Verbose("protocolSolution.Editors.AfterDocumentInEditorSaved");
                    refresher.Refresh(RefreshType.Normal);
                });

                fileSystemTracker.RegisterPrioritySink(lifetime, FileSystemChange, HandlingPriority.Other);
            });
        }
コード例 #21
0
        public UnitySolutionTracker(ISolution solution, IFileSystemTracker fileSystemTracker, Lifetime lifetime, IShellLocks locks,
                                    UnityHost unityHost, UnityReferencesTracker unityReferencesTracker)
        {
            mySolution = solution;
            if (locks.Dispatcher.IsAsyncBehaviorProhibited) // for tests
            {
                return;
            }

            SetValues();

            fileSystemTracker.AdviseDirectoryChanges(lifetime, mySolution.SolutionDirectory.Combine(ProjectExtensions.AssetsFolder), false,
                                                     OnChangeAction);
            // track not only folder itself, but also files inside
            fileSystemTracker.AdviseDirectoryChanges(lifetime, mySolution.SolutionDirectory.Combine(ProjectExtensions.ProjectSettingsFolder), true,
                                                     OnChangeActionProjectSettingsFolder);

            unityHost.PerformModelAction(model =>
            {
                unityReferencesTracker.HasUnityReference.Advise(lifetime, res => { model.HasUnityReference.SetValue(res); });
            });
        }
コード例 #22
0
        private static void NotifyFrontend(UnityHost host, UnityVersion unityVersion)
        {
            var version         = unityVersion.GetActualVersionForSolution();
            var applicationPath = unityVersion.GetActualAppPathForSolution();

            if (PlatformUtil.RuntimePlatform == PlatformUtil.Platform.MacOsX && !applicationPath.ExistsDirectory ||
                PlatformUtil.RuntimePlatform != PlatformUtil.Platform.MacOsX && !applicationPath.ExistsFile)
            {
                var info = UnityInstallationFinder.GetApplicationInfo(version);
                if (info == null)
                {
                    return;
                }
                applicationPath = info.Path;
                version         = info.Version;
            }

            host.PerformModelAction(rd =>
            {
                // ApplicationPath may be already set via UnityEditorProtocol, which will obviously be correct
                if (!rd.ApplicationPath.HasValue())
                {
                    rd.ApplicationPath.SetValue(applicationPath.FullPath);
                }

                if (!rd.ApplicationContentsPath.HasValue())
                {
                    var contentsPath = UnityInstallationFinder.GetApplicationContentsPath(applicationPath);
                    if (!contentsPath.IsEmpty)
                    {
                        rd.ApplicationContentsPath.SetValue(contentsPath.FullPath);
                    }
                }
                if (!rd.ApplicationVersion.HasValue() && version != null)
                {
                    rd.ApplicationVersion.SetValue(UnityVersion.VersionToString(version));
                }
            });
        }
コード例 #23
0
        private void NotifyFrontend(UnityHost host, UnityVersion unityVersion)
        {
            var version         = unityVersion.GetActualVersionForSolution();
            var applicationPath = unityVersion.GetActualAppPathForSolution();

            if (PlatformUtil.RuntimePlatform == PlatformUtil.Platform.MacOsX && !applicationPath.ExistsDirectory ||
                PlatformUtil.RuntimePlatform != PlatformUtil.Platform.MacOsX && !applicationPath.ExistsFile)
            {
                var info = UnityInstallationFinder.GetApplicationInfo(version);
                if (info == null)
                {
                    return;
                }
                applicationPath = info.Path;
                version         = info.Version;
            }

            host.PerformModelAction(rd =>
            {
                // if model is there, then ApplicationPath was already set via UnityEditorProtocol, it would be more correct than any counted value
                if (myUnityEditorProtocol.UnityModel.Value != null)
                {
                    return;
                }

                rd.ApplicationPath.SetValue(applicationPath.FullPath);
                var contentsPath = UnityInstallationFinder.GetApplicationContentsPath(applicationPath);
                if (!contentsPath.IsEmpty)
                {
                    rd.ApplicationContentsPath.SetValue(contentsPath.FullPath);
                }
                if (version != null)
                {
                    rd.ApplicationVersion.SetValue(UnityVersion.VersionToString(version));
                }
            });
        }
コード例 #24
0
        public UnityInstallationSynchronizer(Lifetime lifetime, UnitySolutionTracker solutionTracker,
                                             UnityHost host, UnityInstallationFinder finder, UnityVersion unityVersion)
        {
            solutionTracker.IsUnityProjectFolder.AdviseNotNull(lifetime, isUnityProjectFolder =>
            {
                if (!isUnityProjectFolder)
                {
                    return;
                }
                var version = unityVersion.GetActualVersionForSolution();
                var info    = finder.GetApplicationInfo(version);
                if (info == null)
                {
                    return;
                }

                var contentPath = finder.GetApplicationContentsPath(version);

                host.PerformModelAction(rd =>
                {
                    // ApplicationPath may be already set via UnityEditorProtocol, which is more accurate
                    if (!rd.ApplicationPath.HasValue())
                    {
                        rd.ApplicationPath.SetValue(info.Path.FullPath);
                    }
                    if (!rd.ApplicationContentsPath.HasValue())
                    {
                        rd.ApplicationContentsPath.SetValue(contentPath.FullPath);
                    }
                    if (!rd.ApplicationVersion.HasValue())
                    {
                        rd.ApplicationVersion.SetValue(UnityVersion.VersionToString(info.Version));
                    }
                });
            });
        }
コード例 #25
0
 private void AdviseModelData(Lifetime lifetime)
 {
     myHost.PerformModelAction(rd => rd.Play.Advise(lifetime, p => UnityModel.Value.IfNotNull(editor => editor.Play.Value   = p)));
     myHost.PerformModelAction(rd => rd.Pause.Advise(lifetime, p => UnityModel.Value.IfNotNull(editor => editor.Pause.Value = p)));
     myHost.PerformModelAction(rd => rd.Step.Advise(lifetime, () => UnityModel.Value.DoIfNotNull(editor => editor.Step())));
 }
コード例 #26
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);
                    }
                });
            });
        }
コード例 #27
0
 private void AdviseModelData(Lifetime lifetime)
 {
     myHost.PerformModelAction(rd => rd.Play.AdviseNotNull(lifetime, p => UnityModel.Value.IfNotNull(editor => editor.Play.Value   = p)));
     myHost.PerformModelAction(rd => rd.Pause.AdviseNotNull(lifetime, p => UnityModel.Value.IfNotNull(editor => editor.Pause.Value = p)));
     myHost.PerformModelAction(rd => rd.Step.Advise(lifetime, () => UnityModel.Value.DoIfNotNull(editor => editor.Step.Fire())));
     myHost.PerformModelAction(model => { model.SetScriptCompilationDuringPlay.AdviseNotNull(lifetime,
                                                                                             scriptCompilationDuringPlay => UnityModel.Value.DoIfNotNull(editor => editor.SetScriptCompilationDuringPlay.Fire((int)scriptCompilationDuringPlay))); });
 }
コード例 #28
0
        public MonoInstallTrigger(Lifetime lifetime, ILogger logger, ISolutionLoadTasksScheduler scheduler,
                                  ISolution solution, UnitySolutionTracker unitySolutionTracker, UnityHost host,
                                  NotificationsModel notificationsModel)
        {
            if (PlatformUtil.RuntimePlatform == PlatformUtil.Platform.Windows)
            {
                return;
            }

            scheduler.EnqueueTask(new SolutionLoadTask("Check mono runtime", SolutionLoadTaskKinds.AfterDone, () =>
            {
                if (!unitySolutionTracker.IsUnityGeneratedProject.Value)
                {
                    return;
                }

                if (!HasModernUnityProjects(solution))
                {
                    return;
                }

                solution.Locks.Tasks.Queue(lifetime, () =>
                {
                    var wellKnownMonoRuntimes = MonoRuntimeDetector.DetectWellKnownMonoRuntimes();
                    var installedValidMono    = wellKnownMonoRuntimes
                                                .Any(runtime =>
                    {
                        var parsedVersion = string.Empty;
                        try
                        {
                            parsedVersion = ProcessOutputUtil.ExtractMonoVersion(runtime.ExePath);
                        }
                        catch (Exception e)
                        {
                            logger.Warn(e);
                        }

                        // if we fail to parse version - consider it is old
                        if (Version.TryParse(parsedVersion, out var version))
                        {
                            return(version >= new Version(5, 16));    // mono 5.16+ supports C# 7.3
                        }
                        logger.Warn("Failed to parse ProcessOutputUtil.ExtractMonoVersion output.");
                        return(false);
                    });

                    if (installedValidMono)
                    {
                        return;
                    }

                    if (PlatformUtil.RuntimePlatform == PlatformUtil.Platform.MacOsX)
                    {
                        solution.Locks.ExecuteOrQueue(lifetime, "Show install mono dialog",
                                                      () => { host.PerformModelAction(model => model.ShowInstallMonoDialog()); });
                    }
                    else if (PlatformUtil.RuntimePlatform == PlatformUtil.Platform.Linux)
                    {
                        var notification = new NotificationModel("Mono 5.16+ is required",
                                                                 "<html>Project requires new Mono with MSBuild for new C# language features support.<br>" +
                                                                 RiderContextNotificationHelper.MakeOpenSettingsLink(
                                                                     WellKnownSettingPages.Environment,
                                                                     "Install the latest Mono")
                                                                 + ".<br>" +
                                                                 "If a Mono runtime is available in a non-standard location, please " +
                                                                 RiderContextNotificationHelper.MakeOpenSettingsLink(
                                                                     WellKnownSettingPages.ToolsetAndBuild,
                                                                     "specify the custom runtime location in settings")
                                                                 + ".</html>"

                                                                 , true,
                                                                 RdNotificationEntryType.WARN);
                        solution.Locks.ExecuteOrQueue(lifetime, "MonoInstallTrigger.Notify", () => notificationsModel.Notification(notification));
                    }
                });
            }));
        }
コード例 #29
0
 protected override void ShowNotification()
 {
     myUnityHost.PerformModelAction(t => t.ShowDeferredCachesProgressNotification());
 }