-
Notifications
You must be signed in to change notification settings - Fork 368
Expand file tree
/
Copy pathExecuteScriptCommandBase.cs
More file actions
88 lines (78 loc) · 3.14 KB
/
ExecuteScriptCommandBase.cs
File metadata and controls
88 lines (78 loc) · 3.14 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ScriptCs.Command;
using ScriptCs.Contracts;
namespace ScriptCs
{
public abstract class ExecuteScriptCommandBase
{
protected string Script { get; private set; }
protected IFileSystem FileSystem { get; private set; }
protected IScriptExecutor ScriptExecutor { get; private set; }
protected IScriptPackResolver _scriptPackResolver { get; private set; }
protected ILog Logger { get; private set; }
protected IAssemblyResolver AssemblyResolver { get; private set; }
protected IFileSystemMigrator FileSystemMigrator { get; private set; }
protected IScriptLibraryComposer Composer { get; private set; }
public ExecuteScriptCommandBase(
string script,
string[] scriptArgs,
IFileSystem fileSystem,
IScriptExecutor scriptExecutor,
IScriptPackResolver scriptPackResolver,
ILogProvider logProvider,
IAssemblyResolver assemblyResolver,
IFileSystemMigrator fileSystemMigrator,
IScriptLibraryComposer composer
)
{
Guard.AgainstNullArgument("fileSystem", fileSystem);
Guard.AgainstNullArgument("scriptExecutor", scriptExecutor);
Guard.AgainstNullArgument("scriptPackResolver", scriptPackResolver);
Guard.AgainstNullArgument("logProvider", logProvider);
Guard.AgainstNullArgument("assemblyResolver", assemblyResolver);
Guard.AgainstNullArgument("fileSystemMigrator", fileSystemMigrator);
Guard.AgainstNullArgument("composer", composer);
Script = script;
ScriptArgs = scriptArgs;
FileSystem = fileSystem;
ScriptExecutor = scriptExecutor;
_scriptPackResolver = scriptPackResolver;
Logger = logProvider.ForCurrentType();
AssemblyResolver = assemblyResolver;
FileSystemMigrator = fileSystemMigrator;
Composer = composer;
}
public string[] ScriptArgs { get; private set; }
public abstract CommandResult Execute();
protected CommandResult Inspect(ScriptResult result)
{
if (result == null)
{
return CommandResult.Error;
}
if (result.CompileExceptionInfo != null)
{
var ex = result.CompileExceptionInfo.SourceException;
Logger.ErrorException("Script compilation failed.", ex);
return CommandResult.Error;
}
if (result.ExecuteExceptionInfo != null)
{
var ex = result.ExecuteExceptionInfo.SourceException;
Logger.ErrorException("Script execution failed.", ex);
return CommandResult.Error;
}
if (!result.IsCompleteSubmission)
{
Logger.Error("The script is incomplete.");
return CommandResult.Error;
}
return CommandResult.Success;
}
}
}