Esempio n. 1
0
        public override void CreateCode(Node node, CodeExtension codeExtension)
        {
            DataSourceNodeClass nodeClass = node.Class as DataSourceNodeClass;

            codeExtension.AddSensor(node as DataSource);
            codeExtension.AddExtras(nodeClass.NeededExtras);

            codeExtension.AddImport(nodeClass.OutputType.Name);
            codeExtension.AddImport(nodeClass.MainClass);


            //Add the proxy methods to the Imports:
            nodeClass.ProxyProperties
            .Select(p => p.PropertyType.Name)
            .ForEach(codeExtension.AddImport);


            //We have a special case: Only a DataSource:
            if (codeExtension.RootNode == node)
            {
                string code = " private void transform0(){\n"
                              + "     data = sensor0." + nodeClass.DataMethod + "();\n"
                              + " }\n";

                codeExtension.AddCodeStep(code);
            }
        }
Esempio n. 2
0
        public override void CreateCode(Node node, CodeExtension codeExtension)
        {
            BufferNodeClass nodeClass = node.Class as BufferNodeClass;

            codeExtension.AddImport(nodeClass.MainClass);
            codeExtension.AddExtras(nodeClass.NeededExtras);

            codeExtension.AddBuffer(node as BufferNode);

            //Add the proxy methods to the Imports:
            nodeClass.ProxyProperties
            .Select(p => p.PropertyType.Name)
            .ForEach(codeExtension.AddImport);
        }
Esempio n. 3
0
        public override void CreateCode(Node node, CodeExtension codeExtension)
        {
            var nodeClass = node.Class as TransformationNodeClass;

            codeExtension.AddTransformation(node as Transformation);
            codeExtension.AddExtras(nodeClass.NeededExtras);

            var content          = "";
            var args             = "(";
            var currentTransform = codeExtension.GetCurrentStep();

            for (var i = 0; i < nodeClass.InputTypes.Length; i++)
            {
                var inputType = nodeClass.InputTypes[i];
                var inputNode = node.InputNodes[i];
                var ioData    = node.InputIOData[i];

                //If we have a combined node, we have to proxy it's output node:
                if (inputNode is CombinedNode)
                {
                    inputNode = ((CombinedNode)inputNode).outputNode;
                }

                //Add the args:
                if (i != 0)
                {
                    args += ", ";
                }
                args += "data" + i;

                if (inputNode == null)
                {
                    //We have a default value in the GUI:
                    content += string.Format(ClassTemplates.GENERATION_TEMPLATE_TRANSFORM_VAR_LINE_STATIC,
                                             inputType.MinimizedName,
                                             i,
                                             ioData.Value);
                }
                else
                {
                    var inAsSource    = inputNode as DataSource;
                    var inAsTransform = inputNode as Transformation;
                    var inAsBuffer    = inputNode as BufferNode;

                    var inAsSourceClass = inAsSource?.Class as DataSourceNodeClass;
                    var inAsTransClass  = inAsTransform?.Class as TransformationNodeClass;
                    var inAsBufferClass = inAsBuffer?.Class as BufferNodeClass;


                    var typeName           = "";
                    var optionalMethodCall = "";

                    switch (inputNode.Class.NodeType)
                    {
                    case ClassManager.NodeType.Transformation:
                        typeName = "transform";
                        break;

                    case ClassManager.NodeType.Sensor:
                        typeName           = "sensor";
                        optionalMethodCall = "." + inAsSourceClass.DataMethod + "()";
                        break;

                    case ClassManager.NodeType.Buffer:
                        typeName           = "buffer";
                        optionalMethodCall = "." + inAsBufferClass.BufferGetMethod + "()";
                        break;

                    case ClassManager.NodeType.Combined:
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }



                    var outputIndex = codeExtension.GetOutputIndex(inputNode);

                    content += string.Format(ClassTemplates.GENERATION_TEMPLATE_TRANSFORM_VAR_LINE,
                                             inputType.MinimizedName,
                                             i,
                                             typeName,
                                             outputIndex,
                                             optionalMethodCall);
                }
            }

            args += ")";

            //Extract the method call:
            var methodCall = (nodeClass.IsStatic
                ? (DataType.MinimizeToClass(nodeClass.MainClass))
                : (nodeClass.NodeType.ToString() + codeExtension.GetTransformId(node as Transformation)))
                             + "." + nodeClass.Method + args;

            var template = codeExtension.RootNode == node
                ? ClassTemplates.GENERATION_TEMPLATE_TRANSFORM_LAST
                : ClassTemplates.GENERATION_TEMPLATE_TRANSFORM;

            var code = string.Format(
                template,
                currentTransform,
                content,
                methodCall
                );

            //At last add the important stuff:
            codeExtension.AddCodeStep(code);
            codeExtension.AddImport(nodeClass.MainClass);
            codeExtension.AddImport(nodeClass.OutputType.Name);

            //Add the proxy methods to the Imports:
            nodeClass.ProxyProperties
            .Select(p => p.PropertyType.Name)
            .ForEach(codeExtension.AddImport);
        }