public async Task JobExtensionBuildStepsList() { using (TestHostContext hc = CreateTestContext()) { var jobExtension = new JobExtension(); jobExtension.Initialize(hc); _actionManager.Setup(x => x.PrepareActionsAsync(It.IsAny <IExecutionContext>(), It.IsAny <IEnumerable <Pipelines.JobStep> >(), It.IsAny <Guid>())) .Returns(Task.FromResult(new PrepareResult(new List <JobExtensionRunner>(), new Dictionary <Guid, IActionRunner>()))); List <IStep> result = await jobExtension.InitializeJob(_jobEc, _message); var trace = hc.GetTrace(); trace.Info(string.Join(", ", result.Select(x => x.DisplayName))); Assert.Equal(5, result.Count); Assert.Equal("action1", result[0].DisplayName); Assert.Equal("action2", result[1].DisplayName); Assert.Equal("action3", result[2].DisplayName); Assert.Equal("action4", result[3].DisplayName); Assert.Equal("action5", result[4].DisplayName); Assert.NotNull(result[0].ExecutionContext); Assert.NotNull(result[1].ExecutionContext); Assert.NotNull(result[2].ExecutionContext); Assert.NotNull(result[3].ExecutionContext); Assert.NotNull(result[4].ExecutionContext); } }
static Character Create(JSONObject obj) { var _equipments = GetList("equipment", obj, (arg) => { return(GameModel.Instance.Models.Equipment.Equipments.First(e => e.Code == (int)obj.GetField("equipment" + arg).i)); }); var _skills = GetList("skill", obj, (arg) => { return(GameModel.Instance.Masters.Skill.Datas.First(s => s.id == (int)obj.GetField("skill" + arg).i)); }); var character = new Character( (int)obj.GetField("code").i, (int)obj.GetField("lv").i, obj.GetField("name").str, JobExtension.ToEnum(obj.GetField("job").str), (int)obj.GetField("strong").i, (int)obj.GetField("intelligence").i, (int)obj.GetField("mystery").i, (int)obj.GetField("agile").i, (int)obj.GetField("vital").i, (int)obj.GetField("luck").i, _equipments, _skills ); return(character); }
private void SetField(string key, string value) { PropertyInfo propertyInfo = this.GetType().GetProperty(key, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); if (propertyInfo == null) { return; } if (propertyInfo.PropertyType == typeof(int)) { propertyInfo.SetValue(this, int.Parse(value), null); } else if (propertyInfo.PropertyType == typeof(string)) { propertyInfo.SetValue(this, value, null); } else if (propertyInfo.PropertyType == typeof(double)) { propertyInfo.SetValue(this, double.Parse(value), null); } else if (propertyInfo.PropertyType == typeof(bool)) { propertyInfo.SetValue(this, bool.Parse(value), null); } else if (propertyInfo.PropertyType == typeof(Attribute)) { propertyInfo.SetValue(this, AttributeExtension.ToEnum(value), null); } else if (propertyInfo.PropertyType == typeof(Target)) { propertyInfo.SetValue(this, TargetExtension.ToEnum(value), null); } else if (propertyInfo.PropertyType == typeof(Tribe)) { propertyInfo.SetValue(this, TribeExtension.ToEnum(value), null); } else if (propertyInfo.PropertyType == typeof(EnemyTribe)) { propertyInfo.SetValue(this, EnemyTribeExtension.ToEnum(value), null); } else if (propertyInfo.PropertyType == typeof(Job)) { propertyInfo.SetValue(this, JobExtension.ToEnum(value), null); } else if (propertyInfo.PropertyType == typeof(WeaponType)) { propertyInfo.SetValue(this, WeaponTypeExtension.ToEnum(value), null); } else if (propertyInfo.PropertyType == typeof(SelectType)) { propertyInfo.SetValue(this, SelectTypeExtension.ToEnum(value), null); } // 他の型にも対応させたいときには適当にここに。enumとかもどうにかなりそう。 }
public void DontUploadDiagnosticLogIfEnvironmentVariableMissing() { using (TestHostContext hc = CreateTestContext()) { var jobExtension = new JobExtension(); jobExtension.Initialize(hc); jobExtension.FinalizeJob(_jobEc, _message, DateTime.UtcNow); _diagnosticLogManager.Verify(x => x.UploadDiagnosticLogs( It.IsAny <IExecutionContext>(), It.IsAny <IExecutionContext>(), It.IsAny <Pipelines.AgentJobRequestMessage>(), It.IsAny <DateTime>()), Times.Never); } }
public void EnsureFinalizeJobHandlesNullEnvironment() { using (TestHostContext hc = CreateTestContext()) { var jobExtension = new JobExtension(); jobExtension.Initialize(hc); _message.ActionsEnvironment = null; _jobEc = new Runner.Worker.ExecutionContext { Result = TaskResult.Succeeded }; _jobEc.Initialize(hc); _jobEc.InitializeJob(_message, _tokenSource.Token); jobExtension.FinalizeJob(_jobEc, _message, DateTime.UtcNow); Assert.Equal(TaskResult.Succeeded, _jobEc.Result); } }
public void DontUploadDiagnosticLogIfEnvironmentVariableFalse() { using (TestHostContext hc = CreateTestContext()) { var jobExtension = new JobExtension(); jobExtension.Initialize(hc); _message.Variables[Constants.Variables.Actions.RunnerDebug] = "false"; _jobEc = new Runner.Worker.ExecutionContext(); _jobEc.Initialize(hc); _jobEc.InitializeJob(_message, _tokenSource.Token); jobExtension.FinalizeJob(_jobEc, _message, DateTime.UtcNow); _diagnosticLogManager.Verify(x => x.UploadDiagnosticLogs( It.IsAny <IExecutionContext>(), It.IsAny <IExecutionContext>(), It.IsAny <Pipelines.AgentJobRequestMessage>(), It.IsAny <DateTime>()), Times.Never); } }
public IActionResult NextForm(JobViewModel nextViewModel) { if (ModelState.IsValid) { if (nextViewModel.CurrentJobExtension != null) { if (nextViewModel.CurrentHydroSpecific != null) { if (nextViewModel.CurrentGenericFeatures != null) { if (nextViewModel.CurrentIndicator != null) { if (nextViewModel.CurrentHoistWayData != null) { nextViewModel.CurrentJob.Status = "Working on it"; repository.SaveEngJobView(nextViewModel); nextViewModel.CurrentTab = "Main"; TempData["message"] = $"everything was saved"; // Here the Job Filling Status should be changed the Working on it // Redirect to Hub?? return(View(nextViewModel)); } else { repository.SaveEngJobView(nextViewModel); nextViewModel.CurrentHoistWayData = new HoistWayData { JobID = nextViewModel.CurrentJob.JobID }; nextViewModel.CurrentTab = "HoistWayData"; TempData["message"] = $"indicator was saved"; return(View(nextViewModel)); } } else { repository.SaveEngJobView(nextViewModel); nextViewModel.CurrentIndicator = new Indicator { JobID = nextViewModel.CurrentJob.JobID }; nextViewModel.CurrentHoistWayData = new HoistWayData(); nextViewModel.CurrentTab = "Indicator"; TempData["message"] = $"generic was saved"; return(View(nextViewModel)); } } else { repository.SaveEngJobView(nextViewModel); nextViewModel.CurrentGenericFeatures = new GenericFeatures { JobID = nextViewModel.CurrentJob.JobID }; nextViewModel.CurrentIndicator = new Indicator(); nextViewModel.CurrentHoistWayData = new HoistWayData(); nextViewModel.CurrentTab = "GenericFeatures"; TempData["message"] = $"hydro specific was saved"; return(View(nextViewModel)); } } else { repository.SaveEngJobView(nextViewModel); nextViewModel.CurrentHydroSpecific = new HydroSpecific { JobID = nextViewModel.CurrentJob.JobID }; nextViewModel.CurrentGenericFeatures = new GenericFeatures(); nextViewModel.CurrentIndicator = new Indicator(); nextViewModel.CurrentHoistWayData = new HoistWayData(); nextViewModel.CurrentTab = "HydroSpecifics"; TempData["message"] = $"jobextension was saved"; return(View(nextViewModel)); } } else { repository.SaveEngJobView(nextViewModel); JobExtension jobExt = repository.JobsExtensions.FirstOrDefault(j => j.JobID == nextViewModel.CurrentJob.JobID); nextViewModel.CurrentJobExtension = (jobExt ?? new JobExtension { JobID = nextViewModel.CurrentJob.JobID }); nextViewModel.CurrentHydroSpecific = new HydroSpecific(); nextViewModel.CurrentGenericFeatures = new GenericFeatures(); nextViewModel.CurrentIndicator = new Indicator(); nextViewModel.CurrentHoistWayData = new HoistWayData(); nextViewModel.CurrentTab = "Extension"; TempData["message"] = $"job was saved"; return(View(nextViewModel)); } } else { nextViewModel.CurrentJob = (nextViewModel.CurrentJob ?? new Job()); nextViewModel.CurrentJobExtension = (nextViewModel.CurrentJobExtension ?? new JobExtension()); nextViewModel.CurrentHydroSpecific = (nextViewModel.CurrentHydroSpecific ?? new HydroSpecific()); nextViewModel.CurrentGenericFeatures = (nextViewModel.CurrentGenericFeatures ?? new GenericFeatures()); nextViewModel.CurrentIndicator = (nextViewModel.CurrentIndicator ?? new Indicator()); nextViewModel.CurrentHoistWayData = (nextViewModel.CurrentHoistWayData ?? new HoistWayData()); TempData["message"] = $"nothing was saved"; return(View(nextViewModel)); } }
public void DoJobProgress(JobExtension job) { var tokenSource = new CancellationTokenSource(); var token = tokenSource.Token; _MyListJobsMonitored.Add(job.Job.Name, tokenSource); // to track the task and be able to cancel it later Debug.WriteLine("launch job monitor : " + job.Job.Name); _client.RefreshTokenIfNeeded(); Task.Run(() => { try { Job myJob = null; do { myJob = _client.AMSclient.Jobs.Get(_client.credentialsEntry.ResourceGroup, _client.credentialsEntry.AccountName, job.TransformName, job.Job.Name); if (token.IsCancellationRequested == true) { return; } int index = -1; foreach (JobEntryV3 je in _MyObservJobV3) // let's search for index { if (je.Name == myJob.Name) { index = _MyObservJobV3.IndexOf(je); break; } } if (index >= 0) // we found it { // we update the observation collection var progress = ReturnProgressJob(myJob); _MyObservJobV3[index].Progress = progress.progress; _MyObservJobV3[index].Priority = myJob.Priority; //_MyObservJobV3[index].StartTime = myJob...StartTime.HasValue ? ((DateTime)myJob.StartTime).ToLocalTime().ToString("G") : null; //_MyObservJobV3[index].EndTime = myJob.EndTime.HasValue ? ((DateTime)myJob.EndTime).ToLocalTime().ToString("G") : null; _MyObservJobV3[index].State = myJob.State; /* * // let's calculate the estipated time * string ETAstr = "", Durationstr = ""; * if (progress > 3) * { * DateTime startlocaltime = ((DateTime)myJob.StartTime).ToLocalTime(); * TimeSpan interval = (TimeSpan)(DateTime.Now - startlocaltime); * DateTime ETA = DateTime.Now.AddSeconds((100d / progress - 1d) * interval.TotalSeconds); * TimeSpan estimatedduration = (TimeSpan)(ETA - startlocaltime); * * ETAstr = "Estimated: " + ETA.ToString("G"); * Durationstr = "Estimated: " + estimatedduration.ToString(@"d\.hh\:mm\:ss"); * _MyObservJobV3[index].EndTime = ETA.ToString(@"G") + " ?"; * _MyObservJobV3[index].Duration = myJob.EndTime.HasValue ? * ((TimeSpan)((DateTime)myJob.EndTime - (DateTime)myJob.StartTime)).ToString(@"d\.hh\:mm\:ss") * : estimatedduration.ToString(@"d\.hh\:mm\:ss") + " ?"; * } */ int indexdisplayed = -1; foreach (JobEntryV3 je in _MyObservJobV3) // let's search for index in the page { if (je.Name == myJob.Name) { indexdisplayed = _MyObservJobV3.IndexOf(je); try { this.BeginInvoke(new Action(() => { this.Rows[indexdisplayed].Cells[this.Columns["Progress"].Index].ToolTipText = progress.sb.ToString(); // mouse hover info if (progress.progress != 0) { // this.Rows[indexdisplayed].Cells[this.Columns["EndTime"].Index].ToolTipText = ETAstr;// mouse hover info // this.Rows[indexdisplayed].Cells[this.Columns["Duration"].Index].ToolTipText = Durationstr;// mouse hover info } this.Refresh(); })); } catch { } break; } } } if (myJob != null && myJob.State != Microsoft.Azure.Management.Media.Models.JobState.Finished && myJob.State != Microsoft.Azure.Management.Media.Models.JobState.Error && myJob.State != Microsoft.Azure.Management.Media.Models.JobState.Canceled) { Debug.WriteLine("wait for status : " + myJob.Name); Task.Delay(JobRefreshIntervalInMilliseconds).Wait(); } else { break; } }while (myJob.State != Microsoft.Azure.Management.Media.Models.JobState.Finished && myJob.State != Microsoft.Azure.Management.Media.Models.JobState.Error && myJob.State != Microsoft.Azure.Management.Media.Models.JobState.Canceled); // job finished _client.RefreshTokenIfNeeded(); myJob = _client.AMSclient.Jobs.Get(_client.credentialsEntry.ResourceGroup, _client.credentialsEntry.AccountName, job.TransformName, job.Job.Name); int index2 = -1; foreach (JobEntryV3 je in _MyObservJobV3) // let's search for index { if (je.Name == myJob.Name) { index2 = _MyObservJobV3.IndexOf(je); break; } } if (index2 >= 0) // we found it { // we update the observation collection StringBuilder sb2 = new StringBuilder(); // display percentage for each task for mouse hover (tooltiptext) double progress2 = 0; for (int i = 0; i < myJob.Outputs.Count; i++) { JobOutput output = myJob.Outputs[i]; if (output.State == Microsoft.Azure.Management.Media.Models.JobState.Processing) { progress2 += output.Progress; sb2.AppendLine(string.Format("{0} % ({1})", Convert.ToInt32(output.Progress).ToString(), output.Label)); } } if (myJob.Outputs.Count > 0) { progress2 = progress2 / myJob.Outputs.Count; } _MyObservJobV3[index2].Progress = 101d; // progress; we don't want the progress bar to be displayed _MyObservJobV3[index2].Priority = myJob.Priority; _MyObservJobV3[index2].State = myJob.State; if (_MyListJobsMonitored.ContainsKey(myJob.Name)) // we want to display only one time { _MyListJobsMonitored.Remove(myJob.Name); // let's remove from the list of monitored jobs Mainform myform = (Mainform)this.FindForm(); // string status = Enum.GetName(typeof(Microsoft.Azure.Management.Media.Models.JobState), myJob.State).ToLower(); string status = myJob.State.ToString(); myform.BeginInvoke(new Action(() => { myform.Notify(string.Format("Job {0}", status), string.Format("Job {0}", _MyObservJobV3[index2].Name), myJob.State == Microsoft.Azure.Management.Media.Models.JobState.Error); myform.TextBoxLogWriteLine(string.Format("Job '{0}' : {1}.", _MyObservJobV3[index2].Name, status), myJob.State == Microsoft.Azure.Management.Media.Models.JobState.Error); if (myJob.State == Microsoft.Azure.Management.Media.Models.JobState.Error) { foreach (var output in myJob.Outputs) { if (output.Error != null && output.Error.Details != null) { for (int i = 0; i < output.Error.Details.Count(); i++) { myform.TextBoxLogWriteLine(string.Format("Output '{0}', Error : {1}", output.Label, output.Error + " : " + output.Error.Message), true); } } } } myform.DoRefreshGridAssetV(false); })); this.BeginInvoke(new Action(() => { this.Refresh(); })); } } } catch (Exception ex) { //MessageBox.Show(Program.GetErrorMessage(e), "Job Monitoring Error"); Debug.WriteLine("error job monitor : " + Program.GetErrorMessage(ex)); } }, token); }