Ejemplo n.º 1
0
        public PaketScriptMetadataResolver(string code, string workingDirectory = null)
        {
            workingDirectory = workingDirectory ?? Directory.GetCurrentDirectory();
            _inner           = ScriptMetadataResolver.Default;

            var syntaxTree = CSharpSyntaxTree.ParseText(code, CSharpParseOptions.Default.WithKind(SourceCodeKind.Script));
            var refs       = syntaxTree.GetCompilationUnitRoot().GetReferenceDirectives().Select(x => x.File.ToString().Replace("\"", string.Empty)).Where(x => x.StartsWith(PaketPrefix));

            foreach (var reference in refs)
            {
                PaketDependencies.AppendLine(reference.Replace(PaketPrefix, "nuget "));
            }

            File.WriteAllText(Path.Combine(workingDirectory, "paket.dependencies"), PaketDependencies.ToString());
            var processStartInfo = new ProcessStartInfo(@".paket/paket.exe", "install --generate-load-scripts load-script-framework " + Tfm)
            {
                RedirectStandardOutput = true,
                RedirectStandardError  = true,
                CreateNoWindow         = true,
                UseShellExecute        = false,
                WorkingDirectory       = _inner.BaseDirectory
            };

            using (var process = new Process()
            {
                StartInfo = processStartInfo
            })
            {
                process.OutputDataReceived += (sender, e) =>
                {
                    Console.WriteLine(e.Data);
                };
                process.ErrorDataReceived += (sender, e) =>
                {
                    Console.Error.WriteLine(e.Data);
                };
                process.Start();
                process.BeginErrorReadLine();
                process.BeginOutputReadLine();

                process.WaitForExit();
            }

            var restoredDefs           = File.ReadAllText(Path.Combine(workingDirectory, $".paket/load/{Tfm}/main.group.csx"));
            var restoredDefsSyntaxTree = CSharpSyntaxTree.ParseText(restoredDefs, CSharpParseOptions.Default.WithKind(SourceCodeKind.Script));
            var restoredRefs           = restoredDefsSyntaxTree.GetCompilationUnitRoot().GetReferenceDirectives().Select(x => x.File.ToString().Replace("\"", string.Empty));

            foreach (var restoredRef in restoredRefs)
            {
                if (restoredRef.StartsWith(".."))
                {
                    ResolvedReferences.Add(Path.Combine(workingDirectory, $".paket/load/{Tfm}", restoredRef));
                }
                else
                {
                    //skip GAC by design
                    //Console.WriteLine($"Skipping GAC: {restoredRef}");
                }
            }
        }
Ejemplo n.º 2
0
        private static ScriptOptions CreateScriptOptions(string filename, IEnumerable <string> include_dirs, IEnumerable <string> metadata_dirs)
        {
            string        base_path     = Path.GetDirectoryName(typeof(EntryPoint).GetTypeInfo().Assembly.Location);
            List <string> resolve_paths = new List <string>
            {
                Directory.GetCurrentDirectory(),
                          base_path
            };

            if (filename != null)
            {
                resolve_paths.Add(Path.GetDirectoryName(filename));
            }

            Type template_type = typeof(FixedProxyTemplate);
            SourceFileResolver     resolver          = new SourceFileResolver(include_dirs.Concat(resolve_paths), base_path);
            ScriptMetadataResolver metadata_resolver = ScriptMetadataResolver.Default
                                                       .WithBaseDirectory(base_path)
                                                       .WithSearchPaths(metadata_dirs.Concat(resolve_paths));

            return(ScriptOptions.Default.WithImports(template_type.Namespace, "CANAPE", "System",
                                                     "CANAPE.Utils", "CANAPE.Nodes", "CANAPE.Net.Utils",
                                                     "CANAPE.DataFrames", "CANAPE.Net.Templates.Factories",
                                                     "CANAPE.Net.Templates", "CANAPE.Security.Cryptography.X509Certificates")
                   .WithReferences(template_type.GetTypeInfo().Assembly,
                                   typeof(EntryPoint).GetTypeInfo().Assembly)
                   .WithSourceResolver(resolver)
                   .WithMetadataResolver(metadata_resolver));
        }
 public CachedScriptMetadataResolver(string workingDirectory, bool useCache = false)
 {
     _inner = ScriptMetadataResolver.Default.WithBaseDirectory(workingDirectory);
     if (useCache)
     {
         _cache = new ConcurrentDictionary <string, ImmutableArray <PortableExecutableReference> >();
     }
 }
 public FunctionMetadataResolver(FunctionMetadata metadata, TraceWriter traceWriter)
 {
     _functionMetadata        = metadata;
     _traceWriter             = traceWriter;
     _packageAssemblyResolver = new PackageAssemblyResolver(metadata);
     _privateAssembliesPath   = GetBinDirectory(metadata);
     _scriptResolver          = ScriptMetadataResolver.Default.WithSearchPaths(_privateAssembliesPath);
 }
 public FunctionMetadataResolver(FunctionMetadata metadata, TraceWriter traceWriter)
 {
     _functionMetadata = metadata;
     _traceWriter = traceWriter;
     _packageAssemblyResolver = new PackageAssemblyResolver(metadata);
     _privateAssembliesPath = GetBinDirectory(metadata);
     _scriptResolver = ScriptMetadataResolver.Default.WithSearchPaths(_privateAssembliesPath);
 }
Ejemplo n.º 6
0
 public FunctionMetadataResolver(FunctionMetadata metadata, Collection <ScriptBindingProvider> bindingProviders, TraceWriter traceWriter)
 {
     _functionMetadata                = metadata;
     _traceWriter                     = traceWriter;
     _packageAssemblyResolver         = new PackageAssemblyResolver(metadata);
     _privateAssembliesPath           = GetBinDirectory(metadata);
     _scriptResolver                  = ScriptMetadataResolver.Default.WithSearchPaths(_privateAssembliesPath);
     _extensionSharedAssemblyProvider = new ExtensionSharedAssemblyProvider(bindingProviders);
 }
 public FunctionMetadataResolver(FunctionMetadata metadata, ICollection<ScriptBindingProvider> bindingProviders, TraceWriter traceWriter)
 {
     _functionMetadata = metadata;
     _traceWriter = traceWriter;
     _packageAssemblyResolver = new PackageAssemblyResolver(metadata);
     _privateAssembliesPath = GetBinDirectory(metadata);
     _scriptResolver = ScriptMetadataResolver.Default.WithSearchPaths(_privateAssembliesPath);
     _extensionSharedAssemblyProvider = new ExtensionSharedAssemblyProvider(bindingProviders);
 }
Ejemplo n.º 8
0
 public FunctionMetadataResolver(string scriptFilePath, ICollection <ScriptBindingProvider> bindingProviders, ILogger logger)
 {
     _scriptFileDirectory             = Path.GetDirectoryName(scriptFilePath);
     _scriptFilePath                  = scriptFilePath;
     _packageAssemblyResolver         = new PackageAssemblyResolver(_scriptFileDirectory);
     _privateAssembliesPath           = GetBinDirectory(_scriptFileDirectory);
     _scriptResolver                  = ScriptMetadataResolver.Default.WithSearchPaths(_privateAssembliesPath);
     _extensionSharedAssemblyProvider = new ExtensionSharedAssemblyProvider(bindingProviders);
     _logger = logger;
 }
 public FunctionMetadataResolver(string scriptFileDirectory, ICollection <ScriptBindingProvider> bindingProviders, TraceWriter traceWriter, ILoggerFactory loggerFactory)
 {
     _scriptFileDirectory             = scriptFileDirectory;
     _traceWriter                     = traceWriter;
     _packageAssemblyResolver         = new PackageAssemblyResolver(scriptFileDirectory);
     _privateAssembliesPath           = GetBinDirectory(scriptFileDirectory);
     _scriptResolver                  = ScriptMetadataResolver.Default.WithSearchPaths(_privateAssembliesPath);
     _extensionSharedAssemblyProvider = new ExtensionSharedAssemblyProvider(bindingProviders);
     _loggerFactory                   = loggerFactory;
 }
Ejemplo n.º 10
0
 protected CommonScriptEngine(IScriptHostFactory scriptHostFactory, ILogProvider logProvider)
 {
     Guard.AgainstNullArgument("logProvider", logProvider);
     ScriptMetadataResolver = ScriptMetadataResolver.Default;
     ScriptOptions          = ScriptOptions.Default.
                              WithReferences(typeof(object).Assembly, typeof(TupleElementNamesAttribute).Assembly). // System.ValueTuple
                              WithMetadataResolver(ScriptMetadataResolver);
     _scriptHostFactory = scriptHostFactory;
     Log = logProvider.ForCurrentType();
     SetCSharpVersionToLatest();
 }
Ejemplo n.º 11
0
        private void InjectXMLDocumentationProviderIntoRuntimeMetadataReferenceResolver(ScriptMetadataResolver resolver)
        {
            var runtimeMetadataReferenceResolverField = typeof(ScriptMetadataResolver).GetField(ResolverField, BindingFlags.Instance | BindingFlags.NonPublic);
            var runtimeMetadataReferenceResolverValue = runtimeMetadataReferenceResolverField?.GetValue(resolver);

            if (runtimeMetadataReferenceResolverValue != null)
            {
                var runtimeMetadataReferenceResolverType = typeof(CommandLineScriptGlobals).GetTypeInfo().Assembly.GetType(RuntimeMetadataReferenceResolverType);
                var fileReferenceProviderField           = runtimeMetadataReferenceResolverType?.GetField(FileReferenceProviderField, BindingFlags.Instance | BindingFlags.NonPublic);
                fileReferenceProviderField.SetValue(runtimeMetadataReferenceResolverValue, new Func <string, MetadataReferenceProperties, PortableExecutableReference>((path, properties) =>
                {
                    var documentationFile     = Path.ChangeExtension(path, ".xml");
                    var documentationProvider = File.Exists(documentationFile)
                        ? XmlDocumentationProvider.CreateFromFile(documentationFile)
                        : null;

                    return(MetadataReference.CreateFromFile(path, properties, documentationProvider));
                }));
            }
        }
Ejemplo n.º 12
0
 public NuGetScriptMetadataResolver(NuGetConfiguration nuGetConfiguration, string workingDirectory)
 {
     _nuGetConfiguration = nuGetConfiguration;
     _inner = ScriptMetadataResolver.Default.WithBaseDirectory(workingDirectory);
 }
Ejemplo n.º 13
0
 public LinqPadResolver(ImmutableArray <string> searchPaths, string baseDirectory)
 {
     this.resolver = ScriptMetadataResolver.Default.WithSearchPaths(searchPaths).WithBaseDirectory(baseDirectory);
 }
Ejemplo n.º 14
0
 public NuGetScriptMetadataResolver(INuGetProvider nuGetProvider)
 {
     _nuGetProvider = nuGetProvider;
     _inner         = ScriptMetadataResolver.Default;
 }
Ejemplo n.º 15
0
 public ScriptExecutor()
 {
     scriptMetadataResolver = ScriptMetadataResolver.Default
                              .WithBaseDirectory(Environment.CurrentDirectory);
 }
 public NuGetScriptMetadataResolver(INuGetProvider nuGetProvider, string workingDirectory)
 {
     _nuGetProvider = nuGetProvider;
     _inner = ScriptMetadataResolver.Default.WithBaseDirectory(workingDirectory);
 }