Example #1
0
        private void DaemonFlowEndpoint(IFlowResult result, int nextLevel)
        {
            //If the data is default (empty), just ignore it
            if (result.Data.GetType() == typeof(DefaultFlowResult))
            {
                return;
            }

            //If the type of the data matches the return type, notify the Daemon's initiator via callback
            //Note that there may still be other flows processing which might return data
            if (result.Data.GetType() == typeof(TReturn))
            {
                var returnData = (TReturn)result.Data;
                Callback(returnData);
                return;
            }

            try
            {
                //Otherwise, handle the data according to its requirements
                if (result.MustHandle)
                {
                    ProcessFlowRequired(result, nextLevel);
                }
                else
                {
                    ProcessFlowOptional(result, nextLevel);
                }
            }
            catch (Exception e) when(e is FlowRegistrationException || e is FactoryRegistrationException)
            {
                lock (_TaskCacheSync)
                {
                    //Get all tasks and tell them to die
                    var activeFlows = ActiveFlows.Select(x => x.Value).ToArray();
                    foreach (var flow in activeFlows)
                    {
                        flow.Die();
                    }
                }
                throw;
            }
        }
Example #2
0
        private void CreateFlowTask(IFlow instance, Action action)
        {
            Task.Run(() =>
            {
                var taskId = Guid.NewGuid();

                lock (_TaskCacheSync)
                {
                    ActiveFlows.Add(taskId, instance);
                }

                action();

                lock (_TaskCacheSync)
                {
                    ActiveFlows.Remove(taskId);
                }
            });
        }