示例#1
0
        public void CreateRequestToUnity([NotNull] IDeclaredElement declaredElement, IPsiSourceFile selectedSourceFile, string selectAnchor, bool focusUnity)
        {
            var finder   = mySolution.GetPsiServices().AsyncFinder;
            var consumer = new UnityUsagesFinderConsumer(myUnitySceneDataLocalCache, mySolutionDirectoryPath);

            var selectRequest = (selectedSourceFile == null || selectAnchor == null)
                ? null
                : CreateRequest(mySolutionDirectoryPath, myUnitySceneDataLocalCache, selectAnchor, selectedSourceFile, false);


            var lifetimeDef = myLifetime.CreateNested();
            var pi          = new ProgressIndicator(myLifetime);

            if (myBackgroundTaskHost != null)
            {
                var task = RiderBackgroundTaskBuilder.Create()
                           .WithTitle("Finding usages in Unity for: " + declaredElement.ShortName)
                           .AsIndeterminate()
                           .AsCancelable(() => { pi.Cancel(); })
                           .Build();

                myBackgroundTaskHost.AddNewTask(lifetimeDef.Lifetime, task);
            }

            myLocks.Tasks.StartNew(myLifetime, Scheduling.MainGuard, () =>
            {
                using (ReadLockCookie.Create())
                {
                    finder.FindAsync(new[] { declaredElement }, myYamlSearchDomain,
                                     consumer, SearchPattern.FIND_USAGES, pi,
                                     FinderSearchRoot.Empty, new UnityUsagesAsyncFinderCallback(lifetimeDef, myLifetime, consumer, myUnityHost, myEditorProtocol, myLocks,
                                                                                                declaredElement.ShortName, selectRequest, focusUnity));
                }
            });
        }
        private void RememberExecution([NotNull] FileSystemPath path, bool withProgress)
        {
            var definition = Lifetime.CreateNested();

            if (withProgress)
            {
                var progress = new ProgressIndicator(definition.Lifetime);
                IProgressIndicator iProgress = progress;
                iProgress.Start(1);
                progress.Advance();
                var task = RiderBackgroundTaskBuilder
                           .FromProgressIndicator(progress)
                           .AsIndeterminate()
                           .WithHeader("Executing template")
                           .WithDescription($"{path.Name}")
                           .Build();
                Solution.Locks.ExecuteOrQueueEx(
                    definition.Lifetime,
                    "T4 execution progress launching",
                    () => BackgroundTaskHost.AddNewTask(definition.Lifetime, task)
                    );
            }

            RunningFiles[path] = definition;
        }
        private async Task RefreshInternal(Lifetime lifetime, RefreshType refreshType)
        {
            var lifetimeDef = Lifetime.Define(lifetime);

            myLogger.Verbose($"myPluginProtocolController.UnityModel.Value.Refresh.StartAsTask, force = {refreshType} Started");
            mySolution.GetComponent <RiderBackgroundTaskHost>().AddNewTask(lifetimeDef.Lifetime,
                                                                           RiderBackgroundTaskBuilder.Create().WithHeader("Refreshing solution in Unity Editor...")
                                                                           .AsIndeterminate().AsNonCancelable());
            try
            {
                try
                {
                    var version = UnityVersion.Parse(myEditorProtocol.UnityModel.Value.UnityApplicationData.Value.ApplicationVersion);
                    if (version != null && version.Major < 2018)
                    {
                        using (mySolution.GetComponent <VfsListener>().PauseChanges())
                        {
                            await myEditorProtocol.UnityModel.Value.Refresh.Start(lifetimeDef.Lifetime, refreshType).AsTask();
                        }
                    }
                    else // it is a risk to pause vfs https://github.com/JetBrains/resharper-unity/issues/1601
                    {
                        await myEditorProtocol.UnityModel.Value.Refresh.Start(lifetimeDef.Lifetime, refreshType).AsTask();
                    }
                }
                catch (Exception e)
                {
                    myLogger.Warn("connection usually brakes during refresh.", e);
                }
                finally
                {
                    try
                    {
                        myLogger.Verbose(
                            $"myPluginProtocolController.UnityModel.Value.Refresh.StartAsTask, force = {refreshType} Finished");
                        var solution  = mySolution.GetProtocolSolution();
                        var solFolder = mySolution.SolutionDirectory;
                        var list      = new List <string> {
                            solFolder.FullPath
                        };
                        myLogger.Verbose($"RefreshPaths.StartAsTask Finished.");
                        await solution.GetFileSystemModel().RefreshPaths.Start(lifetimeDef.Lifetime, new RdRefreshRequest(list, true)).AsTask();
                    }
                    finally
                    {
                        myLogger.Verbose($"RefreshPaths.StartAsTask Finished.");
                        lifetimeDef.Terminate();
                    }
                }
            }
            catch (Exception e)
            {
                myLogger.LogException(e);
            }
            finally
            {
                lifetimeDef.Terminate();
            }
        }
示例#4
0
        public void HandleManualInstallPlugin(InstallPluginDescription installPluginDescription)
        {
            var unrealPluginInstallInfo = myPluginDetector.InstallInfoProperty.Value;

            if (unrealPluginInstallInfo == null)
            {
                return;
            }

            Lifetime.UsingNestedAsync(async lt =>
            {
                var lifetimeDefinition = lt.CreateNested();
                var lifetime           = lifetimeDefinition.Lifetime;

                lifetime.Bracket(
                    () => myUnrealHost.myModel.RiderLinkInstallationInProgress.Value = true,
                    () => myUnrealHost.myModel.RiderLinkInstallationInProgress.Value = false
                    );
                var prefix   = unrealPluginInstallInfo.EnginePlugin.IsPluginAvailable ? "Updating" : "Installing";
                var header   = $"{prefix} RiderLink plugin";
                var progress = new Property <double>("UnrealLink.InstallPluginProgress", 0.0);
                var task     = RiderBackgroundTaskBuilder.Create()
                               .AsCancelable(() =>
                {
                    myUnrealHost.myModel.RiderLinkInstallMessage(
                        new InstallMessage("RiderLink installation has been cancelled", ContentType.Error));
                    lifetimeDefinition.Terminate();
                })
                               .WithHeader(header)
                               .WithProgress(progress)
                               .WithDescriptionFromProgress();
                myBackgroundTaskHost.AddNewTask(lifetime, task);
                myUnrealHost.myModel.CancelRiderLinkInstall.AdviseOnce(lifetime, unit =>
                {
                    myUnrealHost.myModel.RiderLinkInstallMessage(
                        new InstallMessage("RiderLink installation has been cancelled", ContentType.Error));
                    lifetimeDefinition.Terminate();
                });
                myUnrealHost.myModel.RiderLinkInstallPanelInit();
                await lifetime.StartBackgroundAsync(async() =>
                {
                    if (installPluginDescription.Location == PluginInstallLocation.Engine)
                    {
                        await InstallPluginInEngineIfRequired(lifetime, unrealPluginInstallInfo, progress,
                                                              installPluginDescription.ForceInstall);
                    }
                    else
                    {
                        await InstallPluginInGameIfRequired(lifetime, unrealPluginInstallInfo, progress,
                                                            installPluginDescription.ForceInstall);
                    }
                });
            });
        }
示例#5
0
        public void Refresh(bool force)
        {
            myLocks.AssertMainThread();
            if (IsRefreshing)
            {
                return;
            }

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

            if (!myBoundSettingsStore.GetValue((UnitySettings s) => s.AllowAutomaticRefreshInUnity) && !force)
            {
                return;
            }

            IsRefreshing = true;
            var result = myPluginProtocolController.UnityModel.Value.Refresh.Start(force)?.Result;

            if (result == null)
            {
                IsRefreshing = false;
                return;
            }

            var lifetimeDef = Lifetimes.Define(myLifetime);
            var solution    = mySolution.GetProtocolSolution();
            var solFolder   = mySolution.SolutionFilePath.Directory;

            mySolution.GetComponent <RiderBackgroundTaskHost>().AddNewTask(lifetimeDef.Lifetime,
                                                                           RiderBackgroundTaskBuilder.Create().WithHeader("Refreshing solution in Unity Editor...").AsIndeterminate().AsNonCancelable());

            result.Advise(lifetimeDef.Lifetime, _ =>
            {
                try
                {
                    var list = new List <string> {
                        solFolder.FullPath
                    };
                    solution.GetFileSystemModel().RefreshPaths.Start(new RdRefreshRequest(list, true));
                }
                finally
                {
                    IsRefreshing = false;
                    lifetimeDef.Terminate();
                }
            });
        }
        public Task Refresh(bool force)
        {
            myLocks.AssertMainThread();
            if (CurrentTask != null)
            {
                return(CurrentTask);
            }

            if (myEditorProtocol.UnityModel.Value == null)
            {
                return(new Task(() => {}));
            }

            if (!myBoundSettingsStore.GetValue((UnitySettings s) => s.AllowAutomaticRefreshInUnity) && !force)
            {
                return(new Task(() => {}));
            }

            myLogger.Verbose($"myPluginProtocolController.UnityModel.Value.Refresh.StartAsTask, force = {force}");
            var task = myEditorProtocol.UnityModel.Value.Refresh.StartAsTask(force);

            CurrentTask = task;

            var lifetimeDef = Lifetimes.Define(myLifetime);
            var solution    = mySolution.GetProtocolSolution();
            var solFolder   = mySolution.SolutionFilePath.Directory;

            mySolution.GetComponent <RiderBackgroundTaskHost>().AddNewTask(lifetimeDef.Lifetime,
                                                                           RiderBackgroundTaskBuilder.Create().WithHeader("Refreshing solution in Unity Editor...").AsIndeterminate().AsNonCancelable());

            task.ContinueWith(_ =>
            {
                mySolution.Locks.ExecuteOrQueueEx(lifetimeDef.Lifetime, "RefreshPaths", () =>
                {
                    try
                    {
                        var list = new List <string> {
                            solFolder.FullPath
                        };
                        solution.GetFileSystemModel().RefreshPaths.Start(new RdRefreshRequest(list, true));
                    }
                    finally
                    {
                        CurrentTask = null;
                        lifetimeDef.Terminate();
                    }
                });
            });
            return(task);
        }
        public void CreateRequestToUnity([NotNull] IDeclaredElement declaredElement, LocalReference location, bool focusUnity)
        {
            var finder   = mySolution.GetPsiServices().AsyncFinder;
            var consumer = new UnityUsagesFinderConsumer(myAssetHierarchyProcessor, myAnimatorContainer, myPersistentIndexManager,
                                                         mySolutionDirectoryPath, declaredElement);

            var sourceFile = myPersistentIndexManager[location.OwningPsiPersistentIndex];

            if (sourceFile == null)
            {
                return;
            }

            var selectRequest = CreateRequest(mySolutionDirectoryPath, myAssetHierarchyProcessor, myAnimatorContainer,
                                              location, sourceFile, declaredElement, false);


            var lifetimeDef = myLifetime.CreateNested();
            var pi          = new ProgressIndicator(myLifetime);

            if (myBackgroundTaskHost != null)
            {
                var task = RiderBackgroundTaskBuilder.Create()
                           .WithTitle("Finding usages in Unity for: " + declaredElement.ShortName)
                           .AsIndeterminate()
                           .AsCancelable(() => { pi.Cancel(); })
                           .Build();

                myBackgroundTaskHost.AddNewTask(lifetimeDef.Lifetime, task);
            }

            myLocks.Tasks.StartNew(myLifetime, Scheduling.MainGuard, () =>
            {
                using (ReadLockCookie.Create())
                {
                    finder.FindAsync(new[] { declaredElement }, myYamlSearchDomain,
                                     consumer, SearchPattern.FIND_USAGES, pi,
                                     FinderSearchRoot.Empty, new UnityUsagesAsyncFinderCallback(lifetimeDef, myLifetime, consumer, myFrontendBackendHost, myBackendUnityHost, myLocks,
                                                                                                declaredElement.ShortName, selectRequest, focusUnity));
                }
            });
        }
示例#8
0
        public void Refresh()
        {
            myLocks.AssertMainThread();
            if (IsRefreshing)
            {
                return;
            }

            IsRefreshing = true;
            var result = myPluginProtocolController.UnityModel?.Refresh.Start(RdVoid.Instance)?.Result;

            if (result == null)
            {
                IsRefreshing = false;
                return;
            }

            var lifetimeDef = Lifetimes.Define(myLifetime);
            var solution    = mySolution.GetProtocolSolution();
            var solFolder   = mySolution.SolutionFilePath.Directory;

            mySolution.GetComponent <RiderBackgroundTaskHost>().AddNewTask(lifetimeDef.Lifetime,
                                                                           RiderBackgroundTaskBuilder.Create().WithHeader("Refresh").AsIndeterminate().AsNonCancelable());

            result.Advise(lifetimeDef.Lifetime, _ =>
            {
                try
                {
                    var list = new List <string> {
                        solFolder.FullPath
                    };
                    solution.FileSystemModel.RefreshPaths.Start(new RdRefreshRequest(list, true));
                }
                finally
                {
                    IsRefreshing = false;
                    lifetimeDef.Terminate();
                }
            });
        }
示例#9
0
        private async Task RefreshInternal(RefreshType force)
        {
            var lifetimeDef = Lifetime.Define(myLifetime);

            myLogger.Verbose(
                $"myPluginProtocolController.UnityModel.Value.Refresh.StartAsTask, force = {force} Started");
            try
            {
                using (mySolution.GetComponent <VfsListener>().PauseChanges())
                {
                    await myEditorProtocol.UnityModel.Value.Refresh.StartAsTask(force);
                }
                myLogger.Verbose(
                    $"myPluginProtocolController.UnityModel.Value.Refresh.StartAsTask, force = {force} Finished");

                var solution  = mySolution.GetProtocolSolution();
                var solFolder = mySolution.SolutionDirectory;

                mySolution.GetComponent <RiderBackgroundTaskHost>().AddNewTask(lifetimeDef.Lifetime,
                                                                               RiderBackgroundTaskBuilder.Create().WithHeader("Refreshing solution in Unity Editor...")
                                                                               .AsIndeterminate().AsNonCancelable());

                var list = new List <string> {
                    solFolder.FullPath
                };
                myLogger.Verbose($"RefreshPaths.StartAsTask Started.");
                await solution.GetFileSystemModel().RefreshPaths.StartAsTask(new RdRefreshRequest(list, true));

                myLogger.Verbose($"RefreshPaths.StartAsTask Finished.");

                myLogger.Verbose($"lifetimeDef.Terminate");
                lifetimeDef.Terminate();
            }
            catch (Exception e)
            {
                myLogger.Log(LoggingLevel.ERROR, "Exception during Refresh.", e);
            }
        }
示例#10
0
        public static void RefreshProjects(Lifetime parentLifetime, [NotNull] ISolution solution,
                                           [CanBeNull] UnrealPluginInstallInfo.InstallDescription installDescription, [CanBeNull] VirtualFileSystemPath engineRoot)
        {
            parentLifetime.UsingNestedAsync(async lt =>
            {
                var lifetimeDefinition = lt.CreateNested();
                var lifetime           = lifetimeDefinition.Lifetime;

                var unrealHost = solution.GetComponent <UnrealHost>();

                lifetime.Bracket(
                    () => unrealHost.myModel.RefreshInProgress.Value = true,
                    () => unrealHost.myModel.RefreshInProgress.Value = false
                    );

                var task = RiderBackgroundTaskBuilder.Create()
                           .AsCancelable(() =>
                {
                    unrealHost.myModel.RiderLinkInstallMessage(
                        new InstallMessage("RiderLink projects refresh has been cancelled", ContentType.Error));
                    lifetimeDefinition.Terminate();
                })
                           .WithHeader("Refreshing project model");
                var backgroundTaskHost = solution.GetComponent <RiderBackgroundTaskHost>();
                backgroundTaskHost.AddNewTask(lifetime, task);
                var uprojectFile = installDescription?.UprojectPath;
                if (uprojectFile.IsNullOrEmpty())
                {
                    var cppUe4SolutionDetector = solution.GetComponent <CppUE4SolutionDetector>();
                    using (solution.Locks.UsingReadLock())
                    {
                        uprojectFile = cppUe4SolutionDetector.GetUProjectPath();
                    }
                }

                await lifetime.StartBackground(() => RegenerateProjectFiles(lifetime, solution, unrealHost, engineRoot, uprojectFile));
            });
        }
示例#11
0
        public override void Start(Lifetime startLifetime)
        {
            if (myRiderBackgroundTaskHost != null)
            {
                // avoid problems with background task host after terminating lifetime on daemon thread
                var lifetimeDef = myLifetime.CreateNested();
                startLifetime.OnTermination(() =>
                {
                    myLocks.Tasks.StartNew(myLifetime, Scheduling.MainDispatcher, () => lifetimeDef.Terminate());
                });

                var count          = myCache.FilesToProcess.Count;
                var processedCount = 0;
                var progress       = new Property <double>(startLifetime, "DeferredCacheProgressBarProgress", 0);

                myCache.AfterRemoveFromProcess.Advise(startLifetime, _ =>
                {
                    processedCount++;
                    if (count != 0)
                    {
                        progress.Value = Math.Min(0.99, ((double)processedCount) / count);
                    }
                });

                var description = new Property <string>(startLifetime, "DeferredCacheProgressBarDescription", "Processing assets");
                var task        = RiderBackgroundTaskBuilder.Create()
                                  .WithTitle("Calculating asset index")
                                  .WithDescription(description)
                                  .WithProgress(progress)
                                  .Build();

                CurrentFile.AdviseNotNull(startLifetime, v => { description.Value = $"Processing {v.DisplayName}"; });

                myLocks.Tasks.StartNew(startLifetime, Scheduling.MainDispatcher,
                                       () => { myRiderBackgroundTaskHost.AddNewTask(lifetimeDef.Lifetime, task); });
            }
        }
        private async Task RefreshInternal(Lifetime lifetime, RefreshType refreshType)
        {
            myLocks.ReentrancyGuard.AssertGuarded();

            if (myBackendUnityHost.BackendUnityModel.Value == null)
            {
                return;
            }

            if (!myBackendUnityHost.IsConnectionEstablished())
            {
                return;
            }

            var lifetimeDef = Lifetime.Define(lifetime);

            try
            {
                myLogger.Verbose($"myPluginProtocolController.UnityModel.Value.Refresh.StartAsTask, force = {refreshType} Started");
                mySolution.GetComponent <RiderBackgroundTaskHost>().AddNewTask(lifetimeDef.Lifetime,
                                                                               RiderBackgroundTaskBuilder.Create().WithHeader("Refreshing solution in Unity Editor...")
                                                                               .AsIndeterminate().AsNonCancelable());

                var version = myUnityVersion.ActualVersionForSolution.Value;
                try
                {
                    if (version != null && version.Major < 2018)
                    {
                        using (mySolution.GetComponent <VfsListener>().PauseChanges())
                        {
                            try
                            {
                                await myBackendUnityHost.BackendUnityModel.Value.Refresh.Start(lifetimeDef.Lifetime, refreshType).AsTask();
                            }
                            finally
                            {
                                await myLocks.Tasks.YieldTo(myLifetime, Scheduling.MainGuard);
                            }
                        }
                    }
                    else // it is a risk to pause vfs https://github.com/JetBrains/resharper-unity/issues/1601
                    {
                        await myBackendUnityHost.BackendUnityModel.Value.Refresh.Start(lifetimeDef.Lifetime, refreshType).AsTask();
                    }
                }
                catch (Exception e)
                {
                    myLogger.Warn(e, comment: "connection usually brakes during refresh.");
                }
                finally
                {
                    await myLocks.Tasks.YieldTo(myLifetime, Scheduling.MainGuard);

                    myLogger.Verbose(
                        $"myPluginProtocolController.UnityModel.Value.Refresh.StartAsTask, force = {refreshType} Finished");
                    var solution  = mySolution.GetProtocolSolution();
                    var solFolder = mySolution.SolutionDirectory;
                    var list      = new List <string> {
                        solFolder.FullPath
                    };
                    myLogger.Verbose("RefreshPaths.StartAsTask Finished.");
                    await solution.GetFileSystemModel().RefreshPaths
                    .Start(lifetimeDef.Lifetime, new RdRefreshRequest(list, true)).AsTask();

                    await myLocks.Tasks.YieldTo(myLifetime, Scheduling.MainGuard);
                }
            }
            catch (Exception e)
            {
                myLogger.LogException(e);
            }
            finally
            {
                lifetimeDef.Terminate();
            }
        }