private IEnumerable <TorrentStatusKey> GetTorrentStatusKeyFlags(TorrentStatusKey keyFlags)
        {
            Type type   = typeof(TorrentStatusKey);
            var  values = Enum.GetValues(type).Cast <TorrentStatusKey>();

            foreach (TorrentStatusKey value in values)
            {
                if (keyFlags.HasFlag(value))
                {
                    yield return(value);
                }
            }
        }
        public async Task <object[]> GetTorrentStatusAsync(Torrent torrent, TorrentStatusKey keyFlags)
        {
            object[] args = GetTorrentStatusKeyFlags(keyFlags).Select(key => key.GetStatusKeyName()).Cast <object>().ToArray();

            IRPCMessage message = await CallMethodAsync(Method.GetTorrentStatus, new object[] { torrent.TorrentId, args });

            RPCResponse responseMessage = message as RPCResponse;

            if (responseMessage == null)
            {
                HandleError(message as RPCError);
            }

            return(responseMessage.ReturnValues);
        }
        public async Task <Dictionary <object, object> > GetTorrentsStatusAsync(TorrentStatusKey keyFlags)
        {
            object[] args = GetTorrentStatusKeyFlags(keyFlags).Select(key => key.GetStatusKeyName()).Cast <object>().ToArray();

            IRPCMessage message = await CallMethodAsync(Method.GetTorrentsStatus, new object[] { new Dictionary <object, object>(), args });

            RPCResponse response = message as RPCResponse;

            if (response == null)
            {
                HandleError(message as RPCError);
            }

            return(response.ReturnValues.Cast <Dictionary <object, object> >().Single());
        }
 public static string GetStatusKeyName(this TorrentStatusKey value)
 {
     return(value.GetCustomAttribute <StatusKeyNameAttribute>().Name);
 }