Ejemplo n.º 1
0
        /// <summary>
        ///     Verifies the audit log data.
        /// </summary>
        /// <param name="data">The data.</param>
        /// <param name="expectedSuccess">if set to <c>true</c> [expected success].</param>
        /// <param name="expectedTypeAlias">The expected type alias.</param>
        /// <param name="expectedMetadataTypeAlias">The expected metadata type alias.</param>
        /// <param name="expectedParametersCount">The expected parameters count.</param>
        /// <returns></returns>
        private bool VerifyAuditLogData(IAuditLogEntryData data, bool expectedSuccess, string expectedTypeAlias, string expectedMetadataTypeAlias, int expectedParametersCount)
        {
            // Get the severity based on success or failure
            AuditLogSeverityEnum             severity             = expectedSuccess ? data.AuditLogEntryMetadata.SeveritySuccess : data.AuditLogEntryMetadata.SeverityFailure;
            AuditLogSeverityEnum_Enumeration expectedSeverityEnum = AuditLogSeverityEnum.ConvertAliasToEnum(severity.Alias) ?? AuditLogSeverityEnum_Enumeration.AuditLogInformation;

            return(data.Success == expectedSuccess &&
                   data.AuditLogEntryType.Alias == expectedTypeAlias &&
                   data.AuditLogEntryMetadata.Alias == expectedMetadataTypeAlias &&
                   data.SeverityEnum == expectedSeverityEnum &&
                   data.Parameters.Count == expectedParametersCount &&
                   data.Parameters.Values.All(v => v != null));
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Initialises the specified audit log entry.
        /// </summary>
        /// <param name="success">if set to <c>true</c> the entry is successfull, false otherwise.</param>
        /// <param name="logEntryMetadataId">The log entry metadata identifier.</param>
        /// <param name="parameters">The parameters.</param>
        private void Initialise(bool success, string logEntryMetadataId, IDictionary <string, object> parameters)
        {
            using (new SecurityBypassContext())
            {
                _createdDate = DateTime.UtcNow;

                // Get the metadata
                _auditLogEntryMetadata = Entity.Get <AuditLogEntryMetadata>(logEntryMetadataId);
                if (_auditLogEntryMetadata == null)
                {
                    throw new ArgumentException("logEntryMetadataId");
                }

                _auditLogEntryType = _auditLogEntryMetadata.AuditLogEntryType;

                // Get the severity based on success or failure
                AuditLogSeverityEnum severity = success ? _auditLogEntryMetadata.SeveritySuccess : _auditLogEntryMetadata.SeverityFailure;

                // Assign properties common to all log entrues
                _success      = success;
                _severity     = severity;
                _severityEnum = AuditLogSeverityEnum.ConvertAliasToEnum(_severity.Alias) ?? AuditLogSeverityEnum_Enumeration.AuditLogInformation;
                _userName     = GetCurrentUserName();
                _tenantName   = RequestContext.GetContext().Tenant.Name;

                // Assign type specific parameters
                if (parameters != null)
                {
                    foreach (var kvp in parameters)
                    {
                        _parameters[kvp.Key] = kvp.Value;
                    }
                }

                string messageFormatString = _auditLogEntryMetadata.MessageFormatString;

                // Generate message from format string
                if (!string.IsNullOrEmpty(messageFormatString))
                {
                    IDictionary <string, object> fields = new Dictionary <string, object>(_parameters);

                    // Add base fields keyed off aliases as this is what is expected in the format string
                    fields["auditLogEntrySuccess"]     = _success;
                    fields["auditLogEntryUser"]        = _userName;
                    fields["auditLogEntryCreatedDate"] = _createdDate;
                    fields["auditLogEntrySeverity"]    = _severityEnum;

                    _message = string.Format(new DictionaryFormatter(), messageFormatString, fields);
                }
            }
        }