Exemplo n.º 1
0
        public IItemData Deserialize(IItemData serializedItemData)
        {
            Assert.ArgumentNotNull(serializedItemData, "serializedItem");

            bool newItemWasCreated;
            var  targetItem = GetOrCreateTargetItem(serializedItemData, out newItemWasCreated);

            var softErrors = new List <TemplateMissingFieldException>();

            try
            {
                ChangeTemplateIfNeeded(serializedItemData, targetItem);

                ChangeBranchIfNeeded(serializedItemData, targetItem);

                RenameIfNeeded(serializedItemData, targetItem);

                ResetTemplateEngineIfItemIsTemplate(targetItem);

                UpdateFieldSharingIfNeeded(serializedItemData, targetItem);

                PasteSharedFields(serializedItemData, targetItem, newItemWasCreated, softErrors);

                PasteVersions(serializedItemData, targetItem, newItemWasCreated, softErrors);

                PasteUnversionedFields(serializedItemData, targetItem, newItemWasCreated, softErrors);

                if (softErrors.Count > 0)
                {
                    throw TemplateMissingFieldException.Merge(softErrors);
                }

                return(new ItemData(targetItem, ParentDataStore));
            }
            catch (ParentForMovedItemNotFoundException)
            {
                throw;
            }
            catch (ParentItemNotFoundException)
            {
                throw;
            }
            catch (TemplateMissingFieldException)
            {
                throw;
            }
            catch (Exception ex)
            {
                if (newItemWasCreated)
                {
                    targetItem.Delete();
                    ClearCaches(targetItem.Database, new ID(serializedItemData.Id));
                }

                throw new DeserializationException("Failed to paste item: " + serializedItemData.Path, ex);
            }
        }
Exemplo n.º 2
0
        public IItemData Deserialize(IItemData serializedItemData)
        {
            Assert.ArgumentNotNull(serializedItemData, "serializedItem");

            // In regards to https://github.com/kamsar/Unicorn/issues/280
            // At no point in these processes, do we expect anything but raw API results - not filtered by version disablers or anything similar
            // Encapsulating the entire Deserialize call to ensure this
            // Updated to try and bring back Sitecore 7 compatibility for Rainbow moving forward. https://github.com/SitecoreUnicorn/Rainbow/issues/25
            using (new VersionSafeEnforceVersionPresenceDisabler())
            {
                bool newItemWasCreated;
                var  targetItem = GetOrCreateTargetItem(serializedItemData, out newItemWasCreated);

                var softErrors = new List <TemplateMissingFieldException>();

                try
                {
                    ChangeTemplateIfNeeded(serializedItemData, targetItem);

                    if (!IgnoreBranchId)
                    {
                        ChangeBranchIfNeeded(serializedItemData, targetItem, newItemWasCreated);
                    }

                    RenameIfNeeded(serializedItemData, targetItem);

                    ResetTemplateEngineIfItemIsTemplate(targetItem);

                    PasteSharedFields(serializedItemData, targetItem, newItemWasCreated, softErrors);

                    PasteUnversionedFields(serializedItemData, targetItem, newItemWasCreated, softErrors);

                    UpdateFieldSharingIfNeeded(serializedItemData, targetItem);

                    PasteVersions(serializedItemData, targetItem, newItemWasCreated, softErrors);

                    if (softErrors.Count > 0)
                    {
                        throw TemplateMissingFieldException.Merge(softErrors);
                    }

                    return(new ItemData(targetItem, ParentDataStore));
                }
                catch (ParentForMovedItemNotFoundException)
                {
                    throw;
                }
                catch (ParentItemNotFoundException)
                {
                    throw;
                }
                catch (TemplateMissingFieldException)
                {
                    throw;
                }
                catch (Exception ex)
                {
                    if (newItemWasCreated)
                    {
                        targetItem.Delete();
                        ClearCaches(targetItem.Database, new ID(serializedItemData.Id));
                    }

                    throw new DeserializationException("Failed to paste item: " + serializedItemData.Path, ex);
                }
            }
        }