public SequenceScript AddScriptToSequence(String sequenceId, String scriptId, ScriptType scriptType, String scriptName, Dictionary <String, String> parameters) { Sequence sequence = _sequenceDataAccess.Get(sequenceId); Script script = _scriptDataAccess.Get(scriptId); if ((sequence != null) && (script != null)) { IGhostRunnerScript ghostRunnerScript = ScriptHelper.GetGhostRunnerScript(script); int scriptPosition = _sequenceScriptDataAccess.GetNextPosition(sequenceId); if (scriptPosition < 1) { scriptPosition = 1; } SequenceScript sequenceScript = new SequenceScript(); sequenceScript.ExternalId = System.Guid.NewGuid().ToString(); sequenceScript.Sequence = sequence; sequenceScript.Type = scriptType; sequenceScript.Name = scriptName; sequenceScript.Content = script.Content; foreach (String scriptParameter in ghostRunnerScript.GetAllParameters()) { String parameterValue = String.Empty; if (parameters.ContainsKey(scriptParameter)) { parameterValue = parameters[scriptParameter]; } sequenceScript.Content = Regex.Replace(sequenceScript.Content, "\\[\\[" + scriptParameter + "\\]\\]", parameterValue); } sequenceScript.Position = scriptPosition; _sequenceScriptDataAccess.Insert(sequenceScript); _sequenceScriptDataAccess.UpdateScriptOrder(sequenceId); return(sequenceScript); } else { return(null); } }
// GET get task parameters public String[] Get(String id) { Script script = _scriptService.GetScript(id); if (script != null) { IGhostRunnerScript ghostRunnerScript = ScriptHelper.GetGhostRunnerScript(script); if (ghostRunnerScript.HasParameters()) { return(ghostRunnerScript.GetAllParameters()); } else { return(new String[0]); } } else { return(new String[0]); } }
// POST create a new task public String Post(String id, JObject parameters) { String itemId = String.Empty; Script script = _scriptService.GetScript(id); if (script != null) { IGhostRunnerScript ghostRunnerScript = ScriptHelper.GetGhostRunnerScript(script); IList <TaskScriptParameter> taskParameters = new List <TaskScriptParameter>(); if (ghostRunnerScript.HasParameters()) { foreach (String parameter in ghostRunnerScript.GetAllParameters()) { if (parameters[parameter] != null) { TaskScriptParameter taskParameter = new TaskScriptParameter(); taskParameter.Name = parameter; taskParameter.Value = parameters[parameter].ToString(); taskParameters.Add(taskParameter); } } } Task task = _taskService.InsertScriptTask(id, script.Name, taskParameters); if (task != null) { return(task.ExternalId); } else { return(string.Empty); } } else { Sequence sequence = _sequenceService.GetSequence(id); if (sequence != null) { Task task = _taskService.InsertSequenceTask(id, sequence.Name); if (task != null) { return(task.ExternalId); } else { return(string.Empty); } } else { return(String.Empty); } } }