예제 #1
0
파일: Daemon.cs 프로젝트: Vecht/Demonology
        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);
                });
            }
        }
예제 #2
0
파일: Daemon.cs 프로젝트: Vecht/Demonology
        private void QueueTasksAndUpdate(FlowTask[] flowTasks)
        {
            foreach (var flowTask in flowTasks)
            {
                FlowTaskQueue.Enqueue(flowTask, flowTask.AbsolutePriority);
            }

            Task.Run(() => Update());
        }
예제 #3
0
파일: Daemon.cs 프로젝트: Vecht/Demonology
        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();
                }
            });
        }