Пример #1
0
        /// <summary>
        /// Invoked when a content is finished. Validates the content's output, and moves to the next content if possible.
        /// </summary>
        private void OnFinish(object sender, ReferenceArgs <Dictionary <string, object> > args)
        {
            content_controller.Current.Finish -= OnFinish;

            string error = null;
            bool?  valid = workflows[current.name].validators[current.stage]?.Invoke(args.Value, out error);

            string name = current.stage < workflows[current.name].stages.Length ?
                          workflows[current.name].stages[current.stage] : null;

            string redirect = null;

            if (valid.Value || !valid.HasValue)
            {
                DebugLog.LogController(string.Format("Stage {0}/{1} has valid output ({2})", name, current.stage, DictToString(args.Value)));

                foreach (KeyValuePair <string, object> entry in args.Value)
                {
                    current.values[entry.Key] = entry.Value;
                }

                redirect = workflows[current.name].redirector?.Invoke(current.stage,
                                                                      name, valid ?? true, current.values);

                current.stage++;


                if (current.stage < workflows[current.name].stages.Length)
                {
                    StartStage(attachevent: true);
                }
            }
            else
            {
                DebugLog.LogController(string.Format("Stage {0}/{1} has invalid output ({2})", name, current.stage, DictToString(args.Value)));

                HoldWorkflow();

                InvokeWorkflow("__CancelRequest(error = " + error + ")", true);

                return;
            }

            if (redirect != null)
            {
                DebugLog.LogController(string.Format("Stage {0}/{1} is redirecting to {2}", name, current.stage, redirect));

                HoldWorkflow();

                InvokeWorkflow(redirect, true);

                return;
            }
            else
            {
                DebugLog.LogController(string.Format("Stage {0}/{1} is not redirecting", name, current.stage));
            }

            if (current.stage == workflows[current.name].stages.Length)
            {
                HandleWorkflowExit();
            }
        }
Пример #2
0
        /// <summary>
        /// Pushes the current workflow into the held workflows, but does not reset anything.
        /// </summary>
        private void HoldWorkflow()
        {
            held_flows.Push(current);

            DebugLog.LogController("Holding workflow '" + current.name + "' - stack size: " + held_flows.Count);
        }