Beispiel #1
0
        private static string Validator(Function f)
        {
            var errors = new List <string>();

            Type t = f.Blocks.Last().GetType();

            var inputBlockCount = f.Blocks.Where(b => b.GetType() == typeof(MyInput)).Count();

            if (inputBlockCount > 1)
            {
                errors.Add("The number of input blocks is invalid");
            }
            if (inputBlockCount == 1 && f.Blocks.First().GetType() != typeof(MyInput))
            {
                errors.Add("Input needs to be the first defined block");
            }
            if (f.Blocks.Last().GetType() == typeof(MyIf) ||
                f.Blocks.Last().GetType() == typeof(MyForeach) ||
                f.Blocks.Last().GetType() == typeof(MyElse))
            {
                errors.Add("Last block cannot define an empty scope");
            }
            if (errors.Count == 0 && !FunctionConverter.RestructureBlocks(f))
            {
                errors.Add("Failed to calculate blockscope");
            }
            return(string.Join("\n", errors));
        }
Beispiel #2
0
        public static string Convert(Function input_function)
        {
            var function = input_function.Clone() as Function;

            if (function.Blocks.Count == 0)
            {
                return("No block to visualize");
            }

            var errors = FunctionConverter.Validator(function);

            if (errors.Count() > 0)
            {
                return(string.Join("\n", errors));
            }

            var output = new List <string>();
            var indent = 0;

            foreach (Base block in function.Blocks)
            {
                output.Add(BlockConverter.ConvertBlock(block, function, ref indent));
                output.Add(string.Empty);
            }


            output.Insert(1, "\tconst factory = getFactory();");
            output.Insert(1, "\tconst me = getCurrentParticipant();");


            return(string.Join("\n", output));
        }