static void Main(string[] args) { // Create a Service Pricipal Authentication object using the Tenant, ClientId and ClientSecret. // To learn how to create an Azure Service Principal see here: // https://docs.microsoft.com/en-us/azure/active-directory/develop/howto-create-service-principal-portal ServicePrincipalAuthentication spa = new ServicePrincipalAuthentication(Tenant, ClientId, ClientSecret); // Create the batch pipeline URL helper. REad the top of PipelineUrl file to understand what it's doing. BatchPipelineUrl pipelineUrl = new BatchPipelineUrl(PipelineUrl); // Retreive the AAD Token for the Service Principal Console.WriteLine("Collecting AAD token......"); String aadToken = spa.GetToken().Result; /// /// Get the status' of all the pipeline runs /// Console.WriteLine("Start the pipeline......"); PipelineRequest start = pipelineUrl.GetJobTrigger(); RunResult startResult = RestRequest.StartBatchJob <RunResult>(start, aadToken, BatchStartPayload); Console.WriteLine("***** JOB START ************"); Console.WriteLine(String.Format("Succesful start : {0}", startResult.IsStarted())); if (startResult.IsStarted()) { Console.WriteLine(String.Format("Run ID : {0}", startResult.Id)); } /// /// Get the status' of all the pipeline runs /// Console.WriteLine("Collecting all Pipeline Runs......"); PipelineRequest prAll = pipelineUrl.GetRunStatus(); List <RunResult> rr = RestRequest.GetRunResults <List <RunResult> >(prAll, aadToken); Console.WriteLine("***** MULTIPLE RUNS ************"); foreach (RunResult r in rr) { ReportOnRun(r); } /// /// Get the status of a single pipeline run /// if (rr.Count > 0) { Console.WriteLine("Collecting one Pipeline Run......"); string runId = rr[rr.Count - 1].Id; PipelineRequest prOne = pipelineUrl.GetRunStatus(runId); RunResult sr = RestRequest.GetRunResults <RunResult>(prOne, aadToken); Console.WriteLine("***** SINGLE RUN ************"); ReportOnRun(sr); } Console.WriteLine("COMPLETE - ENTER TO QUIT"); Console.ReadLine(); }
/// <summary> /// Get the results of a run or batch of runs /// </summary> /// <typeparam name="T">List<RunResult> or RunResult</RunResult></typeparam> /// <param name="requestInfo">Info for retrieving one or many run results</param> /// <param name="authToken">AAD Token for SP</param> /// <returns>Results of the call as a T or null on failure. </returns> public static T GetRunResults <T>(PipelineRequest requestInfo, string authToken) where T : class, new() { RestResponse rr = RestRequest.MakeRequest(requestInfo, authToken).Result; if (rr.Content != null && rr.Content.Length > 0) { return(Newtonsoft.Json.JsonConvert.DeserializeObject <T>(rr.Content)); } return(null); }
/// <summary> /// Start an experiment and get the results. /// </summary> /// <typeparam name="T">Type of object to retrieve</typeparam> /// <param name="requestInfo">Info for retrieving one or many run results</param> /// <param name="authToken">AAD Token for SP</param> /// <param name="payload">Job start body - {"ExperimentName" : "NAME"} </param> /// <returns>Results of the call as a T or null on failure. </returns> public static T StartBatchJob <T>(PipelineRequest requestInfo, string authToken, string payload) where T : class, new() { RestResponse rr = RestRequest.MakeRequest(requestInfo, authToken, payload, "application/json").Result; if (rr.Content != null && rr.Content.Length > 0) { return(Newtonsoft.Json.JsonConvert.DeserializeObject <T>(rr.Content)); } return(null); }
/// <summary> /// Get the appropriate HTTP Method and URL to get all job status'. /// </summary> public PipelineRequest GetRunStatus() { PipelineRequest returnRequest = new PipelineRequest() { Method = System.Net.Http.HttpMethod.Get, Url = this.BaseUrl + "/Pipeline/" + this.PipelineId }; return(returnRequest); }
/// <summary> /// Get the appropriate HTTP Method and URL to trigger a job. /// </summary> public PipelineRequest GetJobTrigger() { PipelineRequest returnRequest = new PipelineRequest() { Method = System.Net.Http.HttpMethod.Post, Url = this.ProvidedUrl }; return(returnRequest); }
/// <summary> /// Get the appropriate HTTP Method and URL to get a single job status. /// </summary> public PipelineRequest GetRunStatus(string jobRun) { PipelineRequest returnRequest = new PipelineRequest() { Method = System.Net.Http.HttpMethod.Get, Url = this.BaseUrl + "/" + jobRun }; return(returnRequest); }