Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
 private async void CreateLogEntry(ActivityLogEntry entry)
 {
     try
     {
         await _activityManager.Create(entry).ConfigureAwait(false);
     }
     catch
     {
         // Logged at lower levels
     }
 }
Exemplo n.º 3
0
        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();
            }
        }
Exemplo n.º 4
0
 public Task Create(ActivityLogEntry entry)
 {
     return Update(entry);
 }
Exemplo n.º 5
0
        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;
        }
Exemplo n.º 6
0
        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();
                        }
                    }
                }
            }
        }