locked
Implemting Get in my homemade fake service RRS feed

  • Question

  • 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!

    Friday, April 27, 2012 3:14 AM

Answers

  • 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..."); });)

    • Marked as answer by r0k3t Wednesday, May 2, 2012 1:38 AM
    Tuesday, May 1, 2012 10:15 PM
    Moderator

All replies

  • 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

    Friday, April 27, 2012 3:19 AM
  • 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..."); });)

    • Marked as answer by r0k3t Wednesday, May 2, 2012 1:38 AM
    Tuesday, May 1, 2012 10:15 PM
    Moderator
  • Ah, duh - I see it :) Thanks
    Wednesday, May 2, 2012 1:38 AM