forked from scriptcs/scriptcs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
58 lines (49 loc) · 1.82 KB
/
Program.cs
File metadata and controls
58 lines (49 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition.Hosting;
using System.Linq;
using System.Text;
using Roslyn.Compilers;
using Roslyn.Scripting;
using Roslyn.Scripting.CSharp;
using System.IO;
namespace Scriptcs
{
internal class Program
{
private static void Main(string[] args)
{
if (args.Length == 0)
{
Console.WriteLine("Usage:\r\n\r\nscriptcs [file] [recipe1] [recipe2] ...\r\n");
return;
}
var script = args[0];
var recipes = new List<string>();
if (args.Length > 1)
{
for (int i = 1; i <= args.Length; i++)
{
recipes.Add(args[i]);
}
}
var container = ConfigureMef();
var fileSystem = container.GetExportedValue<IFileSystem>();
var resolver = container.GetExportedValue<IPackageAssemblyResolver>();
var paths = resolver.GetAssemblyNames();
var executor = container.GetExportedValue<IScriptExecutor>();
var recipeManager = new RecipeManager(container);
executor.Execute(script, paths, recipeManager.GetReceipes(recipes));
}
private static CompositionContainer ConfigureMef()
{
var catalog = new AggregateCatalog();
catalog.Catalogs.Add(new AssemblyCatalog(typeof(Program).Assembly));
var recipesFolder = AppDomain.CurrentDomain.BaseDirectory + @"\Recipes";
if (!Directory.Exists(recipesFolder))
Directory.CreateDirectory(recipesFolder);
catalog.Catalogs.Add(new DirectoryCatalog(AppDomain.CurrentDomain.BaseDirectory + @"\Recipes"));
return new CompositionContainer(catalog);
}
}
}