Example #1
0
        private RdCall <TIn, TOut> CreateEndpoint <TIn, TOut>(Func <TIn, TOut> handler)
        {
            var res = new RdCall <TIn, TOut>();

            res.Set(handler);
            return(res);
        }
Example #2
0
        //primary constructor
        private Solution2(
            [NotNull] RdCall <int, MyClass> get,
            [NotNull] RdProperty <string> version,
            [NotNull] RdProperty <RdDocumentModel> testBuffer
            )
        {
            if (get == null)
            {
                throw new ArgumentNullException("get");
            }
            if (version == null)
            {
                throw new ArgumentNullException("version");
            }
            if (testBuffer == null)
            {
                throw new ArgumentNullException("testBuffer");
            }

            _Get                    = get;
            _Version                = version;
            _TestBuffer             = testBuffer;
            _Version.OptimizeNested = true;
            _Version.ValueCanBeNull = true;
            BindableChildren.Add(new KeyValuePair <string, object>("get", _Get));
            BindableChildren.Add(new KeyValuePair <string, object>("version", _Version));
            BindableChildren.Add(new KeyValuePair <string, object>("testBuffer", _TestBuffer));
        }
Example #3
0
        private RdCall <TIn, TOut> CreateEndpoint <TIn, TOut>(Func <TIn, TOut> handler, IScheduler cancellationScheduler = null, IScheduler handlerScheduler = null)
        {
            var res = new RdCall <TIn, TOut>();

            res.Set(handler, cancellationScheduler, handlerScheduler);
            return(res);
        }
        //primary constructor
        private XamlStylerModel(
            [NotNull] RdCall <RdXamlStylerFormattingRequest, RdXamlStylerFormattingResult> performReformat
            )
        {
            if (performReformat == null)
            {
                throw new ArgumentNullException("performReformat");
            }

            _PerformReformat       = performReformat;
            _PerformReformat.Async = true;
            BindableChildren.Add(new KeyValuePair <string, object>("performReformat", _PerformReformat));
        }
Example #5
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);
        }
Example #6
0
        //primary constructor
        private Solution2(
            [NotNull] RdCall <int, MyClass> get,
            [NotNull] RdProperty <RdDocumentModel> testBuffer
            )
        {
            if (get == null)
            {
                throw new ArgumentNullException("get");
            }
            if (testBuffer == null)
            {
                throw new ArgumentNullException("testBuffer");
            }

            _Get        = get;
            _TestBuffer = testBuffer;
            BindableChildren.Add(new KeyValuePair <string, object>("get", _Get));
            BindableChildren.Add(new KeyValuePair <string, object>("testBuffer", _TestBuffer));
        }
        //primary constructor
        private BSMT_RiderModel(
            [NotNull] RdCall <Unit, ConfigSettings> getUserSettings,
            [NotNull] RdCall <Unit, string[]> foundBeatSaberLocations
            )
        {
            if (getUserSettings == null)
            {
                throw new ArgumentNullException("getUserSettings");
            }
            if (foundBeatSaberLocations == null)
            {
                throw new ArgumentNullException("foundBeatSaberLocations");
            }

            _GetUserSettings                        = getUserSettings;
            _FoundBeatSaberLocations                = foundBeatSaberLocations;
            _GetUserSettings.ValueCanBeNull         = true;
            _FoundBeatSaberLocations.ValueCanBeNull = true;
            BindableChildren.Add(new KeyValuePair <string, object>("getUserSettings", _GetUserSettings));
            BindableChildren.Add(new KeyValuePair <string, object>("foundBeatSaberLocations", _FoundBeatSaberLocations));
        }
Example #8
0
        /// <summary>
        /// Sync call which allow nested call execution with help of <see cref="SwitchingScheduler"/>
        /// </summary>
        public static TRes SyncNested <TReq, TRes>(RdCall <TReq, TRes> call, Lifetime lifetime, TReq request, RpcTimeouts timeouts = null)
        {
            Assertion.Require(call.IsBound, "Not bound: {0}", call);

            // Sync calls can called only under the protocol's scheduler.
            // If you want to mitigate this limitation, keep in mind that if you make a sync call from background thread
            // with some small probability your call can be merged in the sync execution of other call. Usually it is not
            // desired behaviour as you can accidentally obtain undesired locks.
            call.Proto.Scheduler.AssertThread();

            var nestedCallsScheduler = new LifetimeDefinition();
            var responseScheduler    = new RdSimpleDispatcher(nestedCallsScheduler.Lifetime, Log.GetLog(call.GetType()));

            using (new SwitchingScheduler.SwitchCookie(responseScheduler))
            {
                var task = call.Start(lifetime, request, responseScheduler);

                task.Result.Advise(nestedCallsScheduler.Lifetime, result => { nestedCallsScheduler.Terminate(); });

                RpcTimeouts timeoutsToUse = RpcTimeouts.GetRpcTimeouts(timeouts);
                responseScheduler.MessageTimeout = timeoutsToUse.ErrorAwaitTime;

                var stopwatch = Stopwatch.StartNew();
                responseScheduler.Run();
                if (!task.Result.HasValue())
                {
                    throw new TimeoutException($"Sync execution of rpc `{call.Location}` is timed out in {timeoutsToUse.ErrorAwaitTime.TotalMilliseconds} ms");
                }

                stopwatch.Stop();

                var freezeTime = stopwatch.ElapsedMilliseconds;
                if (freezeTime > timeoutsToUse.WarnAwaitTime.TotalMilliseconds)
                {
                    Log.Root.Error("Sync execution of rpc `{0}` executed too long: {1} ms", call.Location, freezeTime);
                }

                return(task.Result.Value.Unwrap());
            }
        }
        //primary constructor
        public UnityModel(
            [NotNull] RdProperty <bool> play,
            [NotNull] RdProperty <bool> pause,
            [NotNull] RdCall <RdVoid, RdVoid> step,
            [NotNull] RdProperty <string> unityPluginVersion,
            [NotNull] RdProperty <int> riderProcessId,
            [NotNull] RdProperty <string> applicationPath,
            [NotNull] RdProperty <string> applicationVersion,
            [NotNull] RdProperty <UnityLogModelInitialized> logModelInitialized,
            [NotNull] RdEndpoint <RdVoid, bool> isClientConnected,
            [NotNull] RdEndpoint <RdOpenFileArgs, bool> openFileLineCol,
            [NotNull] RdCall <string, bool> updateUnityPlugin,
            [NotNull] RdCall <RdVoid, RdVoid> refresh
            )
        {
            if (play == null)
            {
                throw new ArgumentNullException("play");
            }
            if (pause == null)
            {
                throw new ArgumentNullException("pause");
            }
            if (step == null)
            {
                throw new ArgumentNullException("step");
            }
            if (unityPluginVersion == null)
            {
                throw new ArgumentNullException("unityPluginVersion");
            }
            if (riderProcessId == null)
            {
                throw new ArgumentNullException("riderProcessId");
            }
            if (applicationPath == null)
            {
                throw new ArgumentNullException("applicationPath");
            }
            if (applicationVersion == null)
            {
                throw new ArgumentNullException("applicationVersion");
            }
            if (logModelInitialized == null)
            {
                throw new ArgumentNullException("logModelInitialized");
            }
            if (isClientConnected == null)
            {
                throw new ArgumentNullException("isClientConnected");
            }
            if (openFileLineCol == null)
            {
                throw new ArgumentNullException("openFileLineCol");
            }
            if (updateUnityPlugin == null)
            {
                throw new ArgumentNullException("updateUnityPlugin");
            }
            if (refresh == null)
            {
                throw new ArgumentNullException("refresh");
            }

            _Play  = play;
            _Pause = pause;
            _Step  = step;
            _UnityPluginVersion   = unityPluginVersion;
            _RiderProcessId       = riderProcessId;
            _ApplicationPath      = applicationPath;
            _ApplicationVersion   = applicationVersion;
            _LogModelInitialized  = logModelInitialized;
            _IsClientConnected    = isClientConnected;
            _OpenFileLineCol      = openFileLineCol;
            _UpdateUnityPlugin    = updateUnityPlugin;
            _Refresh              = refresh;
            _Play.OptimizeNested  = true;
            _Pause.OptimizeNested = true;
            _UnityPluginVersion.OptimizeNested = true;
            _RiderProcessId.OptimizeNested     = true;
            _ApplicationPath.OptimizeNested    = true;
            _ApplicationVersion.OptimizeNested = true;
        }
Example #10
0
 /// <summary>
 ///  Wrapper method to simplify search with overload resolution for two methods in RdEndpoint
 /// </summary>
 public static void SetHandler <TReq, TRes>(RdCall <TReq, TRes> endpoint, Func <Lifetime, TReq, RdTask <TRes> > handler)
 {
     endpoint.Set(handler);
 }
Example #11
0
 /// <summary>
 ///  Wrapper method to simplify search with overload resolution for two methods in RdEndpoint
 /// </summary>
 public static void SetHandlerTaskVoid <TReq>(RdCall <TReq, Unit> endpoint, Func <Lifetime, TReq, Task> handler)
 {
     endpoint.Set((lt, req) => handler(lt, req).ToRdTask());
 }
Example #12
0
 /// <summary>
 /// Sync call which allow nested call execution with help of <see cref="SwitchingScheduler"/>
 /// </summary>
 public static TRes SyncNested <TReq, TRes>(RdCall <TReq, TRes> call, TReq request, RpcTimeouts timeouts = null)
 {
     return(SyncNested(call, Lifetime.Eternal, request, timeouts));
 }
        //primary constructor
        private UnityModel(
            [NotNull] RdProperty <bool> play,
            [NotNull] RdProperty <bool> pause,
            [NotNull] RdEndpoint <RdVoid, RdVoid> step,
            [NotNull] RdProperty <string> unityPluginVersion,
            [NotNull] RdProperty <int> riderProcessId,
            [NotNull] RdProperty <string> applicationPath,
            [NotNull] RdProperty <string> applicationVersion,
            [NotNull] RdProperty <UnityLogModelInitialized> logModelInitialized,
            [NotNull] RdCall <RdVoid, bool> isBackendConnected,
            [NotNull] RdEndpoint <RdVoid, UnityEditorState> getUnityEditorState,
            [NotNull] RdCall <RdOpenFileArgs, bool> openFileLineCol,
            [NotNull] RdEndpoint <string, bool> updateUnityPlugin,
            [NotNull] RdEndpoint <bool, RdVoid> refresh,
            [NotNull] RdProperty <JetBrains.Platform.Unity.Model.UnitTestLaunch> unitTestLaunch
            )
        {
            if (play == null)
            {
                throw new ArgumentNullException("play");
            }
            if (pause == null)
            {
                throw new ArgumentNullException("pause");
            }
            if (step == null)
            {
                throw new ArgumentNullException("step");
            }
            if (unityPluginVersion == null)
            {
                throw new ArgumentNullException("unityPluginVersion");
            }
            if (riderProcessId == null)
            {
                throw new ArgumentNullException("riderProcessId");
            }
            if (applicationPath == null)
            {
                throw new ArgumentNullException("applicationPath");
            }
            if (applicationVersion == null)
            {
                throw new ArgumentNullException("applicationVersion");
            }
            if (logModelInitialized == null)
            {
                throw new ArgumentNullException("logModelInitialized");
            }
            if (isBackendConnected == null)
            {
                throw new ArgumentNullException("isBackendConnected");
            }
            if (getUnityEditorState == null)
            {
                throw new ArgumentNullException("getUnityEditorState");
            }
            if (openFileLineCol == null)
            {
                throw new ArgumentNullException("openFileLineCol");
            }
            if (updateUnityPlugin == null)
            {
                throw new ArgumentNullException("updateUnityPlugin");
            }
            if (refresh == null)
            {
                throw new ArgumentNullException("refresh");
            }
            if (unitTestLaunch == null)
            {
                throw new ArgumentNullException("unitTestLaunch");
            }

            _Play  = play;
            _Pause = pause;
            _Step  = step;
            _UnityPluginVersion   = unityPluginVersion;
            _RiderProcessId       = riderProcessId;
            _ApplicationPath      = applicationPath;
            _ApplicationVersion   = applicationVersion;
            _LogModelInitialized  = logModelInitialized;
            _IsBackendConnected   = isBackendConnected;
            _GetUnityEditorState  = getUnityEditorState;
            _OpenFileLineCol      = openFileLineCol;
            _UpdateUnityPlugin    = updateUnityPlugin;
            _Refresh              = refresh;
            _UnitTestLaunch       = unitTestLaunch;
            _Play.OptimizeNested  = true;
            _Pause.OptimizeNested = true;
            _UnityPluginVersion.OptimizeNested = true;
            _RiderProcessId.OptimizeNested     = true;
            _ApplicationPath.OptimizeNested    = true;
            _ApplicationVersion.OptimizeNested = true;
            BindableChildren.Add(new KeyValuePair <string, object>("play", _Play));
            BindableChildren.Add(new KeyValuePair <string, object>("pause", _Pause));
            BindableChildren.Add(new KeyValuePair <string, object>("step", _Step));
            BindableChildren.Add(new KeyValuePair <string, object>("unityPluginVersion", _UnityPluginVersion));
            BindableChildren.Add(new KeyValuePair <string, object>("riderProcessId", _RiderProcessId));
            BindableChildren.Add(new KeyValuePair <string, object>("applicationPath", _ApplicationPath));
            BindableChildren.Add(new KeyValuePair <string, object>("applicationVersion", _ApplicationVersion));
            BindableChildren.Add(new KeyValuePair <string, object>("logModelInitialized", _LogModelInitialized));
            BindableChildren.Add(new KeyValuePair <string, object>("isBackendConnected", _IsBackendConnected));
            BindableChildren.Add(new KeyValuePair <string, object>("getUnityEditorState", _GetUnityEditorState));
            BindableChildren.Add(new KeyValuePair <string, object>("openFileLineCol", _OpenFileLineCol));
            BindableChildren.Add(new KeyValuePair <string, object>("updateUnityPlugin", _UpdateUnityPlugin));
            BindableChildren.Add(new KeyValuePair <string, object>("refresh", _Refresh));
            BindableChildren.Add(new KeyValuePair <string, object>("unitTestLaunch", _UnitTestLaunch));
        }
Example #14
0
 /// <summary>
 /// Wrapper method to simplify search with overload resolution for two methods in RdEndpoint.
 ///
 /// Used for sync calls only.
 /// </summary>
 public static void SetHandler <TReq, TRes>(RdCall <TReq, TRes> endpoint, Func <Lifetime, TReq, RdTask <TRes> > handler)
 {
     endpoint.Set(handler, null, new SwitchingScheduler(endpoint));
 }