Exemplo n.º 1
0
 public virtual void StartBatchJob(BatchJobRequest request)
 {
     try
     {
         Task.Run(async() => await RecommendationsRepository.StartBatchJobAsync(request));
     }
     catch (Exception ex)
     {
         Logger.Error("RecommendationsService.StartBatchJob failed", this, ex);
     }
 }
Exemplo n.º 2
0
 public virtual void StartBatchJob(BatchJobRequest request)
 {
     try
     {
         RecommendationsRepository.StartBatchJob(request);
     }
     catch (Exception ex)
     {
         Logger.Error("RecommendationsService.StartBatchJob failed", this, ex);
     }
 }
 public virtual void StartBatchJob(BatchJobRequest request)
 {
     PolicyService.ExecuteRetryAndCapture400Errors(
         "RecommendationsService.StartBatchJob",
         ApiKeys.RecommendationsRetryInSeconds,
         () =>
     {
         RecommendationsRepository.StartBatchJob(request);
         return(true);
     },
         false);
 }
        async Task InvokeBatchExecutionService(string accountNameInput, string accountKeyInput, string containerInput, string inputBlobName, string inputFileName, OutputObject outputObj)
        {
            // Upload file to Blob if pathFile given

            if (isHasInput && input_radio_File.Checked)
            {
                accountNameInput = outputObj.AccountName;
                if (string.IsNullOrEmpty(accountNameInput))
                {
                    //Console.WriteLine("Upload Error");
                    ShowError("Please enter Account Name");
                    return;
                }
                accountKeyInput = outputObj.AccountKey;
                if (string.IsNullOrEmpty(accountKeyInput))
                {
                    //Console.WriteLine("Upload Error");
                    ShowError("Please enter Account Key");
                    return;
                }
                containerInput = outputObj.Container;
                if (string.IsNullOrEmpty(containerInput))
                {
                    //Console.WriteLine("Upload Error");
                    ShowError("Please enter Container Name");
                    return;
                }
                

                if (string.IsNullOrEmpty(_fileUpload.FileName))
                {
                    //Console.WriteLine("Upload Error");
                    ShowError("Please choose input file");
                    return;
                }

                inputBlobName = inputFileName;

                //ScriptManager.RegisterStartupScript(Page, Page.GetType(), "disable", "$(\"#btnclear\").prop(\"disabled\",true);", true);

                bool uploadresult = await uploadBigFile(accountNameInput, accountKeyInput, containerInput, inputFileName);
                //$("#btnclear").prop("disabled",true)
                
                if (!uploadresult)
                {
                    //Console.WriteLine("Upload Error");
                    ShowError("Upload Error");
                    return;
                }
                
            }

            // First collect and fill in the URI and access key for your web service endpoint.
            // These are available on your service's API help page.
            var endpointUri = paramObj.Url;
            string accessKey = Crypto.DecryptStringAES(paramObj.APIKey);

            // Create an Azure Machine Learning runtime client for this endpoint
            var runtimeClient = new RuntimeClient(endpointUri, accessKey);

            // Define the request information for your batch job. This information can contain:
            // -- A reference to the AzureBlob containing the input for your job run
            // -- A set of values for global parameters defined as part of your experiment and service
            // -- A set of output blob locations that allow you to redirect the job's results

            // NOTE: This sample is applicable, as is, for a service with explicit input port and
            // potential global parameters. Also, we choose to also demo how you could override the
            // location of one of the output blobs that could be generated by your service. You might 
            // need to tweak these features to adjust the sample to your service.
            //
            // All of these properties of a BatchJobRequest shown below can be optional, depending on
            // your service, so it is not required to specify all with any request.  If you do not want to
            // use any of the parameters, a null value should be passed in its place.

            // Define the reference to the blob containing your input data. You can refer to this blob by its
            // connection string / container / blob name values; alternatively, we also support references 
            // based on a blob SAS URI

            string ext = ".csv";//inputBlobName.Substring(inputBlobName.LastIndexOf("."));

            BlobReference inputBlob;
            if (isHasInput)
            {
                inputBlob = BlobReference.CreateFromConnectionStringData(
                connectionString: string.Format("DefaultEndpointsProtocol=https;AccountName={0};AccountKey={1}", accountNameInput, accountKeyInput),
                containerName: containerInput,
                blobName: inputBlobName);
                ext = inputBlobName.Substring(inputBlobName.LastIndexOf("."));
            }
            else inputBlob = null;


            
            // If desired, one can override the location where the job outputs are to be stored, by passing in
            // the storage account details and name of the blob where we want the output to be redirected to.

            var outputLocations = new Dictionary<string, BlobReference>();
           
                foreach (var keyvalue in outputObj.NodeOutputName)
                {
                    outputLocations.Add(

                        keyvalue.Key,
                        BlobReference.CreateFromConnectionStringData(
                            connectionString: string.Format("DefaultEndpointsProtocol=https;AccountName={0};AccountKey={1}", outputObj.AccountName, outputObj.AccountKey),
                            containerName: outputObj.Container,
                            blobName: !outputObj.isAddTime ? keyvalue.Value + "_" + DateTime.Now.ToString("MMddyy_hhmmss") + ext : keyvalue.Value + ext
                    ));

                };
          

            // If applicable, you can also set the global parameters for your service
            var globalParameters = new Dictionary<string, string>();
            foreach(var global in paramObj.listGlobalParameter)
            {
                
                string columnValue = "";
                var control = FindControl(global.Name);
                if (control is TextBox)
                {
                    TextBox txt = control as TextBox;
                    if (txt.Text != "")
                        columnValue = txt.Text;
                }
                else if (control is DropDownList)
                {
                    DropDownList lb = control as DropDownList;
                    if (lb.SelectedIndex != -1)
                        columnValue = lb.SelectedValue;
                }
                if (control is RadioButtonList)
                {
                    RadioButtonList ct = control as RadioButtonList;
                    if (ct.SelectedIndex != -1)
                        columnValue = ct.SelectedValue;
                }
                globalParameters.Add(global.Name, columnValue);
            }
            

            var jobRequest = new BatchJobRequest
            {
                Input = inputBlob,
                GlobalParameters = globalParameters,
                Outputs = outputLocations
            };

            try
            {
                // Register the batch job with the system, which will grant you access to a job object
                BatchJob job = await runtimeClient.RegisterBatchJobAsync(jobRequest);

                AddJobIdCookie(job.Id, job.CreatedAt.ToLocalTime().ToString());

                // Start the job to allow it to be scheduled in the running queue
                await job.StartAsync();

                //ScriptManager.RegisterStartupScript(Page, typeof(Page), "OpenWindow", "window.open('Status.aspx?jobid=" + job.Id + "');", true);
                

                Response.Redirect("Status.aspx?jobid=" + job.Id);

                // Wait for the job's completion and handle the output

                //BatchJobStatus jobStatus = await job.WaitForCompletionAsync();
                //while (job.CheckStatus().JobState != JobState.Finished && job.CheckStatus().JobState != JobState.Failed)
                //{
                //    Console.WriteLine(job.Id + ":" + job.CreatedAt.ToLocalTime() + job.CheckStatus().JobState);
                //}

                //BatchJobStatus jobStatus = job.CheckStatus();
                ////job.CreatedAt
                //if (jobStatus.JobState == JobState.Finished)
                //{
                //    // Process job outputs
                //    //Console.WriteLine(@"Job {0} has completed successfully and returned {1} outputs", job.Id, jobStatus.Results.Count);
                //    lblJobIdSuccess.Text = job.Id;
                //    ScriptManager.RegisterStartupScript(Page, Page.GetType(), "CompleteSuccess", "$('#CompleteSuccess').modal();", true);

                //    foreach (var output in jobStatus.Results)
                //    {
                //        //Console.WriteLine(@"\t{0}: {1}", output.Key, output.Value.AbsoluteUri);
                //        Response.Redirect(output.Value.AbsoluteUri);

                //    }
                //}
                //else if (jobStatus.JobState == JobState.Failed)
                //{
                //    // Handle job failure
                //    //Console.WriteLine(@"Job {0} has failed with this error: {1}", job.Id, jobStatus.Details);
                //    txtresultModal.Text = jobStatus.Details;
                //    ScriptManager.RegisterStartupScript(Page, Page.GetType(), "failModal", "$('#failModal').modal();", true);
                //}
            }
            catch (ArgumentException ex)
            {
                //Console.WriteLine("Argument {0} is invalid: {1}", aex.ParamName, aex.Message);
                //txtresultModal.Text = ex.Message;
                //ScriptManager.RegisterStartupScript(Page, Page.GetType(), "failModal", "$('#failModal').modal();", true);
                ShowError(ex.Message);
            }
            catch (RuntimeException runtimeError)
            {
                //Console.WriteLine("Runtime error occurred: {0} - {1}", runtimeError.ErrorCode, runtimeError.Message);
                //Console.WriteLine("Error details:");
                string error = "";
                foreach (var errorDetails in runtimeError.Details)
                {
                    error += string.Format("\t{0} - {1}", errorDetails.Code, errorDetails.Message);
                }
                //txtresultModal.Text = error;
                //ScriptManager.RegisterStartupScript(Page, Page.GetType(), "failModal", "$('#failModal').modal();", true);
                ShowError(error);
            }
            catch (Exception ex)
            {
                //Console.WriteLine("Unexpected error occurred: {0} - {1}", ex.GetType().Name, ex.Message);
                //txtresultModal.Text = ex.Message;
                //ScriptManager.RegisterStartupScript(Page, Page.GetType(), "failModal", "$('#failModal').modal();", true);
                ShowError(ex.Message);
            }
        }
Exemplo n.º 5
0
        async Task InvokeBatchExecutionService(string accountNameInput, string accountKeyInput, string containerInput, string inputBlobName, string inputFileName, OutputObject outputObj)
        {
            // Upload file to Blob if pathFile given

            if (isHasInput && input_radio_File.Checked)
            {
                accountNameInput = outputObj.AccountName;
                if (string.IsNullOrEmpty(accountNameInput))
                {
                    //Console.WriteLine("Upload Error");
                    ShowError("Please enter Account Name");
                    return;
                }
                accountKeyInput = outputObj.AccountKey;
                if (string.IsNullOrEmpty(accountKeyInput))
                {
                    //Console.WriteLine("Upload Error");
                    ShowError("Please enter Account Key");
                    return;
                }
                containerInput = outputObj.Container;
                if (string.IsNullOrEmpty(containerInput))
                {
                    //Console.WriteLine("Upload Error");
                    ShowError("Please enter Container Name");
                    return;
                }


                if (string.IsNullOrEmpty(_fileUpload.FileName))
                {
                    //Console.WriteLine("Upload Error");
                    ShowError("Please choose input file");
                    return;
                }

                inputBlobName = inputFileName;

                //ScriptManager.RegisterStartupScript(Page, Page.GetType(), "disable", "$(\"#btnclear\").prop(\"disabled\",true);", true);

                bool uploadresult = await uploadBigFile(accountNameInput, accountKeyInput, containerInput, inputFileName);

                //$("#btnclear").prop("disabled",true)

                if (!uploadresult)
                {
                    //Console.WriteLine("Upload Error");
                    ShowError("Upload Error");
                    return;
                }
            }

            // First collect and fill in the URI and access key for your web service endpoint.
            // These are available on your service's API help page.
            var    endpointUri = paramObj.Url;
            string accessKey   = Crypto.DecryptStringAES(paramObj.APIKey);

            // Create an Azure Machine Learning runtime client for this endpoint
            var runtimeClient = new RuntimeClient(endpointUri, accessKey);

            // Define the request information for your batch job. This information can contain:
            // -- A reference to the AzureBlob containing the input for your job run
            // -- A set of values for global parameters defined as part of your experiment and service
            // -- A set of output blob locations that allow you to redirect the job's results

            // NOTE: This sample is applicable, as is, for a service with explicit input port and
            // potential global parameters. Also, we choose to also demo how you could override the
            // location of one of the output blobs that could be generated by your service. You might
            // need to tweak these features to adjust the sample to your service.
            //
            // All of these properties of a BatchJobRequest shown below can be optional, depending on
            // your service, so it is not required to specify all with any request.  If you do not want to
            // use any of the parameters, a null value should be passed in its place.

            // Define the reference to the blob containing your input data. You can refer to this blob by its
            // connection string / container / blob name values; alternatively, we also support references
            // based on a blob SAS URI

            string ext = ".csv";//inputBlobName.Substring(inputBlobName.LastIndexOf("."));

            BlobReference inputBlob;

            if (isHasInput)
            {
                inputBlob = BlobReference.CreateFromConnectionStringData(
                    connectionString: string.Format("DefaultEndpointsProtocol=https;AccountName={0};AccountKey={1}", accountNameInput, accountKeyInput),
                    containerName: containerInput,
                    blobName: inputBlobName);
                ext = inputBlobName.Substring(inputBlobName.LastIndexOf("."));
            }
            else
            {
                inputBlob = null;
            }



            // If desired, one can override the location where the job outputs are to be stored, by passing in
            // the storage account details and name of the blob where we want the output to be redirected to.

            var outputLocations = new Dictionary <string, BlobReference>();

            foreach (var keyvalue in outputObj.NodeOutputName)
            {
                outputLocations.Add(

                    keyvalue.Key,
                    BlobReference.CreateFromConnectionStringData(
                        connectionString: string.Format("DefaultEndpointsProtocol=https;AccountName={0};AccountKey={1}", outputObj.AccountName, outputObj.AccountKey),
                        containerName: outputObj.Container,
                        blobName: !outputObj.isAddTime ? keyvalue.Value + "_" + DateTime.Now.ToString("MMddyy_hhmmss") + ext : keyvalue.Value + ext
                        ));
            }
            ;


            // If applicable, you can also set the global parameters for your service
            var globalParameters = new Dictionary <string, string>();

            foreach (var global in paramObj.listGlobalParameter)
            {
                string columnValue = "";
                var    control     = FindControl(global.Name);
                if (control is TextBox)
                {
                    TextBox txt = control as TextBox;
                    if (txt.Text != "")
                    {
                        columnValue = txt.Text;
                    }
                }
                else if (control is DropDownList)
                {
                    DropDownList lb = control as DropDownList;
                    if (lb.SelectedIndex != -1)
                    {
                        columnValue = lb.SelectedValue;
                    }
                }
                if (control is RadioButtonList)
                {
                    RadioButtonList ct = control as RadioButtonList;
                    if (ct.SelectedIndex != -1)
                    {
                        columnValue = ct.SelectedValue;
                    }
                }
                globalParameters.Add(global.Name, columnValue);
            }


            var jobRequest = new BatchJobRequest
            {
                Input            = inputBlob,
                GlobalParameters = globalParameters,
                Outputs          = outputLocations
            };

            try
            {
                // Register the batch job with the system, which will grant you access to a job object
                BatchJob job = await runtimeClient.RegisterBatchJobAsync(jobRequest);

                AddJobIdCookie(job.Id, job.CreatedAt.ToLocalTime().ToString());

                // Start the job to allow it to be scheduled in the running queue
                await job.StartAsync();

                //ScriptManager.RegisterStartupScript(Page, typeof(Page), "OpenWindow", "window.open('Status.aspx?jobid=" + job.Id + "');", true);


                Response.Redirect("Status.aspx?jobid=" + job.Id);

                // Wait for the job's completion and handle the output

                //BatchJobStatus jobStatus = await job.WaitForCompletionAsync();
                //while (job.CheckStatus().JobState != JobState.Finished && job.CheckStatus().JobState != JobState.Failed)
                //{
                //    Console.WriteLine(job.Id + ":" + job.CreatedAt.ToLocalTime() + job.CheckStatus().JobState);
                //}

                //BatchJobStatus jobStatus = job.CheckStatus();
                ////job.CreatedAt
                //if (jobStatus.JobState == JobState.Finished)
                //{
                //    // Process job outputs
                //    //Console.WriteLine(@"Job {0} has completed successfully and returned {1} outputs", job.Id, jobStatus.Results.Count);
                //    lblJobIdSuccess.Text = job.Id;
                //    ScriptManager.RegisterStartupScript(Page, Page.GetType(), "CompleteSuccess", "$('#CompleteSuccess').modal();", true);

                //    foreach (var output in jobStatus.Results)
                //    {
                //        //Console.WriteLine(@"\t{0}: {1}", output.Key, output.Value.AbsoluteUri);
                //        Response.Redirect(output.Value.AbsoluteUri);

                //    }
                //}
                //else if (jobStatus.JobState == JobState.Failed)
                //{
                //    // Handle job failure
                //    //Console.WriteLine(@"Job {0} has failed with this error: {1}", job.Id, jobStatus.Details);
                //    txtresultModal.Text = jobStatus.Details;
                //    ScriptManager.RegisterStartupScript(Page, Page.GetType(), "failModal", "$('#failModal').modal();", true);
                //}
            }
            catch (ArgumentException ex)
            {
                //Console.WriteLine("Argument {0} is invalid: {1}", aex.ParamName, aex.Message);
                //txtresultModal.Text = ex.Message;
                //ScriptManager.RegisterStartupScript(Page, Page.GetType(), "failModal", "$('#failModal').modal();", true);
                ShowError(ex.Message);
            }
            catch (RuntimeException runtimeError)
            {
                //Console.WriteLine("Runtime error occurred: {0} - {1}", runtimeError.ErrorCode, runtimeError.Message);
                //Console.WriteLine("Error details:");
                string error = "";
                foreach (var errorDetails in runtimeError.Details)
                {
                    error += string.Format("\t{0} - {1}", errorDetails.Code, errorDetails.Message);
                }
                //txtresultModal.Text = error;
                //ScriptManager.RegisterStartupScript(Page, Page.GetType(), "failModal", "$('#failModal').modal();", true);
                ShowError(error);
            }
            catch (Exception ex)
            {
                //Console.WriteLine("Unexpected error occurred: {0} - {1}", ex.GetType().Name, ex.Message);
                //txtresultModal.Text = ex.Message;
                //ScriptManager.RegisterStartupScript(Page, Page.GetType(), "failModal", "$('#failModal').modal();", true);
                ShowError(ex.Message);
            }
        }
Exemplo n.º 6
0
 public async Task StartBatchJobAsync(BatchJobRequest request)
 {
     await SendPostAsync(batchUrl, JsonConvert.SerializeObject(request));
 }
 public virtual async Task StartBatchJobAsync(BatchJobRequest request)
 {
     await RepositoryClient.SendJsonPostAsync(ApiKeys.Recommendations, batchUrl, JsonConvert.SerializeObject(request));
 }
 public virtual void StartBatchJob(BatchJobRequest request)
 {
     RepositoryClient.SendJsonPost(ApiKeys.Recommendations, batchUrl, JsonConvert.SerializeObject(request));
 }