private static void ListarContas() { Console.WriteLine("Listar contas"); LogHistory logConsultas = new LogHistory(listaLog.Count, TipoLog.Consulta, usuarioAtivo, 0, $"{usuarioAtivo} fez consulta às contas em {DateTime.Now}"); listaLog.Add(logConsultas); if (listaContas.Count == 0) { Console.WriteLine("Nenhuma conta cadastrada"); return; } for (int i = 0; i < listaContas.Count; i++) { Conta conta = listaContas[i]; Console.Write("#{0} - ", i); Console.WriteLine(conta); } }
private static void InserirConta() { Console.WriteLine("Inserir nova conta"); Console.Write("Digite 1 para Conta Fisica ou 2 para Juridica: "); int entradaTipoConta = int.Parse(Console.ReadLine()); Console.Write("Digite o Nome do Cliente: "); string entradaNome = Console.ReadLine(); Console.Write("Digite o saldo inicial: "); double entradaSaldo = double.Parse(Console.ReadLine()); Console.Write("Digite o crédito: "); double entradaCredito = double.Parse(Console.ReadLine()); Conta novaConta = new Conta(tipoConta: (TipoConta)entradaTipoConta, saldo: entradaSaldo, credito: entradaCredito, nome: entradaNome); listaContas.Add(novaConta); LogHistory contaCriada = new LogHistory(listaLog.Count, TipoLog.ContaCriada, novaConta.GetName(), entradaSaldo, $"Criada conta para {novaConta.GetName()}, com saldo inicial {entradaSaldo}"); listaLog.Add(contaCriada); }
/// <summary> /// Repeatedly De-queues logs from the LogHistory queue until the queue length matches LogHistoryLimit. /// </summary> private static void PruneLogHistory() { while (LogHistory.Count > LogHistoryLimit) { LogHistory.Dequeue(); } }
/// <summary> /// Digest Errors /// </summary> /// <param name="applicationIdentifier">Application Identifier</param> /// <returns>History</returns> public LogHistory <ErrorDisplay> DigestErrors(Guid applicationIdentifier) { Contract.Requires <ArgumentException>(Guid.Empty != applicationIdentifier); Contract.Ensures(Contract.Result <LogHistory <ErrorDisplay> >() != null); var query = new LogQuery() { From = DateTime.UtcNow.AddDays(-7), Top = 50000, ApplicationIdentifier = applicationIdentifier, Deep = true, }; var history = new LogHistory <ErrorDisplay>(); try { history = this.Digest <ErrorDisplay>(this.SelectErrors(query), Error21DaysFormat.FormatWithCulture(applicationIdentifier)); } catch (Exception ex) { this.Log(ex, EventTypes.Error, (int)ServiceFault.PerformanceDigest); } return(history); }
public void Log <TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func <TState, Exception, string> formatter) { if (!IsEnabled(logLevel)) { return; } if (formatter != null) { LogHistory.Add(formatter(state, exception)); } else { if (state != null) { LogHistory.Add($"{DateTime.Now:s} [{logLevel.ToString()}]: {state}"); } if (exception != null) { LogHistory.Add($"{DateTime.Now:s} [{logLevel.ToString()}] Exception Details: {exception.ToString().PadLeft(512, ' ').Substring(0, 511)}"); } } //cleanup LogHistory if (LogHistory.Count > 9999) { for (var i = 0; i < 1000; i++) { LogHistory.RemoveAt(0); } } }
public async Task <IActionResult> PutLogHistory(long id, LogHistory logHistory) { if (id != logHistory.Id) { return(BadRequest()); } _context.Entry(logHistory).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!LogHistoryExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
/// <summary> /// Logs the command, adding it to the log history and triggers an event /// </summary> /// <param name="command"></param> /// <param name="color"></param> private static void LogCommand(string command, string color) { DebugLogItem item = new DebugLogItem(command, color, Time.frameCount, Time.time, 3, true); LogHistory.Add(item); MMDebugLogEvent.Trigger(new DebugLogItem(null, "", Time.frameCount, Time.time, 0, false)); }
/// <summary> /// Digest /// </summary> /// <typeparam name="T">T</typeparam> /// <param name="items">Items</param> /// <param name="objectId">Object Id</param> /// <returns>Log History</returns> public LogHistory <T> Digest <T>(IEnumerable <T> items, string objectId) where T : LogItem { Contract.Requires <ArgumentException>(!string.IsNullOrWhiteSpace(objectId)); Contract.Ensures(Contract.Result <LogHistory <T> >() != null); using (new PerformanceMonitor()) { var history = new LogHistory <T>(); try { if (null != items && 0 < items.Count()) { history.GeneratedOn = DateTime.UtcNow; history.Count = items.Count(); history.Items = items.ToArray(); history.MinimumDate = items.Select(m => m.OccurredOn).Min(); history.MaximumDate = items.Select(m => m.OccurredOn).Max(); var blob = new BinaryBlob <LogHistory <T> >(ServerConfiguration.Default); blob.Save(objectId, history); } } catch (Exception ex) { this.Log(ex, EventTypes.Error, (int)ServiceFault.BlobDigest); } return(history); } }
public async Task <ActionResult <LogHistory> > PostLogHistory(LogHistory logHistory) { _context.LogHistory.Add(logHistory); await _context.SaveChangesAsync(); return(CreatedAtAction("GetLogHistory", new { id = logHistory.Id }, logHistory)); }
public void Messages() { var msg = new LogHistory <MessageDisplay>(); var data = new List <MessageDisplay>().ToArray(); msg.Items = data; Assert.AreEqual <MessageDisplay[]>(data, msg.Items); }
/// <summary> /// Enqueues the supplied <see cref="RealtimeLoggerEventArgs"/> instance to the LogHistory queue. If the queue exceeds /// 200 entries, the oldest log is first de-queued before the new log is enqueued. /// </summary> /// <param name="eventArgs">The event args instance to enqueue.</param> private static void AppendLogHistory(RealtimeLoggerEventArgs eventArgs) { LogHistory.Enqueue(eventArgs); if (LogHistory.Count > LogHistoryLimit) { PruneLogHistory(); } }
public void Log(LogHistory logHistory) { DbParam[] dbParams = new DbParam[] { new DbParam("@Name", DbType.String, string.IsNullOrEmpty(logHistory.Name) ? SqlString.Null : logHistory.Name, ParameterDirection.Input), new DbParam("@Time", DbType.DateTime, logHistory.Time, ParameterDirection.Input), new DbParam("@Action", DbType.String, string.IsNullOrEmpty(logHistory.Action) ? SqlString.Null : logHistory.Action, ParameterDirection.Input) }; this.ExecuteNoQuery("Proc_AddLog", dbParams); }
public void Count() { var random = new Random(); var msg = new LogHistory <MessageDisplay>(); var data = random.Next(); msg.Count = data; Assert.AreEqual <int>(data, msg.Count); }
public void GeneratedOn() { var msg = new LogHistory <MessageDisplay>(); Assert.IsNull(msg.GeneratedOn); var data = DateTime.UtcNow; msg.GeneratedOn = data; Assert.AreEqual <DateTime?>(data, msg.GeneratedOn); }
public void MinimumDate() { var msg = new LogHistory <MessageDisplay>(); Assert.IsNull(msg.MinimumDate); var data = DateTime.UtcNow; msg.MinimumDate = data; Assert.AreEqual <DateTime?>(data, msg.MinimumDate); }
public void LogWillPowerChanged(string name, int oldValue, int newValue) { if (oldValue > newValue) { LogHistory.Add(new Log($"{name}'s Willpower has decremented from {oldValue} to {newValue}")); } else if (newValue > oldValue) { LogHistory.Add(new Log($"{name}'s Willpower has incremented from {oldValue} to {newValue}")); } }
public void LogTurnChange(int newTurn, int previousTurn) { if (newTurn > previousTurn) { LogHistory.Add(new Log($"Incremented to turn {newTurn}")); } else if (newTurn < previousTurn) { LogHistory.Add(new Log($"Decremented to turn {newTurn}")); } }
public IActionResult Index() { var target = (MemoryTarget)LogManager.Configuration.FindTargetByName("memLogger"); var viewModel = new LogHistory { LogMessages = target.Logs.Select(LogMessage.FromString) }; return(View(viewModel)); }
public void LogObsessionPointsChanged(string name, int obsOldPts, int obsNewPts) { if (obsOldPts > obsNewPts) { LogHistory.Add(new Log( $"{name} has lost {obsOldPts - obsNewPts} Obsession Point{(obsOldPts - obsNewPts == 1 ? "" : "s")}")); } else if (obsNewPts > obsOldPts) { LogHistory.Add(new Log( $"{name} has earned {obsNewPts - obsOldPts} Obsession Point{(obsOldPts - obsNewPts == 1 ? "" : "s")}")); } }
private static void ConsultaLog() { if (listaLog.Count == 0) { Console.WriteLine("Não existe histórico para as contas"); return; } for (int i = 0; i < listaLog.Count; i++) { LogHistory logHistory = listaLog[i]; Console.WriteLine(logHistory); } }
private static bool AcessarSistema() { Console.Write("Digite o nome do usuário: "); string userAcesso = Console.ReadLine(); Console.Write("Digite a senha: "); ConsoleKeyInfo infoChave; string senhaAcesso = ""; do { infoChave = Console.ReadKey(true); if (infoChave.Key != ConsoleKey.Backspace && infoChave.Key != ConsoleKey.Enter) { senhaAcesso += infoChave.KeyChar; Console.Write("*"); } else { if (infoChave.Key == ConsoleKey.Backspace && senhaAcesso.Length > 0) { senhaAcesso = senhaAcesso.Substring(0, (senhaAcesso.Length - 1)); Console.Write("b b"); } } } while (infoChave.Key != ConsoleKey.Enter); Usuario confereUser = new Usuario(userAcesso, senhaAcesso); for (int i = 0; i < listaUsuarios.Count; i++) { if (listaUsuarios[i].Equals(confereUser)) { usuarioAtivo = userAcesso; LogHistory logAcesso = new LogHistory(listaLog.Count, TipoLog.Acesso, userAcesso, 0, $"Acesso ao sistema realizado por {userAcesso} em {DateTime.Now}"); listaLog.Add(logAcesso); return(true); } } Console.WriteLine("Usuário e/ou senha incorretos."); return(false); }
private void Enqueue(IConsoleLogMessage message) { if (message.Type > MaxLogLevel) { return; } if (LogHistory.Count > MaxLogRegister) { LogHistory.Dequeue(); } LogHistory.Enqueue(message); OnReceiveMessage?.Invoke(message); }
public void LogDiceRoll(int[] rolls, int modifier) { var output = rolls.Length switch { 0 => throw new NotImplementedException(), 1 => $"{rolls.Length} dice rolled: {rolls.Sum() + modifier}", _ => $"{rolls.Length} dice rolled: {string.Join(", ", rolls)} for a total of {rolls.Sum() + modifier}" }; if (modifier != 0) { output += $" ({modifier:+#;-#} modifier)"; } LogHistory.Add(new Log(output)); }
private static void CadastrarUsuario() { Console.WriteLine("Introduza o nome do novo usário e nova senha"); Console.WriteLine("Regras:"); Console.WriteLine("Usuário tem de ter no mínimo 8 caracteres"); Console.WriteLine("Senhas tem que ter no mínimo 8 caractares, composto por no mínimo: 1 número, 1 letra minúscula, 1 letra maiúscula e 1 caracter especial"); Console.Write("Digite o nome do novo usuário: "); string username = Console.ReadLine(); Console.Write("Digite a nova senha: "); ConsoleKeyInfo infoChave; string senha = ""; do { infoChave = Console.ReadKey(true); if (infoChave.Key != ConsoleKey.Backspace && infoChave.Key != ConsoleKey.Enter) { senha += infoChave.KeyChar; Console.Write("*"); } else { if (infoChave.Key == ConsoleKey.Backspace && senha.Length > 0) { senha = senha.Substring(0, (senha.Length - 1)); Console.Write("b b"); } } } while (infoChave.Key != ConsoleKey.Enter); Usuario novoUsuario = new Usuario(username, senha); if (novoUsuario.CadastarUsuario()) { listaUsuarios.Add(novoUsuario); LogHistory logCria = new LogHistory(listaLog.Count, TipoLog.ContaCriada, username, 0, $"Conta com o nome {username} criada em {DateTime.Now}"); listaLog.Add(logCria); } }
private static void Depositar() { Console.Write("Digite o número da conta: "); int indiceConta = int.Parse(Console.ReadLine()); Console.Write("Digite o valor a ser depositado: "); double valorDeposito = double.Parse(Console.ReadLine()); listaContas[indiceConta].Depositar(valorDeposito); LogHistory logDeposito = new LogHistory(listaLog.Count, TipoLog.Deposito, listaContas[indiceConta].GetName(), valorDeposito, $"Depósito de R${valorDeposito} realizado na conta número {indiceConta} de {listaContas[indiceConta].GetName()}"); listaLog.Add(logDeposito); }
private static void Sacar() { Console.Write("Digite o número da conta: "); int indiceConta = int.Parse(Console.ReadLine()); Console.Write("Digite o valor a ser sacado: "); double valorSaque = double.Parse(Console.ReadLine()); listaContas[indiceConta].Sacar(valorSaque); LogHistory logSaque = new LogHistory(listaLog.Count, TipoLog.Saque, listaContas[indiceConta].GetName(), valorSaque, $"Saque de R${valorSaque} realizado na conta número {indiceConta} de {listaContas[indiceConta].GetName()}"); listaLog.Add(logSaque); }
private void InitUIElement() { _TitleBar = new TitleBar(); _HeadBar = new HeadBar(); _LogHistory = new LogHistory(_HeadBar); //初始化log视图实例 _LogHistoryView = new LogHistoryView(_LogHistory); //预设命令行UI _helperOverLay = new HelperOverLay(); _logModules = new LogModules(_LogHistoryView, _LogHistory); //实例键盘实例对象 _InputField = new KeyBoardInputField(_LogHistoryView, _LogHistory); }
private static void Transferir() { Console.Write("Digite o número da conta de origem: "); int indiceContaOrigem = int.Parse(Console.ReadLine()); Console.Write("Digite o número da conta de destino: "); int indiceContaDestino = int.Parse(Console.ReadLine()); Console.Write("Digite o valor a ser transferido: "); double valorTransferencia = double.Parse(Console.ReadLine()); listaContas[indiceContaOrigem].Transferir(valorTransferencia, listaContas[indiceContaDestino]); LogHistory logTransf = new LogHistory(listaLog.Count, TipoLog.Transferencia, listaContas[indiceContaOrigem].GetName(), valorTransferencia, $"Transferência de R${valorTransferencia} realizada da conta número {indiceContaOrigem} de {listaContas[indiceContaOrigem].GetName()} " + $"para a conta número {indiceContaDestino} de {listaContas[indiceContaDestino].GetName()}"); listaLog.Add(logTransf); }
/// <summary> /// the function executes the get log command /// </summary> /// <param name= args> the commands arguments </param> /// <param name= result> the result of the function, if succeeded or not </param> /// <return> returns the log history as a string </return> public string Execute(string[] args, out bool result) { LogHistory logHistory = LogHistory.CreateLogHistory(); result = true; List <string[]> logList = logHistory.Logs; // the log array to return, each cell has the message type comma message string[] answer = new string[logList.Count]; int i = 0; // create an array of strings representing the log foreach (string[] log in logList.ToArray()) { // log[0] is the message type, log[1] is the message itself answer[i] = log[0] + "," + log[1]; i++; } // return the info converted to Json ready to be sent to client InfoEventArgs info = new InfoEventArgs((int)EnumTranslator.CommandToInfo((int)CommandEnum.LogCommand), answer); return(JsonConvert.SerializeObject(info)); }
public void GetDigest() { var random = new Random(); var digest = new LogHistory <MessageDisplay>() { Count = random.Next(), GeneratedOn = DateTime.UtcNow, MaximumDate = DateTime.UtcNow.AddSeconds(random.Next()), MinimumDate = DateTime.UtcNow.AddMinutes(random.Next()), }; var blob = new BinaryBlob <LogHistory <MessageDisplay> >(CloudStorageAccount.DevelopmentStorageAccount); var objectId = string.Format("happy{0}doodie", random.Next()); blob.Save(objectId, digest); var item = blob.GetDigest <LogHistory <MessageDisplay> >(objectId); Assert.AreEqual <int>(digest.Count, item.Count); Assert.AreEqual <DateTime?>(digest.GeneratedOn, item.GeneratedOn); Assert.AreEqual <DateTime?>(digest.MaximumDate, item.MaximumDate); Assert.AreEqual <DateTime?>(digest.MinimumDate, item.MinimumDate); }