private void CreateControl(string viewPath, bool createCodeBehind, DotvvmProjectMetadata dotvvmProjectMetadata) { var codeBehindPath = PathHelpers.ChangeExtension(viewPath, "cs"); var codeBehindClassName = NamingHelpers.GetClassNameFromPath(viewPath); var codeBehindClassNamespace = NamingHelpers.GetNamespaceFromPath(viewPath, dotvvmProjectMetadata.ProjectDirectory, dotvvmProjectMetadata.RootNamespace); // create control var controlTemplate = new ControlTemplate() { CreateCodeBehind = createCodeBehind }; if (createCodeBehind) { controlTemplate.CodeBehindClassName = codeBehindClassName; controlTemplate.CodeBehindClassNamespace = codeBehindClassNamespace; controlTemplate.CodeBehindClassRootNamespace = dotvvmProjectMetadata.RootNamespace; } FileSystemHelpers.WriteFile(viewPath, controlTemplate.TransformText()); // create code behind if (createCodeBehind) { var codeBehindTemplate = new ControlCodeBehindTemplate() { CodeBehindClassNamespace = codeBehindClassNamespace, CodeBehindClassName = codeBehindClassName }; FileSystemHelpers.WriteFile(codeBehindPath, codeBehindTemplate.TransformText()); } }
private void CreatePage(string viewPath, string masterPagePath, DotvvmProjectMetadata dotvvmProjectMetadata) { var viewModelPath = NamingHelpers.GenerateViewModelPath(viewPath); var viewModelName = NamingHelpers.GetClassNameFromPath(viewModelPath); var viewModelNamespace = NamingHelpers.GetNamespaceFromPath(viewModelPath, dotvvmProjectMetadata.ProjectDirectory, dotvvmProjectMetadata.RootNamespace); // create page var pageTemplate = new PageTemplate() { ViewModelRootNamespace = dotvvmProjectMetadata.RootNamespace, ViewModelName = viewModelName, ViewModelNamespace = viewModelNamespace, IsMasterPage = true }; if (!string.IsNullOrEmpty(masterPagePath)) { pageTemplate.EmbedInMasterPage = true; pageTemplate.MasterPageLocation = masterPagePath; pageTemplate.ContentPlaceHolderIds = new MasterPageBuilder().ExtractPlaceHolderIds(masterPagePath); } FileSystemHelpers.WriteFile(viewPath, pageTemplate.TransformText()); // create viewmodel var viewModelTemplate = new ViewModelTemplate() { ViewModelName = viewModelName, ViewModelNamespace = viewModelNamespace // TODO: BaseViewModel }; FileSystemHelpers.WriteFile(viewModelPath, viewModelTemplate.TransformText()); }
/// <summary> /// Creates a scheduled job to archive /// </summary> /// <param name="mediaChannel"></param> /// <param name="archivalProgram"></param> /// <param name="jobName"></param> /// <returns></returns> private async Task <Microsoft.WindowsAzure.Scheduler.Models.JobCreateOrUpdateResponse> CreateScheduledJob(IChannel mediaChannel, IProgram archivalProgram, string jobName) { var cloudServiceName = NamingHelpers.GetSchedulerCloudServiceName(ServiceConfiguration.MediaServiceAccountName); var cloudServiceLabel = NamingHelpers.GetSchedulerCloudServiceLabel(ServiceConfiguration.MediaServiceAccountName); var cloudServiceDescription = NamingHelpers.GetSchedulerCloudServiceDescription(ServiceConfiguration.MediaServiceAccountName); var jobCollectionName = NamingHelpers.GetSchedulerJobCollectionName(ServiceConfiguration.MediaServiceAccountName); var cloudServiceRegion = ServiceConfiguration.SchedulerRegion; var bodyParameters = new SchedulerParameters { ChannelId = mediaChannel.Id, ProgramId = archivalProgram.Id, JobName = jobName }; var headers = new Dictionary <string, string>() { { "Content-Type", "application/json" }, }; var nextProgramJob = await SchedulerService.CreateOneTimeHttpJobAsync( cloudServiceName, jobCollectionName, jobName, DateTime.UtcNow.AddMinutes(ServiceConfiguration.ArchivalWindowMinutes).AddMinutes(-1 * ServiceConfiguration.OverlappingArchivalWindowMinutes), bodyParameters, headers, "POST", ServiceConfiguration.ScheduleManagerEndpoint); return(nextProgramJob); }
public RunRequestProperty(MethodStructure methodStructure) : base("RunRequestProperty") { tagValues = new Dictionary <string, string> { { nameTag, methodStructure.IsRPC ? methodStructure.Name : NamingHelpers.GetRestfullMethodName(methodStructure) }, { urlTag, methodStructure.URL }, { methodTag, HttpHelpers.GetHTTPMethod(methodStructure) }, { parameterSourceBindingTag, HttpHelpers.GetRequestParametersSourceObject(methodStructure) }, { resultTypeTag, !methodStructure.Result.IsSytemType && methodStructure.Result.TypeName != null?Configuration.Instance.ModelsNameFactory(methodStructure.Result.TypeName) : "null" } }; }
public RunMethodRequest(MethodStructure methodStructure, string name) : base("RunMethodRequest") { tagValues = new Dictionary <string, string> { { controllerNameTag, name }, { nameTag, methodStructure.IsRPC ? methodStructure.Name : NamingHelpers.GetRestfullMethodName(methodStructure) }, { parameterTag, methodStructure.Parameters.GetCSV(x => x.Name) }, { requestObjectTag, methodStructure.Parameters.GetCSV(x => $"{x.Name}:{x.Name}") } }; childRenderbles.Add((JSRenderble)DI.Get <IRunRequestMethodComment>(methodStructure)); }
public RunMethodRequest(MethodStructure methodStructure) : base(Resources.runRequestMethod) { Name = methodStructure.IsRPC ? methodStructure.Name : NamingHelpers.GetRestfullMethodName(methodStructure); Comment = JSBuilderIOCContainer.Instance.CreateComment(); Comment.Description = $"Method to invoke request to {methodStructure.URL}. Method: {HttpHelpers.GetHTTPMethod(methodStructure)}."; Comment.Params = methodStructure.Parameters.ToDictionary(k => k.Name, v => JSTypeMapping.GetJSType(v)); Comment.ReturnType = JSTypeMapping.GetJSType(methodStructure.Result); Comment.ReturnType.IsPromise = true; Parameters = methodStructure.Parameters.Select(x => x.Name).ToList(); }
private void CreateViewModel(string viewModelPath, DotvvmProjectMetadata dotvvmProjectMetadata) { var viewModelName = NamingHelpers.GetClassNameFromPath(viewModelPath); var viewModelNamespace = NamingHelpers.GetNamespaceFromPath(viewModelPath, dotvvmProjectMetadata.ProjectDirectory, dotvvmProjectMetadata.RootNamespace); // create viewmodel var viewModelTemplate = new ViewModelTemplate() { ViewModelName = viewModelName, ViewModelNamespace = viewModelNamespace // TODO: BaseViewModel }; FileSystemHelpers.WriteFile(viewModelPath, viewModelTemplate.TransformText()); }
/// <summary> /// Prepares the scheduler /// </summary> /// <returns></returns> private async Task PrepareScheduler() { var cloudServiceName = NamingHelpers.GetSchedulerCloudServiceName(ServiceConfiguration.MediaServiceAccountName); var cloudServiceLabel = NamingHelpers.GetSchedulerCloudServiceLabel(ServiceConfiguration.MediaServiceAccountName); var cloudServiceDescription = NamingHelpers.GetSchedulerCloudServiceDescription(ServiceConfiguration.MediaServiceAccountName); var jobCollectionName = NamingHelpers.GetSchedulerJobCollectionName(ServiceConfiguration.MediaServiceAccountName); var cloudServiceRegion = ServiceConfiguration.SchedulerRegion; // Create Scheduler Service System.Diagnostics.Trace.TraceInformation("Preparing scheduler for Cloud Service [{0}], Job Collection[{1}]", cloudServiceName, jobCollectionName); var schedulerService = new SchedulerService(ServiceConfiguration); // Create Cloud Service for scheduler (if not exists, otheriwse, returns null) System.Diagnostics.Trace.TraceInformation("Creating Cloud Service for scheduler if it doesn't exist"); var cloudService = await schedulerService.CreateSchedulerCloudServiceIfNotExistsAsync(cloudServiceName, cloudServiceLabel, cloudServiceDescription, cloudServiceRegion); // Create a Job Collection (if not exists, otherwise, returns null) System.Diagnostics.Trace.TraceInformation("Creating Job Collection for scheduler if it doesn't exist"); var jobCollection = await schedulerService.CreateJobCollectionIfNotExistsAsync(cloudServiceName, jobCollectionName); }
// POST api/archives //[Authorize] public HttpResponseMessage Post(SchedulerParameters schedulerParameters) { System.Diagnostics.Trace.TraceInformation("Archiving requested for Channel ID [{0}], Program ID [{1}], Job Name [{2}]", schedulerParameters.ChannelId, schedulerParameters.ProgramId, schedulerParameters.JobName); // Fire and forget because otherwise, the scheduler will timeout after 30 seconds Task.Run(async() => { try { var cloudServiceName = NamingHelpers.GetSchedulerCloudServiceName(ServiceConfiguration.MediaServiceAccountName); var jobCollectionName = NamingHelpers.GetSchedulerJobCollectionName(ServiceConfiguration.MediaServiceAccountName); // Ensure that the scheduler is prepared await PrepareScheduler(); // Get the Channel by Channel Id var currentChannel = ChannelsService.GetChannel(schedulerParameters.ChannelId); System.Diagnostics.Trace.TraceInformation("Retrieved Channel [{0}] is {1}", schedulerParameters.ChannelId, currentChannel); // Update its cross domain access policy if needed ChannelsService.UpdateCrossSiteAccessPoliciesForChannelIfNeeded(currentChannel); // Identify what are we trying to do var runningPrograms = currentChannel.Programs.ToList().Where(p => p.State == Microsoft.WindowsAzure.MediaServices.Client.ProgramState.Running); var countOfRunningPrograms = runningPrograms.Count(); System.Diagnostics.Trace.TraceInformation("Channel [{0}] has [{1}] Running programs", schedulerParameters.ChannelId, countOfRunningPrograms); // If we have more than 2 programs (Default and Archival) running if (countOfRunningPrograms > 2) { // We are in an undefined state System.Diagnostics.Trace.TraceError("Channel [{0}] has [{1}] Running programs. This is an undefined state. Aborting.", schedulerParameters.ChannelId, countOfRunningPrograms); return; } // Now we got this out of the way // If we have no running programs if (countOfRunningPrograms == 0) { // Reset the channel try { System.Diagnostics.Trace.TraceError("Resetting Channel ID [{0}]"); await currentChannel.ResetAsync(); } catch (Exception ex) { System.Diagnostics.Trace.TraceError("Couldn't reset Channel ID [{0}]. \nException: {1}", currentChannel.Id, ex); } System.Diagnostics.Trace.TraceInformation("Starting DefaultProgram"); // Maybe we forgot to run the DefaultProgram from the portal, or deleted it // Start by creating the DefaultProgram then create the first ArchivalProgram and calling the scheduler var defaultProgram = await ChannelsService.CreateDefaultProgramIfNotExistsAsync(currentChannel, ServiceConfiguration.DefaultProgramArchivalWindowMinutes); } // Create an Archival Program System.Diagnostics.Trace.TraceInformation("Starting ArchivalProgram"); var archivalProgram = await ChannelsService.CreateArchivalProgramAsync(currentChannel, DateTime.UtcNow, ServiceConfiguration.ArchivalWindowMinutes, ServiceConfiguration.OverlappingArchivalWindowMinutes); var archivalJobName = NamingHelpers.GetArchivingJobName(currentChannel.Name); // Schedule the next job run System.Diagnostics.Trace.TraceInformation("Scheduling next job run"); var nextProgramJob = await CreateScheduledJob(currentChannel, archivalProgram, archivalJobName); // If we had 2 running programs, then we are trying to schedule the follow-up and toggle the archives if (nextProgramJob != null && countOfRunningPrograms == 2) { System.Diagnostics.Trace.TraceInformation("We had 2 running programs, then we are trying to schedule the follow-up and toggle the archives"); // Stop the current (old) program // Get the Program by Program Id System.Diagnostics.Trace.TraceInformation("Getting current program [{0}]", schedulerParameters.ProgramId); var currentProgram = ChannelsService.GetProgram(schedulerParameters.ProgramId); // Stop it System.Diagnostics.Trace.TraceInformation("Stopping current program [{0}]", schedulerParameters.ProgramId); await currentProgram.StopAsync(); System.Diagnostics.Trace.TraceInformation("Stopped [{0}]", schedulerParameters.ProgramId); } } catch (Exception ex) { System.Diagnostics.Trace.TraceError("Exception: {0}\n", ex); } }); return(Request.CreateResponse(HttpStatusCode.OK)); }
private void setPropertyName(MethodStructure methodStructure) { Name = $"_{(methodStructure.IsRPC ? methodStructure.Name : NamingHelpers.GetRestfullMethodName(methodStructure))}"; }
private async void Button_JobA_Click(object sender, RoutedEventArgs e) { const string DQUOTE = "\""; string joba_task_cmdline = $"cmd /c {DQUOTE}set AZ_BATCH & timeout /t 30 > NUL{DQUOTE}"; StringBuilder sb = new StringBuilder(1024); sb.AppendLine("Submitting job"); string jobid = NamingHelpers.GenJobName("A"); sb.AppendLine($"jobid={jobid}"); string taskid = NamingHelpers.GenTaskName("JOBA"); sb.AppendLine($"taskid={taskid}"); sb.AppendLine($"task command line={joba_task_cmdline}"); // read account settings, dump AccountSettings accountSettings = SampleHelpers.LoadAccountSettings(); // read job settings, dump JobSettings jobSettings = SampleHelpers.LoadJobSettings(); // connect to batch, dump status BatchSharedKeyCredentials cred = new BatchSharedKeyCredentials( accountSettings.BatchServiceUrl, accountSettings.BatchAccountName, accountSettings.BatchAccountKey ); sb.AppendLine($"batchcred created to {accountSettings.BatchAccountName} at {accountSettings.BatchServiceUrl}"); using (BatchClient client = BatchClient.Open(cred)) { PoolInformation pool = new PoolInformation(); pool.PoolId = jobSettings.PoolID; sb.AppendLine("creating job " + jobid); CloudJob ourJob = client.JobOperations.CreateJob(jobid, pool); ourJob.OnAllTasksComplete = Microsoft.Azure.Batch.Common.OnAllTasksComplete.TerminateJob; await ourJob.CommitAsync(); sb.AppendLine("job created " + jobid); // Get the bound version of the job with all of its properties populated CloudJob committedJob = await client.JobOperations.GetJobAsync(jobid); sb.AppendLine("bound version of job retrieved " + jobid); sb.AppendLine("submitting task " + taskid); // Create the tasks that the job will execute CloudTask task = new CloudTask(taskid, joba_task_cmdline); await client.JobOperations.AddTaskAsync(jobid, task); sb.AppendLine("task submitted " + taskid); TextBox_JobID.Text = jobid; TextBox_Task.Text = taskid; sb.AppendLine("task submitted. use job status button to see job and task checks"); TextBlock_Out.Text = sb.ToString(); } }