コード例 #1
0
        public virtual void MoveSerializedItem(ISourceItem sourceItem, ISourceItem newParentItem)
        {
            Assert.ArgumentNotNull(sourceItem, "sourceItem");
            Assert.ArgumentNotNull(newParentItem, "newParentItem");

            var sitecoreSource = sourceItem as SitecoreSourceItem;
            var sitecoreParent = newParentItem as SitecoreSourceItem;

            if (sitecoreParent == null)
            {
                throw new ArgumentException("newParentItem must be a SitecoreSourceItem", "newParentItem");
            }
            if (sitecoreSource == null)
            {
                throw new ArgumentException("sourceItem must be a SitecoreSourceItem", "sourceItem");
            }

            var oldRootDirectory = new SitecoreSerializedReference(SerializationPathUtility.GetSerializedReferencePath(_rootPath, sourceItem), this);
            var oldRootItemPath  = new SitecoreSerializedReference(SerializationPathUtility.GetReferenceItemPath(oldRootDirectory), this);

            var newRootItemPath       = newParentItem.ItemPath + "/" + sourceItem.Name;
            var newRootSerializedPath = SerializationPathUtility.GetSerializedItemPath(_rootPath, newParentItem.DatabaseName, newRootItemPath);

            var syncItem = ItemSynchronization.BuildSyncItem(sitecoreSource.InnerItem);

            // update the path and parent IDs to the new location
            syncItem.ParentID = newParentItem.Id.ToString();
            syncItem.ItemPath = newRootItemPath;

            // if this occurs we're "moving" an item to the same location it started from. Which means we shouldn't do anything.
            if (oldRootDirectory.ItemPath.Equals(syncItem.ItemPath))
            {
                return;
            }

            var serializedNewItem = new SitecoreSerializedItem(syncItem, newRootSerializedPath, this);

            // write the moved sync item to its new destination
            UpdateSerializedItem(serializedNewItem);

            // move any children to the new destination (and fix their paths)
            MoveDescendants(oldRootDirectory, serializedNewItem, sourceItem, false);

            // remove the serialized item in the old location
            DeleteSerializedItem(oldRootItemPath);
        }
コード例 #2
0
        public virtual ISerializedReference GetReference(ISourceItem sourceItem)
        {
            Assert.ArgumentNotNull(sourceItem, "sourceItem");

            var physicalPath = SerializationPathUtility.GetSerializedReferencePath(_rootPath, sourceItem);

            if (!Directory.Exists(physicalPath))
            {
                physicalPath = SerializationPathUtility.GetSerializedItemPath(_rootPath, sourceItem);

                if (!File.Exists(physicalPath))
                {
                    return(null);
                }
            }

            return(new SitecoreSerializedReference(physicalPath, this));
        }
コード例 #3
0
        public virtual void RenameSerializedItem(ISourceItem renamedItem, string oldName)
        {
            if (renamedItem == null || oldName == null)
            {
                return;
            }

            var typed = renamedItem as SitecoreSourceItem;

            if (typed == null)
            {
                throw new ArgumentException("Renamed item must be a SitecoreSourceItem", "renamedItem");
            }

            // write the serialized item under its new name
            var updatedItem = SerializeItem(renamedItem);

            // find the children directory path of the previous item name, if it exists, and move them to the new child path
            var oldItemPath = renamedItem.ItemPath.Substring(0, renamedItem.ItemPath.Length - renamedItem.Name.Length) + oldName;

            var oldSerializedChildrenDirectoryPath = SerializationPathUtility.GetSerializedReferencePath(_rootPath, renamedItem.DatabaseName, oldItemPath);

            var oldSerializedChildrenReference = new SitecoreSerializedReference(oldSerializedChildrenDirectoryPath, this);

            var shortOldSerializedChildrenPath      = SerializationPathUtility.GetShortSerializedReferencePath(_rootPath, oldSerializedChildrenReference);
            var shortOldSerializedChildrenReference = new SitecoreSerializedReference(shortOldSerializedChildrenPath, this);

            if (Directory.Exists(oldSerializedChildrenReference.ProviderId))
            {
                MoveDescendants(oldSerializedChildrenReference, updatedItem, renamedItem, true);
            }

            if (Directory.Exists(shortOldSerializedChildrenPath))
            {
                MoveDescendants(shortOldSerializedChildrenReference, updatedItem, renamedItem, true);
            }

            // delete the original serialized item from pre-rename (unless the names only differ by case, in which case we'd delete the item entirely because NTFS is case insensitive!)
            if (!renamedItem.Name.Equals(oldName, StringComparison.OrdinalIgnoreCase))
            {
                // note that we don't have to worry about short paths here because DeleteSerializedItem() knows how to find them
                DeleteSerializedItem(oldSerializedChildrenReference);
            }
        }