public override int GetHashCode() { unchecked // Overflow is fine, just wrap { int hash = ProcessInstanceId.GetHashCode(); // Suitable nullity checks etc, of course :) if (ProcessKey != null) { hash = hash * 17 + ProcessKey.GetHashCode(); } if (ProcessInstanceName != null) { hash = hash * 17 + ProcessInstanceName.GetHashCode(); } if (BusinessKey != null) { hash = hash * 17 + BusinessKey.GetHashCode(); } hash = hash * 17 + SuspensionState.GetHashCode(); if (UserCandidates != null) { hash = hash * 17 + UserCandidates.GetHashCode(); } if (Owner != null) { hash = hash * 17 + Owner.GetHashCode(); } return(hash); } }
private static DiagProcessFilterEntry CreateFilterEntry(ProcessKey processKey) { var processFilter = DiagProcessFilter.FromProcessKey(processKey); Assert.Single(processFilter.Filters); return(processFilter.Filters.First()); }
public void Add(JobProcess jobProcess) { if (string.IsNullOrWhiteSpace(jobProcess.TraceId)) { throw new ArgumentNullException(nameof(jobProcess.TraceId)); } if (string.IsNullOrWhiteSpace(jobProcess.JobId)) { throw new ArgumentNullException(nameof(jobProcess.JobId)); } if (jobProcess.Sharding <= 0) { throw new ArgumentException($"{nameof(jobProcess.Sharding)} should larger than 0"); } if (jobProcess.ProcessId <= 0) { throw new ArgumentException($"{nameof(jobProcess.ProcessId)} should larger than 0"); } if (string.IsNullOrWhiteSpace(jobProcess.Application)) { throw new ArgumentNullException(nameof(jobProcess.Application)); } var key = new ProcessKey(jobProcess.JobId, jobProcess.TraceId, jobProcess.Sharding); var path = Path.Combine(_folder, key.ToString()); File.WriteAllText(path, JsonConvert.SerializeObject(jobProcess)); }
public override int GetHashCode() { unchecked // Overflow is fine, just wrap { int hash = ProcessTaskId.GetHashCode(); // Suitable nullity checks etc, of course :) if (ProcessTaskName != null) { hash = hash * 17 + ProcessTaskName.GetHashCode(); } if (ProcessTaskOwner != null) { hash = hash * 17 + ProcessTaskOwner.GetHashCode(); } if (ParentTaskId != null) { hash = hash * 17 + ParentTaskId.GetHashCode(); } hash = hash * 17 + Priority.GetHashCode(); if (ProcessKey != null) { hash = hash * 17 + ProcessKey.GetHashCode(); } if (ProcessInstanceId != null) { hash = hash * 17 + ProcessInstanceId.GetHashCode(); } if (ProcessItemDefinitionId != null) { hash = hash * 17 + ProcessItemDefinitionId.GetHashCode(); } hash = hash * 17 + SuspensionState.GetHashCode(); return(hash); } }
public void Remove(ProcessKey key) { var path = Path.Combine(_folder, key.ToString()); if (File.Exists(path)) { File.Delete(path); } }
public JobProcess GetProcess(ProcessKey key) { var path = Path.Combine(_folder, key.ToString()); if (File.Exists(path)) { return(JsonConvert.DeserializeObject <JobProcess>(File.ReadAllText(path))); } return(null); }
public Task <ActionResult <Models.ProcessInfo> > GetProcessInfo( ProcessKey processKey) { return(InvokeForProcess <Models.ProcessInfo>(processInfo => { Models.ProcessInfo processModel = Models.ProcessInfo.FromProcessInfo(processInfo); _logger.WrittenToHttpStream(); return processModel; }, processKey)); }
private static void WriteMainOptions( ) { processKey = ProcessMainOptions; Console.WriteLine(); Console.WriteLine("[1] Start Default Game Window"); Console.WriteLine("[2] Start Game context from JSON config"); Console.WriteLine("[3] Start Game context from Jargon (.jss) config"); Console.WriteLine("___"); Console.WriteLine("[X] Exit current Game Context"); Console.WriteLine("___"); Console.WriteLine("[Q] Quit"); }
public void ConvertProcessKeyTest() { var processKey = new ProcessKey("processName"); var filter = CreateFilterEntry(processKey); ValidateProcessFilter(DiagProcessFilterCriteria.ProcessName, processKey.ProcessName, filter); processKey = new ProcessKey(Guid.NewGuid()); filter = CreateFilterEntry(processKey); ValidateProcessFilter(DiagProcessFilterCriteria.RuntimeId, processKey.RuntimeInstanceCookie.Value.ToString("D"), filter); processKey = new ProcessKey(5); filter = CreateFilterEntry(processKey); ValidateProcessFilter(DiagProcessFilterCriteria.ProcessId, processKey.ProcessId.Value.ToString(CultureInfo.InvariantCulture), filter); }
public static void Main() { KeyEvent kevt = new KeyEvent(); ProcessKey pk = new ProcessKey(); CountKeys ck = new CountKeys(); char ch; kevt.KeyPress += new KeyHandler(pk.keyhandler); kevt.KeyPress += new KeyHandler(ck.keyhandler); Console.WriteLine("Введите несколько символов. " + "Для останова введите точку."); do { ch = (char)Console.Read(); kevt.OnKeyPress(ch); } while (ch != '.'); Console.WriteLine("Было нажато " + ck.count + " клавиш."); }
public void Handle(string jobId, string traceId, int sharding) { var key = new ProcessKey(jobId, traceId, sharding); var proc = _processStore.GetProcess(key); if (proc == null) { return; } try { Process.GetProcessById(proc.ProcessId).Kill(); _processStore.Remove(key); } catch (Exception ex) { _logger.LogError($"Kill PID {proc.ProcessId} Job {jobId} failed: {ex.Message}."); } }
private static void ProcessMainOptions(ConsoleKeyInfo input) { if (input.Key == ConsoleKey.D1) { CreateEmptyApplicationContext(); } else if (input.Key == ConsoleKey.D2) { processKey = ProcessWindowedOptions; WriteWindowedOptions(); } else if (input.Key == ConsoleKey.X) { p.application?.Quit(); } else { WriteMainOptions(); } }
public Task <ActionResult <Dictionary <string, string> > > GetProcessEnvironment( ProcessKey processKey) { return(InvokeForProcess <Dictionary <string, string> >(processInfo => { var client = new DiagnosticsClient(processInfo.EndpointInfo.Endpoint); try { Dictionary <string, string> environment = client.GetProcessEnvironment(); _logger.WrittenToHttpStream(); return environment; } catch (ServerErrorException) { throw new InvalidOperationException("Unable to get process environment."); } }, processKey)); }
static void Main(string[] args) { p = new Program(); processKey = ProcessMainOptions; Console.WriteLine("Hello Application Context!"); WriteMainOptions(); while (!quit) { var input = Console.ReadKey(); Console.WriteLine(); // Q key kills program if (input.Key == ConsoleKey.Q) { quit = true; continue; } processKey(input); } }
private static void ProcessWindowedOptions(ConsoleKeyInfo input) { if (input.Key == ConsoleKey.D1) { CreateCustomWindow(); } else if (input.Key == ConsoleKey.D2) { CreateResizableWindow(); } else if (input.Key == ConsoleKey.M) { processKey = ProcessMainOptions; WriteMainOptions(); } else if (input.Key == ConsoleKey.X) { p.application?.Quit(); } else { WriteWindowedOptions(); } }
public override void Init() { ActionGame lc_OnActionMoveToPlayer = new ActionGame(OnTriggerMoveToPlayer, OnMoveToPlayer); ActionGame lc_OnActionMove = new ActionGame(null, OnMoveToBall); ActionGame lc_OnJump = new ActionGame(OnJump, OnJumpStraight, Endjump, 0.75f); ActionGame lc_OnIdle = new ActionGame(null, OnMoveIde, EndAction, 0.5f); ActionGame lc_OnMoveRandom = new ActionGame(null, OnMoveRandom); ActionGame lc_onMoveToHoop = new ActionGame(null, OnMoveToHoop); ActionGame lc_OnJump_left = new ActionGame(OnTriggerJumpLeft, OnJumpLeft, Endjump, 1f); ActionGame lc_OnJump_right = new ActionGame(OnJump, OnJumpRight, Endjump, 1f); ActionGame lc_OnSlampDunk = new ActionGame(OnTriggerSlampDunk, OnActionSlampDunk, OnEndSlampDunk, 2, true); ActionGame lc_OnStun = new ActionGame(OnTriggerStun, OnStun, OnEndTriggerStun, 0); ActionGame lc_OnAttack = new ActionGame(OnStartActionAttack, OnActtionTriggerAttack, null); ActionGame lc_OnCatchBall = new ActionGame(OnStartActionCatchBall, OnActtionTriggerCatchBall, null); ActionGame lc_OnThrowOnGround = new ActionGame(OnStartThrowOnEarth, OnUpdateThrowOnEarth, OnEndThrowOnEarth, 0.5f); ActionGame lc_OnActionMoveToBall = new ActionGame(null, OnMoveToBall, EndAction, 1); ActionGame lc_OnMoveBackHaveBall = new ActionGame(OnStartMoveBackHaveBall, OnMoveBackHaveBall, EndActionMoveBackHaveBall, 2.5f); ActionGame lc_OnActionJumpThrowBall = new ActionGame(OnJumpThrowBall, OnStartThrowBall, EndAction, 1); ActionGame lc_OnActionMoveProtectBall = new ActionGame(OnTriggerMoveProtectHoop, OnMoveProtectHoop); // Update To Directory // Update Directory_OnActionGame.Add(Key_Move_To_Ball, lc_OnActionMove); Directory_OnActionGame.Add(Key_Move_Ide, lc_OnIdle); Directory_OnActionGame.Add(Key_Move_Random, lc_OnMoveRandom); Directory_OnActionGame.Add(Key_Move_To_Hoop, lc_onMoveToHoop); Directory_OnActionGame.Add(Key_Stun, lc_OnStun); Directory_OnActionGame.Add(Key_Move_To_Player, lc_OnActionMoveToPlayer); // Action Directory_OnActionGame.Add(Key_Action_Move_To_Ball, lc_OnActionMoveToBall); Directory_OnActionGame.Add(Key_Jump_Straight, lc_OnJump); Directory_OnActionGame.Add(Key_Jump_Left, lc_OnJump_left); Directory_OnActionGame.Add(Key_Jump_Right, lc_OnJump_right); Directory_OnActionGame.Add(Key_Thown_On_Ground, lc_OnThrowOnGround); Directory_OnActionGame.Add(Key_Action_Move_Back_Have_Ball, lc_OnMoveBackHaveBall); Directory_OnActionGame.Add(Key_Action_Jump_Throw_Ball, lc_OnActionJumpThrowBall); Directory_OnActionGame.Add(Key_Action_Protect_Ball, lc_OnActionMoveProtectBall); // Action EFF Directory_OnActionGame.Add(Key_Slamp_Dunk, lc_OnSlampDunk); // ACtion Trigger Directory_OnActionGame.Add(Key_Action_Trigger_Attack, lc_OnAttack); Directory_OnActionGame.Add(Key_Action_Trigger_CatchBall, lc_OnCatchBall); // Status Directory_StatusCpu.Add(Key_Trigger_Have_Ball, 0); Directory_StatusCpu.Add(Key_Trigger_Front, 0); Directory_StatusCpu.Add(Key_Trigger_Back, 0); Directory_StatusCpu.Add(Key_Trigger_Jump, 0); Directory_StatusCpu.Add(Key_Trigger_ThrowBall, 0); Directory_StatusCpu.Add(Key_Trigger_Slamp_Dunk, 0); Directory_StatusCpu.Add(Key_Trigger_Jump_Protect_Ball, 0); // Load Text Cpu ProcessKey ProcessProtectBoard = new ProcessKey(OnTriggerStatusMoveProtectBall, ProcessKey_Protect_Board); ProcessKey KeyMoveToBall = new ProcessKey(OnTriggerStatusMoveCatchBall, ProcessStatus); ProcessKey KeyProcessStatusHaveBall = new ProcessKey(OnTriggerCpuHaveBall, ProcessStatusCPUHaveBall); ProcessKey KeyProcessStatusPlayerHave = new ProcessKey(OnTriggerPlayerHaveBall, ProcessStatusPlayerHaveBall); ListProcessKey.Add(ProcessProtectBoard); ListProcessKey.Add(KeyMoveToBall); ListProcessKey.Add(KeyProcessStatusHaveBall); ListProcessKey.Add(KeyProcessStatusPlayerHave); ReadFileCPU(); }
private bool Equals(ProcessKey other) { return(_id == other._id); }
public bool Equals(ProcessTask other) { // Check for null if (ReferenceEquals(other, null)) { return(false); } // Check for same reference if (ReferenceEquals(this, other)) { return(true); } // Not Check ProcessTaskId, because generated Guid // Check for same value return(((ProcessTaskName == null && other.ProcessTaskName == null) || (ProcessTaskName != null && other.ProcessTaskName != null && ProcessTaskName.Equals(other.ProcessTaskName))) && ((ProcessTaskOwner == null && other.ProcessTaskOwner == null) || (ProcessTaskOwner != null && other.ProcessTaskOwner != null && ProcessTaskOwner.Equals(other.ProcessTaskOwner))) && ((ParentTaskId == null && other.ParentTaskId == null) || (ParentTaskId != null && other.ParentTaskId != null && ParentTaskId.Equals(other.ParentTaskId))) && ((ProcessKey == null && other.ProcessKey == null) || (ProcessKey != null && other.ProcessKey != null && ProcessKey.Equals(other.ProcessKey))) && ((ProcessInstanceId == null && other.ProcessInstanceId == null) || (ProcessInstanceId != null && other.ProcessInstanceId != null && ProcessInstanceId.Equals(other.ProcessInstanceId))) && ((ProcessItemDefinitionId == null && other.ProcessItemDefinitionId == null) || (ProcessItemDefinitionId != null && other.ProcessItemDefinitionId != null && ProcessItemDefinitionId.Equals(other.ProcessItemDefinitionId))) && SuspensionState.Equals(other.SuspensionState)); }
public Task <int> Execute(JobContext context, Action <string, string, string> logger) { var key = new ProcessKey(context.JobId, context.TraceId, context.CurrentSharding); if (Processes.ContainsKey(key)) { throw new SwarmClientException( $"[{context.JobId}, {context.TraceId}, {context.CurrentSharding}] is running"); } if (Processes.Keys.Count(k => k.JobId == context.JobId) > 1) { if (context.ConcurrentExecutionDisallowed) { throw new SwarmClientException("job is running"); } } var app = context.Parameters.GetValue(SwarmConts.ApplicationProperty); if (string.IsNullOrWhiteSpace(app)) { throw new SwarmClientException("application path is null"); } var arguments = context.Parameters.GetValue(SwarmConts.ArgumentsProperty); arguments = ReplaceEnvironments(arguments); var logPattern = context.Parameters.GetValue(SwarmConts.LogPatternProperty); var process = new Process { StartInfo = new ProcessStartInfo(app, arguments) { WorkingDirectory = AppContext.BaseDirectory, UseShellExecute = false, CreateNoWindow = true, RedirectStandardOutput = !string.IsNullOrWhiteSpace(logPattern) } }; if (!string.IsNullOrWhiteSpace(logPattern)) { process.OutputDataReceived += (sender, e) => { if (string.IsNullOrEmpty(e.Data)) { return; } _logger.LogInformation(e.Data); if (Regex.IsMatch(e.Data, logPattern)) { logger?.Invoke(context.JobId, context.TraceId, e.Data); } }; } Processes.TryAdd(key, process); process.Start(); if (!string.IsNullOrWhiteSpace(logPattern)) { process.BeginOutputReadLine(); } _logger.LogInformation( $"Start process [{context.Name}, {context.Group}] PID: {process.Id}."); process.WaitForExit(); Processes.TryRemove(key, out _); _logger.LogInformation( $"[{context.Name}, {context.Group}] PID: {process.Id} exited."); return(Task.FromResult(process.ExitCode)); }
public bool Equals(ProcessInstance other) { // Check for null if (ReferenceEquals(other, null)) { return(false); } // Check for same reference if (ReferenceEquals(this, other)) { return(true); } // Not Check ProcessInstanceId, because generated Guid // Check for same value return(((ProcessKey == null && other.ProcessKey == null) || (ProcessKey != null && other.ProcessKey != null && ProcessKey.Equals(other.ProcessKey))) && ((ProcessInstanceName == null && other.ProcessInstanceName == null) || (ProcessInstanceName != null && other.ProcessInstanceName != null && ProcessInstanceName.Equals(other.ProcessInstanceName))) && ((BusinessKey == null && other.BusinessKey == null) || (BusinessKey != null && other.BusinessKey != null && BusinessKey.Equals(other.BusinessKey))) && SuspensionState.Equals(other.SuspensionState) && ((UserCandidates == null && other.UserCandidates == null) || (UserCandidates != null && other.UserCandidates != null && UserCandidates.Equals(other.UserCandidates))) && ((Owner == null && other.Owner == null) || (Owner != null && other.Owner != null && Owner.Equals(other.Owner)))); }
public bool Exists(ProcessKey key) { var path = Path.Combine(_folder, key.ToString()); return(File.Exists(path)); }
public override async Task Execute(JobContext context, HubConnection connection) { var key = new ProcessKey(context.JobId, context.TraceId, context.CurrentSharding); if (Store.Exists(key)) { throw new SwarmClientException( $"[{context.JobId}, {context.TraceId}, {context.CurrentSharding}] is running"); } if (Store.Count(context.JobId) > 1) { if (context.AllowConcurrent) { throw new SwarmClientException("job is running"); } } var application = context.Parameters.GetValue(SwarmConsts.ApplicationProperty); if (string.IsNullOrWhiteSpace(application)) { throw new SwarmClientException("application path is null"); } var arguments = context.Parameters.GetValue(SwarmConsts.ArgumentsProperty); arguments = ReplaceEnvironments(arguments); var logPattern = context.Parameters.GetValue(SwarmConsts.LogPatternProperty); var process = new Process { StartInfo = new ProcessStartInfo(application, arguments) { WorkingDirectory = AppContext.BaseDirectory, UseShellExecute = false, CreateNoWindow = true, RedirectStandardOutput = !string.IsNullOrWhiteSpace(logPattern) } }; if (!string.IsNullOrWhiteSpace(logPattern)) { process.OutputDataReceived += async(sender, e) => { if (string.IsNullOrEmpty(e.Data)) { return; } if (Regex.IsMatch(e.Data, logPattern)) { await OnLog(context, connection, e.Data); } }; } process.Start(); await OnRunning(context, connection, process.Id); if (!string.IsNullOrWhiteSpace(logPattern)) { process.BeginOutputReadLine(); } Store.Add(new JobProcess { JobId = context.JobId, TraceId = context.TraceId, Sharding = context.CurrentSharding, Application = application, Arguments = arguments, StartAt = DateTimeOffset.Now, ProcessId = process.Id }); Logger.LogInformation( $"Start process [{context.Name}, {context.Group}] PID: {process.Id}."); process.WaitForExit(); Store.Remove(key); Logger.LogInformation( $"[{context.Name}, {context.Group}] PID: {process.Id} exited."); await OnExited(context, connection, process.Id, $"Exit: {process.ExitCode}"); }