コード例 #1
0
 private void _ReadFrameworkAssemblies(XElement element, ScriptSequence scriptSequence)
 {
     scriptSequence.FrameworkAssemblies = new HashSet<string>(
         element
             .Element("FrameworkAssemblies")
             .Elements("Assembly")
             .Select(x => x.Attribute("name").Value));
 }
コード例 #2
0
 private void _ReadSourceFiles(XElement element, ScriptSequence scriptSequence)
 {
     string sourcePath = Path.Combine(scriptSequence.SourceDirectory, scriptSequence.Name);
     scriptSequence.SourceFiles.Clear();
     IEnumerable<string> fileNames = element
         .Element("SourceFiles")
         .Elements("SourceFile")
         .Select(x => x.Attribute("name").Value);
     foreach(string fileName in fileNames) {
         string filePath = Path.Combine(sourcePath, fileName);
         scriptSequence.SourceFiles.Add(SourceFile.Load(filePath));
     }
 }
コード例 #3
0
        private XElement _WriteSourceFiles(ScriptSequence sequence)
        {
            // Make sure source directory exists.
            string sourcePath = Path.Combine(sequence.SourceDirectory, sequence.Name);
            Helper.EnsureDirectory(sourcePath);

            // Write the source files and their references.
            return new XElement("SourceFiles", sequence.SourceFiles.Select(x => {
                x.Save(sourcePath);
                return new XElement("SourceFile",
                    new XAttribute("name", x.Name));
            }));
        }
コード例 #4
0
        protected ScriptSequence(string language, ScriptSequence original)
        {
            Length = Forever;

            //SourceFiles = new List<SourceFile>(original.SourceFiles);
            //SourceFiles = new SourceFileCollection();
            //SourceFiles.Files.AddRange(original.SourceFiles.Files);
            _sourceFiles = new SourceFileCollection();
            AddSourceFiles(original.GetAllSourceFiles());
            FrameworkAssemblies = new HashSet <string>(original.FrameworkAssemblies);
            ExternalAssemblies  = new HashSet <string>(original.ExternalAssemblies);

            Language = language;

            ClassName = original.ClassName;
        }
コード例 #5
0
ファイル: ScriptSequence.cs プロジェクト: stewmc/vixen
        protected ScriptSequence(string language, ScriptSequence original)
        {
            Length = Forever;

            //SourceFiles = new List<SourceFile>(original.SourceFiles);
            //SourceFiles = new SourceFileCollection();
            //SourceFiles.Files.AddRange(original.SourceFiles.Files);
            _sourceFiles = new SourceFileCollection();
            AddSourceFiles(original.GetAllSourceFiles());
            FrameworkAssemblies = new HashSet<string>(original.FrameworkAssemblies);
            ExternalAssemblies = new HashSet<string>(original.ExternalAssemblies);

            Language = language;

            ClassName = original.ClassName;
        }
コード例 #6
0
        public IUserScriptHost GenerateScript(ScriptSequence sequence)
        {
            List<string> files = new List<string>();

            Assembly assembly;
            string nameSpace = UserScriptNamespace;

            try {
                // Emit the T4 template to be compiled into the assembly.
                string fileName = Path.GetTempFileName();

                string fileContents = sequence.Language.FrameworkGenerator.Generate(nameSpace, sequence.ClassName);
                File.WriteAllText(fileName, fileContents);
                files.Add(fileName);

                // Add the user's source files.
                foreach(SourceFile sourceFile in sequence.SourceFiles) {
                    fileName = Path.Combine(Path.GetTempPath(), sourceFile.Name);
                    File.WriteAllText(fileName, sourceFile.Contents);
                    files.Add(fileName);
                }

                // Compile the sources.
                assembly = _Compile(files.ToArray(), _GetReferencedAssemblies(sequence), sequence.Language);
            } finally {
                // Delete the temp files.
                foreach(string tempFile in files) {
                    File.Delete(tempFile);
                }
            }

            if(assembly != null) {
                // Get the generated type.
                Type type = assembly.GetType(string.Format("{0}.{1}", nameSpace, sequence.ClassName));
                if(type != null) {
                    // Create and return an instance.
                    return (IUserScriptHost)Activator.CreateInstance(type);
                }
            }

            return null;
        }
コード例 #7
0
 private void _ReadLanguage(XElement element, ScriptSequence scriptSequence)
 {
     scriptSequence.Language = element.Element("Language").Value;
 }
コード例 #8
0
 private void _ReadClassName(XElement element, ScriptSequence scriptSequence)
 {
     scriptSequence.ClassName = element.Element("ClassName").Value;
 }
コード例 #9
0
ファイル: ScriptHostGenerator.cs プロジェクト: komby/vixen
        public IUserScriptHost GenerateScript(ScriptSequence sequence)
        {
            List<string> files = new List<string>();

            Assembly assembly;
            string nameSpace = UserScriptNamespace;

            try {
                // Emit the T4 template to be compiled into the assembly.
                string fileName = Path.GetTempFileName();

                string fileContents = sequence.Language.FrameworkGenerator.Generate(nameSpace, sequence.ClassName);
                File.WriteAllText(fileName, fileContents);
                files.Add(fileName);

                // Add the user's source files.
                foreach (SourceFile sourceFile in sequence.SourceFiles) {
                    fileName = Path.Combine(Path.GetTempPath(), sourceFile.Name);
                    File.WriteAllText(fileName, sourceFile.Contents);
                    files.Add(fileName);
                }

                var assemblyReferences = _GetReferencedAssemblies(sequence);
                HashSet<string> uniqueAssemblyReferences = new HashSet<string>(assemblyReferences);
                // Remove .NET framework and GAC assemblies.
                uniqueAssemblyReferences.RemoveWhere(
                    x => x.StartsWith(Environment.GetFolderPath(Environment.SpecialFolder.Windows), StringComparison.OrdinalIgnoreCase));

                //if (createProject)

                CreateWorkingProject(files.ToArray(), uniqueAssemblyReferences, sequence);

                // Compile the sources.
                assembly = _Compile(files.ToArray(), uniqueAssemblyReferences, sequence);
            } finally {
                // Delete the temp files.
                foreach (string tempFile in files) {
                    File.Delete(tempFile);
                }
            }

            if (assembly != null) {
                // Get the generated type.
                Type type = assembly.GetType(string.Format("{0}.{1}", nameSpace, sequence.ClassName));
                if (type != null) {
                    // Create and return an instance.
                    return (IUserScriptHost)Activator.CreateInstance(type);
                }
            }

            return null;
        }
コード例 #10
0
ファイル: ScriptHostGenerator.cs プロジェクト: komby/vixen
        private IEnumerable<string> _GetReferencedAssemblies(ScriptSequence sequence)
        {
            List<string> assemblyReferences = new List<string>();

            assemblyReferences.AddRange(sequence.FrameworkAssemblies);
            assemblyReferences.AddRange(sequence.ExternalAssemblies);
            assemblyReferences.AddRange(_GetEffectParameterAssemblies());
            assemblyReferences.AddRange(_standardReferences);
            assemblyReferences.Add(VixenSystem.AssemblyFileName);

            return assemblyReferences;
        }
コード例 #11
0
ファイル: ScriptHostGenerator.cs プロジェクト: komby/vixen
        /// <returns>The file name of the compiled assembly.</returns>
        private Assembly _Compile(string[] files, HashSet<string> uniqueAssemblyReferences, ScriptSequence sequence)
        {
            IScriptModuleInstance language = sequence.Language;
            // Assembly references come in two flavors:
            // 1. Framework assemblies -- need only the file name.
            // 2. Other assemblies -- need the qualified file name.
            _errors.Clear();

            ICompilerParameters compilerParameters = new ScriptCompilerParameters {
                GenerateInMemory = true,
                //IncludeDebugInformation = true
            };
            compilerParameters.ReferencedAssemblies.AddRange(uniqueAssemblyReferences.ToArray());

            ICompilerResults results = language.CodeProvider.CompileAssemblyFromFile(compilerParameters, files);

            // Get any errors.
            foreach (ICompilerError error in results.Errors) {
                _errors.Add(string.Format("{0} [{1}]: {2}", Path.GetFileName(error.FileName), error.Line, error.ErrorText));
            }

            return results.HasErrors ? null : results.CompiledAssembly;
        }
コード例 #12
0
ファイル: ScriptHostGenerator.cs プロジェクト: komby/vixen
 private void CreateWorkingProject(string[] files, HashSet<string> assemblyReferences, ScriptSequence sequence)
 {
     new ScriptProjectGenerator(files, assemblyReferences, sequence).Generate();
 }
コード例 #13
0
 private XElement _WriteLanguage(ScriptSequence sequence)
 {
     return new XElement("Language", sequence.Language);
 }
コード例 #14
0
 private XElement _WriteFrameworkAssemblies(ScriptSequence sequence)
 {
     return new XElement("FrameworkAssemblies", sequence.FrameworkAssemblies.Select(x =>
         new XElement("Assembly",
             new XAttribute("name", x))));
 }
コード例 #15
0
 private XElement _WriteExternalAssemblies(ScriptSequence sequence)
 {
     return new XElement("ExternalAssemblies", sequence.ExternalAssemblies.Select(x =>
         new XElement("Assembly",
             new XAttribute("name", x))));
 }
コード例 #16
0
 private XElement _WriteClassName(ScriptSequence sequence)
 {
     return new XElement("ClassName", sequence.ClassName);
 }