Example #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);
        }
Example #2
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);
            }
        }
Example #3
0
        public ISerializedItem GetItemByPath(string database, string path)
        {
            var physicalPath = SerializationPathUtility.GetSerializedItemPath(_rootPath, database, path);

            if (!File.Exists(physicalPath))
            {
                // check for a short-path version
                physicalPath = SerializationPathUtility.GetShortSerializedItemPath(_rootPath, database, path);

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

            var reference = new SitecoreSerializedReference(physicalPath, this);

            return(GetItem(reference));
        }
        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 renamedParentSerializationDirectory = SerializationPathUtility.GetReferenceParentPath(_rootPath, updatedItem);

            var oldSerializedChildrenReference = new SitecoreSerializedReference(renamedParentSerializationDirectory + Path.DirectorySeparatorChar + oldName, this);

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

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

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

            // 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);
            }
        }
        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 = SerializationPathUtility.GetSerializedReferencePath(_rootPath, newParentItem) + Path.DirectorySeparatorChar + sourceItem.Name + PathUtils.Extension;

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

            // update the path and parent IDs to the new location
            syncItem.ParentID = newParentItem.Id.ToString();
            syncItem.ItemPath = string.Concat(newParentItem.ItemPath, "/", syncItem.Name);

            var serializedNewItem = new SitecoreSerializedItem(syncItem, newRootItemPath, 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);

            // remove the serialized item in the old location
            DeleteSerializedItem(oldRootItemPath);
        }
        public ISerializedItem GetItemByPath(string database, string path)
        {
            var physicalPath = SerializationPathUtility.GetSerializedItemPath(_rootPath, database, path);

            if (!File.Exists(physicalPath))
            {
                // check for a short-path version
                physicalPath = SerializationPathUtility.GetShortSerializedItemPath(_rootPath, database, path);

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

            var reference = new SitecoreSerializedReference(physicalPath, this);

            return GetItem(reference);
        }