Beispiel #1
0
        public override IItemData EvaluateUpdate(IItemData sourceItem, IItemData targetItem)
        {
            Assert.ArgumentNotNull(targetItem, "targetItemData");
            Assert.ArgumentNotNull(sourceItem, "sourceItemData");

            var deferredUpdateLog = new DeferredLogWriter <ISerializedAsMasterEvaluatorLogger>();

            _logger.Evaluated(sourceItem ?? targetItem);

            var result = _parentConfiguration.Resolve <IPredicate>().Includes(targetItem);

            // TODO: In reality, `result` should never come back null here. With the current tests it does however, and it's
            // ^&*"$*£"&(* to change them
            if (ShouldUpdateExisting(sourceItem, targetItem, deferredUpdateLog, result?.FieldValueManipulator))
            {
                using (new LogTransaction(_globalLogger))
                {
                    var changeHappened = _sourceDataStore.Save(targetItem, result?.FieldValueManipulator);

                    if (changeHappened)
                    {
                        _logger.SerializedUpdatedItem(targetItem);
                        deferredUpdateLog.ExecuteDeferredActions(_logger);
                    }
                }
                return(targetItem);
            }

            return(null);
        }
        public void EvaluateOrphans(IItemData[] orphanItems)
        {
            Assert.ArgumentNotNull(orphanItems, "orphanItems");

            EvaluatorUtility.RecycleItems(orphanItems, _sourceDataStore, item => _logger.DeletedItem(item));

            foreach (var orphan in orphanItems)
            {
                _logger.Evaluated(orphan);
            }
        }
        public override IItemData EvaluateUpdate(IItemData sourceItem, IItemData targetItem)
        {
            Assert.ArgumentNotNull(targetItem, "targetItemData");
            Assert.ArgumentNotNull(sourceItem, "sourceItemData");

            var deferredUpdateLog = new DeferredLogWriter <ISerializedAsMasterEvaluatorLogger>();

            _logger.Evaluated(sourceItem ?? targetItem);

            if (ShouldUpdateExisting(sourceItem, targetItem, deferredUpdateLog))
            {
                using (new LogTransaction(_globalLogger))
                {
                    _logger.SerializedUpdatedItem(targetItem);
                    deferredUpdateLog.ExecuteDeferredActions(_logger);

                    _sourceDataStore.Save(targetItem);
                }
                return(targetItem);
            }

            return(null);
        }