コード例 #1
0
        public static designGraph openGraphFromXml(string filename)
        {
            StreamReader graphReader    = null;
            designGraph  newDesignGraph = null;

            try
            {
                graphReader = new StreamReader(filename);
                XmlSerializer graphDeserializer = new XmlSerializer(typeof(designGraph));
                newDesignGraph = (designGraph)graphDeserializer.Deserialize(graphReader);
                SearchIO.output(Path.GetFileName(filename) + " successfully loaded.");
                newDesignGraph.internallyConnectGraph();
                if (newDesignGraph.name == null)
                {
                    newDesignGraph.name = Path.GetFileName(filename).TrimEnd(new char[] { '.', 'x', 'm', 'l' });
                }
            }
            catch (Exception ioe)
            { SearchIO.output("Error Opening Graph: " + ioe.ToString()); }
            finally
            {
                if (graphReader != null)
                {
                    graphReader.Close();
                }
            }
            return(newDesignGraph);
        }
コード例 #2
0
ファイル: ruleSetXMLIO.cs プロジェクト: albertut/gearsynth
 public void loadRulesFromFileNames()
 {
     rules = new List <grammarRule>();
     foreach (string ruleName in ruleFileNames)
     {
         SearchIO.output("Loading " + ruleName);
         rules.Add(grammarRule.openRuleFromXml(rulesDir + ruleName));
     }
 }
コード例 #3
0
        /// <summary>
        ///   Finds the source files.
        /// </summary>
        /// <param name = "rulesets">The rulesets.</param>
        /// <param name = "allSourceFiles">All source files.</param>
        /// <param name = "rulesDirectory">The rules directory.</param>
        /// <returns></returns>
        public static Boolean FindSourceFiles(ruleSet[] rulesets, List <string> allSourceFiles,
                                              string rulesDirectory)
        {
            var filesFound = true;

            foreach (var a in rulesets.Where(a => a != null))
            {
                foreach (var file in a.recognizeSourceFiles)
                {
                    var fileLower = file.ToLower();
                    if (File.Exists(rulesDirectory + fileLower))
                    {
                        if (!allSourceFiles.Contains(rulesDirectory + fileLower))
                        {
                            allSourceFiles.Add(rulesDirectory + fileLower);
                        }
                    }
                    else
                    {
                        SearchIO.MessageBoxShow("Missing source file: " + fileLower +
                                                ". Cancelling compilation of C# recognize source file.",
                                                "Missing File", "Error");
                        filesFound = false;
                        break;
                    }
                }
                foreach (var file in a.applySourceFiles)
                {
                    var fileLower = file.ToLower();
                    if (File.Exists(rulesDirectory + fileLower))
                    {
                        if (!allSourceFiles.Contains(rulesDirectory + fileLower))
                        {
                            allSourceFiles.Add(rulesDirectory + fileLower);
                        }
                    }
                    else
                    {
                        SearchIO.MessageBoxShow("Missing source file: " + fileLower +
                                                ". Cancelling compilation of C# apply source file.",
                                                "Missing File", "Error");
                        filesFound = false;
                        break;
                    }
                }
            }
            return(filesFound);
        }
コード例 #4
0
        public static grammarRule openRuleFromXml(string filename)
        {
            try
            {
                StreamReader ruleReader = new StreamReader(filename);
                try
                {
                    XmlSerializer ruleDeserializer = new XmlSerializer(typeof(grammarRule));
                    grammarRule   newGrammarRule   = (grammarRule)ruleDeserializer.Deserialize(ruleReader);
                    if (newGrammarRule.L == null)
                    {
                        newGrammarRule.L = new designGraph();
                    }
                    if (newGrammarRule.R == null)
                    {
                        newGrammarRule.R = new designGraph();
                    }
                    newGrammarRule.L.internallyConnectGraph();
                    newGrammarRule.R.internallyConnectGraph();

                    SearchIO.output("Successfully loaded rule: " + Path.GetFileName(filename), 4);

                    if (newGrammarRule.name == null)
                    {
                        newGrammarRule.name =
                            Path.GetFileName(filename).TrimEnd(new char[] { '.', 'x', 'm', 'l' });
                    }
                    newGrammarRule.rulesDir = Path.GetDirectoryName(filename) + "\\";
                    return(newGrammarRule);
                }
                catch (Exception ioe)
                {
                    MessageBox.Show(ioe.Message, "XML Serialization Error",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(null);
                }
                finally
                {
                    ruleReader.Close();
                }
            }
            catch (FileNotFoundException fnfe)
            {
                MessageBox.Show(fnfe.Message, "File not found", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(null);
            }
        }
コード例 #5
0
ファイル: ruleSetXMLIO.cs プロジェクト: albertut/gearsynth
        public static Boolean CompileSourceFiles(ruleSet[] rulesets, List <string> allSourceFiles,
                                                 out CompilerResults cr, string rulesDir, string execDir, string compiledparamRules)
        {
            cr = null;
            try
            {
                CSharpCodeProvider c = new CSharpCodeProvider();
                // c.CreateCompiler();
//                ICodeCompiler icc = c.CreateCompiler();
                CompilerParameters cp = new CompilerParameters();

                cp.ReferencedAssemblies.Add("system.dll");
                cp.ReferencedAssemblies.Add("system.xml.dll");
                cp.ReferencedAssemblies.Add("system.data.dll");
                cp.ReferencedAssemblies.Add("system.windows.forms.dll");
                cp.ReferencedAssemblies.Add(execDir + "GraphSynth.exe");
                cp.ReferencedAssemblies.Add(execDir + "Representation.dll");

                cp.CompilerOptions  = "/t:library";
                cp.GenerateInMemory = true;
                cp.OutputAssembly   = rulesDir + compiledparamRules;
                string[] allSourceFilesArray = allSourceFiles.ToArray();

                cr = c.CompileAssemblyFromFile(cp, allSourceFilesArray);

                //cr = icc.CompileAssemblyFromFileBatch(cp, allSourceFilesArray);
                if (cr.Errors.Count > 0)
                {
                    throw new Exception();
                }
                else
                {
                    return(true);
                }
            }
            catch
            {
                MessageBox.Show("Error Compiling C# recognize and apply source files.",
                                "Compilation Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                foreach (CompilerError e in cr.Errors)
                {
                    SearchIO.output(e.ToString(), 1);
                }
                return(false);
            }
        }
コード例 #6
0
ファイル: ruleSetXMLIO.cs プロジェクト: albertut/gearsynth
        public static ruleSet openRuleSetFromXml(string filename, nextGenerationSteps[] defaultGenSteps)
        {
            ruleSet      newRuleSet = null;
            StreamReader ruleReader = null;

            try
            {
                ruleReader = new StreamReader(filename);
                XmlSerializer ruleDeserializer = new XmlSerializer(typeof(ruleSet));
                newRuleSet = (ruleSet)ruleDeserializer.Deserialize(ruleReader);
                SearchIO.output(Path.GetFileName(filename) + " successfully loaded.");
                newRuleSet.rulesDir = Path.GetDirectoryName(filename) + "\\";
                newRuleSet.loadRulesFromFileNames();
                newRuleSet.initializeFileWatcher(newRuleSet.rulesDir);
                if (newRuleSet.name == null)
                {
                    newRuleSet.name = Path.GetFileName(filename).TrimEnd(new char[] { '.', 'x',
                                                                                      'm', 'l' });
                }

                for (int i = 0; i != 5; i++)
                {
                    if (newRuleSet.nextGenerationStep[i] == nextGenerationSteps.Unspecified)
                    {
                        newRuleSet.nextGenerationStep[i] = defaultGenSteps[i];
                    }
                }
            }
            catch (Exception ioe)
            {
                MessageBox.Show(ioe.ToString(), "XML Serialization Error", MessageBoxButtons.OK,
                                MessageBoxIcon.Information);
            }
            finally
            {
                if (ruleReader != null)
                {
                    ruleReader.Close();
                }
            }

            return(newRuleSet);
        }
コード例 #7
0
        /// <summary>
        ///   Loads and compiles the source files.
        /// </summary>
        /// <param name = "rulesets">The rulesets.</param>
        /// <param name = "recompileRules">if set to <c>true</c> [recompile rules].</param>
        /// <param name = "compiledparamRules">The compiledparam rules.</param>
        /// <param name = "execDir">The exec dir.</param>
        public static void loadAndCompileSourceFiles(ruleSet[] rulesets, Boolean recompileRules,
                                                     string compiledparamRules, string execDir)
        {
#if NETSTANDARD2_0
            throw new NotImplementedException("There is currently no way to compile parametric rules in this version of GraphSynth.");
#else
            if (rulesets.GetLength(0) == 0)
            {
                return;
            }
            Assembly assem          = null;
            var      allSourceFiles = new List <string>();
            var      rulesDirectory = rulesets[0].rulesDir;

            if (!recompileRules && (compiledFunctionsAlreadyLoaded(rulesets)))
            {
                return;
            }
            if (recompileRules && FindSourceFiles(rulesets, allSourceFiles, rulesDirectory))
            {
                if (allSourceFiles.Count == 0)
                {
                    SearchIO.output("No additional code files to compile.", 4);
                }
                else
                {
                    CompilerResults cr;
                    if (CompileSourceFiles(rulesets, allSourceFiles, out cr,
                                           rulesDirectory, execDir, compiledparamRules))
                    {
                        assem = cr.CompiledAssembly;
                    }
                }
            }
            var filenames = new string[] { };
            if (assem == null)
            {
                /* load .dll since compilation crashed */
                filenames = Directory.GetFiles(rulesDirectory, "*" + compiledparamRules + "*");
                if (filenames.GetLength(0) > 1)
                {
                    SearchIO.MessageBoxShow("More than one compiled library (*.dll) similar to "
                                            + compiledparamRules + "in" + rulesDirectory);
                }
                if (filenames.GetLength(0) == 0)
                {
                    SearchIO.MessageBoxShow("Compiled library: " + compiledparamRules + " not found in\n"
                                            + rulesDirectory + ".\n Attempting to recompile.");
                    CompilerResults cr;
                    if (CompileSourceFiles(rulesets, allSourceFiles, out cr,
                                           rulesDirectory, execDir, compiledparamRules))
                    {
                        assem = cr.CompiledAssembly;
                    }
                }
                else
                {
                    assem = Assembly.LoadFrom(filenames[0]);
                }
            }
            try
            {
                if (assem != null)
                {
                    var compiledFunctions = assem.CreateInstance("GraphSynth.ParamRules.ParamRules");
                    foreach (var rule in rulesets.SelectMany(set => set.rules))
                    {
                        rule.DLLofFunctions = compiledFunctions;
                        rule.recognizeFuncs.Clear();
                        foreach (var functionName in rule.recognizeFunctions)
                        {
                            var func = compiledFunctions.GetType().GetMethod(functionName);
                            if (func != null)
                            {
                                rule.recognizeFuncs.Add(func);
                            }
                            else
                            {
                                SearchIO.MessageBoxShow("Unable to locate function, " + functionName + ", in assembly, " + filenames[0] + ".");
                            }
                        }
                        rule.applyFuncs.Clear();
                        foreach (var functionName in rule.applyFunctions)
                        {
                            var func = compiledFunctions.GetType().GetMethod(functionName);
                            if (func != null)
                            {
                                rule.applyFuncs.Add(func);
                            }
                            else
                            {
                                SearchIO.MessageBoxShow("Unable to locate function, " + functionName + ", in assembly, " + filenames[0] + ".");
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                SearchIO.MessageBoxShow("Compilation Error :" + ErrorLogger.MakeErrorString(e, false),
                                        "Error Compiling Additional Rule Functions", "Error");
            }
#endif
        }