Ejemplo n.º 1
0
        private static void Transformator(object context)
        {
            ThreadContext p = (ThreadContext)context;

            ScriptRuntime   runtime         = Python.CreateRuntime();
            ScriptEngine    engine          = runtime.GetEngine("py");
            LanguageContext languageContext = HostingHelpers.GetLanguageContext(engine);

            while (p.Running)
            {
                string pySrc;
                if (p.Queue.TryDequeue(out pySrc))
                {
                    LocalSink sink = new LocalSink();

                    try
                    {
                        SourceUnit src = HostingHelpers.GetSourceUnit(engine.CreateScriptSourceFromString(pySrc));

                        CompilerContext ctx    = new CompilerContext(src, languageContext.GetCompilerOptions(), sink);
                        Parser          parser = Parser.CreateParser(ctx, (PythonOptions)languageContext.Options);

                        PythonAst           ast       = parser.ParseFile(true);
                        JavascriptGenerator generator = new JavascriptGenerator(src, sink);

                        if (sink.IsError)
                        {
                            p.SetOutput(null);
                        }
                        else
                        {
                            p.SetOutput(generator.ToJavaScript(ast));
                        }
                    }
                    catch (Exception e)
                    {
                        if (!sink.IsError)
                        {
                            p.SetOutput(e.ToString());
                        }
                    }
                    finally
                    {
                        p.SetErrors(sink.Messages);
                    }
                }
                else
                {
                    Thread.Sleep(50);
                    if (p.Queue.Count == 0)
                    {
                        p.Suspend();
                    }
                }
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BlocklyFileGenerator"/> class.
 /// </summary>
 /// <param name="actionList">The action list.</param>
 public BlocklyFileGenerator(List <ActionInfo> actionList)
 {
     _jsGenerator = new JavascriptGenerator();
     _actionList  = actionList;
 }
Ejemplo n.º 3
0
        private void btnGenerate_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(filePath))
            {
                ShowErrorMessage();
                return;
            }

            List <string> listOfClassNames = new List <string>();
            List <FileLinesOverviewModel> listOfProperties = new List <FileLinesOverviewModel>();
            List <string> listOfVarTypes = new List <string>
            {
                "Int",
                "Int16",
                "Int32",
                "Int64",
                "UInt",
                "Short",
                "Bool",
                "Boolean",
                "Byte",
                "SByte",
                "Char",
                // "Date", // TODO: Check what to do with Date type vars, cause it is interfeering with DateTime vars
                "DateTime",
                "Decimal",
                "Double",
                "Float",
                "String",
                "Object",
                "Long"
            };
            List <string> listOfLowerVarTypes = listOfVarTypes.Select(d => d.ToLower()).ToList();

            listOfLowerVarTypes.AddRange(listOfVarTypes.Select(d => d.ToLower() + "?").ToList());

            string line;
            // Read the file and display it line by line.
            StreamReader file = new StreamReader(filePath);

            while ((line = file.ReadLine()) != null)
            {
                // Add all class names (Classes are imidiately stripped)
                if (ClassNamesUtility.IsClass(line))
                {
                    listOfClassNames.Add(ClassNamesUtility.StripClassName(line));
                }
                // And their properties (Properties are stripped down below)
                else if (PropertyNamesUtility.IsProperty(line))
                {
                    listOfProperties.Add(new FileLinesOverviewModel
                    {
                        ClassName            = listOfClassNames.Last(),
                        OriginalPropertyLine = line,
                        LineType             = new LineType()
                    });
                }
            }
            file.Close();

            // First determine property type
            foreach (var pair in listOfProperties)
            {
                pair.LineType = PropertyNamesUtility.GetPropertyType(pair.OriginalPropertyLine, listOfClassNames, listOfLowerVarTypes);
            }

            // Then get property name
            foreach (var pair in listOfProperties)
            {
                pair.PropertyName = PropertyNamesUtility.StripPropertyName(pair.OriginalPropertyLine.Trim(), pair.LineType);
            }

            // Map it into proper model, so data is purposely there
            JSBuilderModel model = ModelsMapper.GetBuilderModel(listOfProperties);

            // Get options model
            var options = GetOptionsModel();

            // Finally generate
            string result = null;

            switch (options.ConversionType)
            {
            case EGenerateOptions.Javascript:
                result = JavascriptGenerator.GenerateJs(model, options);
                break;

            case EGenerateOptions.Ecma6:
                result = Ecma6Generator.GenerateJs(model, options);
                break;

            case EGenerateOptions.KnockoutEcma6:
                result = Ecma6WithKnockoutGenerator.GenerateJs(model, options);
                break;
            }
            // result = JavascriptClassGenerator.GenerateJs(model, options);

            codeTextEditor.Text = result;
        }
Ejemplo n.º 4
0
        protected void OnGenerateCode(object parameter)
        {
            switch (CurrentTool.Language)
            {
            case "javascript":
                //Check for source files
                string fileStatus = DocumentCreator.AddFile(@"D:\Zkit\SourceFiles", @"Output\Scripts", "CommonObjects.js");

                //Create CSS
                CSSGenerator css       = new CSSGenerator(CurrentTool);
                string       cssStatus = DocumentCreator.CreateDocument(@"Output\Styles", (CurrentTool.Parent != null ? ((Project)CurrentTool.Parent).Name : "Project") + "Styles", "css", css.GenerateDoc(), true);

                PHPGenerator php = new PHPGenerator(CurrentTool);
                //set php info here
                php.DB     = "zkit";
                php.Pass   = "******";
                php.Server = "localhost";
                php.User   = "******";

                //Create PHP Scripts
                string phpStatus = DocumentCreator.CreateDocument(@"Output\PHP", "connect", "php", php.GenerateConnectDoc(), true);
                if (!String.IsNullOrWhiteSpace(phpStatus))
                {
                    MessageBox.Show(phpStatus);
                }
                phpStatus = DocumentCreator.CreateDocument(@"Output\PHP", "save_" + (CurrentTool.Parent != null ? ((Project)CurrentTool.Parent).Name : "Project"), "php", php.GenerateSaveDoc(), true);
                if (!String.IsNullOrWhiteSpace(phpStatus))
                {
                    MessageBox.Show(phpStatus);
                }
                phpStatus = DocumentCreator.CreateDocument(@"Output\PHP", "load_" + (CurrentTool.Parent != null ? ((Project)CurrentTool.Parent).Name : "Project"), "php", php.GenerateLoadDoc(), true);
                if (!String.IsNullOrWhiteSpace(phpStatus))
                {
                    MessageBox.Show(phpStatus);
                }

                //Create Javascript files
                JavascriptGenerator js = new JavascriptGenerator(CurrentTool);
                js.ProjectName = CurrentTool.Parent != null ? ((Project)CurrentTool.Parent).Name : "Project";    //Needs to be the name of the objecst
                string jsStatus = DocumentCreator.CreateDocument(@"Output\Scripts", js.ProjectName, "js", js.GenerateDoc(), true);
                if (!String.IsNullOrWhiteSpace(jsStatus))
                {
                    MessageBox.Show(jsStatus);
                }
                jsStatus = DocumentCreator.CreateDocument(@"Output\Scripts", js.ProjectName + "_functions", "js", js.GenerateFunctionsDoc(), true);
                if (!String.IsNullOrWhiteSpace(jsStatus))
                {
                    MessageBox.Show(jsStatus);
                }

                HTMLGenerator g = CurrentTool.HTML;
                g.ProjectName = CurrentTool.Parent != null ? ((Project)CurrentTool.Parent).Name : "Project";
                g.ToolRef     = CurrentTool;
                g.ScriptIncludes.Add("CommonObjects.js");
                g.ScriptIncludes.Add(js.ProjectName + ".js");
                g.ScriptIncludes.Add("https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js");
                g.ScriptIncludes.Add(g.ProjectName + "_functions.js");
                g.GenerateDoc();    //Creates begining point of doc

                //Load js objects
                var htmlTag = g.Tags.Where(x => x.TagName == "html").FirstOrDefault();
                if (htmlTag != null && htmlTag.GetType() == typeof(HTMLTagBase))
                {
                    var headTag = ((HTMLTagBase)htmlTag).Children.Where(x => x.TagName == "head").FirstOrDefault();
                    if (headTag != null)
                    {
                        var         scriptTag = ((HTMLTagBase)headTag).Children.Where(x => x.TagName == "script").FirstOrDefault();
                        HTMLTagBase script    = null;
                        if (scriptTag != null)
                        {
                            script = (HTMLTagBase)scriptTag;
                        }
                        else    //create a script tag
                        {
                            script         = new HTMLTagBase();
                            script.TagName = "script";
                            headTag.Children.Add(script);
                        }
                        List <string> names = new List <string>();
                        foreach (var o in CurrentTool.Objects)
                        {
                            names.Add(o.Name);
                        }
                        script.InnerHTML = JavascriptGenerator.GenerateInitFunction(names);
                    }

                    var bodyTag = ((HTMLTagBase)htmlTag).Children.Where(x => x.TagName == "body").FirstOrDefault();
                    if (bodyTag != null)
                    {
                        bodyTag.Elements.Add("onload", "initObjs();");
                    }
                }
                else    //no html tag found.  Something is wrong.
                {
                }

                string htmlDoc = g.ReOutputDoc();

                string status = DocumentCreator.CreateDocument("Output", CurrentTool.Parent != null ? ((Project)CurrentTool.Parent).Name : "Project", "html", htmlDoc, true);
                if (!String.IsNullOrWhiteSpace(status))
                {
                    MessageBox.Show(status);
                }

                //TODO: Finish adding all report elements - tags in reports.html, additional scripts
                //***** Create Report Document
                HTMLTagBase reportDoc     = g.CreateReportPage();
                var         reportHeadTag = ((HTMLTagBase)reportDoc).Children.Where(x => x.TagName == "head").FirstOrDefault();
                if (reportHeadTag != null)
                {
                    var         scriptTag = ((HTMLTagBase)reportHeadTag).Children.Where(x => x.TagName == "script").FirstOrDefault();
                    HTMLTagBase script    = null;
                    if (scriptTag != null)
                    {
                        script = (HTMLTagBase)scriptTag;
                    }
                    else    //create a script tag
                    {
                        script         = new HTMLTagBase();
                        script.TagName = "script";
                        reportHeadTag.Children.Add(script);
                    }
                    List <string> names = new List <string>();
                    foreach (var o in CurrentTool.Objects)
                    {
                        names.Add(o.Name);
                    }
                    script.InnerHTML = JavascriptGenerator.GenerateReportInitFunction(names, CurrentTool.Objects.ElementAt(0));
                }

                var reportBodyTag = ((HTMLTagBase)reportDoc).Children.Where(x => x.TagName == "body").FirstOrDefault();
                if (reportBodyTag != null)
                {
                    reportBodyTag.Elements["onload"] += "initObjs();";
                }

                status = DocumentCreator.CreateDocument("Output", "Reports", "html", reportDoc.GenerateTag(), true);
                if (!String.IsNullOrWhiteSpace(status))
                {
                    MessageBox.Show(status);
                }

                //***** Create SQL Scripts
                SQLGenerator sql       = new SQLGenerator(CurrentTool);
                string       sqlStatus = DocumentCreator.CreateDocument("Output", "CREATE_TABLES", "sql", sql.GenerateDoc(), true);

                MessageBox.Show("Files Created!");
                break;
            }
        }