/// <summary> /// Compile DMs. /// </summary> /// <param name="files">source files.</param> /// <param name="env">Application Environment</param> public static void Compile(List<string> files, ApplicationEnvironment env) { if (files == null || files.Count == 0) return; DMCompiler cm = new DMCompiler(); string errmes = ""; string finished = ""; try { env.DataManager.CurrentProject.UnloadSimulator(); } catch (Exception e) { env.Console.WriteLine(e.ToString()); env.Console.Flush(); Util.ShowErrorDialog(e.Message); } foreach (string filename in files) { cm.SourceFile = filename; string outdir = Path.Combine(Path.GetDirectoryName(filename), Constants.TmpDirName); if (!Directory.Exists(outdir)) Directory.CreateDirectory(outdir); string dmname = Path.GetFileNameWithoutExtension(filename); string outfile = Path.Combine(outdir, dmname + Constants.FileExtDM); string dmfile = Path.Combine(Path.GetDirectoryName(filename), dmname + Constants.FileExtDM); cm.OutputFile = outfile; cm.DMFile = dmfile; try { cm.Compile(env, true); finished += " " + dmname; } catch (Exception e) { errmes += e.Message + "\n"; env.Console.WriteLine(e.ToString()); env.Console.Flush(); } } env.DMDescriptorKeeper.Load(env.DataManager.CurrentProject.GetDMDirs()); env.DataManager.CurrentProject.ReloadSimulator(); // Error if (!string.IsNullOrEmpty(errmes)) { Util.ShowErrorDialog(errmes); } // Finished if (!string.IsNullOrEmpty(finished)) { string msg = string.Format(MessageResources.InfoCompile, Path.GetFileNameWithoutExtension(finished)); Util.ShowNoticeDialog(msg); } }
/// <summary> /// Comile the source of DM. /// </summary> /// <param name="fileName">the file name of source.</param> /// <param name="env">Application Environment object.</param> public static void Compile(string fileName, ApplicationEnvironment env) { if (fileName == null || !File.Exists(fileName)) return; DMCompiler cm = new DMCompiler(); cm.SourceFile = fileName; string outdir = Path.Combine(Path.GetDirectoryName(fileName), Constants.TmpDirName); if (!Directory.Exists(outdir)) Directory.CreateDirectory(outdir); string outfile = Path.Combine(outdir, Path.GetFileNameWithoutExtension(fileName) + Constants.FileExtDM); string dmfile = Path.Combine(Path.GetDirectoryName(fileName), Path.GetFileNameWithoutExtension(fileName) + Constants.FileExtDM); cm.OutputFile = outfile; cm.DMFile = dmfile; try { env.DataManager.CurrentProject.UnloadSimulator(); cm.Compile(env, true); string msg = string.Format(MessageResources.InfoCompile, Path.GetFileNameWithoutExtension(dmfile)); env.DMDescriptorKeeper.Load(env.DataManager.CurrentProject.GetDMDirs()); env.DataManager.CurrentProject.ReloadSimulator(); Util.ShowNoticeDialog(msg); } catch (Exception e) { env.Console.WriteLine(e.ToString()); env.Console.Flush(); Util.ShowErrorDialog(e.Message); } }