/// <summary>
        /// Add new report to BacktraceDatabase
        /// </summary>
        public BacktraceDatabaseRecord Add(BacktraceData data, bool @lock = true)
        {
            if (data == null || !Enable)
            {
                return(null);
            }
            //remove old reports (if database is full)
            //and check database health state
            var validationResult = ValidateDatabaseSize();

            if (!validationResult)
            {
                return(null);
            }

            // validate if record already exists in the database object
            var hash = BacktraceDatabaseContext.GetHash(data);

            if (!string.IsNullOrEmpty(hash))
            {
                var existingRecord = BacktraceDatabaseContext.GetRecordByHash(hash);
                if (existingRecord != null)
                {
                    BacktraceDatabaseContext.AddDuplicate(existingRecord);
                    return(existingRecord);
                }
            }

            //add built-in attachments
            var attachments = BacktraceDatabaseFileContext.GenerateRecordAttachments(data);

            for (int attachmentIndex = 0; attachmentIndex < attachments.Count(); attachmentIndex++)
            {
                if (!string.IsNullOrEmpty(attachments.ElementAt(attachmentIndex)))
                {
                    data.Attachments.Add(attachments.ElementAt(attachmentIndex));
                }
            }
            // add to fresh new record breadcrumb attachment
            if (Breadcrumbs != null)
            {
                data.Attachments.Add(Breadcrumbs.GetBreadcrumbLogPath());
                data.Attributes.Attributes["breadcrumbs.lastId"] = Breadcrumbs.BreadcrumbId().ToString("F0", CultureInfo.InvariantCulture);
            }

            // now we now we're adding new unique report to database
            var record = new BacktraceDatabaseRecord(data)
            {
                Hash = hash
            };

            // save record on the hard drive and add it to database context
            var saveResult = BacktraceDatabaseFileContext.Save(record);

            if (!saveResult)
            {
                // file context won't remove json object that wasn't stored in the previous method
                // but will clean up attachments associated with this record.
                BacktraceDatabaseFileContext.Delete(record);
                return(null);
            }

            BacktraceDatabaseContext.Add(record);
            if (!@lock)
            {
                record.Unlock();
            }

            return(record);
        }