示例#1
0
        public ProjectProtocolHandler(Lifetime lifetime, IProtocol protocol, ILogger logger)
        {
            logger.Log(LoggingLevel.INFO, $"{protocol.Name} is protocol");
            BsmtRiderModel = new BSMT_RiderModel(lifetime, protocol);
            BSMT_RiderModel.RegisterDeclaredTypesSerializers(protocol.Serializers);

            BsmtRiderModel.FoundBeatSaberLocations
            .Set((t, _) => RdTask <string[]> .Successful(BeatSaberPathUtils.GetInstallDir().ToArray()));
        }
示例#2
0
        protected override void Start()
        {
            Queue(() =>
            {
                var demoModel = new DemoModel(ModelLifetime, Protocol);

                demoModel.Call.Set((lifetime, c) => RdTask <string> .Successful(c.ToString()));

                demoModel.Callback.Start("Csharp");
            });
        }
        private RdTask <RdProjectOutput> GetProjectOutputModel(Lifetime lifetime, RdGetProjectOutputArgs args)
        {
            var project = GetProject(
                VirtualFileSystemPath.Parse(args.ProjectFilePath, InteractionContext.SolutionContext));
            var targetFramework = project.TargetFrameworkIds
                                  // Take .NET Core first, then .NET Framework, and then .NET Standard. The comparer below will hold this order.
                                  .OrderBy(tfm => (!tfm.IsNetCoreApp, !tfm.IsNetFramework, !tfm.IsNetStandard))
                                  .First();

            _logger.Trace("TFM selected for project {0}: {1}", args, targetFramework);
            var assemblyInfo = project.GetOutputAssemblyInfo(targetFramework).NotNull();

            _logger.Trace("Assembly file path detected for project {0}: {1}", args, assemblyInfo.Location);
            return(RdTask <RdProjectOutput> .Successful(
                       new RdProjectOutput(
                           targetFramework.ToRdTargetFrameworkInfo(),
                           assemblyInfo.Location.ToString())));
        }
示例#4
0
        public void TestBindable()
        {
            ClientWire.AutoTransmitMode = true;
            ServerWire.AutoTransmitMode = true;


            var call1 = new RdCall <Unit, RdSignal <int> >(Serializers.ReadVoid, Serializers.WriteVoid, RdSignal <int> .Read, RdSignal <int> .Write);
            var call2 = new RdCall <Unit, RdSignal <int> >(Serializers.ReadVoid, Serializers.WriteVoid, RdSignal <int> .Read, RdSignal <int> .Write);

            var respSignal           = new RdSignal <int>();
            var endpointLfTerminated = false;

            call2.Set((endpointLf, _) =>
            {
                endpointLf.OnTermination(() => endpointLfTerminated = true);
                return(RdTask <RdSignal <int> > .Successful(respSignal));
            });

            var serverEntity = BindToServer(LifetimeDefinition.Lifetime, call1, ourKey);
            var clientEntity = BindToClient(LifetimeDefinition.Lifetime, call2, ourKey);

            var ld     = new LifetimeDefinition();
            var lf     = ld.Lifetime;
            var signal = call1.Start(lf, Unit.Instance).AsTask().GetOrWait(lf);
            var log    = new List <int>();

            signal.Advise(Lifetime.Eternal, v =>
            {
                log.Add(v);
                Console.WriteLine(v);
            });

            respSignal.Fire(1);
            respSignal.Fire(2);
            respSignal.Fire(3);
            ld.Terminate();
            Assert.False(respSignal.IsBound);

            SpinWaitEx.SpinUntil(() => log.Count >= 3);
            Thread.Sleep(100);
            Assert.AreEqual(new [] { 1, 2, 3 }, log.ToArray());

            Assert.True(endpointLfTerminated);
        }
示例#5
0
        public void TestNullability()
        {
            ClientWire.AutoTransmitMode = true;
            ServerWire.AutoTransmitMode = true;

            var serverEntity = BindToServer(LifetimeDefinition.Lifetime, new RdCall <string, string>(), ourKey);
            var clientEntity = BindToClient(LifetimeDefinition.Lifetime, new RdEndpoint <string, string>(x => x.ToString()), ourKey);

            clientEntity.Reset((lf, req) => RdTask <string> .Successful(req == null ? "NULL" : null));

            Assert.Throws <Assertion.AssertionException>(() => { serverEntity.Sync(null); });

            Assert.Throws <Assertion.AssertionException>(() =>
            {
                using (Log.UsingLogFactory(new TestThrowingLogFactory()))
                {
                    var task = serverEntity.Start("Value");
                    Assert.AreEqual(RdTaskStatus.Faulted, task.Result.Value.Status);
                }
            });
        }
示例#6
0
        private RdTask <RdProjectOutput> GetProjectOutputModel(Lifetime lifetime, RdGetProjectOutputArgs args)
        {
            var projectsHostContainer      = _solution.ProjectsHostContainer();
            var solutionStructureContainer = projectsHostContainer.GetComponent <ISolutionStructureContainer>();
            var projectMark = solutionStructureContainer
                              .GetProjectsByLocation(FileSystemPath.Parse(args.ProjectFilePath))
                              .First();

            var project         = _solution.GetProjectByMark(projectMark).NotNull();
            var targetFramework = project.TargetFrameworkIds
                                  // Take .NET Core first, then .NET Framework, and then .NET Standard. The comparer below will hold this order.
                                  .OrderBy(tfm => (!tfm.IsNetCoreApp, !tfm.IsNetFramework, !tfm.IsNetStandard))
                                  .First();

            _logger.Trace("TFM selected for project {0}: {1}", args, targetFramework);
            var assemblyInfo = project.GetOutputAssemblyInfo(targetFramework).NotNull();

            _logger.Trace("Assembly file path detected for project {0}: {1}", args, assemblyInfo.Location);
            return(RdTask <RdProjectOutput> .Successful(
                       new RdProjectOutput(targetFramework.Name, assemblyInfo.Location.ToString())));
        }
示例#7
0
        private void ResetModel(Lifetime lf, IProtocol protocol)
        {
            myUnrealHost.PerformModelAction(riderModel =>
            {
                UE4Library.RegisterDeclaredTypesSerializers(riderModel.SerializationContext.Serializers);
                riderModel.EditorId.SetValue(riderModel.EditorId.Value + 1);
            });

            var unrealModel = new RdEditorModel(lf, protocol);

            UE4Library.RegisterDeclaredTypesSerializers(unrealModel.SerializationContext.Serializers);

            unrealModel.AllowSetForegroundWindow.Set((lt, pid) =>
            {
                return(myUnrealHost.PerformModelAction(riderModel =>
                                                       riderModel.AllowSetForegroundWindow.Start(lt, pid)) as RdTask <bool>);
            });

            unrealModel.UnrealLog.Advise(lf,
                                         logEvent =>
            {
                myUnrealHost.PerformModelAction(riderModel => { OnMessageReceived(riderModel, logEvent); });
            });

            unrealModel.OnBlueprintAdded.Advise(lf, blueprintClass =>
            {
                //todo
            });

            unrealModel.Play.Advise(lf, val =>
            {
                myUnrealHost.PerformModelAction(riderModel =>
                {
                    if (PlayedFromRider)
                    {
                        return;
                    }
                    try
                    {
                        PlayedFromUnreal = true;
                        riderModel.Play.Set(val);
                    }
                    finally
                    {
                        PlayedFromUnreal = false;
                    }
                });
            });
            unrealModel.PlayMode.Advise(lf, val =>
            {
                myUnrealHost.PerformModelAction(riderModel =>
                {
                    if (PlayModeFromRider)
                    {
                        return;
                    }
                    try
                    {
                        PlayModeFromUnreal = true;
                        riderModel.PlayMode.Set(val);
                    }
                    finally
                    {
                        PlayModeFromUnreal = false;
                    }
                });
            });

            myUnrealHost.PerformModelAction(riderModel =>
            {
                riderModel.FilterLinkCandidates.Set((lifetime, candidates) =>
                                                    RdTask <ILinkResponse[]> .Successful(candidates
                                                                                         .Select(request => myLinkResolver.ResolveLink(request, unrealModel.IsBlueprintPathName))
                                                                                         .AsArray()));
                riderModel.IsMethodReference.Set((lifetime, methodReference) =>
                {
                    var b = myEditorNavigator.IsMethodReference(methodReference);
                    return(RdTask <bool> .Successful(b));
                });
                riderModel.OpenBlueprint.Advise(lf, blueprintReference =>
                                                OnOpenedBlueprint(unrealModel, blueprintReference));

                riderModel.NavigateToClass.Advise(lf,
                                                  uClass => myEditorNavigator.NavigateToClass(uClass));

                riderModel.NavigateToMethod.Advise(lf,
                                                   methodReference => myEditorNavigator.NavigateToMethod(methodReference));

                riderModel.Play.Advise(lf, val =>
                {
                    if (PlayedFromUnreal)
                    {
                        return;
                    }
                    try
                    {
                        PlayedFromRider = true;
                        unrealModel.Play.Set(val);
                    }
                    finally
                    {
                        PlayedFromRider = false;
                    }
                });

                riderModel.PlayMode.Advise(lf, val =>
                {
                    if (PlayModeFromUnreal)
                    {
                        return;
                    }
                    try
                    {
                        PlayModeFromRider = true;
                        unrealModel.PlayMode.Set(val);
                    }
                    finally
                    {
                        PlayModeFromRider = false;
                    }
                });
                riderModel.FrameSkip.Advise(lf, skip =>
                                            unrealModel.FrameSkip.Fire(skip));
            });

            if (myComponentLifetime.IsAlive)
            {
                myLocks.ExecuteOrQueueEx(myComponentLifetime, "setModel",
                                         () => { myEditorModel.SetValue(unrealModel); });
            }
        }
示例#8
0
        public T4TestHost(
            [NotNull] T4TestModel model,
            [NotNull] SolutionsManager solutionsManager
            )
        {
            model.PreprocessFile.Set(location =>
            {
                using var cookie = ReadLockCookie.Create();
                var solution     = solutionsManager.Solution;
                if (solution == null)
                {
                    return(Unit.Instance);
                }

                var host        = solution.GetComponent <ProjectModelViewHost>();
                var projectFile = host.GetItemById <IProjectFile>(location.Id).NotNull();
                var sourceFile  = projectFile.ToSourceFile().NotNull();
                sourceFile.GetPsiServices().Files.CommitAllDocuments();
                var file = sourceFile.GetPsiFiles(T4Language.Instance).OfType <IT4File>().SingleItem().NotNull();

                var templatePreprocessingManager = solution.GetComponent <IT4TemplatePreprocessingManager>();
                templatePreprocessingManager.Preprocess(file);
                return(Unit.Instance);
            });
            model.WaitForIndirectInvalidation.Set((lifetime, unit) =>
            {
                using var cookie = ReadLockCookie.Create();
                var solution     = solutionsManager.Solution;
                if (solution == null)
                {
                    return(RdTask <Unit> .Successful(Unit.Instance));
                }
                var cache = solution.GetComponent <T4FileDependencyCache>();

                var result = new RdTask <Unit>();

                void Requeue(int n)
                {
                    if (n == 1)
                    {
                        result.Set(Unit.Instance);
                        return;
                    }
                    solution.Locks.Queue(lifetime, "T4TestHost::.ctor::lambda::Requeue", () =>
                    {
                        if (cache.HasDirtyFiles)
                        {
                            Commit(n - 1);
                        }
                        else
                        {
                            Requeue(n - 1);
                        }
                    });
                }

                void Commit(int n) => solution.GetPsiServices().Files.ExecuteAfterCommitAllDocuments(() => Requeue(n));
                // First commit applies all changes in files.
                // Then we re-queue the action to make sure that indirect invalidation happens,
                // then we commit the files again to apply the indirect changes
                // Commit(2) -> Requeue(2) -> Commit(1) -> Requeue(1)
                Commit(2);

                return(result);
            });
        }
示例#9
0
 public void Set(Func <TReq, TRes> handler)
 {
     Set((lf, req) => RdTask <TRes> .Successful(handler(req)));
 }
示例#10
0
 public RdEndpoint(Func <TReq, TRes> handler) : this((lf, req) => RdTask <TRes> .Successful(handler(req)))
 {
 }