Esempio n. 1
0
        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);
            }
        }
Esempio n. 2
0
        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);
            }
        }