Esempio n. 1
0
        /// <summary>
        /// Reads the JSON representation of the object.
        /// </summary>
        /// <param name="reader">The <see cref="T:Newtonsoft.Json.JsonReader" /> to read from.</param>
        /// <param name="objectType">Type of the object.</param>
        /// <param name="existingValue">The existing value of object being read.</param>
        /// <param name="serializer">The calling serializer.</param>
        /// <returns>
        /// The object value.
        /// </returns>
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            JToken jtoken = JToken.Load(reader);
            object target = null;

            if (jtoken != null && jtoken.HasValues && jtoken["type"] != null)
            {
                var typeValue = jtoken["type"].Value <string>();
                var type      = new AuditBackendType(typeValue);

                if (type == AuditBackendType.File)
                {
                    target = new FileAuditBackend();
                }
                else
                {
                    if (type == AuditBackendType.Syslog)
                    {
                        target = new SyslogAuditBackend();
                    }
                }

                if (target == null)
                {
                    target = new CustomAuditBackend(new AuditBackendType(typeValue));
                }

                serializer.Populate(jtoken.CreateReader(), target);
            }

            return(target);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="CustomAuditBackend"/> class.
 /// </summary>
 /// <param name="auditBackendType">Type of the audit backend.</param>
 public CustomAuditBackend(AuditBackendType auditBackendType)
 {
     Type = auditBackendType;
 }