public static bool Regenerate(string inputPath, string outputPath, Guid guid, string name, string description) { // load existing component IComponentSearchMethod searchMethod = null; ComponentLoader componentLoader = new ComponentLoader { SearchMethod = searchMethod }; Component comp = componentLoader.LoadComponent(inputPath); // instantiate PluginGenerator PluginGenerator generator = new PluginGenerator { AssemblyCompany = comp.Author, AssemblyDescription = comp.Description, AssemblyVersion = comp.Version, DrawingName = string.IsNullOrEmpty(name) ? comp.Name : name, DrawingDescription = string.IsNullOrEmpty(description) ? comp.Description : description, Guid = guid != Guid.Empty ? guid : Guid.NewGuid(), DrawingCode = comp.SourceCode }; if (comp.HasEmbeddedThumbnail) { // get thumbnail image Bitmap bmp = comp.Thumbnail; // save thumbnail image as bmp string bitmapPath = Path.ChangeExtension(Path.GetTempFileName(), "bmp"); bmp.Save(bitmapPath, System.Drawing.Imaging.ImageFormat.Bmp); // set thumbnail path in generator generator.ThumbnailPath = bitmapPath; } generator.OutputDirectory = Path.GetTempPath(); CompilerResults res = generator.Build(); if (res.Errors.Count > 0) { return(false); } // copy compiler output to new path File.Copy( res.PathToAssembly , outputPath , true /*overwrite*/ ); return(true); }
static void Main(string[] args) { try { // sourceCode1 { string sourceCodePath = @"K:\GitHub\PLMPackLib\Pic.Plugin.PluginGenerator.Test.Console\sourceCode1.cs"; string outputPath = @"K:\GitHub\PLMPackLib\PicPlugins\"; string thumbnailPath = string.Empty; if (!File.Exists(sourceCodePath)) { System.Console.WriteLine(string.Format("{0} could not be found!", sourceCodePath)); return; } // instantiate plugin generator Pic.Plugin.PluginGenerator pluginGenerator = new Pic.Plugin.PluginGenerator(); // company / author pluginGenerator.AssemblyCompany = "treeDiM"; // description pluginGenerator.AssemblyDescription = "Sample test for plugin generator version 1"; // assembly description pluginGenerator.AssemblyTitle = "Generated plugin 1"; // version pluginGenerator.AssemblyVersion = "1.0.0.0"; // description pluginGenerator.DrawingDescription = "Sample test for plugin generator"; // drawing name pluginGenerator.DrawingName = "SampleTest1"; pluginGenerator.OutputName = "component1.dll"; // read and set source System.IO.StreamReader sr = new System.IO.StreamReader(sourceCodePath, Encoding.ASCII); pluginGenerator.DrawingCode = sr.ReadToEnd(); sr.Close(); pluginGenerator.OutputDirectory = outputPath; // thumbnail file path if (!string.IsNullOrEmpty(thumbnailPath) && File.Exists(thumbnailPath)) { pluginGenerator.ThumbnailPath = thumbnailPath; } System.CodeDom.Compiler.CompilerResults compilerRes = pluginGenerator.Build(); if (compilerRes.Errors.Count != 0) { foreach (System.CodeDom.Compiler.CompilerError error in compilerRes.Errors) { System.Console.WriteLine(error.ToString()); } } else { System.Console.WriteLine("Success!"); } } // sourceCode2 { string sourceCodePath = @"K:\GitHub\PLMPackLib\Pic.Plugin.PluginGenerator.Test.Console\sourceCode2.cs"; string outputPath = @"K:\GitHub\PLMPackLib\PicPlugins\"; string thumbnailPath = string.Empty; if (!File.Exists(sourceCodePath)) { System.Console.WriteLine(string.Format("{0} could not be found!", sourceCodePath)); return; } // instantiate plugin generator Pic.Plugin.PluginGenerator pluginGenerator = new Pic.Plugin.PluginGenerator(); // company / author pluginGenerator.AssemblyCompany = "treeDiM"; // description pluginGenerator.AssemblyDescription = "Sample test for plugin generator"; // assembly description pluginGenerator.AssemblyTitle = "Generated plugin 2"; // version pluginGenerator.AssemblyVersion = "2.0.0.0"; // description pluginGenerator.DrawingDescription = "Sample test for plugin generator version 2"; // drawing name pluginGenerator.DrawingName = "SampleTest2"; // read and set source System.IO.StreamReader sr = new System.IO.StreamReader(sourceCodePath, Encoding.ASCII); pluginGenerator.DrawingCode = sr.ReadToEnd(); sr.Close(); pluginGenerator.OutputDirectory = outputPath; pluginGenerator.OutputName = "component2.dll"; // thumbnail file path if (!string.IsNullOrEmpty(thumbnailPath) && File.Exists(thumbnailPath)) { pluginGenerator.ThumbnailPath = thumbnailPath; } System.CodeDom.Compiler.CompilerResults compilerRes = pluginGenerator.Build(); if (compilerRes.Errors.Count != 0) { foreach (System.CodeDom.Compiler.CompilerError error in compilerRes.Errors) { System.Console.WriteLine(error.ToString()); } } else { System.Console.WriteLine("Success!"); } } } catch (Exception ex) { System.Console.WriteLine("Exception:"); System.Console.WriteLine(ex.ToString()); } }
public static bool Regenerate(string inputPath, string outputPath, Guid guid, string name, string description) { // load existing component Pic.Plugin.IComponentSearchMethod searchMethod = null; ComponentLoader componentLoader = new ComponentLoader(); componentLoader.SearchMethod = searchMethod; Component comp = componentLoader.LoadComponent(inputPath); // instantiate PluginGenerator PluginGenerator generator = new PluginGenerator(); generator.AssemblyCompany = comp.Author; generator.AssemblyDescription = comp.Description; generator.AssemblyVersion = comp.Version; generator.DrawingName = string.IsNullOrEmpty(name) ? comp.Name : name; generator.DrawingDescription = string.IsNullOrEmpty(description) ? comp.Description : description; generator.Guid = guid != Guid.Empty ? guid : Guid.NewGuid(); generator.DrawingCode = comp.SourceCode; if (comp.HasEmbeddedThumbnail) { // get thumbnail image Bitmap bmp = comp.Thumbnail; // save thumbnail image as bmp string bitmapPath = Path.ChangeExtension(Path.GetTempFileName(), "bmp"); bmp.Save(bitmapPath, System.Drawing.Imaging.ImageFormat.Bmp); // set thumbnail path in generator generator.ThumbnailPath = bitmapPath; } generator.OutputDirectory = Path.GetTempPath(); CompilerResults res = generator.Build(); if (res.Errors.Count > 0) return false; // copy compiler output to new path File.Copy( res.PathToAssembly , outputPath , true /*overwrite*/ ); return true; }
static void Main(string[] args) { try { // sourceCode1 { string sourceCodePath = @"K:\GitHub\PLMPackLib\Pic.Plugin.PluginGenerator.Test.Console\sourceCode1.cs"; string outputPath = @"K:\GitHub\PLMPackLib\PicPlugins\"; string thumbnailPath = string.Empty; if (!File.Exists(sourceCodePath)) { System.Console.WriteLine(string.Format("{0} could not be found!", sourceCodePath)); return; } // instantiate plugin generator Pic.Plugin.PluginGenerator pluginGenerator = new Pic.Plugin.PluginGenerator(); // company / author pluginGenerator.AssemblyCompany = "treeDiM"; // description pluginGenerator.AssemblyDescription = "Sample test for plugin generator version 1"; // assembly description pluginGenerator.AssemblyTitle = "Generated plugin 1"; // version pluginGenerator.AssemblyVersion = "1.0.0.0"; // description pluginGenerator.DrawingDescription = "Sample test for plugin generator"; // drawing name pluginGenerator.DrawingName = "SampleTest1"; pluginGenerator.OutputName = "component1.dll"; // read and set source System.IO.StreamReader sr = new System.IO.StreamReader(sourceCodePath, Encoding.ASCII); pluginGenerator.DrawingCode = sr.ReadToEnd(); sr.Close(); pluginGenerator.OutputDirectory = outputPath; // thumbnail file path if (!string.IsNullOrEmpty(thumbnailPath) && File.Exists(thumbnailPath)) pluginGenerator.ThumbnailPath = thumbnailPath; System.CodeDom.Compiler.CompilerResults compilerRes = pluginGenerator.Build(); if (compilerRes.Errors.Count != 0) { foreach (System.CodeDom.Compiler.CompilerError error in compilerRes.Errors) System.Console.WriteLine(error.ToString()); } else System.Console.WriteLine("Success!"); } // sourceCode2 { string sourceCodePath = @"K:\GitHub\PLMPackLib\Pic.Plugin.PluginGenerator.Test.Console\sourceCode2.cs"; string outputPath = @"K:\GitHub\PLMPackLib\PicPlugins\"; string thumbnailPath = string.Empty; if (!File.Exists(sourceCodePath)) { System.Console.WriteLine(string.Format("{0} could not be found!", sourceCodePath)); return; } // instantiate plugin generator Pic.Plugin.PluginGenerator pluginGenerator = new Pic.Plugin.PluginGenerator(); // company / author pluginGenerator.AssemblyCompany = "treeDiM"; // description pluginGenerator.AssemblyDescription = "Sample test for plugin generator"; // assembly description pluginGenerator.AssemblyTitle = "Generated plugin 2"; // version pluginGenerator.AssemblyVersion = "2.0.0.0"; // description pluginGenerator.DrawingDescription = "Sample test for plugin generator version 2"; // drawing name pluginGenerator.DrawingName = "SampleTest2"; // read and set source System.IO.StreamReader sr = new System.IO.StreamReader(sourceCodePath, Encoding.ASCII); pluginGenerator.DrawingCode = sr.ReadToEnd(); sr.Close(); pluginGenerator.OutputDirectory = outputPath; pluginGenerator.OutputName = "component2.dll"; // thumbnail file path if (!string.IsNullOrEmpty(thumbnailPath) && File.Exists(thumbnailPath)) pluginGenerator.ThumbnailPath = thumbnailPath; System.CodeDom.Compiler.CompilerResults compilerRes = pluginGenerator.Build(); if (compilerRes.Errors.Count != 0) { foreach (System.CodeDom.Compiler.CompilerError error in compilerRes.Errors) System.Console.WriteLine(error.ToString()); } else System.Console.WriteLine("Success!"); } } catch (Exception ex) { System.Console.WriteLine("Exception:"); System.Console.WriteLine(ex.ToString()); } }
private void onGenerate(object sender, EventArgs e) { try { // check text boxes content if (!ValidateControlContent()) return; // invalid content // save some control content Registry.SetValue(@"HKEY_CURRENT_USER\Software\TreeDim\PicSharp", "PluginCompany", txtCompany.Text); // instantiate plugin generator and compile PluginGenerator generator = new PluginGenerator(); generator.AssemblyTitle = txtName.Text; generator.AssemblyDescription = txtDescription.Text; generator.AssemblyVersion = PluginVersion; generator.AssemblyCompany = txtCompany.Text; generator.DrawingName = txtName.Text; generator.DrawingDescription = txtDescription.Text; generator.Guid = new Guid(txtGuid.Text); generator.DrawingCode = codeEditorCtrl.Text; if (chbThumbnail.Checked) generator.ThumbnailPath = fileSelectCtrl.FileName; generator.OutputDirectory = Path.GetTempPath(); CompilerResults res = generator.Build(); // show any errors in list view control lvwErrors.Items.Clear(); foreach (CompilerError err in res.Errors) { ListViewItem lvi = new ListViewItem(err.ErrorText); lvi.SubItems.Add((err.Line - generator.LineOffset).ToString()); lvwErrors.Items.Add(lvi); } // send event if no errors were found if (res.Errors.Count == 0) { using (PluginViewer frmPluginViewer = new PluginViewer(_componentSearchMethod, res.PathToAssembly)) { if (frmPluginViewer.ShowDialog() == DialogResult.OK) { try { File.Copy( res.PathToAssembly , OutputPath , true /*overwrite*/ ); } catch (System.IO.IOException /*ex*/) { MessageBox.Show(string.Format("File {0} appears to be locked. Please, provide a different path for copy", OutputPath), Application.ProductName, MessageBoxButtons.OK); OpenFileDialog fd = new OpenFileDialog(); fd.FileName = OutputPath; fd.Filter = "Component (*.dll)|*.dll|All Files|*.*"; fd.FilterIndex = 0; if (DialogResult.OK == fd.ShowDialog()) File.Copy( res.PathToAssembly , fd.FileName , true /*overwrite*/ ); else return; } // emit event if an event handler was defined if (null != PluginValidated) PluginValidated(this, new GeneratorCtrlEventArgs(OutputPath)); } } } } catch (Exception ex) { MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Stop); } }