/// <summary>
 /// Sends a request to a scene that doesn't return data.
 /// </summary>
 /// <typeparam name="TData">The type of parameter to send.</typeparam>
 /// <param name="scene">The target scene.</param>
 /// <param name="route">The name of the route used to send the request.</param>
 /// <param name="parameter">A parameter object that will be sent as content of the request.</param>
 /// <param name="priority">An optional priority level for the request.</param>
 /// <returns>A task completing with the request.</returns>
 /// <remarks>Uses the RPC plugin</remarks>
 public static async Task SendVoidRequest <TData>(this Scene scene, string route, TData parameter, PacketPriority priority = PacketPriority.MEDIUM_PRIORITY)
 {
     await scene.Rpc(route, s =>
     {
         scene.Host.Serializer().Serialize(parameter, s);
     }, priority).FirstOrDefaultAsync();
 }
        /// <summary>
        /// Sends a RPC to a scene host.
        /// </summary>
        /// <typeparam name="TData">The type of parameter to send.</typeparam>
        /// <typeparam name="TResponse">The type of the data returned by the request.</typeparam>
        /// <param name="scene">The target scene.</param>
        /// <param name="route">The target route.</param>
        /// <param name="priority">The request priority. Only applies to the request, not the response.</param>
        /// <param name="parameter">The request parameter</param>
        /// <returns>A task completing with the request.</returns>
        public static IObservable <TResponse> SendRequest <TData, TResponse>(this Scene scene, string route, TData parameter, PacketPriority priority = PacketPriority.MEDIUM_PRIORITY)
        {
            return(scene.Rpc(route, s =>
            {
                scene.Host.Serializer().Serialize(parameter, s);
            }, priority).Select(packet =>
            {
                var value = packet.Serializer().Deserialize <TResponse>(packet.Stream);

                return value;
            }));
        }
示例#3
0
        public Task FindMatch(string provider, int deckIndex)
        {
            var tcs = new TaskCompletionSource <bool>();

            _isMatching = true;

            var observable = _scene.Rpc("match.find", stream =>
            {
                var serializer = _scene.Host.Serializer();
                serializer.Serialize(provider, stream);
                serializer.Serialize(deckIndex, stream);
            }, PacketPriority.MEDIUM_PRIORITY);

            Action <Packet <IScenePeer> > onNext = packet =>
            {
                using (_matchmakingSubscription)
                {
                    _isMatching = false;
                    _matchmakingSubscription = null;
                }
                tcs.SetResult(true);
            };

            Action <Exception> onError = exception =>
            {
                using (_matchmakingSubscription)
                {
                    _isMatching = false;
                    _matchmakingSubscription = null;
                }
                tcs.SetException(exception);
            };

            _matchmakingSubscription = observable.Subscribe(onNext, onError);

            return(tcs.Task);
        }
 /// <summary>
 /// Sends a request to a scene without expecting a response
 /// </summary>
 /// <param name="scene">The scene on which the message will be sent.</param>
 /// <param name="route">A string containing the name of the route used to send the request.</param>
 /// <param name="priority"></param>
 /// <returns>A task completing with the request.</returns>
 /// <remarks>
 /// Uses the RPC plugin
 /// </remarks>
 public static async Task SendVoidRequest(this Scene scene, string route, PacketPriority priority = PacketPriority.MEDIUM_PRIORITY)
 {
     await scene.Rpc(route, s =>
     {
     }, priority).FirstOrDefaultAsync();
 }
 /// <summary>
 /// Sends a remote procedure call using raw binary data as input and output, expecting exactly one answer
 /// </summary>
 /// <param name="scene">The target scene. </param>
 /// <param name="route">The target route.</param>
 /// <param name="writer">A writer method writing the data to send.</param>
 /// <param name="priority">The priority level used to send the request.</param>
 /// <returns>A task representing the remote procedure, whose return value is the raw answer to the remote procedure call.</returns>
 public static async Task <Packet <IScenePeer> > RpcTask(this Scene scene, string route, Action <Stream> writer, PacketPriority priority = PacketPriority.MEDIUM_PRIORITY)
 {
     return(await scene.Rpc(route, writer, priority));
 }
 /// <summary>
 /// Sends a remote procedure call using raw binary data as input, expecting no answer
 /// </summary>
 /// <param name="scene">The target scene. </param>
 /// <param name="route">The target route.</param>
 /// <param name="writer">A writer method writing the data to send.</param>
 /// <param name="priority">The priority level used to send the request.</param>
 /// <returns>A task representing the remote procedure.</returns>
 public async static Task RpcVoid(this Scene scene, string route, Action <Stream> writer, PacketPriority priority = PacketPriority.MEDIUM_PRIORITY)
 {
     await scene.Rpc(route, writer, priority).DefaultIfEmpty();
 }
 /// <summary>
 /// Sends a remote procedure call with an object as input, expecting any number of answers.
 /// </summary>
 /// <typeparam name="TData">The type of data to send</typeparam>
 /// <typeparam name="TResponse">The expected type of the responses.</typeparam>
 /// <param name="scene">The target scene.</param>
 /// <param name="route">The target route.</param>
 /// <param name="data">The data object to send.</param>
 /// <param name="priority">The priority level used to send the request.</param>
 /// <returns>An IObservable instance that provides return values for the request.</returns>
 public static IObservable <TResponse> Rpc <TData, TResponse>(this Scene scene, string route, TData data, PacketPriority priority = PacketPriority.MEDIUM_PRIORITY)
 {
     return(scene.Rpc(route, s => scene.Host.Serializer().Serialize(data, s), priority)
            .Select(p => p.ReadObject <TResponse>()));
 }
示例#8
0
 /// <summary>
 /// Sends a remote procedure call using raw binary data as input, expecting no answer
 /// </summary>
 /// <param name="scene">The target scene. </param>
 /// <param name="route">The target route.</param>
 /// <param name="writer">A writer method writing the data to send.</param>
 /// <param name="priority">The priority level used to send the request.</param>
 /// <returns>A task representing the remote procedure.</returns>
 public static Task RpcVoid(this Scene scene, string route, Action <Stream> writer, PacketPriority priority = PacketPriority.MEDIUM_PRIORITY)
 {
     return(scene.Rpc(route, writer, priority).DefaultIfEmpty().ToVoidTask());
 }
        /// <summary>
        /// Sends a remote procedure call using raw binary data as input and output, expecting exactly one answer
        /// </summary>
        /// <param name="scene">The target scene. </param>
        /// <param name="route">The target route.</param>
        /// <param name="writer">A writer method writing the data to send.</param>
        /// <param name="priority">The priority level used to send the request.</param>
        /// <returns>A task representing the remote procedure, whose return value is the raw answer to the remote procedure call.</returns>
        public static Task <Packet <IScenePeer> > RpcTask(this Scene scene, string route, Action <Stream> writer, CancellationToken cancellationToken, PacketPriority priority = PacketPriority.MEDIUM_PRIORITY)
        {
            var observable = scene.Rpc(route, writer, priority);

            return(observable.ToTask(cancellationToken));
        }
        /// <summary>
        /// Sends a remote procedure call using raw binary data as input, expecting no answer
        /// </summary>
        /// <param name="scene">The target scene. </param>
        /// <param name="route">The target route.</param>
        /// <param name="writer">A writer method writing the data to send.</param>
        /// <param name="priority">The priority level used to send the request.</param>
        /// <returns>A task representing the remote procedure.</returns>
        public static Task RpcVoid(this Scene scene, string route, Action <Stream> writer, CancellationToken cancellationToken, PacketPriority priority = PacketPriority.MEDIUM_PRIORITY)
        {
            var observable = scene.Rpc(route, writer, priority).DefaultIfEmpty();

            return(observable.ToVoidTask(cancellationToken));
        }
 /// <summary>
 /// Sends a remote procedure call with no input, expecting any number of answers.
 /// </summary>
 /// <typeparam name="TResponse">The expected type of the responses.</typeparam>
 /// <param name="scene">The target scene.</param>
 /// <param name="route">The target route.</param>
 /// <param name="priority">The priority level used to send the request.</param>
 /// <returns>An IObservable instance that provides return values for the request.</returns>
 public static IObservable <TResponse> Rpc <TResponse>(this Scene scene, string route, PacketPriority priority = PacketPriority.MEDIUM_PRIORITY)
 {
     return(scene.Rpc(route, s => { }, priority)
            .Select(p => p.ReadObject <TResponse>()));
 }