private void EvaluateExitCriteria() { ExitReason reason; if (UpdateCount >= MinUpdateCount && DrawCount >= MinDrawCount) { reason = ExitReason.MinimumsSatisfied; } else if (UpdateCount >= MaxUpdateCount) { reason = ExitReason.MaxUpdateSatisfied; } else if (DrawCount >= MaxDrawCount) { reason = ExitReason.MaxDrawSatisfied; } else { reason = ExitReason.None; } if (reason != ExitReason.None) { ExitReason = reason; DoExit(); } }
// Attempts to stop all processes, then clears the process list. public void StopAll(ExitReason exitReason) { List <KeyValuePair <IProcess, ProcessStopHandler> > processesCopy; lock (_processes) { processesCopy = _processes.ToList(); _processes.Clear(); } foreach (var(process, stopHandler) in processesCopy.Select(x => (x.Key, x.Value))) { try { try { stopHandler?.Invoke(process, exitReason); } finally { process.Kill(); } } finally { process.Dispose(); } } }
public ExitReason Run(string addr, int port) { ExitReason exitReason = ExitReason.NORMAL; if (addr == null) { addr = "::"; } if (port < 0 || port > 65535) { return(ExitReason.PORT); } if (IPAddress.TryParse(addr, out IPAddress ipAddr)) { IPEndPoint bindEndpoint = new IPEndPoint(ipAddr, port); serverSocket = new Socket(bindEndpoint.AddressFamily, SocketType.Dgram, ProtocolType.Udp); if (bindEndpoint.Address.Equals(IPAddress.IPv6Any)) { serverSocket.DualMode = true; } try { serverSocket.Bind(bindEndpoint); } catch (SocketException e) { switch (e.SocketErrorCode) { case SocketError.AccessDenied: return(ExitReason.DENIED); case SocketError.AddressAlreadyInUse: return(ExitReason.INUSE); } } IPEndPoint any = new IPEndPoint(IPAddress.Any, 0); if (bindEndpoint.AddressFamily == AddressFamily.InterNetworkV6) { any = new IPEndPoint(IPAddress.IPv6Any, 0); } while (Program.running) { EndPoint recvFrom = any; if (serverSocket.Poll(1024, SelectMode.SelectRead)) { int bytesRead = serverSocket.ReceiveFrom(buffer, ref recvFrom); if (bytesRead == 0) { continue; } handler.Handle(buffer, bytesRead, recvFrom as IPEndPoint); } } } else { return(ExitReason.ADDR); } return(exitReason); }
private void ExceptionTestHelper( ExceptionCondition exceptionCondition, RuntimeConditions runtimeConditions, ExitReason expectedExitReason = ExitReason.None, TestAnalyzeOptions analyzeOptions = null) { ExceptionRaisingRule.s_exceptionCondition = exceptionCondition; analyzeOptions = analyzeOptions ?? new TestAnalyzeOptions() { TargetFileSpecifiers = new string[0] }; analyzeOptions.Quiet = true; var command = new TestAnalyzeCommand(); Assembly[] plugInAssemblies = null; if (analyzeOptions.DefaultPlugInFilePaths != null) { var assemblies = new List <Assembly>(); foreach (string plugInFilePath in analyzeOptions.DefaultPlugInFilePaths) { assemblies.Add(Assembly.LoadFrom(plugInFilePath)); } plugInAssemblies = new Assembly[assemblies.Count]; assemblies.CopyTo(plugInAssemblies, 0); } else { plugInAssemblies = new Assembly[] { typeof(ExceptionRaisingRule).Assembly }; } command.DefaultPlugInAssemblies = plugInAssemblies; int result = command.Run(analyzeOptions); int expectedResult = (runtimeConditions & ~RuntimeConditions.Nonfatal) == RuntimeConditions.None ? TestAnalyzeCommand.SUCCESS : TestAnalyzeCommand.FAILURE; Assert.Equal(runtimeConditions, command.RuntimeErrors); Assert.Equal(expectedResult, result); if (expectedExitReason != ExitReason.None) { Assert.NotNull(command.ExecutionException); if (expectedExitReason != ExitReason.UnhandledExceptionInEngine) { var eax = command.ExecutionException as ExitApplicationException <ExitReason>; Assert.NotNull(eax); } } else { Assert.Null(command.ExecutionException); } ExceptionRaisingRule.s_exceptionCondition = ExceptionCondition.None; }
protected override void OnExit(GameState prev, ExitReason reason) { this.App.HotKeyManager.RemoveListener((IKeyBindListener)this); if (this._manager != null) { this._manager.Dispose(); this._manager = (FleetManager)null; } if (this._fleetWidget != null) { this._fleetWidget.OnFleetsModified -= new FleetWidget.FleetsModifiedDelegate(this.FleetsModified); this._fleetWidget.Dispose(); this._fleetWidget = (FleetWidget)null; } foreach (ShipDummy shipDummy in this._shipDummies) { shipDummy.Dispose(); } this._shipDummies = (List <ShipDummy>)null; if (this._camera != null) { this._camera.Dispose(); this._camera = (OrbitCameraController)null; } if (this._crits != null) { this._crits.Dispose(); this._crits = (GameObjectSet)null; } this.App.UI.DestroyPanel(this._contextMenuID); this.App.UI.DestroyPanel(this._shipContextMenuID); this.App.UI.GameEvent -= new UIEventGameEvent(this.UICommChannel_GameEvent); }
protected override void OnExit(GameState prev, ExitReason reason) { if (this._crits == null) { return; } this._crits.Dispose(); }
public void Exit(ExitReason reason, double exitTime, Exception exception) { Active = false; ExitTime = exitTime; ExitReason = reason; Exception = exception; WaitForNextCommandTime = double.PositiveInfinity; }
protected void ThrowExitApplicationException(TContext context, ExitReason exitReason, Exception innerException = null) { RuntimeErrors |= context.RuntimeErrors; throw new ExitApplicationException <ExitReason>(DriverResources.MSG_UnexpectedApplicationExit, innerException) { ExitReason = exitReason }; }
protected override void OnExit(GameState prev, ExitReason reason) { if (this._scene != null) { this._scene.Exit(); this._scene = (MainMenuScene)null; } this.App.UI.PanelMessage -= new UIEventPanelMessage(this.UICommChannel_PanelMessage); this.App.UI.DeleteScreen("MainMenu"); }
private async Task ReadPipeAsync(PipeReader reader, Action <NmeaMessage> callback, CancellationToken cancellationToken = default) { while (!cancellationToken.IsCancellationRequested) { try { var result = await reader.ReadAsync(cancellationToken).ConfigureAwait(false); var buffer = result.Buffer; SequencePosition?position = null; do { // Look for a EOL in the buffer position = buffer.PositionOf(ByteLF); if (position != null) { // Process the line if (ParseSentence(buffer.Slice(0, position.Value), out var message)) { callback(message); } // Skip the line + the \n character (basically position) buffer = buffer.Slice(buffer.GetPosition(1, position.Value)); } }while (position != null && !cancellationToken.IsCancellationRequested); // Tell the PipeReader how much of the buffer we have consumed reader.AdvanceTo(buffer.Start, buffer.End); // Stop reading if there's no more data coming if (result.IsCompleted) { _logger.LogTrace("ReadPipeAsync: Writer is Completed"); break; } } catch (OperationCanceledException) { break; } if (AbortAfterUnparsedLines != 0 && _unparsedSequenceLength >= AbortAfterUnparsedLines) { _logger.LogTrace("ReadPipeAsync: Sequntial Unparsed Lines: {0} Limit: {1}", _unparsedSequenceLength, AbortAfterUnparsedLines); _exitReason = ExitReason.TooManySequentialUnparsedLines; break; } } // Mark the PipeReader as complete reader.Complete(); }
protected override void OnExit(GameState prev, ExitReason reason) { this.App.UI.GameEvent -= new UIEventGameEvent(this.UICommChannel_GameEvent); this._starsystem = (StarSystem)null; if (this._crits == null) { return; } this._crits.Dispose(); this._crits = (GameObjectSet)null; }
internal void Exit(GameState next, ExitReason reason) { GameState.Trace(string.Format("Exiting {0}.", (object)this.Name)); this.App.UI.PanelMessage -= new UIEventPanelMessage(this.UICommChannel_PanelMessage); if (this.App.Game != null) { this.App.Game.ShowCombatDialog(false, (GameState)null); } this.OnExit(next, reason); this._entered = false; }
protected override void OnExit(GameState next, ExitReason reason) { foreach (PlanetWidget planetWidget in this._planetWidgets) { planetWidget.Terminate(); } foreach (SystemWidget systemWidget in this._systemWidgets) { systemWidget.Terminate(); } }
protected override void OnExit(GameState next, ExitReason reason) { this.App.UI.SetPropertyBool("movie", "movie_done", true); this._movie = null; this._action = (Action)null; this._actionPerformed = false; this._preparingState = false; this._nextState = (GameState)null; this._nextStateParams = (object[])null; this.App.UI.GameEvent -= new UIEventGameEvent(this.UICommChannel_GameEvent); }
protected override void OnExit(GameState prev, ExitReason reason) { this.App.HotKeyManager.RemoveListener((IKeyBindListener)this); this._pendingObjects.Clear(); this._fleetWidget.Dispose(); this._defenseWidget.Dispose(); this._dmcrits.Dispose(); this._dmcrits = (GameObjectSet)null; this._manager.Dispose(); base.OnExit(prev, reason); }
protected override void OnExit(GameState prev, ExitReason reason) { this._piechart = (BudgetPiechart)null; this._manager.Dispose(); this._crits.Dispose(); this._crits = (GameObjectSet)null; this._dummies.Dispose(); this._dummies = (GameObjectSet)null; this._sim = (GameSession)null; this._designsToBuild = (List <int>)null; base.OnExit(prev, reason); }
protected override void OnExit(GameState prev, ExitReason reason) { if (this._crits != null) { this._crits.Dispose(); } if (this._planet != null) { this.App.ReleaseObject((IGameObject)this._planet); } this._planet = (StellarBody)null; }
protected override void OnExit(GameState next, ExitReason reason) { this.App.UI.DeleteScreen("LoadingScreen"); this._minTime = 0.0f; this._text = null; this._image = null; this._action = (Action)null; this._actionPerformed = false; this._preparingState = false; this._nextState = (GameState)null; this._nextStateParams = (object[])null; }
public override bool Run() { //mPriority = new InteractionPriority(InteractionPriorityLevel.MaxDeath); //CancellableByPlayer = false; Target.BuffManager.RemoveElement(BuffEWGraveWound.buffName); Target.BuffManager.RemoveElement(BuffEWSeriousWound.buffName); Target.BuffManager.RemoveElement(BuffEWMinorWound.buffName); if (Loader.kAllowPetDeath) { StyledNotification.Show(new StyledNotification.Format(Localization.LocalizeString("Echoweaver/PetFighting/EWFightPet:PetFightDie", Target.Name), StyledNotification.NotificationStyle.kGameMessageNegative)); Target.Kill(Loader.fightDeathType); } else { if (!Target.IsSleeping) { EnterStateMachine("PetPassOut", "Enter", "x"); AnimateSim("PassOutLoop"); Target.SetIsSleeping(value: true); } StyledNotification.Show(new StyledNotification.Format(Localization.LocalizeString("Echoweaver/PetFighting/EWFightPet:PetFightRecuperate", Target.Name), StyledNotification.NotificationStyle.kGameMessageNegative)); // TODO: Needs an origin for succumb to wounds Target.BuffManager.AddElement(BuffEWRecuperateCat.StaticGuid, Origin.FromFight); Target.Motives.FreezeDecay(CommodityKind.Hunger, false); Target.Motives.FreezeDecay(CommodityKind.Energy, true); float passOutMinutes = 720f; ExitReason acceptedExitReasons = ~(ExitReason.Finished); float startTime = SimClock.ElapsedTime(TimeUnit.Minutes); while (!Target.WaitForExitReason(1f, acceptedExitReasons)) { float currentTime = SimClock.ElapsedTime(TimeUnit.Minutes); if (currentTime - startTime > passOutMinutes) { AnimateSim(kJazzStateSleep); break; } } Target.Motives.RestoreDecay(CommodityKind.Hunger); Target.Motives.RestoreDecay(CommodityKind.Energy); AnimateSim("Exit"); Target.SetIsSleeping(false); } return(true); }
public void HandleResultWhenNormal(ExitReason expected) { var ei = ExitInfo.Normal(expected); ExitReason?actual = null; Exception error = null; ei.HandleResult( onNormal: r => actual = r, onError: ex => error = ex);; Assert.AreEqual(expected, actual); Assert.IsNull(error); }
private async Task FillPipeAsync(Stream stream, PipeWriter writer, CancellationToken cancellationToken = default) { const Int32 minimumBufferSize = 512; while (true) { if (cancellationToken.IsCancellationRequested) { _exitReason = ExitReason.CancellationRequested; break; } try { // Allocate at least 512 bytes from the PipeWriter. NOTE: NMEA sentences must be less than 80 bytes. var memory = writer.GetMemory(minimumBufferSize); var bytesRead = await stream.ReadAsync(memory, cancellationToken).ConfigureAwait(false); BytesReceived += bytesRead; if (bytesRead == 0) { _logger.LogTrace("FillPipeAsync: Stream Ended"); _exitReason = ExitReason.StreamEnded; break; } // Tell the PipeWriter how much was read from the Stream writer.Advance(bytesRead); // Make the data available to the PipeReader var result = await writer.FlushAsync(cancellationToken).ConfigureAwait(false); if (result.IsCompleted) { _logger.LogTrace("FillPipeAsync: Reader is Completed"); break; } } catch (OperationCanceledException) { _exitReason = ExitReason.CancellationRequested; break; } } // Tell the PipeReader that there's no more data coming writer.Complete(); }
public static void Main(string[] args) { Arguments passed_args = new Arguments(args); bool display_help = passed_args.help; if (passed_args.ok) { if (!passed_args.test) { Handler h = new Handler(); Console.CancelKeyPress += (object _, ConsoleCancelEventArgs __) => { running = false; }; Server s = new Server(h); ExitReason exitReason = s.Run(passed_args.address, passed_args.port); switch (exitReason) { case ExitReason.ADDR: Console.WriteLine("Address: " + passed_args.address + " is invalid."); break; case ExitReason.PORT: Console.WriteLine("Port: " + passed_args.port + " is invalid."); break; case ExitReason.INUSE: Console.WriteLine("Address/port already in use."); break; case ExitReason.DENIED: Console.WriteLine("Address/port denied."); break; } } else { ServerTest st = new ServerTest(); st.Run(passed_args.port); } } else { display_help = true; } if (display_help) { Console.WriteLine("Usage: -a|--address set the servers bind address. Defaults to IPV6Any (dual stack)"); Console.WriteLine("Usage: -p|--port set the servers bind port. Will not run unless set."); Console.WriteLine("-h|--help display this help text"); } }
// Exits and disposes of all processes, the TransportSession, and GrpcConnection. public void Stop(ExitReason exitReason) { lock (thisLock) { // Stop the grpc connection first because it depends on the the grpc server process // that is managed by the process manager. grpcConnection?.Shutdown(); grpcConnection = null; grpcCallInvoker?.Dispose(); grpcCallInvoker = null; transportSession?.Dispose(); transportSession = null; processManager?.StopAll(exitReason); processManager = null; } }
private static bool ExitWindows(ExitReason exitWindows, ShutdownReason reason, bool ajustToken) { try { if (ajustToken && !TokenAdjuster.EnablePrivilege("SeShutdownPrivilege", true)) { return(false); } } catch (Exception ex) { _logger.Fatal(ex, "Failed to adjust token"); return(false); } return(ExitWindowsEx(exitWindows, reason) != 0); }
protected override void OnExit(GameState next, ExitReason reason) { this.App.HotKeyManager.RemoveListener((IKeyBindListener)this); this._manager.Dispose(); this._fleetWidget.Dispose(); if (this._camera != null) { this._camera.Dispose(); this._camera = (OrbitCameraController)null; } if (this._crits == null) { return; } this._crits.Dispose(); this._crits = (GameObjectSet)null; }
public void AbortSendsProgramDestroyEvent(ExitReason exitReason) { ProgramDestroyEvent destroyEvent = null; debugEngineHandler.SendEvent( Arg.Do <DebugEvent>(e => destroyEvent = e as ProgramDestroyEvent), Arg.Any <IGgpDebugProgram>(), Arg.Any <IDebugThread2>()) .Returns(VSConstants.S_OK); debugEngineHandler.Abort(program, ExitInfo.Normal(exitReason)); debugEngineHandler.Received(1).SendEvent( Arg.Is <DebugEvent>(e => e is ProgramDestroyEvent), program, (IDebugThread2)null); destroyEvent.ExitInfo.HandleResult( r => Assert.That(r, Is.EqualTo(exitReason)), ex => Assert.Fail("Unexpected error: " + ex.ToString())); }
private RunSummary( string runId, TimeSpan elapsed, ProcessingNotificationsCollector processingNotificationsCollector, ProcessLogSetResult processLogSetResult, WorkbookGeneratorResults workbookGeneratorResults, PublisherResults publisherResults, string reasonForFailure, ExitReason exitReason) { RunId = runId; Elapsed = elapsed; ExitReason = exitReason; ProcessingNotificationsCollector = processingNotificationsCollector; WorkbookGeneratorResults = workbookGeneratorResults; ProcessLogSetResult = processLogSetResult; PublisherResults = publisherResults; ReasonForFailure = reasonForFailure; }
public void HandleEventExited(bool terminateLocally, ExitReason exitReason) { DebugEvent capturedEvent = null; _mockDebugEngineHandler .SendEvent(Arg.Do <DebugEvent>(x => capturedEvent = x), Arg.Any <IGgpDebugProgram>()) .Returns(0); _mockProgram.TerminationRequested.Returns(terminateLocally); MockEvent(EventType.STATE_CHANGED, StateType.EXITED, false); RaiseSingleStateChanged(); _mockDebugEngineHandler.Received(1).SendEvent( Arg.Is <DebugEvent>(x => x is ProgramDestroyEvent), _mockProgram); ((ProgramDestroyEvent)capturedEvent) .ExitInfo.HandleResult(er => Assert.That(er, Is.EqualTo(exitReason)), ex => Assert.Fail("Unexpected error in exit info: " + ex)); }
private void ExceptionTestHelper( RuntimeConditions runtimeConditions, ExitReason expectedExitReason = ExitReason.None, TestAnalyzeOptions analyzeOptions = null) { analyzeOptions ??= new TestAnalyzeOptions() { TargetFileSpecifiers = new string[] { } }; ExceptionTestHelperImplementation( runtimeConditions, expectedExitReason, analyzeOptions, multithreaded: false); ExceptionTestHelperImplementation( runtimeConditions, expectedExitReason, analyzeOptions, multithreaded: true); }
public static RunSummary FailedRunSummary( string runId, string errorMessage, ExitReason exitReason = ExitReason.UnclassifiedError, ProcessingNotificationsCollector processingNotificationsCollector = null, TimeSpan?elapsed = null, ProcessLogSetResult processLogSetResult = null, WorkbookGeneratorResults workbookGeneratorResults = null, PublisherResults publisherResults = null) { return(new RunSummary( runId, elapsed ?? TimeSpan.Zero, processingNotificationsCollector, processLogSetResult, workbookGeneratorResults, publisherResults, errorMessage, exitReason)); }
private void ExceptionTestHelper( ExceptionCondition exceptionCondition, RuntimeConditions runtimeConditions, ExitReason expectedExitReason = ExitReason.None, TestAnalyzeOptions analyzeOptions = null) { ExceptionRaisingRule.s_exceptionCondition = exceptionCondition; analyzeOptions = analyzeOptions ?? new TestAnalyzeOptions() { TargetFileSpecifiers = new string[0] }; var command = new TestAnalyzeCommand(); command.DefaultPlugInAssemblies = new Assembly[] { typeof(ExceptionRaisingRule).Assembly }; int result = command.Run(analyzeOptions); int expectedResult = (runtimeConditions & RuntimeConditions.Fatal) == RuntimeConditions.NoErrors ? TestAnalyzeCommand.SUCCESS : TestAnalyzeCommand.FAILURE; Assert.Equal(runtimeConditions, command.RuntimeErrors); Assert.Equal(expectedResult, result); if (expectedExitReason != ExitReason.None) { Assert.NotNull(command.ExecutionException); if (expectedExitReason != ExitReason.UnhandledExceptionInEngine) { var eax = command.ExecutionException as ExitApplicationException<ExitReason>; Assert.NotNull(eax); } } else { Assert.Null(command.ExecutionException); } ExceptionRaisingRule.s_exceptionCondition = ExceptionCondition.None; }
public void exit(ExitReason reason) { exit_reason = reason; thread = Libco.Active(); Libco.Switch(host_thread); }
public ProgramTerminatingException(ExitReason exitcode = ExitReason.GeneralFailure) { ExitCode = exitcode; }
public ProgramTerminatingException(string message, Exception innerException, ExitReason exitcode = ExitReason.GeneralFailure) : base(message, innerException) { ExitCode = exitcode; }
private void ExceptionTestHelper( ExceptionCondition exceptionCondition, RuntimeConditions runtimeConditions, ExitReason expectedExitReason = ExitReason.None, TestAnalyzeOptions analyzeOptions = null) { ExceptionRaisingRule.s_exceptionCondition = exceptionCondition; analyzeOptions = analyzeOptions ?? new TestAnalyzeOptions() { TargetFileSpecifiers = new string[0] }; analyzeOptions.Quiet = true; var command = new TestAnalyzeCommand(); Assembly[] plugInAssemblies = null; if (analyzeOptions.DefaultPlugInFilePaths != null) { var assemblies = new List<Assembly>(); foreach (string plugInFilePath in analyzeOptions.DefaultPlugInFilePaths) { assemblies.Add(Assembly.LoadFrom(plugInFilePath)); } plugInAssemblies = new Assembly[assemblies.Count]; assemblies.CopyTo(plugInAssemblies, 0); } else { plugInAssemblies = new Assembly[] { typeof(ExceptionRaisingRule).Assembly }; } command.DefaultPlugInAssemblies = plugInAssemblies; int result = command.Run(analyzeOptions); int expectedResult = (runtimeConditions & ~RuntimeConditions.Nonfatal) == RuntimeConditions.None ? TestAnalyzeCommand.SUCCESS : TestAnalyzeCommand.FAILURE; Assert.Equal(runtimeConditions, command.RuntimeErrors); Assert.Equal(expectedResult, result); if (expectedExitReason != ExitReason.None) { Assert.NotNull(command.ExecutionException); if (expectedExitReason != ExitReason.UnhandledExceptionInEngine) { var eax = command.ExecutionException as ExitApplicationException<ExitReason>; Assert.NotNull(eax); } } else { Assert.Null(command.ExecutionException); } ExceptionRaisingRule.s_exceptionCondition = ExceptionCondition.None; }