Exemple #1
0
        // CTORS

        static TS3QueryClient()
        {
            // get all classes deriving from Notification
            var derivedNtfy = from asm in AppDomain.CurrentDomain.GetAssemblies()
                              from type in asm.GetTypes()
                              where type.IsInterface
                              where typeof(INotification).IsAssignableFrom(type)
                              let ntfyAtt = type.GetCustomAttribute(typeof(QueryNotificationAttribute), false)
                                            where ntfyAtt != null
                                            select new KeyValuePair <string, Type>(((QueryNotificationAttribute)ntfyAtt).Name, type);

            notifyLookup = derivedNtfy.ToDictionary(x => x.Key, x => x.Value);

            Helper.Init(ref convertMap);
            convertMap.Add(typeof(bool), (v, t) => v != "0");
            convertMap.Add(typeof(sbyte), (v, t) => sbyte.Parse(v, CultureInfo.InvariantCulture));
            convertMap.Add(typeof(byte), (v, t) => byte.Parse(v, CultureInfo.InvariantCulture));
            convertMap.Add(typeof(short), (v, t) => short.Parse(v, CultureInfo.InvariantCulture));
            convertMap.Add(typeof(ushort), (v, t) => ushort.Parse(v, CultureInfo.InvariantCulture));
            convertMap.Add(typeof(int), (v, t) => int.Parse(v, CultureInfo.InvariantCulture));
            convertMap.Add(typeof(uint), (v, t) => uint.Parse(v, CultureInfo.InvariantCulture));
            convertMap.Add(typeof(long), (v, t) => long.Parse(v, CultureInfo.InvariantCulture));
            convertMap.Add(typeof(ulong), (v, t) => ulong.Parse(v, CultureInfo.InvariantCulture));
            convertMap.Add(typeof(float), (v, t) => float.Parse(v, CultureInfo.InvariantCulture));
            convertMap.Add(typeof(double), (v, t) => double.Parse(v, CultureInfo.InvariantCulture));
            convertMap.Add(typeof(string), (v, t) => TS3QueryTools.Unescape(v));
            convertMap.Add(typeof(TimeSpan), (v, t) => TimeSpan.FromSeconds(double.Parse(v, CultureInfo.InvariantCulture)));
            convertMap.Add(typeof(DateTime), (v, t) => PrimitiveParameter.unixTimeStart.AddSeconds(double.Parse(v, CultureInfo.InvariantCulture)));
        }
Exemple #2
0
        private static ErrorStatus GenerateErrorStatus(string line)
        {
            var kvpList     = ParseKeyValueLine(line, true);
            var errorStatus = new ErrorStatus();

            foreach (var responseParam in kvpList)
            {
                switch (responseParam.Key.ToUpperInvariant())
                {
                case "ID": errorStatus.Id = int.Parse(responseParam.Value); break;

                case "MSG": errorStatus.Message = TS3QueryTools.Unescape(responseParam.Value); break;

                case "FAILED_PERMID": errorStatus.MissingPermissionId = int.Parse(responseParam.Value); break;
                }
            }
            return(errorStatus);
        }
Exemple #3
0
        protected IEnumerable <IResponse> SendInternal(string command, Parameter[] parameter, Option[] options, Type targetType)
        {
            if (string.IsNullOrWhiteSpace(command))
            {
                throw new ArgumentNullException(nameof(command));
            }
            if (!commandMatch.IsMatch(command))
            {
                throw new ArgumentException("Invalid command characters", nameof(command));
            }

            StringBuilder strb = new StringBuilder(TS3QueryTools.Escape(command));

            foreach (var param in parameter)
            {
                strb.Append(' ').Append(param.QueryString);
            }

            foreach (var option in options)
            {
                strb.Append(option.Value);
            }

            string finalCommand = strb.ToString();

            using (WaitBlock wb = new WaitBlock(targetType))
            {
                lock (lockObj)
                {
                    requestQueue.Enqueue(wb);

                    tcpWriter.WriteLine(finalCommand);
                    tcpWriter.Flush();
                }

                return(wb.WaitForMessage());
            }
        }
Exemple #4
0
 public PrimitiveParameter(string value)
 {
     QueryValue = TS3QueryTools.Escape(value);
 }