static async Task Loop(CancellationToken token) { int iterations = 0; var r = new Random(); while (!token.IsCancellationRequested) { try { await Task.Delay(17500 + r.Next(10000), token).ConfigureAwait(false); if (++iterations % 2 == 0) { ChaosHelper.StopRavenDB(); } else { ChaosHelper.KillRavenDB(); } ChaosHelper.StartRavenDB(); } catch (Exception ex) { LogManager.GetLogger <RavenDBChoasEngine>().Warn("Loop", ex); } } }
private static void ShowComputedHash <T>(string algDisplayName, byte[] data, System.IO.TextWriter w) where T : HashAlgorithm, new() { using (var alg = new T()) { var hash = alg.ComputeHash(data); w.WriteLine("{0}:", algDisplayName); foreach (ChaosHelper.KeyEncoding item in Enum.GetValues(typeof(ChaosHelper.KeyEncoding))) { w.WriteLine("{0,-20}{1}", item, ChaosHelper.FormatByteArray(hash, item)); } w.WriteLine(); } }
static void InitAppDomainEventLogging() { ChaosHelper.StartRavenDB(); var firstChanceLog = LogManager.GetLogger("FirstChanceException"); var unhandledLog = LogManager.GetLogger("UnhandledException"); var domain = AppDomain.CurrentDomain; domain.FirstChanceException += (o, ea) => { firstChanceLog.Debug(ea.Exception.Message, ea.Exception); }; domain.UnhandledException += (o, ea) => { var exception = ea.ExceptionObject as Exception; if (exception != null) { unhandledLog.Fatal(exception.Message, exception); } }; }
// GET: api/Passwords public IHttpActionResult Get(int count = 20, int length = 12, string chars = "ulns") { if (count < 1 || count > 50) { count = 20; } if (length < 5 || length > 20) { length = 12; } ChaosHelper.PasswordChars allowedChars = 0; if (chars.IndexOf('u') > -1) { allowedChars |= ChaosHelper.PasswordChars.UpperCaseLetters; } if (chars.IndexOf('l') > -1) { allowedChars |= ChaosHelper.PasswordChars.LowerCaseLetters; } if (chars.IndexOf('n') > -1) { allowedChars |= ChaosHelper.PasswordChars.Numbers; } if (chars.IndexOf('s') > -1) { allowedChars |= ChaosHelper.PasswordChars.Special; } if (allowedChars == 0) { allowedChars = ChaosHelper.PasswordChars.All; } var output = new StringBuilder(); for (int i = 0; i < count; i++) { output.AppendLine(ChaosHelper.GeneratePassword(length, allowedChars)); } return(Ok(output.ToString())); }
// GET: api/OtherKeys public IHttpActionResult Get(int count = 20, int length = 64, string encoding = "Hex") { var encodingFlag = (ChaosHelper.KeyEncoding)Enum.Parse(typeof(ChaosHelper.KeyEncoding), encoding); if (count < 1 || count > 50) { count = 20; } if (length < 16 || length > 8192) { length = 64; } var output = new StringBuilder(); for (int i = 0; i < count; i++) { output.AppendLine(ChaosHelper.GenerateKey(length, encodingFlag)); } return(Ok(output.ToString())); }
public async Task ReceiveAsync(IContext context) { switch (context.Message) { case Started _: { _logger.LogInformation($"{nameof(UserActor)} ID='{context.Self.Id}' has started"); using (_tracer.BuildSpan("Recovering actor state").StartActive()) { await _persistence.RecoverStateAsync(); } } break; case GetUsers msg: { var @event = _state.GetAllUsers(msg.Limit, msg.Skip); context.Respond(@event); } break; case GetUser msg: { var @event = _state.GetUserById(msg.Id); context.Respond(@event); } break; case CreateUser msg: { try { using (var scope = _tracer.BuildSpan("Persisting UserCreated event").StartActive()) { if (ChaosHelper.ShouldCreateUserCrash(scope.Span)) { throw new Exception("Creating user disabled by Chaos"); } var @event = _state.CreateUser(msg.Id, msg.Name); if (@event is UserCreated) { scope.Span.Log(new Dictionary <string, object> { [nameof(@event)] = JsonConvert.SerializeObject(@event) }); await _persistence.PersistEventAsync(@event) .ContinueWith(t => _persistence.PersistSnapshotAsync(_state)); } context.Respond(@event); } } catch (Exception e) { _logger.LogError(e, "Error creating user"); context.Respond(new UnexpectedErrorOcurred(msg.Id)); } } break; case DeleteUser msg: { try { var @event = _state.DeleteUser(msg.Id); if (@event is UserDeleted) { using (var scope = _tracer.BuildSpan("Persisting UserDeleted event").StartActive()) { scope.Span.Log(new Dictionary <string, object> { [nameof(@event)] = JsonConvert.SerializeObject(@event), }); await _persistence.PersistEventAsync(@event) .ContinueWith(t => _persistence.PersistSnapshotAsync(_state)); } } context.Respond(@event); } catch (Exception e) { _logger.LogError(e, "Error deleting user"); context.Respond(new UnexpectedErrorOcurred(msg.Id)); } } break; } }
// GET: api/MachineKey public IHttpActionResult Get(string validation = "HMACSHA256", string decryption = "AES256") { int validationKeyLength, decryptionKeyLength; switch (validation) { case "MD5": validationKeyLength = 128; break; case "SHA1": validationKeyLength = 160; break; case "3DES": validationKeyLength = 192; break; case "AES": case "HMACSHA256": validationKeyLength = 256; break; case "HMACSHA384": validationKeyLength = 384; break; case "HMACSHA512": validationKeyLength = 512; break; default: return(BadRequest("Invalid parameter 'validation'")); } switch (decryption) { case "DES": decryptionKeyLength = 64; break; case "3DES": decryptionKeyLength = 192; break; case "AES128": decryption = "AES"; decryptionKeyLength = 128; break; case "AES192": decryption = "AES"; decryptionKeyLength = 192; break; case "AES256": decryption = "AES"; decryptionKeyLength = 256; break; default: return(BadRequest("Invalid parameter 'decryption'")); } var output = string.Format(XML_CODE, validation, decryption, ChaosHelper.GenerateKey(validationKeyLength / 8, ChaosHelper.KeyEncoding.UpperHex), ChaosHelper.GenerateKey(decryptionKeyLength / 8, ChaosHelper.KeyEncoding.UpperHex)); return(Ok(output)); }