Exemple #1
0
        public override string CompileScript(string ScriptCode, Template TemplateObj, bool RunScript)
        {
            if (RecordedTests.Count == 0)
            {
                return(Properties.Resources.NoTestsToRun);
            }

            if (!Template.AllFilesExistInList(TemplateObj.IncludedFiles))
            {
                frmLocateResource frm = new frmLocateResource();
                frm.ShowResourceList(TemplateObj, FunctionAssemblies, true);

                // make sure all items can be found
                if (!Template.AllFilesExistInList(TemplateObj.IncludedFiles))
                {
                    return(Properties.Resources.NecessaryCodeFilesCouldNotBeFound);
                }
            }

            if (!File.Exists(TemplateObj.StartupApplication))
            {
                frmLocateResource frm = new frmLocateResource();
                if (TemplateObj.StartupApplication.Trim() == "")
                {
                    TemplateObj.StartupApplication = @"c:\Perl\bin\perl.exe";
                }
                frm.ShowResourceList(TemplateObj, FunctionAssemblies, true);
            }

            if (!settings.CompilePath.EndsWith(@"\"))
            {
                settings.CompilePath = Path.GetDirectoryName(settings.CompilePath) + "\\";
            }

            if (!Directory.Exists(settings.CompilePath))
            {
                try
                {
                    Directory.CreateDirectory(settings.CompilePath);
                }
                catch (Exception ex)
                {
                    return(string.Format(Properties.Resources.CompilePathCouldNotBeCreated, settings.CompilePath));
                }
            }

            // just save it to the compilation directory
            string Filename = System.IO.Path.ChangeExtension(ExecutableFilename, ".pl");

            SaveScript(Filename, TemplateObj);
            string runoutput = RunScriptOutput(TemplateObj.StartupApplication.Trim(), Filename.Trim());

            return(runoutput);
        }
Exemple #2
0
        private void dgvResources_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == 3)
            {
                openFileDialog1.FileName = ItemList[e.RowIndex].Filename;
                openFileDialog1.Title    = string.Format("Find {0}", System.IO.Path.GetFileName(ItemList[e.RowIndex].Filename));
                if (openFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    if (!File.Exists(openFileDialog1.FileName))
                    {
                        return;
                    }

                    // change the information
                    switch (ItemList[e.RowIndex].Source)
                    {
                    case "Assembly": CurrentTemplate.ModifyAssemblyPath(ItemList[e.RowIndex].Filename, openFileDialog1.FileName); break;

                    case "Includes": CurrentTemplate.ModifyIncludePath(ItemList[e.RowIndex].Filename, openFileDialog1.FileName); break;

                    case "Functions": ModifyFunctionAssemblyPath(ItemList[e.RowIndex].Filename, openFileDialog1.FileName); break;

                    case "Startup": CurrentTemplate.ModifyStartupApplication(openFileDialog1.FileName); break;
                    }

                    dgvResources.Rows[e.RowIndex].Cells[2].Value = openFileDialog1.FileName;
                    ItemList[e.RowIndex].Filename = openFileDialog1.FileName;
                    dgvResources.Rows[e.RowIndex].Cells[0].Value = imageList1.Images[1];
                }

                StringCollection scFiles = new StringCollection();
                for (int i = 0; i < ItemList.Count; i++)
                {
                    scFiles.Add(ItemList[i].Filename);
                }
                if (Template.AllFilesExistInList(scFiles) && OnlyNotFound)
                {
                    this.Close();
                }
            }
        }
Exemple #3
0
        public virtual string CompileScript(string ScriptCode, Template TemplateObj, bool RunScript)
        {
            if (RecordedTests.Count == 0)
            {
                return(Properties.Resources.NoTestsToCompile);
            }

            if (!TemplateObj.CanCompile)
            {
                return(Properties.Resources.TargetTemplateIsSetNotToCompile);
            }

            if (!Template.AllFilesExistInList(TemplateObj.ReferencedAssemblies) || !Template.AllFilesExistInList(TemplateObj.IncludedFiles))
            {
                frmLocateResource frm = new frmLocateResource();
                frm.ShowResourceList(TemplateObj, FunctionAssemblies, true);

                // make sure all items can be found
                if (!Template.AllFilesExistInList(TemplateObj.ReferencedAssemblies) || !Template.AllFilesExistInList(TemplateObj.IncludedFiles))
                {
                    return(Properties.Resources.NecessaryCodeFilesCouldNotBeFound);
                }
            }

            if (!settings.CompilePath.EndsWith(@"\"))
            {
                settings.CompilePath = Path.GetDirectoryName(settings.CompilePath) + "\\";
            }

            if (!Directory.Exists(settings.CompilePath))
            {
                try
                {
                    Directory.CreateDirectory(settings.CompilePath);
                }
                catch (Exception ex)
                {
                    return(string.Format(Properties.Resources.CompilePathCouldNotBeCreated, settings.CompilePath));
                }
            }

            StringBuilder sbErrors = new StringBuilder();

            CompilerParameters cps = new CompilerParameters();

            cps.OutputAssembly          = ExecutableFilename;
            cps.GenerateExecutable      = true;
            cps.IncludeDebugInformation = true;

            if (!TemplateObj.CanRun)
            {
                cps.OutputAssembly     = System.IO.Path.ChangeExtension(cps.OutputAssembly, ".dll");
                cps.GenerateExecutable = false;
            }

            StringCollection scAssemblies = TemplateObj.GetAssemblyList();

            for (int i = 0; i < scAssemblies.Count; i++)
            {
                cps.ReferencedAssemblies.Add(scAssemblies[i]);
            }

            // add assemblies from function explorer
            for (int i = 0; i < FunctionAssemblies.Count; i++)
            {
                if (!AssemblyAlreadyInList(FunctionAssemblies[i], cps.ReferencedAssemblies))
                {
                    cps.ReferencedAssemblies.Add(FunctionAssemblies[i]);
                }
            }

            string[] sourcefiles = new string[TemplateObj.IncludedFiles.Count + 1];
            for (int i = 0; i < TemplateObj.IncludedFiles.Count; i++)
            {
                if (TemplateObj.IncludedFiles[i].Trim() == "")
                {
                    continue;
                }
                sourcefiles[i] = System.IO.File.ReadAllText(TemplateObj.IncludedFiles[i]);
            }

            if (ScriptCode.Trim() != "")
            {
                NameValueCollection nvTest = new NameValueCollection();
                nvTest.Add("CurrentTest", ScriptCode);
                sourcefiles[sourcefiles.Length - 1] = TemplateObj.PrepareScript(nvTest);
            }
            else
            {
                sourcefiles[sourcefiles.Length - 1] = TemplateObj.PrepareScript(this.RecordedTests);
            }


            // Compile the source code
            CompilerResults cr = null;

            try
            {
                if (TemplateObj.CodeLanguage == AppSettings.CodeLanguages.CSharp)
                {
                    Microsoft.CSharp.CSharpCodeProvider codeprovider = new Microsoft.CSharp.CSharpCodeProvider();
                    cr = codeprovider.CompileAssemblyFromSource(cps, sourcefiles);
                }
                else if (TemplateObj.CodeLanguage == AppSettings.CodeLanguages.VBNet)
                {
                    Microsoft.VisualBasic.VBCodeProvider codeprovider = new Microsoft.VisualBasic.VBCodeProvider();
                    cr = codeprovider.CompileAssemblyFromSource(cps, sourcefiles);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(string.Format(Properties.Resources.CompilerError, ex.Message));
            }

            // Check for errors
            if (cr.Errors.Count > 0)
            {
                // Has errors so display them
                foreach (CompilerError ce in cr.Errors)
                {
                    sbErrors.AppendFormat(Properties.Resources.ErrorLineListing + System.Environment.NewLine, ce.ErrorNumber, ce.Line, ce.Column, ce.ErrorText, (ce.IsWarning) ? "Warning" : "Error");
                }
                System.Diagnostics.Debug.WriteLine(sbErrors.ToString());
                return(sbErrors.ToString());
            }

            // copy imported assemblies (not in .NET main)
            string NetPath = RuntimeEnvironment.GetRuntimeDirectory();

            for (int i = 0; i < scAssemblies.Count; i++)
            {
                if (scAssemblies[i] == null || scAssemblies[i].Trim() == "")
                {
                    continue;
                }
                if (!File.Exists(scAssemblies[i]))
                {
                    return(string.Format(Properties.Resources.CompileSuccessfulButCantFind, scAssemblies[i]));
                }

                if (Path.GetDirectoryName(NetPath) != Path.GetDirectoryName(scAssemblies[i]))
                {
                    System.IO.File.Copy(scAssemblies[i], Path.Combine(settings.CompilePath, Path.GetFileName(scAssemblies[i])), true);
                }
            }

            if (RunScript && TemplateObj.CanRun)
            {
                string scriptrun = RunScriptOutput(TemplateObj.StartupApplication, cps.OutputAssembly);
                if (scriptrun != "")
                {
                    return(scriptrun);
                }
            }

            return("");
        }