Ejemplo n.º 1
0
 private void ItemCopyingEvenHandler(object sender, CancellableDestinationEventArgs e)
 {
     if (security.Enabled && security.ScopeEnabled)
     {
         OnItemCopying(e.AffectedItem, e.Destination);
     }
 }
Ejemplo n.º 2
0
        /// <summary>Update a page version with another, i.e. save a version of the current item and replace it with the replacement item. Returns a version of the previously published item.</summary>
        /// <param name="currentItem">The item that will be stored as a previous version.</param>
        /// <param name="replacementItem">The item that will take the place of the current item using it's ID. Any saved version of this item will not be modified.</param>
        /// <param name="storeCurrentVersion">Create a copy of the currently published version before overwriting it.</param>
        /// <returns>A version of the previously published item or the current item when storeCurrentVersion is false.</returns>
        public virtual ContentItem ReplaceVersion(ContentItem currentItem, ContentItem replacementItem, bool storeCurrentVersion = true)
        {
            if (currentItem == null)
            {
                throw new ArgumentNullException("currentItem");
            }
            if (replacementItem == null)
            {
                throw new ArgumentNullException("replacementItem");
            }

            CancellableDestinationEventArgs args = new CancellableDestinationEventArgs(currentItem, replacementItem);

            if (ItemReplacingVersion != null)
            {
                ItemReplacingVersion.Invoke(this, args);
            }
            if (!args.Cancel)
            {
                currentItem     = args.AffectedItem;
                replacementItem = args.Destination;

                using (ITransaction transaction = itemRepository.BeginTransaction())
                {
                    if (storeCurrentVersion)
                    {
                        ContentItem versionOfCurrentItem = AddVersion(currentItem);

                        Replace(currentItem, replacementItem);

                        if ((replacementItem.State == ContentState.Draft || replacementItem.State == ContentState.Waiting) && replacementItem.VersionOf.Value == currentItem)
                        {
                            // drafts can be removed once they have been published
                            currentItem.VersionIndex = replacementItem.VersionIndex;
                            itemRepository.SaveOrUpdate(currentItem);

                            Repository.Delete(replacementItem);
                        }

                        transaction.Commit();
                        return(versionOfCurrentItem);
                    }
                    else
                    {
                        Replace(currentItem, replacementItem);

                        if (replacementItem.State == ContentState.Draft && replacementItem.VersionOf.Value == currentItem)
                        {
                            // drafts can be removed once they have been published
                            //itemRepository.Delete(replacementItem);
                            Repository.Delete(replacementItem);
                        }

                        transaction.Commit();
                        return(currentItem);
                    }
                }
            }
            return(currentItem);
        }
Ejemplo n.º 3
0
 void OnItemCopying(object sender, CancellableDestinationEventArgs e)
 {
     InvokeBehaviors <IAddingBehavior>(
         e.AffectedItem,
         e.Destination,
         "Adding",
         (behavior, ctx) => behavior.OnAddingChild(ctx),
         (behavior, ctx) => behavior.OnAdding(ctx));
 }
Ejemplo n.º 4
0
 private void OnItemMoved(object sender, CancellableDestinationEventArgs e)
 {
     if (LeavingTrash(e))
     {
         trashHandler.RestoreValues(e.AffectedItem);
     }
     else if (trashHandler.IsInTrash(e.Destination))
     {
         trashHandler.ExpireTrashedItem(e.AffectedItem);
     }
 }
Ejemplo n.º 5
0
        void persister_ItemMoving(object sender, CancellableDestinationEventArgs e)
        {
            var originalAction = e.FinalAction;

            e.FinalAction = (from, to) =>
            {
                var result = originalAction(from, to);
                ItemDeleted(from.ID);
                return(result);
            };
        }
Ejemplo n.º 6
0
 private void OnItemMoved(object sender, CancellableDestinationEventArgs e)
 {
     if (LeavingTrash(e))
     {
         trashHandler.RestoreValues(e.AffectedItem);
     }
     else if (trashHandler.IsInTrash(e.Destination))
     {
         trashHandler.ExpireTrashedItem(e.AffectedItem);
     }
 }
Ejemplo n.º 7
0
        /// <summary>Update a page version with another, i.e. save a version of the current item and replace it with the replacement item. Returns a version of the previously published item.</summary>
        /// <param name="currentItem">The item that will be stored as a previous version.</param>
        /// <param name="replacementItem">The item that will take the place of the current item using it's ID. Any saved version of this item will not be modified.</param>
        /// <param name="storeCurrentVersion">Create a copy of the currently published version before overwriting it.</param>
        /// <returns>A version of the previously published item or the current item when storeCurrentVersion is false.</returns>
        public virtual ContentItem ReplaceVersion(ContentItem currentItem, ContentItem replacementItem, bool storeCurrentVersion)
        {
            CancellableDestinationEventArgs args = new CancellableDestinationEventArgs(currentItem, replacementItem);

            if (ItemReplacingVersion != null)
            {
                ItemReplacingVersion.Invoke(this, args);
            }
            if (!args.Cancel)
            {
                currentItem     = args.AffectedItem;
                replacementItem = args.Destination;

                using (ITransaction transaction = itemRepository.BeginTransaction())
                {
                    if (storeCurrentVersion)
                    {
                        ContentItem versionOfCurrentItem = SaveVersion(currentItem); //TODO: remove?

                        Replace(currentItem, replacementItem);

                        if (replacementItem.State == ContentState.Draft && replacementItem.VersionOf == currentItem)
                        {
                            // drafts can be removed once they have been published
                            itemRepository.Delete(replacementItem);
                        }

                        transaction.Commit();
                        return(versionOfCurrentItem);
                    }
                    else
                    {
                        Replace(currentItem, replacementItem);

                        if (replacementItem.State == ContentState.Draft && replacementItem.VersionOf == currentItem)
                        {
                            // drafts can be removed once they have been published
                            itemRepository.Delete(replacementItem);
                        }

                        transaction.Commit();
                        return(currentItem);
                    }
                }
            }
            return(currentItem);
        }
Ejemplo n.º 8
0
 private void ItemCopyingEvenHandler(object sender, CancellableDestinationEventArgs e)
 {
     OnItemCopying(e.AffectedItem, e.Destination);
 }
Ejemplo n.º 9
0
		/// <summary>Update a page version with another, i.e. save a version of the current item and replace it with the replacement item. Returns a version of the previously published item.</summary>
		/// <param name="currentItem">The item that will be stored as a previous version.</param>
		/// <param name="replacementItem">The item that will take the place of the current item using it's ID. Any saved version of this item will not be modified.</param>
		/// <param name="storeCurrentVersion">Create a copy of the currently published version before overwriting it.</param>
		/// <returns>A version of the previously published item or the current item when storeCurrentVersion is false.</returns>
		public virtual ContentItem ReplaceVersion(ContentItem currentItem, ContentItem replacementItem, bool storeCurrentVersion = true)
		{
			if (currentItem == null)
				throw new ArgumentNullException("currentItem");
			if (replacementItem == null)
				throw new ArgumentNullException("replacementItem");

			CancellableDestinationEventArgs args = new CancellableDestinationEventArgs(currentItem, replacementItem);
			if (ItemReplacingVersion != null)
				ItemReplacingVersion.Invoke(this, args);
			if (!args.Cancel)
			{
				currentItem = args.AffectedItem;
				replacementItem = args.Destination;

				using (ITransaction transaction = itemRepository.BeginTransaction())
				{
					if (storeCurrentVersion)
					{
						ContentItem versionOfCurrentItem = AddVersion(currentItem);

						Replace(currentItem, replacementItem);

						if ((replacementItem.State == ContentState.Draft || replacementItem.State == ContentState.Waiting) && replacementItem.VersionOf.Value == currentItem)
						{
							// drafts can be removed once they have been published
							currentItem.VersionIndex = replacementItem.VersionIndex;
							itemRepository.SaveOrUpdate(currentItem);

							Repository.Delete(replacementItem);
						}

						transaction.Commit();
						return versionOfCurrentItem;
					}
					else
					{
						Replace(currentItem, replacementItem);

						if (replacementItem.State == ContentState.Draft && replacementItem.VersionOf.Value == currentItem)
							// drafts can be removed once they have been published
							//itemRepository.Delete(replacementItem);
							Repository.Delete(replacementItem);

						transaction.Commit();
						return currentItem;
					}
				}
			}
			return currentItem;
		}
Ejemplo n.º 10
0
 void Persister_ItemCopying(object sender, CancellableDestinationEventArgs e)
 {
     events.AppendLine(DateTime.Now + ": " + MethodBase.GetCurrentMethod().Name + ", " + e.AffectedItem);
 }
Ejemplo n.º 11
0
 void Events_ItemReplacingVersion(object sender, CancellableDestinationEventArgs e)
 {
     events.AppendLine(DateTime.Now + ": " + MethodBase.GetCurrentMethod().Name + ", " + e.AffectedItem);
 }
Ejemplo n.º 12
0
 void Persister_ItemCopying(object sender, CancellableDestinationEventArgs e)
 {
     events.AppendLine(DateTime.Now + ": " + MethodBase.GetCurrentMethod().Name + ", " + e.AffectedItem);
 }
Ejemplo n.º 13
0
        /// <summary>Update a page version with another, i.e. save a version of the current item and replace it with the replacement item. Returns a version of the previously published item.</summary>
        /// <param name="currentItem">The item that will be stored as a previous version.</param>
        /// <param name="replacementItem">The item that will take the place of the current item using it's ID. Any saved version of this item will not be modified.</param>
        /// <param name="storeCurrentVersion">Create a copy of the currently published version before overwriting it.</param>
        /// <returns>A version of the previously published item or the current item when storeCurrentVersion is false.</returns>
        public virtual ContentItem ReplaceVersion(ContentItem currentItem, ContentItem replacementItem, bool storeCurrentVersion)
        {
            CancellableDestinationEventArgs args = new CancellableDestinationEventArgs(currentItem, replacementItem);
            if (ItemReplacingVersion != null)
                ItemReplacingVersion.Invoke(this, args);
            if (!args.Cancel)
            {
                currentItem = args.AffectedItem;
                replacementItem = args.Destination;

                using (ITransaction transaction = itemRepository.BeginTransaction())
                {
                    if (storeCurrentVersion)
                    {
                        ContentItem versionOfCurrentItem = SaveVersion(currentItem); //TODO: remove?

                        Replace(currentItem, replacementItem);

                        if (replacementItem.State == ContentState.Draft && replacementItem.VersionOf == currentItem)
                            // drafts can be removed once they have been published
                            itemRepository.Delete(replacementItem);

                        transaction.Commit();
                        return versionOfCurrentItem;
                    }
                    else
                    {
                        Replace(currentItem, replacementItem);

                        if (replacementItem.State == ContentState.Draft && replacementItem.VersionOf == currentItem)
                            // drafts can be removed once they have been published
                            itemRepository.Delete(replacementItem);

                        transaction.Commit();
                        return currentItem;
                    }
                }
            }
            return currentItem;
        }
Ejemplo n.º 14
0
 private void ItemCopyingEvenHandler(object sender, CancellableDestinationEventArgs e)
 {
     OnItemCopying(e.AffectedItem, e.Destination);
 }
Ejemplo n.º 15
0
 void Events_ItemReplacingVersion(object sender, CancellableDestinationEventArgs e)
 {
     events.AppendLine(DateTime.Now + ": " + MethodBase.GetCurrentMethod().Name + ", " + e.AffectedItem);
 }
Ejemplo n.º 16
0
 void persister_ItemMoving(object sender, CancellableDestinationEventArgs e)
 {
     var originalAction = e.FinalAction;
     e.FinalAction = (from, to) =>
     {
         var result = originalAction(from, to);
         ItemDeleted(from.ID);
         return result;
     };
 }
Ejemplo n.º 17
0
 private void ItemMovingEvenHandler(object sender, CancellableDestinationEventArgs e)
 {
     if (security.Enabled && security.ScopeEnabled)
         OnItemMoving(e.AffectedItem, e.Destination);
 }