Exemplo n.º 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);
        }
Exemplo n.º 2
0
        public virtual ISerializedItem GetItem(ISerializedReference reference)
        {
            Assert.ArgumentNotNull(reference, "reference");

            var path = SerializationPathUtility.GetReferenceItemPath(reference);

            if (File.Exists(path))
            {
                return(ReadItemFromDisk(path));
            }

            var shortPath = SerializationPathUtility.GetShortSerializedItemPath(_rootPath, reference);

            if (File.Exists(shortPath))
            {
                return(ReadItemFromDisk(shortPath));
            }

            return(null);
        }