private WorkflowInstanceQuery Match(WorkflowInstanceRecord workflowRecord)
        {
            WorkflowInstanceQuery trackingQuery = null;

            if (_workflowEventSubscriptions != null)
            {
                if (!_workflowEventSubscriptions.TryGetValue(workflowRecord.State, out trackingQuery))
                {
                    _workflowEventSubscriptions.TryGetValue("*", out trackingQuery);
                }
            }
            return(trackingQuery);
        }
        private void AddWorkflowSubscription(WorkflowInstanceQuery workflowTrackingQuery)
        {
            _trackingRecordPreFilter.TrackWorkflowInstanceRecords = true;

            if (_workflowEventSubscriptions == null)
            {
                _workflowEventSubscriptions = new Dictionary <string, WorkflowInstanceQuery>();
            }
            if (workflowTrackingQuery.HasStates)
            {
                foreach (string state in workflowTrackingQuery.States)
                {
                    //if duplicates are found, use only the first subscription for a given state.
                    if (!_workflowEventSubscriptions.ContainsKey(state))
                    {
                        _workflowEventSubscriptions.Add(state, workflowTrackingQuery);
                    }
                }
            }
        }