Пример #1
0
        /// <summary>
        /// Initialization of ScriptParser instance
        /// </summary>
        /// <param name="fileName">Script file name</param>
        /// <param name="searchDirs">Extra ScriptLibrary directory(ies) </param>
        private void Init(string fileName, string[] searchDirs)
        {
            referencedNamespaces = new ArrayList();
            referencedAssemblies = new ArrayList();
            referencedResources  = new ArrayList();

            //process main file
            FileParser mainFile = new FileParser(fileName, null, true, false, searchDirs);

            this.apartmentState = mainFile.ThreadingModel;

            foreach (string namespaceName in mainFile.ReferencedNamespaces)
            {
                PushNamespace(namespaceName);
            }

            foreach (string asmName in mainFile.ReferencedAssemblies)
            {
                PushAssembly(asmName);
            }

            foreach (string resFile in mainFile.ReferencedResources)
            {
                PushResource(resFile);
            }

            ArrayList dirs = new ArrayList();

            dirs.Add(Path.GetDirectoryName(mainFile.fileName));            //note: mainFile.fileName is warrantied to be a full name but fileName is not
            if (searchDirs != null)
            {
                dirs.AddRange(searchDirs);
            }
            this.searchDirs = (string[])dirs.ToArray(typeof(string));

            //process impported files if any
            foreach (ScriptInfo fileInfo in mainFile.ReferencedScripts)
            {
                ProcessFile(fileInfo);
            }

            //Main script file shall always be the first. Add it now as previously array was sorted a few times
            this.fileParsers.Insert(0, mainFile);
        }
Пример #2
0
        int IComparer.Compare(object x, object y)
        {
            if (x == null && y == null)
            {
                return(0);
            }

            int retval = x == null ? -1 : (y == null ? 1 : 0);

            if (retval == 0)
            {
                FileParser xParser = (FileParser)x;
                FileParser yParser = (FileParser)y;
                retval = string.Compare(xParser.fileName, yParser.fileName, true);
                if (retval == 0)
                {
                    retval = ParsingParams.Compare(xParser.prams, yParser.prams);
                }
            }

            return(retval);
        }
Пример #3
0
        void ProcessFile(ScriptInfo fileInfo)
        {
            FileParserComparer fileComparer = new FileParserComparer();

            FileParser importedFile = new FileParser(fileInfo.fileName, fileInfo.parseParams, false, true, this.SearchDirs, throwOnError); //do not parse it yet (the third param is false)

            if (fileParsers.BinarySearch(importedFile, fileComparer) < 0)
            {
                if (File.Exists(importedFile.fileName))
                {
                    importedFile.ProcessFile(); //parse now namespaces, ref. assemblies and scripts; also it will do namespace renaming

                    this.fileParsers.Add(importedFile);
                    this.fileParsers.Sort(fileComparer);

                    foreach (string namespaceName in importedFile.ReferencedNamespaces)
                    {
                        PushNamespace(namespaceName);
                    }

                    foreach (string asmName in importedFile.ReferencedAssemblies)
                    {
                        PushAssembly(asmName);
                    }

                    foreach (string packageName in importedFile.Packages)
                    {
                        PushPackage(packageName);
                    }

                    foreach (string file in importedFile.Precompilers)
                    {
                        PushPrecompiler(file);
                    }

                    foreach (ScriptInfo scriptFile in importedFile.ReferencedScripts)
                    {
                        ProcessFile(scriptFile);
                    }

                    foreach (string resFile in importedFile.ReferencedResources)
                    {
                        PushResource(resFile);
                    }

                    foreach (string file in importedFile.IgnoreNamespaces)
                    {
                        PushIgnoreNamespace(file);
                    }

                    List <string> dirs = new List <string>(this.SearchDirs);
                    foreach (string dir in importedFile.ExtraSearchDirs)
                    {
                        if (Path.IsPathRooted(dir))
                        {
                            dirs.Add(Path.GetFullPath(dir));
                        }
                        else
                        {
                            dirs.Add(Path.Combine(Path.GetDirectoryName(importedFile.fileName), dir));
                        }
                    }
                    this.SearchDirs = dirs.ToArray();
                }
                else
                {
                    importedFile.fileNameImported = importedFile.fileName;
                    this.fileParsers.Add(importedFile);
                    this.fileParsers.Sort(fileComparer);
                }
            }
        }
Пример #4
0
        /// <summary>
        /// Initialization of ScriptParser instance
        /// </summary>
        /// <param name="fileName">Script file name</param>
        /// <param name="searchDirs">Extra ScriptLibrary directory(ies) </param>
        void Init(string fileName, string[] searchDirs)
        {
            ScriptPath = fileName;

            packages             = new List <string>();
            referencedNamespaces = new List <string>();
            referencedAssemblies = new List <string>();
            referencedResources  = new List <string>();
            ignoreNamespaces     = new List <string>();
            precompilers         = new List <string>();
            compilerOptions      = new List <string>();

            //process main file
            FileParser mainFile = new FileParser(fileName, null, true, false, searchDirs, throwOnError);

            this.apartmentState = mainFile.ThreadingModel;

            foreach (string file in mainFile.Precompilers)
            {
                PushPrecompiler(file);
            }

            foreach (string namespaceName in mainFile.IgnoreNamespaces)
            {
                PushIgnoreNamespace(namespaceName);
            }

            foreach (string namespaceName in mainFile.ReferencedNamespaces)
            {
                PushNamespace(namespaceName);
            }

            foreach (string asmName in mainFile.ReferencedAssemblies)
            {
                PushAssembly(asmName);
            }

            foreach (string name in mainFile.Packages)
            {
                PushPackage(name);
            }

            foreach (string resFile in mainFile.ReferencedResources)
            {
                PushResource(resFile);
            }

            foreach (string opt in mainFile.CompilerOptions)
            {
                PushCompilerOptions(opt);
            }

            List <string> dirs = new List <string>();

            dirs.Add(Path.GetDirectoryName(mainFile.fileName));//note: mainFile.fileName is warrantied to be a full name but fileName is not
            if (searchDirs != null)
            {
                dirs.AddRange(searchDirs);
            }

            foreach (string dir in mainFile.ExtraSearchDirs)
            {
                if (Path.IsPathRooted(dir))
                {
                    dirs.Add(Path.GetFullPath(dir));
                }
                else
                {
                    dirs.Add(Path.Combine(Path.GetDirectoryName(mainFile.fileName), dir));
                }
            }

            this.SearchDirs = Utils.RemovePathDuplicates(dirs.ToArray());

            //process imported files if any
            foreach (ScriptInfo fileInfo in mainFile.ReferencedScripts)
            {
                ProcessFile(fileInfo);
            }

            //Main script file shall always be the first. Add it now as previously array was sorted a few times
            this.fileParsers.Insert(0, mainFile);
        }
Пример #5
0
        /// <summary>
        /// Processes the imported script. Processing involves lookup for 'static Main' and renaming it so it does not
        /// interfere with the 'static Main' of the primary script. After renaming is done the new content is saved in the
        /// CS-Script cache and the new file location is returned. The saved file can be used late as an "included script".
        /// This technique can be from 'precompiler' scripts.
        /// <para>If the script file does not require renaming (static Main is not present) the method returns the
        /// original script file location.</para>
        /// </summary>
        /// <param name="scriptFile">The script file.</param>
        /// <returns></returns>
        public static string ProcessImportedScript(string scriptFile)
        {
            var parser = new FileParser(scriptFile, new ParsingParams(), true, true, new string[0], true);

            return(parser.FileToCompile);
        }
Пример #6
0
		private void ProcessFile(ScriptInfo fileInfo)
		{
			FileParserComparer fileComparer = new FileParserComparer();
			
			FileParser importedFile = new FileParser(fileInfo.fileName, fileInfo.parseParams, false, true, this.searchDirs); //do not parse it yet (the third param is false)
			if (fileParsers.BinarySearch(importedFile, fileComparer) < 0)
			{
				importedFile.ProcessFile(); //parse now namespaces, ref. assemblies and scripts; also it will do namespace renaming

				this.fileParsers.Add(importedFile);
				this.fileParsers.Sort(fileComparer);

				foreach (string namespaceName in importedFile.ReferencedNamespaces)
					PushNamespace(namespaceName);

				foreach (string asmName in importedFile.ReferencedAssemblies)
					PushAssembly(asmName);

				foreach(ScriptInfo scriptFile in importedFile.ReferencedScripts)
					ProcessFile(scriptFile);
			}
		}
Пример #7
0
		/// <summary>
		/// Initialization of ScriptParser instance
		/// </summary>
		/// <param name="fileName">Script file name</param>
		/// <param name="searchDirs">Extra ScriptLibrary directory(ies) </param>
		private void Init(string fileName, string[] searchDirs)
		{
			referencedNamespaces = new ArrayList(); 
			referencedAssemblies = new ArrayList();
			referencedResources = new ArrayList();
			
			//process main file
			FileParser mainFile = new FileParser(fileName, null, true, false, searchDirs);
			this.apartmentState = mainFile.ThreadingModel;

			foreach (string namespaceName in mainFile.ReferencedNamespaces)
				PushNamespace(namespaceName);

			foreach (string asmName in mainFile.ReferencedAssemblies)
				PushAssembly(asmName);
			
			foreach (string resFile in mainFile.ReferencedResources)
				PushResource(resFile);

			ArrayList dirs = new ArrayList();
			dirs.Add(Path.GetDirectoryName(mainFile.fileName));//note: mainFile.fileName is warrantied to be a full name but fileName is not
			if (searchDirs != null)
				dirs.AddRange(searchDirs);
			this.searchDirs = (string[])dirs.ToArray(typeof(string)); 

			//process impported files if any
			foreach (ScriptInfo fileInfo in mainFile.ReferencedScripts)
				ProcessFile(fileInfo);

			//Main script file shall always be the first. Add it now as previously array was sorted a few times
			this.fileParsers.Insert(0, mainFile); 
		}