Ejemplo n.º 1
0
        public void ShowResourceList(Template TemplateFile, StringCollection FunctionAssemblies, bool OnlyIfNotFound)
        {
            OnlyNotFound = OnlyIfNotFound;
            if (OnlyIfNotFound)
            {
                lblLocate.Text = Properties.Resources.SomeItemsCannotBeFound;
            }
            else
            {
                lblLocate.Text = Properties.Resources.ListOfResources;
            }

            CurrentTemplate = TemplateFile;
            this.FunctionAssemblies = FunctionAssemblies;

            StringCollection files = TemplateFile.GetAssemblyList();
            AddFileCollection("Assembly", files, OnlyIfNotFound);
            AddFileCollection("Includes", TemplateFile.IncludedFiles, OnlyIfNotFound);
            AddFileCollection("Functions", FunctionAssemblies, OnlyIfNotFound);
            AddFile("Startup", TemplateFile.StartupApplication);

            ShowDialog();
        }
Ejemplo n.º 2
0
        public void ShowResourceList(Template TemplateFile, StringCollection FunctionAssemblies, bool OnlyIfNotFound)
        {
            OnlyNotFound = OnlyIfNotFound;
            if (OnlyIfNotFound)
            {
                lblLocate.Text = Properties.Resources.SomeItemsCannotBeFound;
            }
            else
            {
                lblLocate.Text = Properties.Resources.ListOfResources;
            }

            CurrentTemplate         = TemplateFile;
            this.FunctionAssemblies = FunctionAssemblies;

            StringCollection files = TemplateFile.GetAssemblyList();

            AddFileCollection("Assembly", files, OnlyIfNotFound);
            AddFileCollection("Includes", TemplateFile.IncludedFiles, OnlyIfNotFound);
            AddFileCollection("Functions", FunctionAssemblies, OnlyIfNotFound);
            AddFile("Startup", TemplateFile.StartupApplication);

            ShowDialog();
        }
Ejemplo n.º 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("");
        }
Ejemplo n.º 4
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 "";
        }