//********************************************************************* /// /// <summary> /// This method returns a ScriptJob type /// </summary> /// <param name="scriptJob"></param> /// <param name="wapSubscriptionId"></param> /// <returns>ScriptJob</returns> /// //********************************************************************* public static ScriptJob SubmitScriptJob(ScriptJob scriptJob, string wapSubscriptionId) { if (scriptJob == null) { throw new ArgumentNullException("scriptJob"); } if (wapSubscriptionId == null) { throw new ArgumentNullException("wapSubscriptionId"); } try { var seqSpec = Convert(scriptJob); seqSpec = CmpClient.CmpScriptClient.ExecuteSmaScript(seqSpec); var sequenceRequest = new SequenceRequest { Active = true, CmpRequestID = 0, Config = seqSpec.Serialize(), ExceptionMessage = null, Id = 0, LastStatusUpdate = seqSpec.RunResult.LastUpdate, ServiceProviderJobId = seqSpec.RunResult.JobId, ServiceProviderName = seqSpec.SmaConfig.SmaServerUrl, ServiceProviderTypeCode = seqSpec.Engine, StatusCode = seqSpec.RunResult.StatusCode, StatusMessage = seqSpec.RunResult.StatusMessage, TagData = seqSpec.TagData, TagID = 0, TagOpName = seqSpec.SmaConfig.RunbookName, TargetName = scriptJob.TargetName, TargetTypeCode = scriptJob.TargetTypeCode, WapSubscriptionID = wapSubscriptionId, Warnings = null, WhenRequested = seqSpec.RunResult.WhenSubmitted, WhoRequested = null }; var cdb = new CmpWapDb(); sequenceRequest = cdb.InsertSequenceRequest(sequenceRequest); seqSpec.ID = sequenceRequest.Id; return(Convert(seqSpec)); } catch (Exception ex) { throw new Exception("ScriptInterface.SubmitScriptJob() : " + Utilities.UnwindExceptionMessages(ex)); } }
private void SubmitTest() { var subId = ""; var paramList = new List <ScriptJobPoshParamSpec> { new ScriptJobPoshParamSpec() { Name = "scriptblock", Value = "write-output get-process" }, new ScriptJobPoshParamSpec() { Name = "Computername", Value = "localhost" } }; var sj = new ScriptJob { BreakOn = CmpInterfaceModel.Models.SequenceSpec.BreakOnEnum.Exception.ToString(), Config = null, Engine = CmpInterfaceModel.Models.SequenceSpec.SequenceEngineEnum.SMA.ToString(), ExecuteInState = CmpInterfaceModel.Constants.StatusEnum.Submitted.ToString(), Waitmode = CmpInterfaceModel.Models.SequenceSpec.WaitmodeEnum.Synchronous.ToString(), ID = 1, Locale = CmpInterfaceModel.Models.SequenceSpec.SequenceLocaleEnum.Remote.ToString(), Name = "The Sequence Name", TagData = "<Tag Data>", ScriptList = null, SmaConfig = new ScriptJobSmaConfigSpec() { SmaServerUrl = "", RunbookId = "", RunbookName = "execute-scriptblock", ParamList = paramList } }; var sjc = new ScriptJobsController(); var sjOut = sjc.SubmitScriptJob(subId, sj); }
//********************************************************************* /// /// <summary> /// This method is used to convert to SequenceSpec type /// </summary> /// <param name="scriptJob"></param> /// <returns>SequenceSpec</returns> /// //********************************************************************* private static SequenceSpec Convert(ScriptJob scriptJob) { if (null == scriptJob) { return(null); } try { return(new SequenceSpec { BreakOn = scriptJob.BreakOn, Config = scriptJob.Config, Engine = scriptJob.Engine, ErrorList = scriptJob.ErrorList, ExecuteInState = scriptJob.ExecuteInState, ID = scriptJob.ID, Locale = scriptJob.Locale, Name = scriptJob.Name, ResultCode = scriptJob.ResultCode, RunResult = Convert(scriptJob.RunResult), ScriptList = scriptJob.ScriptList, SmaConfig = Convert(scriptJob.SmaConfig), TagData = scriptJob.TagData, TimeoutMinutes = scriptJob.TimeoutMinutes, Waitmode = scriptJob.Waitmode, TargetName = scriptJob.TargetName, TargetTypeCode = scriptJob.TargetTypeCode }); } catch (Exception ex) { throw new Exception("Exception in ScriptInterface.Convert() : " + CmpInterfaceModel.Utilities.UnwindExceptionMessages(ex)); } }
public IHttpActionResult SubmitScriptJob( string subscriptionId, [FromBody] ScriptJob scriptJob) { try { LogThis(EventLogEntryType.Information, "ScriptJob Submitted", 2, 1); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } scriptJob = ScriptInterface.SubmitScriptJob(scriptJob, subscriptionId); LogThis(EventLogEntryType.Information, "ScriptJob Submitted OK", 2, 2); return(Ok(scriptJob)); } catch (Exception ex) { LogThis(ex, EventLogEntryType.Error, "CmpWapExtension.ScriptJobsController.SubmitScriptJob()", 100, 1); return(InternalServerError(ex)); } }
public void Mute(bool muted) { ScriptJob job = ScriptEngine.CurrentJob; ScriptEngine.CurrentJob.muted = muted ? job.id : 0; }