Beispiel #1
0
        public override Task <R <T[], CommandError> > Send <T>(TsCommand com)
        {
            using var wb = new WaitBlock(msgProc.Deserializer);
            lock (sendQueueLock)
            {
                msgProc.EnqueueRequest(wb);
                SendRaw(com.ToString());
            }

            return(wb.WaitForMessageAsync <T>());
        }
Beispiel #2
0
        /// <summary>
        /// Sends a command to the server. Commands look exactly like query commands and mostly also behave identically.
        /// <para>NOTE: Do not expect all commands to work exactly like in the query documentation.</para>
        /// </summary>
        /// <typeparam name="T">The type to deserialize the response to. Use <see cref="ResponseDictionary"/> for unknow response data.</typeparam>
        /// <param name="com">The command to send.
        /// <para>NOTE: By default does the command expect an answer from the server. Set <see cref="TsCommand.ExpectResponse"/> to false
        /// if the client hangs after a special command (<see cref="Send{T}(TsCommand)"/> will return a generic error instead).</para></param>
        /// <returns>Returns <code>R(OK)</code> with an enumeration of the deserialized and split up in <see cref="T"/> objects data.
        /// Or <code>R(ERR)</code> with the returned error if no response is expected.</returns>
        public override async Task <R <T[], CommandError> > Send <T>(TsCommand com)
        {
            using var wb = new WaitBlock(msgProc.Deserializer);
            var result = SendCommandBase(wb, com);

            if (!result.Ok)
            {
                return(result.Error);
            }
            if (com.ExpectResponse)
            {
                return(await wb.WaitForMessageAsync <T>());
            }
            else
            {
                // This might not be the nicest way to return in this case
                // but we don't know what the response is, so this acceptable.
                return(CommandError.NoResult);
            }
        }
Beispiel #3
0
 public async Task <R <IEnumerable <T>, CommandError> > SendCommandAsync <T>(Ts3Command com) where T : IResponse, new()
 {
     using (var wb = new WaitBlock(true))
     {
         var result = SendCommandBase(wb, com);
         if (!result.Ok)
         {
             return(result.Error);
         }
         if (com.ExpectResponse)
         {
             return(await wb.WaitForMessageAsync <T>());
         }
         else
         {
             // This might not be the nicest way to return in this case
             // but we don't know what the response is, so this acceptable.
             return(Util.NoResultCommandError);
         }
     }
 }