I have the following two observables
System.Net.WebRequest req = System.Net.HttpWebRequest.Create("http://test.com/data.xml");
req.Method = "HEAD";
var ob = Observable.FromAsyncPattern(req.BeginGetResponse, req.EndGetResponse);
ob().Select(x => x).Select(x => x.Headers["Last-Modified"]).DistinctUntilChanged(x => x);
Observable .Interval(TimeSpan.FromSeconds(1.0)) .Select(_ => XDocument.Load("http://test.com/data.xml"));
I would like it that the XDocument observable is only executed when "last-modified" header is greater then the previously requested document any ideas?
Firstly .Select(x=>x) is a no-op so you can remove that.
I would change the code up a little bit. First lets break it down into its constituent parts:
1) The Timer. Every second poll the server.
var poll = Observable.Interval(TimeSpan.FromSeconds(1));
2) The call to get the header
var lastModified = Observable.FromAsyncPattern(req.BeginGetResponse, req.EndGetResponse).Select(x => x.Headers["Last-Modified"]);
3) The Select to get the Document
.Select(_ => XDocument.Load("http://test.com/data.xml"));
We should be able to compose that nicely:
Cavet I just typed that straight into the browser. I would be amazing if it compiles.