Esempio n. 1
0
        private E <CommandError> SendCommandBase(WaitBlock wb, TsCommand com)
        {
            scheduler.VerifyOwnThread();

            if (status != TsClientStatus.Connecting && status != TsClientStatus.Connected)
            {
                return(CommandError.ConnectionClosed);
            }

            if (context is null)
            {
                throw new InvalidOperationException("context should be set");
            }

            if (com.ExpectResponse)
            {
                var responseNumber   = unchecked (++returnCode);
                var retCodeParameter = new CommandParameter("return_code", responseNumber);
                com.Add(retCodeParameter);
                msgProc.EnqueueRequest(retCodeParameter.Value, wb);
            }

            var message = com.ToString();

            Log.Debug("[O] {0}", message);
            byte[] data       = Tools.Utf8Encoder.GetBytes(message);
            var    sendResult = context.PacketHandler.AddOutgoingPacket(data, PacketType.Command);

            if (!sendResult)
            {
                Log.Debug("packetHandler couldn't send packet: {0}", sendResult.Error);
            }
            return(R.Ok);
        }
Esempio n. 2
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>());
        }
Esempio n. 3
0
        public override R <T[], CommandError> Send <T>(TsCommand com)       // Synchronous
        {
            using (var wb = new WaitBlock(msgProc.Deserializer, false))
            {
                lock (sendQueueLock)
                {
                    msgProc.EnqueueRequest(wb);
                    SendRaw(com.ToString());
                }

                return(wb.WaitForMessage <T>());
            }
        }
Esempio n. 4
0
        public async Task <R <LazyNotification, CommandError> > SendNotifyCommand(TsCommand com, params NotificationType[] dependsOn)
        {
            if (!com.ExpectResponse)
            {
                throw new ArgumentException("A special command must take a response");
            }

            using var wb = new WaitBlock(msgProc.Deserializer, dependsOn);
            var result = SendCommandBase(wb, com);

            if (!result.Ok)
            {
                return(result.Error);
            }
            return(await wb.WaitForNotificationAsync());
        }
Esempio n. 5
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>());
         }
     }
 }
Esempio n. 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 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);
            }
        }
Esempio n. 7
0
        private E <CommandError> SendCommandBase(WaitBlock wb, TsCommand com)
        {
            lock (statusLock)
            {
                if (context.WasExit || (!Connected && com.ExpectResponse))
                {
                    return(CommandError.TimeOut);
                }

                if (com.ExpectResponse)
                {
                    var responseNumber   = ++returnCode;
                    var retCodeParameter = new CommandParameter("return_code", responseNumber);
                    com.Add(retCodeParameter);
                    msgProc.EnqueueRequest(retCodeParameter.Value, wb);
                }

                var message = com.ToString();
                Log.Debug("[O] {0}", message);
                byte[] data = Tools.Utf8Encoder.GetBytes(message);
                packetHandler.AddOutgoingPacket(data, PacketType.Command);
            }
            return(R.Ok);
        }
Esempio n. 8
0
        public override async Task <R <T[], CommandError> > SendHybrid <T>(TsCommand com, NotificationType type)
        {
            var notification = await SendNotifyCommand(com, type);

            return(notification.UnwrapNotification <T>());
        }
Esempio n. 9
0
        // ***

        /// <summary>
        /// Sends a command without expecting a 'error' return code.
        /// <para>NOTE: Do not use this method unless you are sure the ts3 command fits the criteria.</para>
        /// </summary>
        /// <param name="command">The command to send.</param>
        public Task SendNoResponsed(TsCommand command)
        {
            return(SendVoid(command.ExpectsResponse(false)));
        }
Esempio n. 10
0
 public override R <T[], CommandError> SendHybrid <T>(TsCommand com, NotificationType type)
 => SendNotifyCommand(com, type).UnwrapNotification <T>();
Esempio n. 11
0
 /// <summary>
 /// Sends a command without expecting a 'error' return code.
 /// <para>NOTE: Do not use this method unless you are sure the ts3 command fits the criteria.</para>
 /// </summary>
 /// <param name="command">The command to send.</param>
 public CmdR SendNoResponsed(TsCommand command)
 => SendVoid(command.ExpectsResponse(false));
Esempio n. 12
0
 public async Task <E <CommandError> > SendVoid(TsCommand com)
 => await Send <ResponseVoid>(com);
Esempio n. 13
0
 /// <summary>Sends a command to the server. Commands look exactly like query commands and mostly also behave identically.</summary>
 /// <typeparam name="T">The type to deserialize the response to. Use <see cref="ResponseDictionary"/> for unknown response data.</typeparam>
 /// <param name="com">The raw command to send.</param>
 /// <returns>Returns an enumeration of the deserialized and split up in <see cref="T"/> objects data.</returns>
 public abstract Task <R <T[], CommandError> > Send <T>(TsCommand com) where T : IResponse, new();
Esempio n. 14
0
 public virtual async Task <R <T[], CommandError> > SendHybridAsync <T>(TsCommand com, NotificationType type) where T : class, IResponse, new()
 => throw new NotImplementedException();
Esempio n. 15
0
#pragma warning disable CS1998
        public virtual async Task <R <T[], CommandError> > SendAsync <T>(TsCommand com) where T : IResponse, new()
        => throw new NotImplementedException();
Esempio n. 16
0
 /// <summary>
 /// Sends a TS-command.
 ///
 /// The response (if any) is not deserialized and is discarded.
 /// </summary>
 /// <param name="command">The command name.</param>
 /// <param name="parameter">The parameters to be added to this command.
 /// See <see cref="CommandParameter"/>, <see cref="CommandOption"/> or <see cref="CommandMultiParameter"/> for more information.</param>
 ///
 ///
 public E <CommandError> SendVoid(TsCommand com)
 => Send <ResponseVoid>(com);
Esempio n. 17
0
 /// <summary>
 /// Sends a TS-command.
 ///
 /// The response (if any) is not deserialized and is discarded.
 /// </summary>
 /// <param name="command">The command name.</param>
 /// <param name="parameter">The parameters to be added to this command.
 /// See <see cref="CommandParameter"/>, <see cref="CommandOption"/> or <see cref="CommandMultiParameter"/> for more information.</param>
 ///
 ///
 public async Task <E <CommandError> > SendVoidAsync(TsCommand com)
 => await SendAsync <ResponseVoid>(com).ConfigureAwait(false);
Esempio n. 18
0
 /// <summary>
 /// Sends a command and depending on the client type waits for a response or notification.
 /// <para>NOTE: Do not use this method unless you are sure the ts command fits the criteria.</para>
 /// </summary>
 /// <param name="command">The command to send.</param>
 /// <param name="type">The notification type to wait for and serialize to.</param>
 public abstract Task <R <T[], CommandError> > SendHybrid <T>(TsCommand com, NotificationType type) where T : class, IResponse, new();
Esempio n. 19
0
 public override R <T[], CommandError> SendHybrid <T>(TsCommand com, NotificationType type)
 => Send <T>(com);