Пример #1
0
        private static IControlBlock ParseDFGBreaker(XmlNode node, DFG <Block> dfg, ParserInfo parserInfo)
        {
            string id        = node.GetAttributeValue(Block.ID_FIELD_NAME);
            string blockType = node.Attributes[Block.TYPE_FIELD_NAME].Value;

            switch (blockType)
            {
            case If.XML_TYPE_NAME:
                return(new If(node, dfg, parserInfo));

            case Repeat.XML_TYPE_NAME:
                return(new Repeat(node, dfg, parserInfo));

            case While.XML_TYPE_NAME:
                return(new While(node, dfg, parserInfo));

            case InlineProgram.XML_TYPE_NAME:
                InlineProgram program = ProgramCache.GetProgram(node, id, parserInfo);
                if (!program.IsValidProgram)
                {
                    parserInfo.ParseExceptions.Add(new ParseException(id, "There is program errors in the program: " + program.ProgramName));
                    return(null);
                }
                return(program.GetProgram(node, parserInfo));

            default:
                throw new UnknownBlockException(id);
            }
        }
Пример #2
0
        private async void Window_Loaded(object sender, RoutedEventArgs e)
        {
            CompilerOptions.PROGRAM_FOLDER_PATH = PROGRAMS_FOLDER_PATH;
            var programData = InlineProgram.LoadProgram("Basic protocol for E. coli Quick");
            //var programData = InlineProgram.LoadProgram("showcasing using inline program block");
            //var programData = InlineProgram.LoadProgram("UsingDiluter3");

            var sassdad = XmlParser.Parse("<xml xmlns='http://www.w3.org/1999/xhtml'><variables><variable type='' id='gZ,c_HQgu:,yfA:J+Lxt'>input_fluid_name</variable></variables><block type='start' id='7skRs`d%@XtBz=rV_7{/' x='528' y='219'><statement name='program'><block type='inputDeclaration' id='2lbQ[al;v|T3G{$fy9Tn'><field name='inputName' id='gZ,c_HQgu:,yfA:J+Lxt' variabletype=''>asd</field><field name='inputAmount'>1</field></block></statement></block></xml>");

            for (int i = 0; i < 1; i++)
            {
                BenchmarkExecutor        executor = new BenchmarkExecutor();
                ProgramExecutor <string> CurrentlyExecutionProgram = new ProgramExecutor <string>(executor);
                CurrentlyExecutionProgram.TimeBetweenCommands     = 0;
                CurrentlyExecutionProgram.ShowEmptyRectangles     = false;
                CurrentlyExecutionProgram.EnableOptimizations     = true;
                CurrentlyExecutionProgram.EnableGarbageCollection = true;
                CurrentlyExecutionProgram.EnableSparseElectrodes  = false;

                CurrentlyExecutionProgram.Run(45, 45, programData.cdfg, false);
            }

            this.Close();

            //Run in another thread to not block the UI
            await Task.Run(() =>
            {
                SettingsInfo settings = new SettingsInfo();
                settings.LoadSettings(SETTINGS_FILE_PATH);

                this.Updater = new WebUpdater(Browser, settings);

                Browser.Load("costum://index.html");
                Browser.JavascriptObjectRepository.Register("saver", new Saver(Browser), true);
                Browser.JavascriptObjectRepository.Register("webUpdater", Updater, true);
                //Wait for the MainFrame to finish loading
                Browser.FrameLoadEnd += async(s, args) =>
                {
                    //Wait for the MainFrame to finish loading
                    if (args.Frame.IsMain)
                    {
                        //Run in another thread to not block the UI
                        await Task.Run(() =>
                        {
                            GiveSettingsToJS(settings);
                            GiveProgramsToJS();
                        });
                    }
                };
            });
        }
Пример #3
0
        public static InlineProgram GetProgram(XmlNode node, string id, ParserInfo parserInfo)
        {
            lock (Locker)
            {
                string programName = InlineProgram.GetProgramName(node, id);

                if (Cache.ContainsKey(programName))
                {
                    return(Cache[programName]);
                }

                if (StoredFiles.TryGetValue(programName, out string fileContent))
                {
                    Cache.Add(programName, new InlineProgram(node, parserInfo, fileContent));
                }
                else
                {
                    Cache.Add(programName, new InlineProgram(node, parserInfo));
                }

                return(Cache[programName]);
            }
        }
Пример #4
0
        private void GiveProgramsToJS()
        {
            CompilerOptions.PROGRAM_FOLDER_PATH = PROGRAMS_FOLDER_PATH;
            string[]      files          = Directory.GetFiles(PROGRAMS_FOLDER_PATH);
            List <string> loadedPrograms = new List <string>();

            foreach (string file in files)
            {
                if (System.IO.Path.GetExtension(file) == Saver.DEFAULT_FILE_EXTENSION)
                {
                    try
                    {
                        string fileContent = File.ReadAllText(file);
                        (CDFG cdfg, List <ParseException> exceptions) = XmlParser.Parse(fileContent);
                        if (exceptions.Count == 0)
                        {
                            string programName = System.IO.Path.GetFileNameWithoutExtension(file);
                            (string[] inputStrings, string[] outputStrings, string[] variableStrings, string programXml, _) = InlineProgram.LoadProgram(programName);

                            string inputs    = String.Join(",", inputStrings.Select(x => "\"" + x + "\""));
                            string outputs   = String.Join(",", outputStrings.Select(x => "\"" + x + "\""));
                            string variables = String.Join(", ", variableStrings.Select(x => "\"" + x + "\""));
                            programXml = programXml.Replace("\"", "'");
                            loadedPrograms.Add($"{{name: \"{programName}\", inputs: [{inputs}], outputs: [{outputs}], variables: [{variables}], programXml: \"{programXml}\"}}");
                        }
                    }
                    catch (Exception ee)
                    {
                        MessageBox.Show(ee.Message + Environment.NewLine + ee.StackTrace);
                    }
                }
            }

            string allPrograms  = $"[{String.Join(",", loadedPrograms)}]";
            string startBlockly = $"startBlockly({allPrograms});";

            Browser.ExecuteScriptAsync(startBlockly);
        }