public async Task ReleasesInmatesAsync() { var workDir = Common.GetWorkDir(); await IoHelpers.TryDeleteDirectoryAsync(workDir); // Create prison. CoordinatorParameters coordinatorParameters = new(workDir); coordinatorParameters.RuntimeCoordinatorConfig.ReleaseUtxoFromPrisonAfter = TimeSpan.FromMilliseconds(1); using var w = new Warden(coordinatorParameters.UtxoWardenPeriod, coordinatorParameters.PrisonFilePath, coordinatorParameters.RuntimeCoordinatorConfig); await w.StartAsync(CancellationToken.None); var i1 = new Inmate(BitcoinFactory.CreateOutPoint(), Punishment.Noted, DateTimeOffset.FromUnixTimeSeconds(DateTimeOffset.UtcNow.ToUnixTimeSeconds()), uint256.Zero); var i2 = new Inmate(BitcoinFactory.CreateOutPoint(), Punishment.Banned, DateTimeOffset.FromUnixTimeSeconds(DateTimeOffset.UtcNow.ToUnixTimeSeconds()), uint256.Zero); var p = w.Prison; p.Punish(i1); p.Punish(i2); Assert.NotEmpty(p.GetInmates()); // Wait until releases from prison. await w.TriggerAndWaitRoundAsync(TimeSpan.FromSeconds(7)); Assert.Empty(p.GetInmates()); await w.StopAsync(CancellationToken.None); }
public async Task NoPrisonSerializationAsync() { // Don't serialize when there's no change. var workDir = Common.GetWorkDir(); await IoHelpers.TryDeleteDirectoryAsync(workDir); // Create prison. CoordinatorParameters coordinatorParameters = new(workDir); using var w = new Warden(coordinatorParameters.UtxoWardenPeriod, coordinatorParameters.PrisonFilePath, coordinatorParameters.RuntimeCoordinatorConfig); await w.StartAsync(CancellationToken.None); var i1 = new Inmate(BitcoinFactory.CreateOutPoint(), Punishment.Noted, DateTimeOffset.FromUnixTimeSeconds(DateTimeOffset.UtcNow.ToUnixTimeSeconds()), uint256.Zero); var i2 = new Inmate(BitcoinFactory.CreateOutPoint(), Punishment.Banned, DateTimeOffset.FromUnixTimeSeconds(DateTimeOffset.UtcNow.ToUnixTimeSeconds()), uint256.Zero); w.Prison.Punish(i1); w.Prison.Punish(i2); // Wait until serializes. await w.TriggerAndWaitRoundAsync(TimeSpan.FromSeconds(7)); // Make sure it does not serialize again as there was no change. File.Delete(w.PrisonFilePath); await w.TriggerAndWaitRoundAsync(TimeSpan.FromSeconds(7)); Assert.False(File.Exists(w.PrisonFilePath)); await w.StopAsync(CancellationToken.None); }
public override async Task StopAsync(CancellationToken cancellationToken) { await base.StopAsync(cancellationToken).ConfigureAwait(false); await ConfigWatcher.StopAsync(cancellationToken).ConfigureAwait(false); await Warden.StopAsync(cancellationToken).ConfigureAwait(false); }
public ValidationResponse Validate(int request, Warden warden) { if (request != warden.WardenId) { return(new ValidationResponse(false, "Incorrect id code.")); } return(new ValidationResponse(true)); }
protected override async Task ExecuteAsync(CancellationToken stoppingToken) { await ConfigWatcher.StartAsync(stoppingToken).ConfigureAwait(false); await Warden.StartAsync(stoppingToken).ConfigureAwait(false); await Arena.StartAsync(stoppingToken).ConfigureAwait(false); }
public override void Dispose() { CoinJoinFeeRateStatStore.NewStat -= FeeRateStatStore_NewStat; Arena.CoinJoinBroadcast -= Arena_CoinJoinBroadcast; ConfigWatcher.Dispose(); Warden.Dispose(); base.Dispose(); }
public WardenController() { _memberRepo = new MemberRepo(); _validator = new WardenValidator(); _theWarden = new Warden() { WardenId = 123456 }; }
public Warden AddWarden(string username, string password) { var newWarden = new Warden(username, password); newWarden.Id = _wardens.Count + 1; _wardens.Add(newWarden); return(newWarden); }
public async Task CanStartAndStopAsync() { var workDir = Common.GetWorkDir(); await IoHelpers.TryDeleteDirectoryAsync(workDir); CoordinatorParameters coordinatorParameters = new(workDir); using var w = new Warden(coordinatorParameters.UtxoWardenPeriod, coordinatorParameters.PrisonFilePath, coordinatorParameters.RuntimeCoordinatorConfig); await w.StartAsync(CancellationToken.None); await w.StopAsync(CancellationToken.None); }
public override async Task StopAsync(CancellationToken cancellationToken) { await base.StopAsync(cancellationToken).ConfigureAwait(false); await Arena.StopAsync(cancellationToken).ConfigureAwait(false); await ConfigWatcher.StopAsync(cancellationToken).ConfigureAwait(false); await Warden.StopAsync(cancellationToken).ConfigureAwait(false); await CoinJoinFeeRateStatStore.StopAsync(cancellationToken).ConfigureAwait(false); }
private void _on_Magic_Bullet_body_entered(object body) { if (body.ToString() != "player" && body.ToString() != "Orb") { explode(); } if (body.ToString() == "Warden") { Warden warden = (Warden)body; warden.take_damage(damage); } }
static void Main(string[] args) { Settings.InitDefaults(); GameContext context = null; StateMachine sm = new StateMachine(); LoggerFactory loggerFactory = new LoggerFactory(); loggerFactory.AddProvider(new ConsoleLogger()); loggerFactory.AddProvider(new FileLogger()); sm.Init(new Init()).Wait(); while (true) { IEnumerable <string> lastGamePlayers = context?.LoggedInPlayers .Where(x => x.Team != HQMTeam.NoTeam) .Select(x => x.Name) ?? new List <string>(); context = new GameContext(); Warden warden = new Warden(context); CommandListener commandListener = new CommandListener(); LoginHandler loginHandler = new LoginHandler(context, commandListener); SubstitutionHandler subHandler = new SubstitutionHandler(context, commandListener); loginHandler.Init().Wait(); sm.AddState(new WaitingForPlayers(context, warden)); sm.AddState(new GameSetup(context, lastGamePlayers)); sm.AddState(new Gameplay()); sm.AddState(new EndGame(context, warden)); while (!sm.Update().Result) { Thread.Sleep(50); loginHandler.HandleLogins(); subHandler.Update(); warden.Watch(); } ; } }
public async Task <WardenDetailViewData> Handle(AddWardenCommand request, CancellationToken cancellationToken) { var res = new Warden() { Name = request.Name, Address = request.Address, City = request.City, ContactNumber = request.ContactNumber, MailId = request.MailId, Pin = request.Pin, StartDate = request.StartDate, EndDate = request.EndDate, CurrentStatus = request.Status, WardenAndHostelRelations = request.WardenAndHostelRelations }; _context.Wardens.Add(res); await _context.SaveChangesAsync(cancellationToken); return(request); }
public async Task PrisonSerializationAsync() { var workDir = Common.GetWorkDir(); await IoHelpers.TryDeleteDirectoryAsync(workDir); // Create prison. CoordinatorParameters coordinatorParameters = new(workDir); using var w = new Warden(coordinatorParameters.UtxoWardenPeriod, coordinatorParameters.PrisonFilePath, coordinatorParameters.RuntimeCoordinatorConfig); await w.StartAsync(CancellationToken.None); var i1 = new Inmate(BitcoinFactory.CreateOutPoint(), Punishment.Noted, DateTimeOffset.FromUnixTimeSeconds(DateTimeOffset.UtcNow.ToUnixTimeSeconds()), uint256.Zero); var i2 = new Inmate(BitcoinFactory.CreateOutPoint(), Punishment.Banned, DateTimeOffset.FromUnixTimeSeconds(DateTimeOffset.UtcNow.ToUnixTimeSeconds()), uint256.Zero); w.Prison.Punish(i1); w.Prison.Punish(i2); // Wait until serializes. await w.TriggerAndWaitRoundAsync(TimeSpan.FromSeconds(7)); await w.StopAsync(CancellationToken.None); // See if prev UTXOs are loaded. CoordinatorParameters coordinatorParameters2 = new(workDir); using var w2 = new Warden(coordinatorParameters2.UtxoWardenPeriod, coordinatorParameters2.PrisonFilePath, coordinatorParameters2.RuntimeCoordinatorConfig); await w2.StartAsync(CancellationToken.None); Assert.True(w2.Prison.TryGet(i1.Utxo, out var sameI1)); Assert.True(w2.Prison.TryGet(i2.Utxo, out var sameI2)); Assert.Equal(i1.LastDisruptedRoundId, sameI1 !.LastDisruptedRoundId); Assert.Equal(i2.LastDisruptedRoundId, sameI2 !.LastDisruptedRoundId); Assert.Equal(i1.Punishment, sameI1 !.Punishment); Assert.Equal(i2.Punishment, sameI2 !.Punishment); Assert.Equal(i1.Started, sameI1 !.Started); Assert.Equal(i2.Started, sameI2 !.Started); await w2.StopAsync(CancellationToken.None); }
public static void Main(string[] args) { //Setup Random random = new Random(); //Initalize Switches ISwitch switchOne = new Switch(new IntIdentifier(1), (SwitchPosition)random.Next(2)); ISwitch switchTwo = new Switch(new IntIdentifier(2), (SwitchPosition)random.Next(2)); //Initalize SwitchRoom ISwitchRoom switchRoom = new SwitchRoom(new List <ISwitch>() { switchOne, switchTwo }); //Initalize Prisoners ILeader leader = new Leader(new IntIdentifier(1)); List <IPrisoner> prisoners = new List <IPrisoner>() { leader }; for (int prisonerId = 2; prisonerId <= 23; prisonerId++) { prisoners.Add(new Prisoner(new IntIdentifier(prisonerId))); } //Initalize Warden IWarden warden = new Warden(switchRoom, prisoners); //Execute do { warden.Action(); } while (!warden.FreePrisoners()); //Finalize Console.WriteLine("Prisoners are Free!"); }
public static int addWarden(Warden warden) { int a = 0; int result = 0; SqlConnection db = new SqlConnection(ConfigurationSettings.AppSettings["ConStr"]); db.Open(); try { warden.Ptype = 1; SqlCommand insert = new SqlCommand("insert into PersonTbl values ('" + warden.FirstName + "','" + warden.LastName + "','" + warden.CNIC + "','" + warden.contact + "','" + warden.Email + "','" + warden.Address + "','" + warden.Ptype + "')", db); result = insert.ExecuteNonQuery(); insert.Dispose(); } catch (Exception e) { Console.WriteLine(e.Message); } SqlCommand select = new SqlCommand("select Id from PersonTbl where CNIC='" + warden.CNIC + "'", db); try { SqlDataReader r = select.ExecuteReader(); if (r.Read()) { a = Convert.ToInt32(r["Id"]); } r.Close(); SqlCommand cmd = new SqlCommand("insert into WardenTbl (Id, RoomId, LoginId, Designation,OfficeLocation,Password) values ('" + a + "','" + warden.RoomNo + "','" + warden.LoginId + "','" + warden.Designation + "','" + warden.OfficeLocation + "','" + warden.Password + "')", db); result = cmd.ExecuteNonQuery(); }catch (Exception e) { MessageBox.Show(e.Message); } db.Close(); return(result); }
public EndGame(GameContext context, Warden warden) { m_Context = context; m_Warden = warden; }
private static IWarden ConfigureWarden() { var wardenConfiguration = WardenConfiguration .Create() .AddDiskWatcher(cfg => { cfg.WithFilesToCheck(@"D:\Test\File1.txt", @"D:\Test\File2.txt") .WithPartitionsToCheck("D", @"E:\") .WithDirectoriesToCheck(@"D:\Test"); }) .AddMongoDbWatcher("mongodb://*****:*****@"Data Source=.\sqlexpress;Initial Catalog=MyDatabase;Integrated Security=True", cfg => { cfg.WithQuery("select * from users where id = @id", new Dictionary <string, object> { ["id"] = 1 }) .EnsureThat(users => users.Any(user => user.Name == "admin")); }) .AddPerformanceWatcher(cfg => cfg.EnsureThat(usage => usage.Cpu < 50 && usage.Ram < 5000), hooks => hooks.OnCompleted(result => System.Console.WriteLine(result.WatcherCheckResult.Description))) .AddRedisWatcher("localhost", 1, cfg => { cfg.WithQuery("get test") .EnsureThat(results => results.Any(x => x == "test-value")); }) .AddWebWatcher("http://httpstat.us/200", hooks => { hooks.OnStartAsync(check => WebsiteHookOnStartAsync(check)) .OnSuccessAsync(check => WebsiteHookOnSuccessAsync(check)) .OnCompletedAsync(check => WebsiteHookOnCompletedAsync(check)) .OnFailureAsync(check => WebsiteHookOnFailureAsync(check)); }) .AddWebWatcher("API watcher", "http://httpstat.us/200", HttpRequest.Post("users", new { name = "test" }, headers: new Dictionary <string, string> { ["User-Agent"] = "Warden", ["Authorization"] = "Token MyBase64EncodedString" }), cfg => cfg.EnsureThat(response => response.Headers.Any()) ) //Set proper API key or credentials. //.IntegrateWithSendGrid("api-key", "*****@*****.**", cfg => //{ // cfg.WithDefaultSubject("Monitoring status") // .WithDefaultReceivers("*****@*****.**"); //}) //.SetAggregatedWatcherHooks((hooks, integrations) => //{ // hooks.OnFirstFailureAsync(result => // integrations.SendGrid().SendEmailAsync("Monitoring errors have occured.")) // .OnFirstSuccessAsync(results => // integrations.SendGrid().SendEmailAsync("Everything is up and running again!")); //}) //Set proper URL of the Warden Web API .IntegrateWithHttpApi("http://localhost:11223/api", "1pi0Tp9/n2wdLSRsUBAKXwHGPXoFU/58wV8Dc+vIL+k2/fWF14VXPiuK", "0b8351f1-dc93-4137-90b9-e3a7d7e12054") .SetGlobalWatcherHooks(hooks => { hooks.OnStart(check => GlobalHookOnStart(check)) .OnFailure(result => GlobalHookOnFailure(result)) .OnSuccess(result => GlobalHookOnSuccess(result)) .OnCompleted(result => GlobalHookOnCompleted(result)); }) .SetHooks((hooks, integrations) => { hooks.OnIterationCompleted(iteration => OnIterationCompleted(iteration)) .OnIterationCompletedAsync(iteration => integrations.HttpApi() .PostIterationToWardenPanelAsync(iteration)) .OnError(exception => System.Console.WriteLine(exception)); }) .Build(); return(Warden.Create(wardenConfiguration)); }
public override void Dispose() { ConfigWatcher.Dispose(); Warden.Dispose(); base.Dispose(); }
public WaitingForPlayers(GameContext context, Warden warden) { m_Context = context; m_Warden = warden; }