Exemple #1
0
 /// <summary>
 /// Fires the <see cref="Logged"/> event.
 /// </summary>
 /// <param name="args">The event arguments.</param>
 protected virtual void OnLogged(SysEventArgs args) => Logged?.Invoke(this, args);
Exemple #2
0
        /// <summary>
        /// Asynchronously adds an event entry to the log.
        /// </summary>
        /// <param name="args">The arguments of the event to log.</param>
        /// <returns></returns>
        public virtual async Task LogAsync(SysEventArgs args)
        {
            try
            {
                await OnLoggingAsync(args);

                if (args.Cancel)
                {
                    return;
                }

                var    type       = args.EventType;
                var    data       = args.Data;
                var    item       = data as ILogItem;
                var    dataId     = item?.Id;
                var    dataName   = item?.Name;
                var    state      = args.ObjectState;
                var    userName   = GetUserName(type);
                var    sysComment = false;
                string message    = null;

                switch (type)
                {
                case SysEventType.LoginFailure:
                    sysComment = true;
                    message    = Format(SysEventLoginFailure, userName);
                    break;

                case SysEventType.LoginSuccess:
                    message = Format(SysEventLoginSuccess, userName);
                    break;

                case SysEventType.Logout:
                    message = Format(SysEventLogout, userName);
                    break;

                case SysEventType.IssueCreated:
                    await AddSysCommentAsync(TicketCreated, dataId);
                    await AddEventEntryAsync(type, Format(SysEventIssueCreated, userName));

                    break;

                case SysEventType.IssueAssigned:
                    sysComment = true;
                    message    = Format(SysEventIssueAssigned, dataId, userName);
                    break;

                case SysEventType.IssueUpdated:
                    message = Format(SysEventIssueUpdated, dataId, userName);
                    break;

                case SysEventType.IssueClosed:
                    sysComment = true;
                    message    = Format(SysEventIssueClosed, dataId, userName);
                    break;

                case SysEventType.IssueReopened:
                    sysComment = true;
                    message    = Format(SysEventIssueReopened, userName);
                    break;

                case SysEventType.IssueDeleted:
                    message = Format(SysEventIssueDeleted, userName);
                    break;

                case SysEventType.UserRegistered:
                    message = Format(SysEventUserRegistered, userName);
                    break;

                case SysEventType.UserCreated:
                    message = Format(SysEventUserCreated, userName);
                    break;

                case SysEventType.UserUpdated:
                    message = Format(SysEventUserUpdated, userName);
                    break;

                case SysEventType.UserDeleted:
                    message = Format(SysEventUserDeleted, userName);
                    break;

                case SysEventType.UserImported:
                    message = Format(SysEventUserImported, userName);
                    break;

                case SysEventType.UserPasswordChanged:
                    message = Format(SysEventUserPasswordChanged, userName);
                    break;

                case SysEventType.CategoryCreated:
                    message = Format(SysEventCategoryCreated, dataName);
                    break;

                case SysEventType.CategoryUpdated:
                    message = Format(SysEventCategoryUpdated, dataName);
                    break;

                case SysEventType.CategoryDeleted:
                    message = Format(SysEventCategoryDeleted, dataName);
                    break;

                case SysEventType.EmailConfigUpdated:
                    message = SysEventEmailConfigUpdated;
                    break;

                case SysEventType.EmailSendFailed:
                    message = SysEventEmailSendFailed;
                    break;

                case SysEventType.EmailSendSuccess:
                    message = SysEventEmailSendSuccess;
                    break;

                default:
                    break;
                }

                if (sysComment)
                {
                    await AddSysCommentAsync(message, dataId);
                }
                else if (message != null)
                {
                    await AddEventEntryAsync(type, message, state);
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex);
            }
            finally
            {
                OnLogged(args);
            }
        }
Exemple #3
0
 /// <summary>
 /// Asynchronously fires the <see cref="Logging"/> event.
 /// </summary>
 /// <param name="args">The event arguments.</param>
 /// <returns></returns>
 protected virtual Task OnLoggingAsync(SysEventArgs args)
 => Logging != null?Logging.Invoke(this, args) : Task.CompletedTask;