public ActionResult Index(SAJobConfigModel saJobConfig) { if (ModelState.IsValid) { DeployASJob(saJobConfig); return(RedirectToAction("About")); } return(View(saJobConfig)); }
private void DeployASJob(SAJobConfigModel cfg) { // Get authentication token TokenCloudCredentials aadTokenCredentials = new TokenCloudCredentials(cfg.subscriptionID, GetAuthorizationHeader()); // Create Stream Analytics management client StreamAnalyticsManagementClient client = new StreamAnalyticsManagementClient(aadTokenCredentials); // Create a Stream Analytics job JobCreateOrUpdateParameters jobCreateParameters = new JobCreateOrUpdateParameters() { Job = new Job() { Name = cfg.streamAnalyticsJobName, Location = cfg.location, Properties = new JobProperties() { EventsOutOfOrderPolicy = EventsOutOfOrderPolicy.Adjust, Sku = new Sku() { Name = "Standard" } } } }; JobCreateOrUpdateResponse jobCreateResponse = client.StreamingJobs.CreateOrUpdate(cfg.resourceGroupName, jobCreateParameters); TempData["jobName"] = jobCreateResponse.Job.Name; TempData["jobCreationStatus"] = jobCreateResponse.StatusCode; // Create a Stream Analytics input source InputCreateOrUpdateParameters jobInputCreateParameters = new InputCreateOrUpdateParameters() { Input = new Input() { Name = cfg.streamAnalyticsInputName, Properties = new StreamInputProperties() { Serialization = new CsvSerialization { Properties = new CsvSerializationProperties { Encoding = "UTF8", FieldDelimiter = "," } }, DataSource = new EventHubStreamInputDataSource { Properties = new EventHubStreamInputDataSourceProperties { EventHubName = cfg.EventHubName, ServiceBusNamespace = cfg.ServiceBusNamespace, SharedAccessPolicyKey = cfg.SharedAccessPolicyKey, SharedAccessPolicyName = cfg.SharedAccessPolicyName, } } } } }; InputCreateOrUpdateResponse inputCreateResponse = client.Inputs.CreateOrUpdate(cfg.resourceGroupName, cfg.streamAnalyticsJobName, jobInputCreateParameters); TempData["jobInputName"] = inputCreateResponse.Input.Name; TempData["jobInputCreationStatus"] = inputCreateResponse.StatusCode; }