Just wondering, if there's existed class of framework, which would deal with request queuing.
When request is sent, is should be added to the queue. If something is wrong (no internet), request should be stored, and tried to be sent again later.
Meanwhile, more requests can be created. If there's still no network, all new requests should be stored in the queue, and sent again while network would return.
Going to make same functional, wondering if it is already implemented.
EDIT1: I'm using HttpWebRequest for Posting/Getting json data to/from server.
EDIT2: Sample case:
User press Button1. First request is sent, added to queue, (internet is avaivable), app got answer, request is removed from the queue.
User press Button2. Second request is sent, added to queue, no internet connection -> request is stored in the queue.
User press Button3. Third request is going to be send, but as queue is not empty, it is just stored to the queue. Request2 tries to be delivered, but still no connection.
Some time later, connection is established again, so Request2 succeeded, removed from the queue, then Request3 also succeeded and removed from the queue.
What is important - it should be resistant to tombstoning. If phone goes to sleep before calling request, it should be stored. Is request is in progress, it should be cancelled (or exactly this message should not be stored).
EDIT3: For avoiding delivery exceptions, i'm using this wrapper:
public async Task<string> GetAsync(string url)
{
var httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
httpWebRequest.Method = HttpMethod.Get;
httpWebRequest.Accept = "application/json";
try
{
var response = (HttpWebResponse)await httpWebRequest.GetResponseAsync();
if (response == null || response.StatusCode != HttpStatusCode.OK)
return String.Empty;
string data;
using (var responseStream = response.GetResponseStream())
{
using (var postStreamReader = new StreamReader(responseStream))
{
data = await postStreamReader.ReadToEndAsync();
postStreamReader.Close();
}
responseStream.Close();
}
return data ?? String.Empty;
}
catch (Exception ex)
{
return String.Empty;
}
}
It returns String.Empty if there's any exceptions, otherwise, it returns server answer's string. What i need now is a pattern, which would guarantee that call was successful (result is not empty), otherwise, keep it in queue (to keep order) and would try to raise call again, until it would be delivered.
EDIT4: for now, i'm considering having a queue in a semaphore, and call it when i need to force pushing. Any thoughts if it would work fine?