public void Execute()
        {
            if (this.Node.IsNew)
            {
                var gc = Node.Parent as GenericContent;
                if (gc != null)
                {
                    gc.AssertAllowedChildType(Node);
                }
            }

            ContentNamingProvider.ValidateName(this.Node.Name);

            var autoNamingAllowed = false;

            if (this.Node.AllowIncrementalNaming.HasValue)
            {
                autoNamingAllowed = this.Node.AllowIncrementalNaming.Value;
            }
            else
            {
                autoNamingAllowed = this.Node.Id == 0 && ContentType.GetByName(this.Node.NodeType.Name).AllowIncrementalNaming;
            }

            while (true)
            {
                try
                {
                    Node.Save(this);
                    break;
                }
                catch (AggregateException ae)
                {
                    if (!autoNamingAllowed)
                    {
                        throw;
                    }
                    if (!(ae.InnerException is Storage.Data.NodeAlreadyExistsException))
                    {
                        throw;
                    }
                }
                catch (Storage.Data.NodeAlreadyExistsException)
                {
                    if (!autoNamingAllowed)
                    {
                        throw;
                    }
                }

                this.Node.Name = ContentNamingProvider.IncrementNameSuffixToLastName(Node.Name, Node.ParentId);
            }
        }
Beispiel #2
0
        public void Execute()
        {
            if (this.Node.IsNew)
            {
                var gc = Node.Parent as GenericContent;
                if (gc != null)
                {
                    gc.AssertAllowedChildType(Node);
                }
            }

            // Assert SharedLock
            //UNDONE: uncomment when SharedLock storage is implemented
            //if (null != SharedLock.GetLock(this.Node.Id))
            //    throw new InvalidContentActionException(InvalidContentActionReason.CheckedOutToSomeoneElse,
            //        this.Node.Path);

            ContentNamingProvider.ValidateName(this.Node.Name);

            var autoNamingAllowed = false;

            if (this.Node.AllowIncrementalNaming.HasValue)
            {
                autoNamingAllowed = this.Node.AllowIncrementalNaming.Value;
            }
            else
            {
                autoNamingAllowed = this.Node.Id == 0 && ContentType.GetByName(this.Node.NodeType.Name).AllowIncrementalNaming;
            }

            while (true)
            {
                try
                {
                    Node.Save(this);
                    break;
                }
                catch (Storage.Data.NodeAlreadyExistsException)
                {
                    if (!autoNamingAllowed)
                    {
                        throw;
                    }

                    this.Node.Name = ContentNamingProvider.IncrementNameSuffixToLastName(Node.Name, Node.ParentId);
                }
            }
        }