public void openSourceCodeEditor()
        {
            var sourceCodeEditor  = O2Gui.open <Panel>("Source Code Editor", 600, 400).add_SourceCodeEditor();
            var defaultSourceCode = CompileEngine.findScriptOnLocalScriptFolder("Hello_O2_World.cs").fileContents();

            sourceCodeEditor.open(defaultSourceCode.saveWithExtension(".cs"));
        }
Ejemplo n.º 2
0
        public void Main_O2_Gui_h2()
        {
            //CompileEngine.clearLocalScriptFileMappings();

            var scriptName = "Main O2 Gui.h2"; // this is the script used in ascx_Execute_Scripts.NEW_GUI_SCRIPT
            var file       = scriptName.local();
            var h2Code     = file.h2_SourceCode();


            //compile using internal methods

            var csharpCode = new CSharp_FastCompiler().createCSharpCodeWith_Class_Method_WithMethodText(h2Code);

            assert_Not_Null(scriptName);
            assert_Not_Null(file);
            assert_Not_Null(h2Code);
            assert_Not_Null(csharpCode);

            csharpCode.assert_Contains("public class", "DynamicType", "{", "}")
            .assert_Contains("using System;", "System.Linq;")
            .assert_Contains("FluentSharp.REPL.Utils");

            var compileEngine = new CompileEngine();
            var assembly      = compileEngine.compileSourceCode(csharpCode);

            assert_Is_Null(compileEngine.sbErrorMessage);
            assert_Not_Null(assembly);

            //check that we can also compile using the main wrapper methods
            assert_Not_Null(file.compile_H2Script());
        }
Ejemplo n.º 3
0
        public static List <String> compileAllFilesIndividually(List <String> filesToCompile, O2Thread.FuncVoidT1 <string> currentTask, O2Thread.FuncVoidT1 <int> numberOfStepsToPerform, O2Thread.FuncVoid onStepEvent)
        {
            currentTask("Compiling all rules individualy (one file at the time)");
            numberOfStepsToPerform(filesToCompile.Count);
            var compileEngine = new CompileEngine();

            PublicDI.log.info("Compiling All XRules source code files ONE at the time");
            var results = new List <String>();

            foreach (var fileToCompile in filesToCompile)
            {
                var assembly = compileEngine.compileSourceFile(fileToCompile);

                if (assembly != null)
                {
                    results.Add(assembly.Location);
                }
                else
                {
                    PublicDI.log.error("In XRules_Execution.compileAllFilesIndividually, could not compile file: {0}", fileToCompile);
                }
                onStepEvent();
            }
            return(results);
        }
 public static void mapUnitTestToXRules(string assemblyWithUnitTest, TreeView tvTarget_XLoadedRules)
 {
     if (Files.IsExtension(assemblyWithUnitTest, ".cs"))
     {
         var compiledAssembly = new CompileEngine().compileSourceFile(assemblyWithUnitTest);
         if (compiledAssembly == null)
         {
             DI.log.error("aborting mapUnitTestToXRules since could not compile CSharp file: {0}",
                          assemblyWithUnitTest);
         }
         else
         {
             DI.log.info("Mapping dynamically compiled CSharp file: {0}", compiledAssembly.Location);
             mapAssembliesIntoXRules(new List <string>()
             {
                 compiledAssembly.Location
             }, tvTarget_XLoadedRules);
         }
     }
     else
     {
         mapAssembliesIntoXRules(new List <string>()
         {
             assemblyWithUnitTest
         }, tvTarget_XLoadedRules);
     }
 }
Ejemplo n.º 5
0
        public void SetupFixture_SetUp()
        {
            CompileEngine.clearCompilationCache();              // ensure the compilatation cache is clean

            var o2PlatformScripts = new O2_Platform_Scripts();
            var scriptsFolder     = o2PlatformScripts.ScriptsFolder();

            if ("".offline())                    // we can't do the sync when offline
            {
                return;
            }

            Assert.IsTrue(o2PlatformScripts.SetUp());  // call SetUp which will trigger the git clone (if needed)

            scriptsFolder.assert_Folder_Exists()
            .assert_Is_True(path => path.isGitRepository());

            //check that expected O2.Platform.Scripts files are in there:
            var nGit      = o2PlatformScripts.nGit;
            var fullPath1 = nGit.file_FullPath("README.md");
            var fullPath2 = nGit.file_FullPath(@"_DataFiles\_Images\O2_Logo.gif");

            Assert.IsTrue(nGit.pull());
            Assert.IsTrue(fullPath1.fileExists());
            Assert.IsTrue(fullPath2.fileExists());
        }
Ejemplo n.º 6
0
        public static void downloadO2Scripts(Action <string> statusMessage)
        {
            statusMessage("Downloading zip with latest rules");
            var url     = "https://github.com/o2platform/O2.Platform.Scripts/zipball/master";
            var zipFile = url.download();

            statusMessage("Unziping files into temp folder");
            var targetFolder = @"_Downloaded_O2Scripts".tempDir(false).fullPath();

            if (targetFolder.size() > 120)
            {
                "[downloadO2Scripts] targetFolder path was more than 120 chars: {0}".error(targetFolder);
                targetFolder = System.IO.Path.GetTempPath().pathCombine(targetFolder.fileName());
                "[downloadO2Scripts] set targetFolder to: {0}".info(targetFolder);
            }
            zipFile.unzip_File(targetFolder);

            statusMessage("Copying files into scripts folder");
            var baseDir       = targetFolder.folders().first();
            var scriptsFolder = PublicDI.config.LocalScriptsFolder;
            var filesCopied   = 0;

            foreach (var file in baseDir.files(true))
            {
                var targetFile = file.replace(baseDir, scriptsFolder);
                targetFile.parentFolder().createDir();
                file.file_Copy(targetFile);
                filesCopied++;
            }
            "copied: {0}".info(filesCopied);
            CompileEngine.clearLocalScriptFileMappings();
            statusMessage("Done");
        }
        static void Main(string[] args)
        {
            if (Control.ModifierKeys == Keys.Shift)
            {
                showLogViewer().parentForm().width(1000).height(400);
            }
            var firstScript = "O2_1st_Script.cs";

            Console.WriteLine("Welcome to the O2 Platform v2.0");

            "Current AppDomain: {0}".info(AppDomain.CurrentDomain.BaseDirectory);

            CompileEngine.lsGACExtraReferencesToAdd.Clear();
            var assembly = new CompileEngine().compileSourceFile(firstScript);

            if (assembly.notNull())
            {
                Console.WriteLine("Executing script {0} from location {1}".info(firstScript, assembly.Location));
                if (assembly.methods().size() > 0)
                {
                    assembly.methods()[0].invoke();
                    Console.WriteLine("Invocation complete");
                }
                else
                {
                    Console.WriteLine("Error: there were no methods in compiled assembly");
                }
            }
            else
            {
                Console.WriteLine("Error: could not find, compile or execute first script ({0})".format(firstScript));
            }
        }
        public void compileTestFileAndCheckIfAllIsStillThere()
        {
            if (false == compiledAssemblySettings.dontCompileIfFileExists ||
                false == File.Exists(compiledAssemblySettings.pathToCreatedAssemblyFile))
            {
                Assembly compiledExeFile = new CompileEngine().compileSourceCode(compiledAssemblySettings.sourceCode,
                                                                                 compiledAssemblySettings.exeMainClass,
                                                                                 compiledAssemblySettings.outputAssemblyName);
                // copy all dependentDlls to current directly (so that we can load this exe)

                Assert.That(compiledExeFile != null, "in MockObjects_CompiledExe.compileTestFileAndCheckIfAllIsStillThere Compiled Assembly was null");
                CecilAssemblyDependencies.copyAssemblyDependenciesToAssemblyDirectory(compiledExeFile.Location,
                                                                                      new List <string>
                {
                    DI.config.
                    hardCodedO2LocalBuildDir
                });

                Assert.That(compiledExeFile != null, "Compilation failed");
                Assert.That(File.Exists(compiledExeFile.Location), "Could not find assembly on disk!");
                DI.log.info("test Assembly file compiled into: {0}", compiledExeFile);
                compiledAssemblySettings.pathToCreatedAssemblyFile = compiledExeFile.Location;
                Assert.That(compiledAssemblySettings.checkIfAssemblyWasCreatedOK(), "Created assembly was not OK");
            }
        }
Ejemplo n.º 9
0
 public void loadDefaultSetOfFilesToConvert()
 {
     dotNetAssembliesToConvert.clearMappings();
     dotNetAssembliesToConvert.setExtensionsToShow(".dll .exe");
     dotNetAssembliesToConvert.addFiles(CompileEngine.getListOfO2AssembliesInExecutionDir());
     dotNetAssembliesToConvert.addFiles(AppDomainUtils.getDllsInCurrentAppDomain_FullPath());
     runOnLoad = false;
 }
        //public ascx_ScriptsFolder scriptsFolder;

/*        public void addCurrentAppDomainsDllsAsReferences()
 *      {
 *          foreach(var assembly in AppDomain.CurrentDomain.GetAssemblies())
 *          {
 *              var assemblyName = Path.GetFileName(assembly.Location);
 *              if (false == lsExtraReferenceAssembliesToAdd.Contains(assemblyName))
 *                  if (assemblyName.IndexOf("JetBrains")==-1 &&
 *                      assemblyName.IndexOf("VisualStudio") == -1 &&
 *                      assemblyName.IndexOf("SMDiagnostics") == -1) // don't add these assemblies
 *                      lsExtraReferenceAssembliesToAdd.Add(assemblyName);
 *
 *          }
 *      }*/


        public void compileSourceCode()
        {
            if (sourceCodeEditor.partialFileViewMode == false)
            {
                if (this.okThread(delegate { compileSourceCode(); }))
                {
                    var      lsExtraReferencesToAdd = new List <string>(); //lsExtraReferenceAssembliesToAdd.ToArray());
                    String   sErrorMessages         = "";
                    var      compileEngine          = new CompileEngine();
                    Assembly aCompiledAssembly      = null;
                    if (tbExtraReferencesToAdd.Text != "")
                    {
                        lsExtraReferencesToAdd.AddRange(tbExtraReferencesToAdd.Text.Split(new[] { Environment.NewLine },
                                                                                          StringSplitOptions.
                                                                                          RemoveEmptyEntries));
                    }

                    lbSourceCode_CompilationResult.Items.Clear();
                    var exeMainClass       = (rbCreateExe.Checked) ? tbMainClass.Text : "";
                    var outputAssemblyName = ""; // todo expose outputAssemblyName on GUI

                    //DI.config.addPathToCurrentExecutableEnvironmentPathVariable(DI.config.O2TempDir);

                    sourceCodeEditor.saveSourceCode();
                    var filesToCompile = new List <String> {
                        sourceCodeEditor.sPathToFileLoaded
                    };
                    if (compileEngine.compileSourceFiles(filesToCompile, lsExtraReferencesToAdd.ToArray(),
                                                         ref aCompiledAssembly, ref sErrorMessages, false /*verbose*/,
                                                         exeMainClass,
                                                         outputAssemblyName))
                    {
                        // if we only have 1 class in the completed code, set tbMainClass.Text to it
                        if (aCompiledAssembly.GetTypes().Length == 1)
                        {
                            tbMainClass.Text = aCompiledAssembly.GetTypes()[0].FullName;
                        }
                        lbSourceCode_CompilationResult.ForeColor = Color.Black;
                        lbSourceCode_CompilationResult.Items.Add("No errors");
                        O2Messages.dotNetAssemblyAvailable(aCompiledAssembly.Location);
                        //if (assemblyInvoke != null)
                        //    assemblyInvoke.loadAssembly(aCompiledAssembly, cbAutoExecuteOnMethodCompile.Checked);
                    }
                    else
                    {
                        //assemblyInvoke.setControlsEnableState(false);
                        lbSourceCode_CompilationResult.ForeColor = Color.Red;
                        compileEngine.addErrorsListToListBox(sErrorMessages, lbSourceCode_CompilationResult);
                    }
                    if (cbAutoSaveOnCompile.Checked)
                    {
                        sourceCodeEditor.saveSourceCode();
                    }
                }
            }
        }
Ejemplo n.º 11
0
        public static Panel add_WinForm_Control_from_O2Script(this O2_VS_AddIn o2Addin, string title, string o2Script, string type, int width = -1, int height = -1)
        {
            var assembly   = new CompileEngine().compileSourceFile(o2Script.local());
            var editorType = assembly.type(type);

            var panel = o2Addin.add_WinForm_Panel(title, width, height);

            panel.add_Control(editorType);
            return(panel);
        }
Ejemplo n.º 12
0
        public bool removeCachedAssemblyForCode(string codeSnippet)
        {
            if (codeSnippet.notValid())
            {
                "in removeCachedAssemblyforCode, there was no codeSnippet passed".error();
                return(false);
            }
            var filesMd5 = codeSnippet.md5Hash();

            return(CompileEngine.removeCachedAssemblyForCode_MD5(filesMd5));
        }
Ejemplo n.º 13
0
        public Assembly compileScript(string o2Script)
        {
            var compileEngine = new CompileEngine();
            var assembly      = compileEngine.compileSourceFile(o2Script.local());

            if (assembly.isNull())
            {
                MessageBox.Show(compileEngine.sbErrorMessage.str(), @"Compilation error in Start_O2:");
            }
            return(assembly);
        }
Ejemplo n.º 14
0
 //O2 Script Library
 [Test] public void CompileAllScripts()
 {
     PublicDI.log.writeToDebug(true);
     CompileEngine.clearCompilationCache();
     foreach (var method in typeof(O2_Script_Library).methods())
     {
         var code     = method.invoke().str();
         var assembly = code.compileCodeSnippet();
         Assert.IsNotNull(assembly, "Failed for compile {0} with code: \n\n {1}".format(method.Name, code));
         "Compiled OK: {0}".info(method.Name);
     }
 }
        public string compileFileToExe()
        {
            var assembly = new  CompileEngine().compileSourceFiles(new List <string> {
                scriptToInstrument
            }, "O2_Scanner_DotNet._TestScripts.TestScript_MultipleCalls");

            Assert.That(assembly != null);
            Assert.That(Path.GetExtension(assembly.Location) == ".exe");
            log.debug("File Successfully compiled: {0}", assembly.Location);
            log.info("compileFileToExe executed ok");
            return(assembly.Location);
        }
Ejemplo n.º 16
0
        public static bool compileAndOpen(this API_NUnit nUnitApi, string fileToCompile, string extraStartupOptions)
        {
            var assembly = new CompileEngine().compileSourceFile(fileToCompile);

            if (assembly.notNull())
            {
                var location = assembly.Location;
                nUnitApi.openNUnitGui(location, extraStartupOptions);
                return(true);
            }
            return(false);
        }
Ejemplo n.º 17
0
        public static bool compileAndOpen(this API_NUnit_Gui nUnitGui, string fileToCompile)
        {
            var assembly = new CompileEngine().compileSourceFile(fileToCompile);

            if (assembly.notNull())
            {
                var location = assembly.Location;
                nUnitGui.openProject(location);
                return(true);
            }
            return(false);
        }
        public bool injectIntoProcess(Process process, bool x64, bool runtime40, string sourceCodeFile)
        {
            //fixedCourceCode.showInCodeViewer();
            var compileEngine = new CompileEngine(runtime40 ? "v4.0" : "v3.5")
            {
                useCachedAssemblyIfAvailable = false
            };
            //var compiledAssembly = compileEngine.compileSourceCode(fixedCourceCode);
            var compiledAssembly = compileEngine.compileSourceFile(sourceCodeFile);

            return(injectIntoProcess(process, x64, runtime40, compiledAssembly));
        }
 // we need to use CompileEngine (which is slower but supports multiple file compilation
 public void compileExtraSourceCodeReferencesAndUpdateReferencedAssemblies()
 {
     if (ExtraSourceCodeFilesToCompile.size() > 0)
     {
         var assembly = new CompileEngine().compileSourceFiles(ExtraSourceCodeFilesToCompile);
         if (assembly != null)
         {
             ReferencedAssemblies.Add(assembly.Location);
             generateDebugSymbols = true;                // if there are extra assemblies we can't generate the assembly in memory
         }
     }
 }
        public static Ast_CSharp mapCodeO2References(this Ast_CSharp astCSharp, CSharp_FastCompiler_CompilerOptions compilerOptions)
        {
            compilerOptions.ExtraSourceCodeFilesToCompile = new List <string>();
            var compilationUnit = astCSharp.CompilationUnit;

            compilerOptions.ReferencedAssemblies   = new List <string>();               // this should be cleared in a more global location
            compilerOptions.Extra_Using_Statements = new List <string>();               // same here

            var filesToDownload = new List <string>();

            var currentUsingDeclarations = new List <string>();

            foreach (var usingDeclaration in astCSharp.AstDetails.UsingDeclarations)
            {
                currentUsingDeclarations.Add(usingDeclaration.Text);
            }

            compilerOptions.mapOptionsDefinedInsideComments(astCSharp.AstDetails.comments())
            .mapNuGetReferences()
            .Extra_Using_Statements.forEach(value => astCSharp.CompilationUnit.add_Using(value));

            //resolve location of ExtraSourceCodeFilesToCompile
            astCSharp.resolveFileLocationsOfExtraSourceCodeFilesToCompile(compilerOptions);

            CompileEngine.handleReferencedAssembliesInstallRequirements(astCSharp.AstDetails.CSharpCode);

            //use the same technique to download files that are needed for this script (for example *.zip files or other unmanaged/support files)
            CompileEngine.tryToResolveReferencesForCompilation(filesToDownload, compilerOptions.WorkOffline);


            if (compilerOptions.onlyAddReferencedAssemblies.isFalse())
            {
                foreach (var defaultRefAssembly in CompileEngine.DefaultReferencedAssemblies)
                {
                    if (compilerOptions.ReferencedAssemblies.Contains(defaultRefAssembly).isFalse())
                    {
                        compilerOptions.ReferencedAssemblies.add(defaultRefAssembly);
                    }
                }
                foreach (var usingStatement in CompileEngine.DefaultUsingStatements)
                {
                    if (false == currentUsingDeclarations.Contains(usingStatement))
                    {
                        compilationUnit.add_Using(usingStatement);
                    }
                }
            }

            //make sure the referenced assemblies are in the current execution directory
            CompileEngine.tryToResolveReferencesForCompilation(compilerOptions.ReferencedAssemblies, compilerOptions.WorkOffline);
            return(astCSharp);
        }
Ejemplo n.º 21
0
        public void _test_createJarStubForAllO2Assemblies()
        {
            var o2Timer      = new O2Timer("created Jar Stubs for all O2Assemblies").start();
            var o2Assemblies = CompileEngine.getListOfO2AssembliesInExecutionDir();

            foreach (var o2Assembly in o2Assemblies)
            {
                var jarStubFile = JavaCompile.createJarStubForDotNetDll(o2Assembly, IKVMConfig.jarStubsCacheDir);
                Assert.That(File.Exists(jarStubFile), "jarStubFile didn't exist: {0}", jarStubFile);
            }
            DI.log.info("\n...all done\n");
            o2Timer.stop();
        }
Ejemplo n.º 22
0
 // we need to use CompileEngine (which is slower but supports multiple file compilation
 public void compileExtraSourceCodeReferencesAndUpdateReferencedAssemblies()
 {
     if (ExtraSourceCodeFilesToCompile.size() > 0)
     {
         "[CSharp Compiler] Compiling provided {0} external source code references".info(ExtraSourceCodeFilesToCompile.size());
         var assembly = new CompileEngine(UseCachedAssemblyIfAvailable).compileSourceFiles(ExtraSourceCodeFilesToCompile);
         if (assembly != null)
         {
             ReferencedAssemblies.Add(assembly.Location);
             CompileEngine.setCachedCompiledAssembly(ExtraSourceCodeFilesToCompile, assembly);
             generateDebugSymbols = true;                // if there are extra assemblies we can't generate the assembly in memory
         }
     }
 }
Ejemplo n.º 23
0
        [Test] public void resolveCompilationReferencePath()
        {
            //testing NuGet assembly resolution (other parts of resolveCompilationReferencePath are missing)

            var assemblyName = "FluentSharp.HtmlAgilityPack";
            var nuGet        = new API_NuGet();

            nuGet.install(assemblyName);
            nuGet.path_Package(assemblyName).assert_Folder_Exists();

            CompileEngine.resolveCompilationReferencePath(assemblyName).assert_File_Exists()
            .assert_Contains(assemblyName)
            .fileName().assert_Is(assemblyName.append(".dll"));
        }
Ejemplo n.º 24
0
 public override void create()
 {
     this.ButtonText = "O2 Script - with Panel";
     this.ToolTip    = "Opens the O2 Script Guid (with a top panel)";
     this.TargetMenu = "O2 Platform";
     base.create();
     this.Execute = () =>
     {
         var script   = "ascx_Quick_Development_GUI.cs.o2".local();
         var assembly = new CompileEngine().compileSourceFile(script);
         assembly.methods()[0].invoke(new object[] { });
         //assembly.executeFirstMethod();
     };
 }
Ejemplo n.º 25
0
        void createTypes(Type type1, Type type2, PersistentAssemblyBuilder persistentAssemblyBuilder, string type1Name, string type2Name)
        {
            var persistentClassInfo1 = persistentAssemblyBuilder.PersistentAssemblyInfo.PersistentClassInfos[0];
            var persistentClassInfo2 = persistentAssemblyBuilder.PersistentAssemblyInfo.PersistentClassInfos[1];

            addInterface(type1, persistentClassInfo1);
            addInterface(type2, persistentClassInfo2);
            _XPObjectSpace.CommitChanges();

            var compileModule = new CompileEngine().CompileModule(persistentAssemblyBuilder, Path.GetDirectoryName(Application.ExecutablePath));

            _t1Type = compileModule.Assembly.GetTypes().Single(type => type.Name == type1Name);
            _t2Type = compileModule.Assembly.GetTypes().Where(type => type.Name == type2Name).Single();
        }
Ejemplo n.º 26
0
        public static Process console_Run(this API_NUnit nUnitApi, string target, string extraStartupOptions, Action <string> consoleOut)
        {
            if (target.extension(".cs"))
            {
                var assembly = new CompileEngine().compileSourceFile(target);
                if (assembly.isNull())
                {
                    "[API_NUnit][console_Run] failed to compile C# file: {0}".error(target);
                    return(null);
                }
                target = assembly.Location;
            }
            var startUpOptions = "\"{0}\" {1}".format(target ?? "", extraStartupOptions ?? "");

            return(nUnitApi.executeNUnitConsole(startUpOptions, consoleOut));
        }
        public static API_CatNet_GUI scanCSharpFile(this API_CatNet_GUI catNetGui, string file)
        {
            catNetGui.SolutionLoaded         = "";
            catNetGui.TriggerOnSelectedEvent = false;
            var catNet   = new API_CatNet().loadRules();
            var assembly = new CompileEngine().compileSourceFile(file);

            if (assembly.notNull())
            {
                catNetGui.openReport(catNet.scan(assembly).savedReport());
            }
            else
            {
                catNetGui.CodeViewer.open(file);
            }
            return(catNetGui);
        }
 public static void addExtraFileReferencesToTreeNode(TreeNode treeNode, string file)
 {
     if (treeNode != null && File.Exists(file))
     {
         treeNode.Nodes.Clear();
         // this will get the list of files to compile (which includes the extra files referenced in the source code that we want to add to this treeview)
         var filesToCompile = new List <string>();
         filesToCompile.Add(file);
         CompileEngine.addSourceFileOrFolderIncludedInSourceCode(filesToCompile, new List <string>(), new List <string>());
         filesToCompile.Remove(file);
         foreach (var extraFile in filesToCompile)
         {
             O2Forms.newTreeNode(treeNode, Path.GetFileName(extraFile), 5, extraFile);
         }
         treeNode.ExpandAll();
     }
 }
Ejemplo n.º 29
0
        private static string getMethodName(string arg0)
        {
            string[] splittedArg0 = arg0.Split('!');
            switch (splittedArg0.Length)
            {
            case 2:
                string file       = splittedArg0[0];
                string methodName = splittedArg0[1];
                O2Cmd.log.write("Trying to load file {0} and execute method {1}", file, methodName);
                switch (Path.GetExtension(file))
                {
                case ".cs":
                    O2Cmd.log.write("\n*.cs file provided, compiling code\n");
                    Assembly assembly = new CompileEngine().compileSourceFile(file);
                    if (assembly == null)
                    {
                        O2Cmd.log.write("Error: could not compile provided code");
                    }
                    else
                    {
                        O2Cmd.log.write("Source code successfully compiled, loading types\n");
                        foreach (Type typeToLoad in assembly.GetTypes())
                        {
                            O2CmdApi.typesWithCommands.Add(typeToLoad);
                        }
                        O2Cmd.log.write("\nHere is the updated list of available command line methods\n");
                        O2Cmd.help();
                        O2Cmd.log.write("\nExecuting method:{0}\n", methodName);
                        return(methodName);
                    }
                    break;

                case ".dll":
                    break;

                default:
                    O2Cmd.log.error("ERROR: unsupported file extension (it must be *.cs or *.dll");
                    break;
                }
                return("");

            default:
                return(arg0);
            }
            //return arg0;
        }
Ejemplo n.º 30
0
        [Test] public void LocalScriptFolders()
        {
            var localScripts      = CompileEngine.LocalScriptFileMappings;
            var localScriptFolder = PublicDI.config.LocalScriptsFolder.createDir();
            var fileName          = "testFile{0}.cs".format(4.randomLetters());
            var fileContents      = "some code";
            var testFile          = localScriptFolder.pathCombine(fileName);

            Assert.IsNotNull(localScripts);
            //Assert.IsEmpty  (localScripts);
            Assert.AreEqual(fileName.local(), "");
            Assert.IsNotNull(localScriptFolder);

            fileContents.saveAs(testFile);
            CompileEngine.resetLocalScriptsFileMappings();

            Assert.IsTrue(testFile.fileExists(), "File didn't exist: {0}".format(testFile));
            Assert.AreEqual(fileContents, testFile.fileContents());
            Assert.IsNotEmpty(localScripts);
            Assert.IsNotNull(fileName.local());
            Assert.AreEqual(fileName.local(), testFile);
            Assert.IsFalse(localScripts.hasKey(fileName), "localscripts");
            Assert.IsTrue(localScripts.hasKey(fileName.lower()), "localscripts (lowercase search)");
            Assert.AreEqual(localScripts[fileName.lower()], testFile);

            //ExtraLocalScriptFolders

            var tempDir           = "ExtraScripts".tempDir();
            var extraFileName     = "extraFile.cs";
            var extraFile         = tempDir.pathCombine("extraFile.cs");
            var extraFileContents = "some more code";

            extraFileContents.saveAs(extraFile);

            Assert.IsFalse(localScripts.hasKey(fileName));
            Assert.AreEqual(extraFileName.local(), "");

            CompileEngine.LocalFoldersToAddToFileMappings.add(tempDir);
            CompileEngine.resetLocalScriptsFileMappings();

            Assert.IsFalse(localScripts.hasKey(extraFileName));
            Assert.IsTrue(localScripts.hasKey(extraFileName.lower()));
            Assert.AreEqual(extraFileName.local(), extraFile);
            Assert.AreEqual(extraFileName.local().fileContents(), extraFileContents);
        }