/// <summary> /// Loops thru the audit detail collections /// and builds a lift of audit data changes /// </summary> /// <param type="AuditDetailCollections" name="details"></param> /// <returns> Returns a List of AuditDataChanges </returns> private List <AuditDataChange> _ProcessAuditDetails(AuditDetailCollection details) { try { var auditExtractList = new List <AuditDataChange>(); foreach (var detail in details.AuditDetails) { var detailType = detail.GetType(); if (detailType == typeof(AttributeAuditDetail)) { var attributeDetail = (AttributeAuditDetail)detail; var attributeValue = attributeDetail.NewValue ?? attributeDetail.OldValue; var modifiedDateTime = (DateTime)detail.AuditRecord.Attributes["createdon"]; var user = ((EntityReference)detail.AuditRecord.Attributes["userid"]).Name.ToString(); if (attributeValue != null && attributeValue.Attributes != null) { foreach (var attribute in attributeValue.Attributes) { if (Util.AuditExportFields.Any(item => item.Equals(attribute.Key))) { var change = new AuditDataChange(); Object valueNew = null; Object valueOld = null; if (attributeDetail.NewValue != null) { valueNew = (attributeDetail.NewValue.Attributes.ContainsKey(attribute.Key)) ? attributeDetail.NewValue.Attributes[attribute.Key] : null; } if (attributeDetail.OldValue != null) { valueOld = (attributeDetail.OldValue.Attributes.ContainsKey(attribute.Key)) ? attributeDetail.OldValue.Attributes[attribute.Key] : null; } change.ActionType = detail.AuditRecord.FormattedValues["action"]; change.AttributeName = attribute.Key; change.AttributeNewValue = _ProcessAuditDetailBasedOnType(valueNew, attribute.Key); change.AttributeOldValue = _ProcessAuditDetailBasedOnType(valueOld, attribute.Key); change.ModifiedDate = modifiedDateTime.ToLocalTime(); change.ModifiedBy = user; auditExtractList.Add(change); } } } } } return(auditExtractList); } catch (Exception ex) { Util.WriteErrorToLog("_ProcessAuditDetails", new Dictionary <string, string>(), ex); throw ex; } }
/// <summary> /// Loops thru the audit detail collections /// and builds a lift of audit data changes /// </summary> /// <param type="AuditDetailCollections" name="details"></param> /// <returns> Returns a List of AuditDataChanges </returns> private List<AuditDataChange> _ProcessAuditDetails(AuditDetailCollection details) { try { var auditExtractList = new List<AuditDataChange>(); foreach (var detail in details.AuditDetails) { var detailType = detail.GetType(); if (detailType == typeof(AttributeAuditDetail)) { var attributeDetail = (AttributeAuditDetail)detail; var attributeValue = attributeDetail.NewValue ?? attributeDetail.OldValue; var modifiedDateTime = (DateTime)detail.AuditRecord.Attributes["createdon"]; var user = ((EntityReference)detail.AuditRecord.Attributes["userid"]).Name.ToString(); if (attributeValue != null && attributeValue.Attributes != null) { foreach (var attribute in attributeValue.Attributes) { if (Util.AuditExportFields.Any(item => item.Equals(attribute.Key))) { var change = new AuditDataChange(); Object valueNew = null; Object valueOld = null; if (attributeDetail.NewValue != null) { valueNew = (attributeDetail.NewValue.Attributes.ContainsKey(attribute.Key)) ? attributeDetail.NewValue.Attributes[attribute.Key] : null; } if (attributeDetail.OldValue != null) { valueOld = (attributeDetail.OldValue.Attributes.ContainsKey(attribute.Key)) ? attributeDetail.OldValue.Attributes[attribute.Key] : null; } change.ActionType = detail.AuditRecord.FormattedValues["action"]; change.AttributeName = attribute.Key; change.AttributeNewValue = _ProcessAuditDetailBasedOnType(valueNew, attribute.Key); change.AttributeOldValue = _ProcessAuditDetailBasedOnType(valueOld, attribute.Key); change.ModifiedDate = modifiedDateTime.ToLocalTime(); change.ModifiedBy = user; auditExtractList.Add(change); } } } } } return auditExtractList; } catch (Exception ex) { Util.WriteErrorToLog("_ProcessAuditDetails", new Dictionary<string, string>(), ex); throw ex; } }