コード例 #1
0
ファイル: Templates.cs プロジェクト: pusp/o2platform
        // create loads the list of templates for language
        public Templates(string path)
        {
            if (!System.IO.Directory.Exists(path))
            {
                return;
            }

            string[] arrFiles = System.IO.Directory.GetFiles(path, "*.trt");

            for (int i = 0; i < arrFiles.Length; i++)
            {
                Template temp = new Template(arrFiles[i]);
                TemplateList.Add(temp);
            }
        }
コード例 #2
0
ファイル: frmLocateResource.cs プロジェクト: pusp/o2platform
        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();
        }
コード例 #3
0
ファイル: WatiNPHP.cs プロジェクト: pusp/o2platform
        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:\PHP\php.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, ".php");
            SaveScript(Filename, TemplateObj);
            string runoutput = RunScriptOutput(TemplateObj.StartupApplication.Trim(), Filename.Trim());
            return runoutput;
        }
コード例 #4
0
ファイル: WatinScript.cs プロジェクト: pusp/o2platform
        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 "";
        }
コード例 #5
0
ファイル: WatinScript.cs プロジェクト: pusp/o2platform
 public virtual string CompileScript(Template TemplateObj, bool RunScript)
 {
     return CompileScript("", TemplateObj, RunScript);
 }
コード例 #6
0
ファイル: WatinScript.cs プロジェクト: pusp/o2platform
        /// <summary>
        /// Saves the test script using the template file indicated
        /// </summary>
        /// <param name="Filename">Filename to save to</param>
        /// <param name="TemplateFile">Template to apply</param>
        public void SaveScript(string Filename, Template TemplateFile)
        {
            try
            {
                if (System.IO.File.Exists(Filename))
                {
                    System.IO.File.Delete(Filename);
                }

                string code = TemplateFile.PrepareScript(RecordedTests);
                System.IO.File.WriteAllText(Filename, code);
                UnsavedScript = false;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, Properties.Resources.SaveErrorNotSaved, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }