/// <summary> /// Gather data for request. Prepare class structure for serialization. /// Names of inputs are NOT random but required like this. /// </summary> /// <param name="inputdata">points to input dataset, like csv file</param> /// <param name="outputData">points to output blob .ilearner file used later to update predictive web service</param> private BatchExecutionRequest PrepareRequest(AzureStorageData inputdata, AzureStorageData outputData) { return(new BatchExecutionRequest { Inputs = new Dictionary <string, AzureBlobDataReference> { { "input2", new AzureBlobDataReference { ConnectionString = inputdata.DataConnectionString, RelativeLocation = $"{inputdata.ContainerName}/{inputdata.BlobName}" } }, }, Outputs = new Dictionary <string, AzureBlobDataReference> { { "output2", new AzureBlobDataReference { ConnectionString = outputData.DataConnectionString, RelativeLocation = $"{outputData.ContainerName}/{outputData.BlobName}" } } }, GlobalParameters = new Dictionary <string, string>() }); }
/// <summary> /// Retrain method. /// Prepares request based in input and output /// With usage of HttpClient POSTs this request to WebService /// Starts retrain job, monitors status /// Returns Tuple with message string as Item1 and collection of BlobData for each .ilearner file created. /// When error appears, message contains error details and collection is null. /// </summary> /// <param name="inputStorageData"></param> /// <param name="outputStorageData"></param> /// <returns></returns> public async Task <Tuple <string, IEnumerable <AzureBlobDataReference> > > Retrain(AzureStorageData inputStorageData, AzureStorageData outputStorageData) { var request = PrepareRequest(inputStorageData, outputStorageData); using (var client = new HttpClient()) { client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", ApiKey); // submit var response = await client.PostAsJsonAsync(ServiceJobsUrl + "?api-version=2.0", request); if (!response.IsSuccessStatusCode) { return(new Tuple <string, IEnumerable <AzureBlobDataReference> >(await Utilities.GetFailedResponse(response), null)); } var jobId = await response.Content.ReadAsAsync <string>(); var jobLocation = ServiceJobsUrl + "/" + jobId + "?api-version=2.0"; // if submitted correctly, start retraining job response = await client.PostAsync(ServiceJobsUrl + "/" + jobId + "/start?api-version=2.0", null); if (!response.IsSuccessStatusCode) { return(new Tuple <string, IEnumerable <AzureBlobDataReference> >(await Utilities.GetFailedResponse(response), null)); } return(await MonitorProgress(client, jobId, jobLocation)); } }