Ejemplo n.º 1
0
        private void Update()
        {
            if (!FlowTaskQueue.Any())
            {
                return;
            }

            while (UnderTaskLimit())
            {
                var taskFound = FlowTaskQueue.TryDequeue(out var nextTask);
                if (!taskFound)
                {
                    break;
                }

                var flowType     = nextTask.Flow;
                var multiplicity = nextTask.Multiplicity;
                var permanence   = nextTask.Permanence;
                var level        = nextTask.ExecutionLevel;
                var data         = nextTask.DataToProcess;
                var instance     = FlowCache.Request(flowType, multiplicity, permanence);

                CreateFlowTask(instance, () =>
                {
                    //Since the Daemon is the creator of this instance, create a callback to dynamically handle the result of the flow
                    void Callback(IFlowResult result) => DaemonFlowEndpoint(result, level + 1);

                    //Invoke!
                    instance.Process(data, (Action <IFlowResult>)Callback);
                });
            }
        }
Ejemplo n.º 2
0
        private void QueueTasksAndUpdate(FlowTask[] flowTasks)
        {
            foreach (var flowTask in flowTasks)
            {
                FlowTaskQueue.Enqueue(flowTask, flowTask.AbsolutePriority);
            }

            Task.Run(() => Update());
        }
Ejemplo n.º 3
0
        public void Invoke(TData data)
        {
            //Will throw if nothing was registered
            var flowTasks = ResolverCache.FlowResolver
                            .GetFlowTypesFor <TData>()
                            .Select(t => new FlowTask(t, data, 0))
                            .ToArray();

            foreach (var flowTask in flowTasks)
            {
                FlowTaskQueue.Enqueue(flowTask, flowTask.AbsolutePriority);
            }

            Task.Run(() =>
            {
                Update();
                while (Busy)
                {
                    Thread.Sleep(1000);
                    Update();
                }
            });
        }