Click here to Skip to main content
14,301,895 members
Rate this:
Please Sign up or sign in to vote.
Hi,

Quick overview:

I have a service that starts two processes:
1: A message based workflow
2: An event based 'tracker'

The tracker handles several third party APIs that either push data (async) or that we pull data from. I have managed to set this up so that all of the data collected from each API is raised as an event with identical data args. I merge all of the event streams into a single Observable object.

My workflow starts and finds out what id's need to be tracked. It created a sub-workflow for each of the tracker APIs, which set up a subscription to the observable object.

The Observable object, as well as the subscription method are both static in the same static class. This is my 'Event Bridge':

namespace WorkFlowEngine.EventBridge
{
 public static class TrackerEventHandler
 {
  public static IObservable<TrackerInstanceEventArgs> GetDataObservable()
  {
   return Observable
   .FromEvent<TrackerInstanceHandler, TrackerInstanceEventArgs>(handler =>
   {
    TrackerInstanceHandler dataHandler = e =>
    {
     handler(e);
    };
    return dataHandler ;
   },
   dataHandler => TrackerInstanceEvents.TrackerInstance += dataHandler ,
   dataHandler => TrackerInstanceEvents.TrackerInstance -= dataHandler 
  );
 }

 public static void SubscribeToTrackerInstanceHandler(int trackerInstanceId, int id, int? workflowId)
 {
  GetDataObservable().Where(fd => fd.TrackerInstanceId == trackerInstanceId).Subscribe(o => OnNext(o, id, workflowId));
 }

 public static void OnNext(TrackerInstanceEventArgs args, int id, int? workflowId)
 {
   //Parse data and create new workflow message
 }
}

//Also, TrackerInstance event is static:

...
 public class TrackerInstanceEvents 
 {
  public static event TrackerInstanceHandler TrackerInstance;

  public static void OnTrackerInstance(TrackerInstanceEventArgs args)
  {
   if (TrackerInstance != null)
     TrackerInstance(args);
  }
 }
...


The issue is that OnNext never fires.

SubscribeToTrackerInstanceHandler is called correctly and before the event is triggered. The event does propagate up to the Observable

I created the bridge so that I could link up the two processes (Workflow and 'tracker'). My alternative is to pass an instance of this class to the trackers, but I hoped this would be better.

Am I fundamentally wrong about the use of this static class or am I close?

Thanks ^_^


EDIT - Solved:
GAH - the code works fine >_<

I hadn't set TrackerInstanceEventArgs.TrackerInstanceId

Please forgive my stupidity ^_^
Posted
Updated 11-May-15 5:47am
v2

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

GAH - the code works fine >_<

I hadn't set TrackerInstanceEventArgs.TrackerInstanceId

Please forgive my stupidity ^_^
   
Comments
Sergey Alexandrovich Kryukov 11-May-15 11:22am
   
It's all quite fine, only — don't post such things as "answer", to avoid abuse reports and down-voting, better move it to the question using "Improve question".
—SA
Andy Lanng 11-May-15 11:46am
   
cool - ok.

Do I just leave the question unanswered? I wanted to leave it there is case anyone else found it useful, but also wanted to withdraw the question from the list.
(I'll delete the solution after I hear back from you)
Sergey Alexandrovich Kryukov 11-May-15 12:08pm
   
Just edit the question and leave it as is. Or delete it.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100