private void ReplaceTags(List <DanuComponent> chosenOnes) { foreach (DanuComponent comp in chosenOnes) { foreach (DanuComponent compChild in chosenOnes) { foreach (DanuInterfaceObject io in comp.Interfaces) { foreach (DanuSocket so in compChild.Sockets) { if (io.PossibleSockets.Contains(so.Parent)) { string newCode = FreyrCSharpCodeGenerator.ReplaceInterface(comp.Name + "/" + comp.Name, compChild.Name, io.Name); File.Delete("./Repository/" + comp.Name + "/" + comp.Name + ".cs"); TextWriter writer = new StreamWriter("./Repository/" + comp.Name + "/" + comp.Name + ".cs"); writer.Write(newCode); writer.Close(); } } } } } }
/// <summary> /// Button Compile interaction logic. /// </summary> private void buttonCompile_Click(object sender, RoutedEventArgs i) { try { // String pathFull = @"C:\Users\COC-DELL-20\Desktop\head\__output\Coc.Apps.PlugSpl\Projects\plets\Repository"; string source = "./Source/"; string target = "./Repository/"; //string oldEnvDir = Environment.CurrentDirectory; if (!File.Exists(textBoxCompilerPath.Text)) { MessageBox.Show("Compiler not found. Invalid property value or file do not exists."); return; } String subDir = @"Source"; // String pathFull = System.IO.Path.GetFullPath(repository); Assembly caminho = Assembly.GetExecutingAssembly(); String s = caminho.Location; String pathFull; pathFull = s.Replace("ProductInstantiator.dll", "Source"); //pathFull = configuratorPath.Substring(0, configuratorPath.LastIndexOf("\\"))+ "\\"+repository; DirectoryInfo pasta = new DirectoryInfo(pathFull); List <String> list = ListaDiretorios(pasta, pathFull, subDir); //XmlDocument document = new XmlDocument(); //document = Generator.ToXmi(list); //document.Save(pathFull); /* * FileInfo cm = new FileInfo(textBoxRed.Text); * FileInfo pc = new FileInfo(textBoxGreen.Text); * if (!cm.DirectoryName.Equals(pc.DirectoryName)) * { * MessageBox.Show("Component metadata and product configuration must be in the same directory."); * return; * } */ //change directory pro project path /* * string oldlocation = Environment.CurrentDirectory; * string lowername = oldlocation + @"\Projects\" + textBoxRed.Text.Split('\\').Last().Split('.').First(); * Environment.CurrentDirectory = lowername; */ //set up compiler Process p = new Process(); p.StartInfo.FileName = textBoxCompilerPath.Text; if (checkBoxOptmize.IsChecked == true) { p.StartInfo.Arguments += " /optmize"; } p.StartInfo.Arguments = target + "PlugSPLCompileProject.csproj"; textBoxLog.Text += Environment.NewLine + "Trying to call compiler with command line \"" + p.StartInfo.FileName + " " + p.StartInfo.Arguments + "\" at " + DateTime.Now.ToShortTimeString(); List <DanuComponent> chosenOnes = null; try { //Gera CSPROJ chosenOnes = FreyrCSharpCodeGenerator.GenerateProductProject(danu, configuratorPath, list); textBoxLog.Text += Environment.NewLine + "[" + DateTime.Now.ToShortTimeString() + "] Project file generated successfully."; } catch (Exception e) { textBoxLog.Text += Environment.NewLine + "[" + DateTime.Now.ToShortTimeString() + "] Project file NOT generated."; textBoxLog.Text += Environment.NewLine + e.ToString(); } try { //Copy files Utils.CopyDirectory(source, target); textBoxLog.Text += Environment.NewLine + "[" + DateTime.Now.ToShortTimeString() + "] Source code copyied to work directory."; } catch (Exception ee) { textBoxLog.Text += Environment.NewLine + "[" + DateTime.Now.ToShortTimeString() + "] Source code NOT copyied to work directory."; textBoxLog.Text += Environment.NewLine + ee.ToString(); } //Replace Tags try { ReplaceTags(chosenOnes); textBoxLog.Text += Environment.NewLine + "[" + DateTime.Now.ToShortTimeString() + "] Tags replaced successfully."; } catch (Exception eee) { textBoxLog.Text += Environment.NewLine + "[" + DateTime.Now.ToShortTimeString() + "] Tags NOT replaced."; textBoxLog.Text += Environment.NewLine + eee.ToString(); } //call compiler try { p.StartInfo.UseShellExecute = false; p.StartInfo.ErrorDialog = false; p.StartInfo.RedirectStandardError = true; p.StartInfo.RedirectStandardInput = true; p.StartInfo.RedirectStandardOutput = true; p.Start(); textBoxLog.Text += p.StandardOutput.ReadToEnd(); textBoxLog.Text += p.StandardError.ReadToEnd(); } catch (Exception eeee) { textBoxLog.Text += Environment.NewLine + eeee.ToString(); } finally { p.WaitForExit(); } //launch application if (checkBoxLaunch.IsChecked == true && File.Exists(source + "product.exe")) { p.StartInfo.FileName += "product.exe"; p.StartInfo.Arguments = ""; try { p.Start(); } catch (Exception eeeee) { textBoxLog.Text += Environment.NewLine + eeeee.ToString(); } } //return directory to original value // Environment.CurrentDirectory = oldlocation; } catch (Exception ex) { textBoxLog.Text += Environment.NewLine + ex.ToString(); } }