示例#1
0
        protected override IEnumerable <T> SendCommand <T>(Ts3Command com)       // Synchronous
        {
            using (var wb = new WaitBlock())
            {
                lock (SendQueueLock)
                {
                    msgProc.EnqueueRequest(wb);
                    SendRaw(com.ToString());
                }

                return(wb.WaitForMessage <T>());
            }
        }
示例#2
0
        public override R <T[], CommandError> Send <T>(Ts3Command com)       // Synchronous
        {
            using (var wb = new WaitBlock(msgProc.Deserializer, false))
            {
                lock (sendQueueLock)
                {
                    msgProc.EnqueueRequest(wb);
                    SendRaw(com.ToString());
                }

                return(wb.WaitForMessage <T>());
            }
        }
示例#3
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 raw command to send.
 /// <para>NOTE: By default does the command expect an answer from the server. Set <see cref="Ts3Command.ExpectResponse"/> to false
 /// if the client hangs after a special command (<see cref="SendCommand{T}"/> will return <code>null</code> instead).</para></param>
 /// <returns>Returns an enumeration of the deserialized and split up in <see cref="T"/> objects data.
 /// Or <code>null</code> if no reponse is expected.</returns>
 /// <exception cref="Ts3CommandException">When the response has an error code.</exception>
 public override IEnumerable <T> SendCommand <T>(Ts3Command com)
 {
     using (var wb = new WaitBlock())
     {
         SendCommandBase(wb, com);
         if (com.ExpectResponse)
         {
             return(wb.WaitForMessage <T>());
         }
         else
         {
             return(null);
         }
     }
 }
示例#4
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 R <T[], CommandError> Send <T>(TsCommand com)
 {
     using (var wb = new WaitBlock(msgProc.Deserializer, false))
     {
         var result = SendCommandBase(wb, com);
         if (!result.Ok)
         {
             return(result.Error);
         }
         if (com.ExpectResponse)
         {
             return(wb.WaitForMessage <T>());
         }
         else
         {
             return(Array.Empty <T>());
         }
     }
 }
示例#5
0
        protected override IEnumerable <T> SendCommand <T>(Ts3Command com)
        {
            var retCode = new CommandParameter("return_code", returnCode);

            if (com.ExpectResponse)
            {
                com.AppendParameter(retCode);
            }

            using (var wb = new WaitBlock())
            {
                lock (CommmandQueueLock)
                {
                    if (com.ExpectResponse)
                    {
                        msgProc.EnqueueRequest(retCode.Value, wb);
                        returnCode++;
                    }

                    byte[] data = Util.Encoder.GetBytes(com.ToString());
                    lock (StatusLock)
                    {
                        if (wasExit)
                        {
                            throw new Ts3CommandException(new CommandError {
                                Id = Ts3ErrorCode.custom_error, Message = "Connection closed"
                            });
                        }
                        packetHandler.AddOutgoingPacket(data, PacketType.Command);
                    }
                }

                if (com.ExpectResponse)
                {
                    return(wb.WaitForMessage <T>());
                }
                else
                {
                    return(null);
                }
            }
        }
示例#6
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 raw command to send.
 /// <para>NOTE: By default does the command expect an answer from the server. Set <see cref="Ts3Command.ExpectResponse"/> to false
 /// if the client hangs after a special command (<see cref="SendCommand{T}"/> will return <code>null</code> 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 R <IEnumerable <T>, CommandError> SendCommand <T>(Ts3Command com)
 {
     using (var wb = new WaitBlock(false))
     {
         var result = SendCommandBase(wb, com);
         if (!result.Ok)
         {
             return(result.Error);
         }
         if (com.ExpectResponse)
         {
             return(wb.WaitForMessage <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);
         }
     }
 }
示例#7
0
 public R <T[], CommandError> SendCommand <T>(Ts3Command com) where T : IResponse, new()
 {
     using (var wb = new WaitBlock(msgProc.Deserializer, false))
     {
         var result = SendCommandBase(wb, com);
         if (!result.Ok)
         {
             return(result.Error);
         }
         if (com.ExpectResponse)
         {
             return(wb.WaitForMessage <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);
         }
     }
 }