Implemting Get in my homemade fake service
-
27 aprilie 2012 03:14
So I have created a "FakeSensor" it's a variation from the online tutorials - I got Subscribe working, I can subscribe and pump out random data back to the consumer. The problem is with Get - I thought I had done it right but it doesn't seem to do anything. I was just looking at a sample on page 92 of Professional MSRDS and mine looks exactly the same so I am thinking maybe I am calling it wrong? Here is some code samples - the first from my "FakeSensor" and then from the consumer
//Get impl. in FakeSensor.cs [ServiceHandler(ServiceHandlerBehavior.Concurrent)] public IEnumerator<ITask> GetHandler(Get get) { get.ResponsePort.Post(_state); yield break; }Here is the code I am using in FakeSensorConsumer.cs to call it and try to get the state back, basically instead of using a timer to have the fake sensor spew out updates every second or whatever I am trying to use the timer in the consuming service to get them, not for any reason - I just wanted to try it.
private void timerPortHandler(DateTime time) { LogInfo("Timer Port Handler!"); Arbiter.Choice(fakeSensorPort.Get(), x => LogInfo(x.CurrentReading.ToString()), x => { LogInfo("Didn't get an update..."); }); Activate(Arbiter.Receive(false, TimeoutPort(1000), x => timerPort.Post(time))); }
If someone could point me in the right direction that would be awesome - thanks so much!
Toate mesajele
-
27 aprilie 2012 03:19
Hey, check this out. For fun I tried this
private void timerPortHandler(DateTime time) { LogInfo("Timer Port Handler!"); SpawnIterator(GetFakeSensorStatus); Activate(Arbiter.Receive(false, TimeoutPort(1000), x => timerPort.Post(time))); } IEnumerator<ITask> GetFakeSensorStatus() { yield return Arbiter.Choice(fakeSensorPort.Get(), x => LogInfo(x.CurrentReading.ToString()), x => { LogInfo("Didn't get an update..."); }); }That works! Awesome but why? Shouldn't the original version work, just synchronously instead of asynchronously?
Thanks
- Propus ca răspuns de Harshavardhana Kikkeri [MSFT]Microsoft Employee, Moderator 1 mai 2012 22:15
-
1 mai 2012 22:15Moderator
You are missing the Activate on the Choice. You either use an yield return or wrap you call with an Activate.
Try this
Activate(Arbiter.Choice(fakeSensorPort.Get(),
x => LogInfo(x.CurrentReading.ToString()),
x => { LogInfo("Didn't get an update..."); });)
- Marcat ca răspuns de r0k3t 2 mai 2012 01:38
-
2 mai 2012 01:38Ah, duh - I see it :) Thanks