/// <summary>
        /// Casts changed Item to specific type and populates the message.
        /// </summary>
        /// <param name="changedItem">ChangedItem to convert</param>
        /// <param name="entityRecordMessages">collection of entityname to EntityRecordMessage</param>
        /// <returns>Portal cache message converted from ChangedItem</returns>
        private PluginMessage CreateMessage(IChangedItem changedItem, Dictionary <string, EntityRecordMessage> entityRecordMessages)
        {
            switch (changedItem.Type)
            {
            case ChangeType.NewOrUpdated:

                var newOrUpdated = changedItem as NewOrUpdatedItem;
                if (newOrUpdated == null || newOrUpdated.NewOrUpdatedEntity == null)
                {
                    break;
                }

                if (!entityRecordMessages.ContainsKey(newOrUpdated.NewOrUpdatedEntity.LogicalName))
                {
                    ADXTrace.Instance.TraceWarning(TraceCategory.Application, string.Format("Collection of entity name to EntityRecordMessages is not holding the changed item with entity name {0}, which shouldn't happen.", newOrUpdated.NewOrUpdatedEntity.LogicalName));
                    break;
                }

                return(this.CreateMessageForNewOrUpdatedItem(newOrUpdated, entityRecordMessages[newOrUpdated.NewOrUpdatedEntity.LogicalName]));

            case ChangeType.RemoveOrDeleted:

                var removedOrDeleted = changedItem as RemovedOrDeletedItem;
                if (removedOrDeleted == null || removedOrDeleted.RemovedItem == null)
                {
                    break;
                }

                if (!entityRecordMessages.ContainsKey(removedOrDeleted.RemovedItem.LogicalName))
                {
                    ADXTrace.Instance.TraceWarning(TraceCategory.Application, string.Format("Collection of entity name to EntityRecordMessages is not holding the the changed item with entity name {0} which shouldn't happen.", removedOrDeleted.RemovedItem.LogicalName));
                    break;
                }

                return(this.CreateMessageForRemovedOrDeletedItem(removedOrDeleted, entityRecordMessages[removedOrDeleted.RemovedItem.LogicalName]));

            default:
                ADXTrace.Instance.TraceWarning(TraceCategory.Application, string.Format("While casting the changed item to specific type, found unhandled ChangeType: {0}", changedItem.Type.ToString()));
                break;
            }

            return(null);
        }
Beispiel #2
0
        private SyncXMLDataObject GetXMLDataObjInChangedItem(IChangedItem item)
        {
            SyncXMLDataObject obj = null;
            var itemType          = item.GetType();
            var objProperties     = itemType.GetProperties();

            foreach (var property in objProperties)
            {
                if (property.GetCustomAttribute <XMLDataFieldType>() != null)
                {
                    obj = property.GetValue(item) as SyncXMLDataObject;
                    if (obj != null)
                    {
                        break;
                    }
                }
            }

            return(obj);
        }
 /// <summary>
 /// Gets entity name from changed item.
 /// </summary>
 /// <param name="item">Changed item.</param>
 /// <returns>Casted entity.</returns>
 private string GetEntityNameFromChangedItem(IChangedItem item)
 {
     return(item.Type == ChangeType.NewOrUpdated
                         ? (item as NewOrUpdatedItem).NewOrUpdatedEntity.LogicalName
                         : (item as RemovedOrDeletedItem).RemovedItem.LogicalName);
 }
 /// <summary>
 /// Gets entity id from changed item.
 /// </summary>
 /// <param name="item">Changed item.</param>
 /// <returns></returns>
 private Guid GetEntityIdFromChangeItem(IChangedItem item)
 {
     return(item.Type == ChangeType.NewOrUpdated
                         ? (item as NewOrUpdatedItem).NewOrUpdatedEntity.Id
                         : (item as RemovedOrDeletedItem).RemovedItem.Id);
 }