public IHandler Create( IExecutionContext executionContext, Pipelines.ActionStepDefinitionReference action, IStepHost stepHost, ActionExecutionData data, Dictionary <string, string> inputs, Dictionary <string, string> environment, Variables runtimeVariables, string actionDirectory) { // Validate args. Trace.Entering(); ArgUtil.NotNull(executionContext, nameof(executionContext)); ArgUtil.NotNull(stepHost, nameof(stepHost)); ArgUtil.NotNull(data, nameof(data)); ArgUtil.NotNull(inputs, nameof(inputs)); ArgUtil.NotNull(environment, nameof(environment)); ArgUtil.NotNull(runtimeVariables, nameof(runtimeVariables)); // Create the handler. IHandler handler; if (data.ExecutionType == ActionExecutionType.Container) { handler = HostContext.CreateService <IContainerActionHandler>(); (handler as IContainerActionHandler).Data = data as ContainerActionExecutionData; } else if (data.ExecutionType == ActionExecutionType.NodeJS) { handler = HostContext.CreateService <INodeScriptActionHandler>(); (handler as INodeScriptActionHandler).Data = data as NodeJSActionExecutionData; } else if (data.ExecutionType == ActionExecutionType.Script) { handler = HostContext.CreateService <IScriptHandler>(); (handler as IScriptHandler).Data = data as ScriptActionExecutionData; } else if (data.ExecutionType == ActionExecutionType.Plugin) { // Runner plugin handler = HostContext.CreateService <IRunnerPluginHandler>(); (handler as IRunnerPluginHandler).Data = data as PluginActionExecutionData; } else { // This should never happen. throw new NotSupportedException(data.ExecutionType.ToString()); } handler.Action = action; handler.Environment = environment; handler.RuntimeVariables = runtimeVariables; handler.ExecutionContext = executionContext; handler.StepHost = stepHost; handler.Inputs = inputs; handler.ActionDirectory = actionDirectory; return(handler); }
public override object ReadJson( JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer) { if (reader.TokenType != JsonToken.StartObject) { return(null); } JObject value = JObject.Load(reader); if (value.TryGetValue("Type", StringComparison.OrdinalIgnoreCase, out JToken actionTypeValue)) { ActionSourceType actionType; if (actionTypeValue.Type == JTokenType.Integer) { actionType = (ActionSourceType)(Int32)actionTypeValue; } else if (actionTypeValue.Type != JTokenType.String || !Enum.TryParse((String)actionTypeValue, true, out actionType)) { return(null); } ActionStepDefinitionReference reference = null; switch (actionType) { case ActionSourceType.Repository: reference = new RepositoryPathReference(); break; case ActionSourceType.ContainerRegistry: reference = new ContainerRegistryReference(); break; case ActionSourceType.Script: reference = new ScriptReference(); break; } using (var objectReader = value.CreateReader()) { serializer.Populate(objectReader, reference); } return(reference); } else { return(null); } }