/// <inheritdoc /> public void Create(ActivityLogEntry entry) { if (entry == null) { throw new ArgumentNullException(nameof(entry)); } using var connection = GetConnection(); connection.RunInTransaction(db => { using var statement = db.PrepareStatement("insert into ActivityLog (Name, Overview, ShortOverview, Type, ItemId, UserId, DateCreated, LogSeverity) values (@Name, @Overview, @ShortOverview, @Type, @ItemId, @UserId, @DateCreated, @LogSeverity)"); statement.TryBind("@Name", entry.Name); statement.TryBind("@Overview", entry.Overview); statement.TryBind("@ShortOverview", entry.ShortOverview); statement.TryBind("@Type", entry.Type); statement.TryBind("@ItemId", entry.ItemId); if (entry.UserId.Equals(Guid.Empty)) { statement.TryBindNull("@UserId"); } else { statement.TryBind("@UserId", entry.UserId.ToString("N", CultureInfo.InvariantCulture)); } statement.TryBind("@DateCreated", entry.Date.ToDateTimeParamValue()); statement.TryBind("@LogSeverity", entry.Severity.ToString()); statement.MoveNext(); }, TransactionMode); }
public async Task Update(ActivityLogEntry entry) { if (entry == null) { throw new ArgumentNullException("entry"); } using (WriteLock.Write()) { using (var connection = CreateConnection()) { connection.RunInTransaction(db => { using (var statement = db.PrepareStatement("replace into ActivityLogEntries (Id, Name, Overview, ShortOverview, Type, ItemId, UserId, DateCreated, LogSeverity) values (@Id, @Name, @Overview, @ShortOverview, @Type, @ItemId, @UserId, @DateCreated, @LogSeverity)")) { statement.TryBind("@Id", entry.Id.ToGuidBlob()); statement.TryBind("@Name", entry.Name); statement.TryBind("@Overview", entry.Overview); statement.TryBind("@ShortOverview", entry.ShortOverview); statement.TryBind("@Type", entry.Type); statement.TryBind("@ItemId", entry.ItemId); statement.TryBind("@UserId", entry.UserId); statement.TryBind("@DateCreated", entry.Date.ToDateTimeParamValue()); statement.TryBind("@LogSeverity", entry.Severity.ToString()); statement.MoveNext(); } }, TransactionMode); } } }
public void Create(ActivityLogEntry entry) { entry.Date = DateTime.UtcNow; _repo.Create(entry); EntryCreated?.Invoke(this, new GenericEventArgs <ActivityLogEntry>(entry)); }
public async Task CreateAsync(ActivityLogEntry entry) { entry.Date = DateTime.UtcNow; await _repo.CreateAsync(entry); EntryCreated?.Invoke(this, new GenericEventArgs <ActivityLogEntry>(entry)); }
public void Create(ActivityLogEntry entry) { entry.Date = DateTime.UtcNow; _repo.Create(entry); EventHelper.FireEventIfNotNull(EntryCreated, this, new GenericEventArgs <ActivityLogEntry>(entry), _logger); }
public async Task Create(ActivityLogEntry entry) { entry.Id = Guid.NewGuid().ToString("N"); entry.Date = DateTime.UtcNow; await _repo.Create(entry).ConfigureAwait(false); EventHelper.FireEventIfNotNull(EntryCreated, this, new GenericEventArgs <ActivityLogEntry>(entry), _logger); }
private ActivityLogEntry GetEntry(IDataReader reader) { var index = 0; var info = new ActivityLogEntry { Id = reader.GetGuid(index).ToString("N") }; index++; if (!reader.IsDBNull(index)) { info.Name = reader.GetString(index); } index++; if (!reader.IsDBNull(index)) { info.Overview = reader.GetString(index); } index++; if (!reader.IsDBNull(index)) { info.ShortOverview = reader.GetString(index); } index++; if (!reader.IsDBNull(index)) { info.Type = reader.GetString(index); } index++; if (!reader.IsDBNull(index)) { info.ItemId = reader.GetString(index); } index++; if (!reader.IsDBNull(index)) { info.UserId = reader.GetString(index); } index++; info.Date = reader.GetDateTime(index).ToUniversalTime(); index++; if (!reader.IsDBNull(index)) { info.Severity = (LogSeverity)Enum.Parse(typeof(LogSeverity), reader.GetString(index), true); } return(info); }
private ActivityLogEntry GetEntry(IReadOnlyList <IResultSetValue> reader) { var index = 0; var info = new ActivityLogEntry { Id = reader[index].ReadGuidFromBlob().ToString("N") }; index++; if (reader[index].SQLiteType != SQLiteType.Null) { info.Name = reader[index].ToString(); } index++; if (reader[index].SQLiteType != SQLiteType.Null) { info.Overview = reader[index].ToString(); } index++; if (reader[index].SQLiteType != SQLiteType.Null) { info.ShortOverview = reader[index].ToString(); } index++; if (reader[index].SQLiteType != SQLiteType.Null) { info.Type = reader[index].ToString(); } index++; if (reader[index].SQLiteType != SQLiteType.Null) { info.ItemId = reader[index].ToString(); } index++; if (reader[index].SQLiteType != SQLiteType.Null) { info.UserId = reader[index].ToString(); } index++; info.Date = reader[index].ReadDateTime(); index++; if (reader[index].SQLiteType != SQLiteType.Null) { info.Severity = (LogSeverity)Enum.Parse(typeof(LogSeverity), reader[index].ToString(), true); } return(info); }
private static ActivityLogEntry GetEntry(IReadOnlyList <IResultSetValue> reader) { var index = 0; var info = new ActivityLogEntry { Id = reader[index].ToInt64() }; index++; if (reader[index].SQLiteType != SQLiteType.Null) { info.Name = reader[index].ToString(); } index++; if (reader[index].SQLiteType != SQLiteType.Null) { info.Overview = reader[index].ToString(); } index++; if (reader[index].SQLiteType != SQLiteType.Null) { info.ShortOverview = reader[index].ToString(); } index++; if (reader[index].SQLiteType != SQLiteType.Null) { info.Type = reader[index].ToString(); } index++; if (reader[index].SQLiteType != SQLiteType.Null) { info.ItemId = reader[index].ToString(); } index++; if (reader[index].SQLiteType != SQLiteType.Null) { info.UserId = new Guid(reader[index].ToString()); } index++; info.Date = reader[index].ReadDateTime(); index++; if (reader[index].SQLiteType != SQLiteType.Null) { info.Severity = Enum.Parse <LogLevel>(reader[index].ToString(), true); } return(info); }
/// <summary> Gets a row. </summary> /// <param name="item"> The item. </param> /// <returns> The row. </returns> private ReportRow GetRow(ActivityLogEntry item) { ReportRow rRow = new ReportRow { Id = item.Id.ToString(), UserId = item.UserId }; return(rRow); }
private async Task CreateLogEntry(ActivityLogEntry entry) { try { await _activityManager.CreateAsync(entry); } catch { // Logged at lower levels } }
private void CreateLogEntry(ActivityLogEntry entry) { try { _activityManager.Create(entry); } catch { // Logged at lower levels } }
private async void CreateLogEntry(ActivityLogEntry entry) { try { await _activityManager.Create(entry).ConfigureAwait(false); } catch { // Logged at lower levels } }
public int AddUpdate(ActivityLogEntry Entry, string SessionUserId) { using (var connection = new SqlConnection(base.ConnectionString)) { return(Task.FromResult(connection.ExecuteScalar <int>("spActivityLogEntryAddUpdate", new { @ACTIVITYLOGENTRYID = Entry.ActivityLogEntryId, @ACTIVITYLOGID = Entry.ActivityLogId, @ACTIVITYID = Entry.ActivityId, @ACTIVITYLOGENTRYMARKID = Entry.ActivityLogEntryMarkId, @ENTRYDATE = Entry.EntryDate, @SESSIONUSERID = SessionUserId }, null, null, CommandType.StoredProcedure)).Result); } }
public void Update(ActivityLogEntry entry) { if (entry == null) { throw new ArgumentNullException("entry"); } using (WriteLock.Write()) { using (var connection = CreateConnection()) { connection.RunInTransaction(db => { using (var statement = db.PrepareStatement("Update ActivityLog set Name=@Name,Overview=@Overview,ShortOverview=@ShortOverview,Type=@Type,ItemId=@ItemId,UserId=@UserId,DateCreated=@DateCreated,LogSeverity=@LogSeverity where Id=@Id")) { statement.TryBind("@Id", entry.Id); statement.TryBind("@Name", entry.Name); statement.TryBind("@Overview", entry.Overview); statement.TryBind("@ShortOverview", entry.ShortOverview); statement.TryBind("@Type", entry.Type); statement.TryBind("@ItemId", entry.ItemId); if (entry.UserId.Equals(Guid.Empty)) { statement.TryBindNull("@UserId"); } else { statement.TryBind("@UserId", entry.UserId.ToString("N")); } statement.TryBind("@DateCreated", entry.Date.ToDateTimeParamValue()); statement.TryBind("@LogSeverity", entry.Severity.ToString()); statement.MoveNext(); } }, TransactionMode); } } }
private IEnumerable <ActivityLogEntry> CreateDebugEntries() { List <ActivityLogEntry> entries = new List <ActivityLogEntry>(); ActivityLogEntry entry1 = new ActivityLogEntry() { ActivityId = 1, ActivityLogEntryId = 1, ActivityLogId = 1, EntryDate = new DateTime(2016, 11, 7), Mark = new ActivityLogEntryMark() { ActivityEntryLogMarkId = 1, ActivityLogId = 1, Color = "#38c695", Description = "Did It!" } }; ActivityLogEntry entry2 = new ActivityLogEntry() { ActivityId = 1, ActivityLogEntryId = 2, ActivityLogId = 1, EntryDate = new DateTime(2016, 11, 8), Mark = new ActivityLogEntryMark() { ActivityEntryLogMarkId = 1, ActivityLogId = 1, Color = "#38c695", Description = "Did It!" } }; ActivityLogEntry entry3 = new ActivityLogEntry() { ActivityId = 2, ActivityLogEntryId = 3, ActivityLogId = 1, EntryDate = new DateTime(2016, 11, 8), Mark = new ActivityLogEntryMark() { ActivityEntryLogMarkId = 1, ActivityLogId = 1, Color = "#38c695", Description = "Did It!" } }; ActivityLogEntry entry4 = new ActivityLogEntry() { ActivityId = 2, ActivityLogEntryId = 4, ActivityLogId = 1, EntryDate = new DateTime(2016, 11, 9), Mark = new ActivityLogEntryMark() { ActivityEntryLogMarkId = 1, ActivityLogId = 1, Color = "#38c695", Description = "Did It!" } }; entries.Add(entry1); entries.Add(entry2); entries.Add(entry3); entries.Add(entry4); return(entries); }
public async Task WriteActivityLog(ActivityLogAction logAction, ClaimsPrincipal user, int environmentId, int articleId, string amount) { Article article = await _context.Articles .Include(a => a.Unit) .FirstOrDefaultAsync(a => a.Id == articleId); amount = article.UnitId == 1 ? $"{amount} {article.Unit.Abbreviation}" : $"{amount}x {article.ContentAmount}{article.Unit.Abbreviation}"; var newEntry = new ActivityLogEntry() { EnvironmentId = environmentId, Action = (int)logAction, Amount = amount, Description = article.Name, ImgUrl = article.ImageUrl, Username = user.FindFirstValue(ClaimTypes.Name), ActionDate = DateTime.Now }; await _context.ActivityLogEntries.AddAsync(newEntry); await _context.SaveChangesAsync(); }
public void RemoveActivityLogEntry(ActivityLogEntry e) { ActivityList.Remove(e); }
public async Task Update(ActivityLogEntry entry) { if (entry == null) { throw new ArgumentNullException("entry"); } await _writeLock.WaitAsync().ConfigureAwait(false); IDbTransaction transaction = null; try { transaction = _connection.BeginTransaction(); var index = 0; _saveActivityCommand.GetParameter(index++).Value = new Guid(entry.Id); _saveActivityCommand.GetParameter(index++).Value = entry.Name; _saveActivityCommand.GetParameter(index++).Value = entry.Overview; _saveActivityCommand.GetParameter(index++).Value = entry.ShortOverview; _saveActivityCommand.GetParameter(index++).Value = entry.Type; _saveActivityCommand.GetParameter(index++).Value = entry.ItemId; _saveActivityCommand.GetParameter(index++).Value = entry.UserId; _saveActivityCommand.GetParameter(index++).Value = entry.Date; _saveActivityCommand.GetParameter(index++).Value = entry.Severity.ToString(); _saveActivityCommand.Transaction = transaction; _saveActivityCommand.ExecuteNonQuery(); transaction.Commit(); } catch (OperationCanceledException) { if (transaction != null) { transaction.Rollback(); } throw; } catch (Exception e) { _logger.ErrorException("Failed to save record:", e); if (transaction != null) { transaction.Rollback(); } throw; } finally { if (transaction != null) { transaction.Dispose(); } _writeLock.Release(); } }
public Task Create(ActivityLogEntry entry) { return(Update(entry)); }
public async Task CreateAsync(ActivityLogEntry entry) { await ActivityLogs.AddAsync(entry); await SaveChangesAsync(); }
public int AddUpdate(ActivityLogEntry Entry, string SessionUserId) { return(_entryRepository.AddUpdate(Entry, SessionUserId)); }
public async Task Update(ActivityLogEntry entry) { if (entry == null) { throw new ArgumentNullException("entry"); } using (var connection = await CreateConnection().ConfigureAwait(false)) { using (var saveActivityCommand = connection.CreateCommand()) { saveActivityCommand.CommandText = "replace into ActivityLogEntries (Id, Name, Overview, ShortOverview, Type, ItemId, UserId, DateCreated, LogSeverity) values (@Id, @Name, @Overview, @ShortOverview, @Type, @ItemId, @UserId, @DateCreated, @LogSeverity)"; saveActivityCommand.Parameters.Add(saveActivityCommand, "@Id"); saveActivityCommand.Parameters.Add(saveActivityCommand, "@Name"); saveActivityCommand.Parameters.Add(saveActivityCommand, "@Overview"); saveActivityCommand.Parameters.Add(saveActivityCommand, "@ShortOverview"); saveActivityCommand.Parameters.Add(saveActivityCommand, "@Type"); saveActivityCommand.Parameters.Add(saveActivityCommand, "@ItemId"); saveActivityCommand.Parameters.Add(saveActivityCommand, "@UserId"); saveActivityCommand.Parameters.Add(saveActivityCommand, "@DateCreated"); saveActivityCommand.Parameters.Add(saveActivityCommand, "@LogSeverity"); IDbTransaction transaction = null; try { transaction = connection.BeginTransaction(); var index = 0; saveActivityCommand.GetParameter(index++).Value = new Guid(entry.Id); saveActivityCommand.GetParameter(index++).Value = entry.Name; saveActivityCommand.GetParameter(index++).Value = entry.Overview; saveActivityCommand.GetParameter(index++).Value = entry.ShortOverview; saveActivityCommand.GetParameter(index++).Value = entry.Type; saveActivityCommand.GetParameter(index++).Value = entry.ItemId; saveActivityCommand.GetParameter(index++).Value = entry.UserId; saveActivityCommand.GetParameter(index++).Value = entry.Date; saveActivityCommand.GetParameter(index++).Value = entry.Severity.ToString(); saveActivityCommand.Transaction = transaction; saveActivityCommand.ExecuteNonQuery(); transaction.Commit(); } catch (OperationCanceledException) { if (transaction != null) { transaction.Rollback(); } throw; } catch (Exception e) { Logger.ErrorException("Failed to save record:", e); if (transaction != null) { transaction.Rollback(); } throw; } finally { if (transaction != null) { transaction.Dispose(); } } } } }
private void CreateLogEntry(ActivityLogEntry entry) => _activityManager.Create(entry);
public void Create(ActivityLogEntry entry) { Update(entry); }
public void AddActivityLogEntry(ActivityLogEntry e) { ActivityList.Add(e); }