private static DBData ParsarBanco(FileInfo banco) { DBData dados = new DBData(); if (banco.Exists) { using (var reader = banco.OpenText()) { string rawLine; while ((rawLine = reader.ReadLine()) != null) { dados.Add(Entrada.Parsar(rawLine)); } } } return(dados); }
public void Update(Entrada entrada, Action <DBException> onCompleted) { SGDB.Locks.Request(entrada.Id.Value, false, (toRelease) => { if (SGDB.MinhaVisão(this).FromID(entrada.Id.Value) == null) { onCompleted(new DBException($"Não é possível alterar o registro de ID {entrada.Id.Value} pois o mesmo não existe.")); toRelease.Release(); } else { Ações.Add(new Ação(Classes.Ações.Modificar, entrada)); OnAçãoChanged?.Invoke(this, null); onCompleted.Invoke(null); Logger.Log($"Transação {Id}: Update {entrada}"); } }, this); }
public void Insert(Entrada entrada, Action <DBException> onCompleted) { SGDB.Locks.Request(entrada.Id.Value, false, (toRelease) => { foreach (Entrada ent in SGDB.MinhaVisão(this)) { if (ent.Id == entrada.Id) { onCompleted.Invoke(new DBException("Não é possível inserir esse registro. Um com o mesmo ID já existe.")); toRelease.Release(); return; } } Ações.Add(new Ação(Classes.Ações.Inserir, entrada)); OnAçãoChanged?.Invoke(this, null); onCompleted.Invoke(null); Logger.Log($"Transação {Id}: Insert {entrada}"); }, this); }
public LogEvent(string fromLog) { if (fromLog.StartsWith("Checkpoint")) { Type = LogEventTypes.Checkpoint; } else { var regex = Regex.Match(fromLog, "(\\S*) (\\S*): (\\S*) ?(.*)?"); Id = regex.Groups[2].Value; if (!Enum.TryParse(regex.Groups[3].Value, out _LogEventTypes)) { throw new Exception($"Evento '{regex.Groups[3].Value}' do log não foi reconhecido"); } if (regex.Groups[4].Success && regex.Groups[4].Value.Length > 0) { Data = Entrada.Parsar(regex.Groups[4].Value); } } }
public Ação(Ações tipo, Entrada diferença) { Tipo = tipo; Dados = diferença; }