示例#1
0
        /// <summary>
        /// Restoring items from the recycle bin does not invoke the data provider at all, so we have to attach to its event
        /// to cause restored items to be rewritten to disk if they are included.
        /// </summary>
        protected virtual void HandleItemRestored(RestoreItemCompletedEvent restoreItemCompletedEvent)
        {
            if (!restoreItemCompletedEvent.DatabaseName.Equals(Database.Name, StringComparison.Ordinal))
            {
                return;
            }

            // we use a timer to delay the execution of our handler for a couple seconds.
            // at the time the handler is called, calling Database.GetItem(id) returns NULL,
            // or without cache an item with an orphan path. The delay allows Sitecore to catch up
            // with it.
            new Timer(state =>
            {
                var item = GetSourceItemDataFromId(new ID(restoreItemCompletedEvent.ItemId), true);

                Assert.IsNotNull(item, "Item that was restored was null.");

                SerializeItemIfIncluded(item, "Restored");
            }, null, 2000, Timeout.Infinite);
        }
        /// <summary>
        /// Restoring items from the recycle bin does not invoke the data provider at all, so we have to attach to its event
        /// to cause restored items to be rewritten to disk if they are included.
        /// </summary>
        protected virtual void HandleItemRestored(RestoreItemCompletedEvent restoreItemCompletedEvent)
        {
            if (!restoreItemCompletedEvent.DatabaseName.Equals(Database.Name, StringComparison.Ordinal)) return;

            // we use a timer to delay the execution of our handler for a couple seconds.
            // at the time the handler is called, calling Database.GetItem(id) returns NULL,
            // or without cache an item with an orphan path. The delay allows Sitecore to catch up
            // with it.
            new Timer(state =>
            {
                var item = GetItemFromId(new ID(restoreItemCompletedEvent.ItemId), true);

                Assert.IsNotNull(item, "Item that was restored was null.");

                var iitem = new ItemData(item);

                SerializeItemIfIncluded(iitem, "Restored");
            }, null, 2000, Timeout.Infinite);
        }