Esempio n. 1
0
        /// <summary>
        /// Function to export the audit history to database
        /// </summary>
        public static void ExportAuditHistoryToDb()
        {
            var auditExtract = new AuditExtract();

            var counter = 0;

            Console.WriteLine();

            var totalCaseEntities = CrmUtil.GetEntityList("incident", new string[] { "incidentid" },
                                                          new FilterExpression()
            {
                FilterOperator = LogicalOperator.And,
                Conditions     =
                {
                    new ConditionExpression("new_legacyguid", ConditionOperator.Null)
                }
            });


            Console.WriteLine("Starting processing at: " + DateTime.Now.ToShortTimeString() + "\n");

            // parallelize the processing of each case
            Parallel.ForEach(totalCaseEntities, entity =>
            {
                var auditDetailsList = auditExtract.GetAuditDetails(entity.Id, "incident");

                var auditExport = new AuditExport(auditDetailsList);

                // export all fields specified
                Util.AuditExportFields.ForEach(audit => auditExport.LogFieldRange(audit));

                counter++;
                Console.Write("\rCases Processed: " + counter.ToString());
            });
        }
Esempio n. 2
0
        /// <summary>
        /// Process New/Old Value based on the fieldName type
        /// </summary>
        /// <param name="value"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        private string _ProcessAuditDetailBasedOnType(Object value, string key)
        {
            string result = null;

            switch (key)
            {
            case "statuscode":
                result = (value != null) ? CrmUtil.LookUpDictFieldValue("statuscode", ((OptionSetValue)value).Value.ToString()) : null;
                break;

            case "statecode":
                result = (value != null) ? CrmUtil.LookUpDictFieldValue("statecode", ((OptionSetValue)value).Value.ToString()) : null;
                break;

            //get ownerid in format Guid,string -> Id, ownerType (team or systemuser)
            case "ownerid":
                var tempVal = (EntityReference)value;
                result = (value != null) ? tempVal.Id.ToString() + "," + tempVal.LogicalName : null;
                break;
            }

            // handle dates
            if (Util.DateFieldList.Any(item => item.Equals(key)))
            {
                result = (value != null) ? ((DateTime)value).ToString() : null;
            }

            // handle strings
            else if (Util.StringFieldList.Any(item => item.Equals(key)))
            {
                result = (value != null) ? value.ToString() : null;
            }

            // handle dropdowns
            else if (Util.DropdownFieldList.Any(item => item.Equals(key)))
            {
                result = (value != null) ? CrmUtil.LookUpDictFieldValue(key, ((OptionSetValue)value).Value.ToString()) : null;
            }

            // handle lookup fields
            else if (Util.LookupFieldList.Any(item => item.Equals(key)))
            {
                var tempVal = (EntityReference)value;
                result = (value != null) ? tempVal.Name : null;
            }

            return(result);
        }