Ejemplo n.º 1
0
        /// <summary>
        /// Calls Refresh in Unity, and RefreshPaths in vfs. If called multiple times while already running, schedules itself again
        /// </summary>
        /// <param name="lifetime"></param>
        /// <param name="refreshType"></param>
        public Task Refresh(Lifetime lifetime, RefreshType refreshType)
        {
            myLocks.AssertMainThread();

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

            if (!myBoundSettingsStore.GetValue((UnitySettings s) => s.AllowAutomaticRefreshInUnity) &&
                refreshType == RefreshType.Normal)
            {
                return(Task.CompletedTask);
            }

            if (myRunningRefreshTask != null && !myRunningRefreshTask.IsCompleted)
            {
                // we may schedule secondary refresh here, which will start after first refresh and protocol reconnect
                // we already do something like that in UnitTesting
                myLogger.Verbose($"Refresh already running. Skip starting a new one.");
                return(myRunningRefreshTask);
            }

            lifetime.OnTermination(() => myRunningRefreshTask = Task.CompletedTask);

            myRunningRefreshTask = RefreshInternal(lifetime, refreshType);
            return(myRunningRefreshTask);
        }
Ejemplo n.º 2
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();
                }
            });
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
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();
                }
            });
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Calls Refresh in Unity, and RefreshPaths in vfs. If called multiple times while already running, schedules itself again
        /// </summary>
        /// <param name="lifetime"></param>
        /// <param name="refreshType"></param>
        public Task Refresh(Lifetime lifetime, RefreshType refreshType)
        {
            myLocks.AssertMainThread();
            myLocks.ReentrancyGuard.AssertGuarded();

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

            if (!myBoundSettingsStore.GetValue((UnitySettings s) => s.AllowAutomaticRefreshInUnity) &&
                refreshType == RefreshType.Normal)
            {
                return(Task.CompletedTask);
            }



            if (myRunningRefreshTask != null && !myRunningRefreshTask.IsCompleted)
            {
                myLogger.Verbose($"Secondary execution with {refreshType} type saved.");
                mySecondaryRefreshType = refreshType;
                return(myRunningRefreshTask);
            }

            myRunningRefreshTask = RefreshInternal(lifetime, refreshType);
            return(myRunningRefreshTask.ContinueWith(_ =>
            {
                myRunningRefreshTask = null;
                // if refresh signal came during execution preserve it and execute after finish
                if (mySecondaryRefreshType != null)
                {
                    myLogger.Verbose($"Secondary execution with {mySecondaryRefreshType}");
                    return Refresh(lifetime, (RefreshType)mySecondaryRefreshType)
                    .ContinueWith(___ => { mySecondaryRefreshType = null; }, lifetime);
                }

                return Task.CompletedTask;
            }, lifetime).Unwrap());
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Calls Refresh in Unity, and RefreshPaths in vfs. If called multiple times while already running, schedules itself again
        /// </summary>
        /// <param name="force"></param>
        public async void Refresh(RefreshType force)
        {
            myLocks.AssertMainThread();
            if (myEditorProtocol.UnityModel.Value == null)
            {
                return;
            }

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

            if (myIsRunning)
            {
                myLogger.Verbose($"Secondary execution with {force} type saved.");
                myRefreshType = force;
                return;
            }

            myIsRunning = true;

            await RefreshInternal(force);

            myIsRunning = false;

            if (myRefreshType == null)
            {
                return;
            }

            var type = myRefreshType.Value;

            myRefreshType = null;

            myLogger.Verbose($"Secondary execution with {type}");
            Refresh(type); // if refresh signal came during execution preserve it and execute after finish
        }