private AniDBRequest QueueCommand(string command, IEnumerable <KeyValuePair <string, string> > parValues) { if (SessionKey != "") { parValues = parValues.ToDictionary(p => p.Key, p => p.Value); } ((Dictionary <string, string>)parValues).Add("s", SessionKey); var request = new AniDBRequest(command, parValues); if (_sentRequests.ContainsKey(request.Tag)) { throw new ArgumentException("A request with that tag has already been sent"); } _sendBucket.Input(request); return(request); }
private void SendPacket(AniDBRequest request) { //In theory this should never fail (GUIDs are supposed to be globally unique) if (!_sentRequests.TryAdd(request.Tag, request)) { request.OnResponse(null); return; } byte[] requestBytes = request.ToByteArray(_encoding); _udpClient.Send(requestBytes, requestBytes.Count()); Debug.Print(requestBytes.ToString()); request.Timeout.Elapsed += (o, a) => { AniDBRequest r; _sentRequests.TryRemove(request.Tag, out r); }; request.Timeout.Interval = Timeout; request.Timeout.Enabled = true; }
private AniDBRequest QueueCommand(string command, IEnumerable<KeyValuePair<string, string>> parValues) { if (SessionKey != "") parValues = parValues.ToDictionary(p => p.Key, p => p.Value); ((Dictionary<string, string>) parValues).Add("s", SessionKey); var request = new AniDBRequest(command, parValues); if(_sentRequests.ContainsKey(request.Tag)) throw new ArgumentException("A request with that tag has already been sent"); _sendBucket.Input(request); return request; }