private void LogInterestingPropertyValues(COWContactLogging.ContactChangeLogEvent loggingEvent, COWTriggerAction operation, CoreItem item, IEnumerable <StorePropertyDefinition> allUniqueInterestingProperties)
        {
            StringBuilder stringBuilder = new StringBuilder(200);

            foreach (StorePropertyDefinition storePropertyDefinition in allUniqueInterestingProperties)
            {
                stringBuilder.Clear();
                object obj = this.GetPropertyValueForLogging(item, storePropertyDefinition);
                obj = this.SanitizePropertyValueForLogging(obj);
                stringBuilder.Append("[New=");
                stringBuilder.Append(obj);
                bool flag = item.PropertyBag.IsPropertyDirty(storePropertyDefinition);
                if (flag && operation != COWTriggerAction.Create)
                {
                    object obj2 = this.GetOriginalPropertyValueForLogging(item, storePropertyDefinition);
                    obj2 = this.SanitizePropertyValueForLogging(obj2);
                    if (obj2 != obj)
                    {
                        stringBuilder.Append(",Old=");
                        stringBuilder.Append(obj2);
                    }
                }
                stringBuilder.Append("]");
                string key = SpecialCharacters.SanitizeForLogging(storePropertyDefinition.Name);
                loggingEvent.Add(key, stringBuilder.ToString());
            }
        }
        public void ItemOperation(COWSettings settings, IDumpsterItemOperations dumpster, COWTriggerAction operation, COWTriggerActionState state, StoreSession session, StoreObjectId itemId, CoreItem item, CoreFolder folder, bool onBeforeNotification, OperationResult result, CallbackContext callbackContext)
        {
            Util.ThrowOnNullArgument(session, "session");
            Util.ThrowOnNullArgument(item, "item");
            EnumValidator.ThrowIfInvalid <COWTriggerAction>(operation, "operation");
            EnumValidator.ThrowIfInvalid <COWTriggerActionState>(state, "state");
            EnumValidator.ThrowIfInvalid <OperationResult>(result, "result");
            COWContactLogging.Tracer.TraceDebug((long)this.GetHashCode(), "COWContactLogging.ItemOperation: Start.");
            string valueOrDefault = item.PropertyBag.GetValueOrDefault <string>(StoreObjectSchema.ItemClass, string.Empty);

            COWContactLogging.Tracer.TraceDebug <string>((long)this.GetHashCode(), "COWContactLogging.ItemOperation: ItemClass: {0}", valueOrDefault);
            HashSet <StorePropertyDefinition> hashSet = new HashSet <StorePropertyDefinition>();
            List <IContactChangeTracker>      list    = new List <IContactChangeTracker>(COWContactLogging.ChangeTrackers.Length);

            foreach (IContactChangeTracker contactChangeTracker in COWContactLogging.ChangeTrackers)
            {
                if (contactChangeTracker.ShouldLoadPropertiesForFurtherCheck(operation, valueOrDefault, itemId, item))
                {
                    COWContactLogging.Tracer.TraceDebug <string>((long)this.GetHashCode(), "COWContactLogging.ItemOperation: Tracker {0} interested.", contactChangeTracker.Name);
                    list.Add(contactChangeTracker);
                    StorePropertyDefinition[] properties = contactChangeTracker.GetProperties(itemId, item);
                    if (properties != null && properties.Length > 0)
                    {
                        COWContactLogging.Tracer.TraceDebug <string, int>((long)this.GetHashCode(), "COWContactLogging.ItemOperation: Tracker {0} returned {1} properties for tracking", contactChangeTracker.Name, properties.Length);
                        hashSet.UnionWith(properties);
                    }
                }
            }
            if (hashSet.Count == 0)
            {
                COWContactLogging.Tracer.TraceDebug((long)this.GetHashCode(), "COWContactLogging.ItemOperation: No properties marked as interesting by any tracker.");
                return;
            }
            hashSet.Add(ItemSchema.Id);
            hashSet.Add(StoreObjectSchema.ItemClass);
            StorePropertyDefinition[] array = new StorePropertyDefinition[hashSet.Count];
            hashSet.CopyTo(array, 0, hashSet.Count);
            item.PropertyBag.Load(array);
            bool flag = false;

            foreach (IContactChangeTracker contactChangeTracker2 in list)
            {
                if (contactChangeTracker2.ShouldLogContact(itemId, item))
                {
                    flag = true;
                    break;
                }
            }
            if (!flag)
            {
                COWContactLogging.Tracer.TraceDebug((long)this.GetHashCode(), "COWContactLogging.ItemOperation: No trackers are interested after doing further checks.");
                return;
            }
            COWContactLogging.ContactChangeLogEvent contactChangeLogEvent = new COWContactLogging.ContactChangeLogEvent();
            contactChangeLogEvent.Add("ClientInfo", session.ClientInfoString);
            contactChangeLogEvent.Add("Action", operation.ToString());
            COWContactLogging.Tracer.TraceDebug <COWTriggerAction, string, int>((long)this.GetHashCode(), "COWContactLogging.ItemOperation: Tracking change {0} made by client {1} across a total of {2} properties", operation, session.ClientInfoString, hashSet.Count);
            this.LogInterestingPropertyValues(contactChangeLogEvent, operation, item, hashSet);
            ContactChangeLogger contactChangeLogger = new ContactChangeLogger(session);

            contactChangeLogger.LogEvent(contactChangeLogEvent);
        }
        public CowClientOperationSensitivity SkipGroupOperation(COWSettings settings, IDumpsterItemOperations dumpster, COWTriggerAction operation, FolderChangeOperationFlags flags, StoreSession sourceSession, StoreSession destinationSession, StoreObjectId sourceFolderId, StoreObjectId destinationFolderId, ICollection <StoreObjectId> itemIds, bool onBeforeNotification, bool onDumpster, CallbackContext callbackContext)
        {
            if (!COWContactLogging.COWContactLoggingConfiguration.Instance.IsLoggingEnabled())
            {
                return(CowClientOperationSensitivity.Skip);
            }
            EnumValidator.ThrowIfInvalid <COWTriggerAction>(operation, "operation");
            EnumValidator.ThrowIfInvalid <FolderChangeOperationFlags>(flags, "flags");
            Util.ThrowOnNullArgument(sourceSession, "sourceSession");
            if (!onBeforeNotification)
            {
                COWContactLogging.Tracer.TraceDebug((long)this.GetHashCode(), "COWContactLogging.SkipGroupOperation: not OnBeforeNotification");
                return(CowClientOperationSensitivity.Skip);
            }
            COWContactLogging.Tracer.TraceDebug((long)this.GetHashCode(), "COWContactLogging.SkipGroupOperation: SourceFolderId.ObjectType={0}, DestinationFolderId.ObjectType={1}", new object[]
            {
                (sourceFolderId == null) ? "<<Null>>" : sourceFolderId.ObjectType,
                (destinationFolderId == null) ? "<<Null>>" : destinationFolderId.ObjectType
            });
            bool flag = true;

            if ((sourceFolderId != null && sourceFolderId.ObjectType == StoreObjectType.ContactsFolder) || (destinationFolderId != null && destinationFolderId.ObjectType == StoreObjectType.ContactsFolder))
            {
                flag = false;
            }
            else if (itemIds != null)
            {
                foreach (StoreObjectId storeObjectId in itemIds)
                {
                    COWContactLogging.Tracer.TraceDebug <StoreObjectType>((long)this.GetHashCode(), "COWContactLogging.SkipGroupOperation: ItemId.ObjectType = {0}", storeObjectId.ObjectType);
                    if (storeObjectId.ObjectType == StoreObjectType.Contact || storeObjectId.ObjectType == StoreObjectType.DistributionList)
                    {
                        flag = false;
                        break;
                    }
                }
            }
            if (!flag)
            {
                foreach (IContactChangeTracker contactChangeTracker in COWContactLogging.ChangeTrackers)
                {
                    if (contactChangeTracker.ShouldLogGroupOperation(operation, sourceSession, sourceFolderId, destinationSession, destinationFolderId, itemIds))
                    {
                        COWContactLogging.Tracer.TraceDebug((long)this.GetHashCode(), "COWContactLogging.SkipGroupOperation: A tracker interested.");
                        COWContactLogging.ContactChangeLogEvent contactChangeLogEvent = new COWContactLogging.ContactChangeLogEvent();
                        contactChangeLogEvent.Add("Action", operation.ToString());
                        contactChangeLogEvent.Add("FolderChangeOperationFlags", flags.ToString());
                        contactChangeLogEvent.Add("ClientInfo", sourceSession.ClientInfoString);
                        if (destinationSession != null && destinationSession.ClientInfoString != sourceSession.ClientInfoString)
                        {
                            contactChangeLogEvent.Add("DestinationClientInfo", destinationSession.ClientInfoString);
                        }
                        if (sourceFolderId != null)
                        {
                            contactChangeLogEvent.Add("FolderId", sourceFolderId.ToString());
                        }
                        if (destinationFolderId != null && !object.Equals(sourceFolderId, destinationFolderId))
                        {
                            contactChangeLogEvent.Add("DestinationFolderId", destinationFolderId.ToString());
                        }
                        if (destinationSession != null && !object.Equals(sourceSession.MailboxGuid, destinationSession.MailboxGuid))
                        {
                            contactChangeLogEvent.Add("DestinationMailboxGuid", destinationSession.MailboxGuid.ToString());
                        }
                        string value = this.SanitizePropertyValueForLogging(itemIds);
                        contactChangeLogEvent.Add("ItemIds", value);
                        ContactChangeLogger contactChangeLogger = new ContactChangeLogger(sourceSession);
                        contactChangeLogger.LogEvent(contactChangeLogEvent);
                        break;
                    }
                }
            }
            return(CowClientOperationSensitivity.Skip);
        }