예제 #1
0
        /// <summary>
        /// This method is called just before a node is updated by the repository.
        /// </summary>
        /// <param name="context">The <see cref="IMansionContext"/>.</param>
        /// <param name="node">The node which will be modified.</param>
        /// <param name="modifiedProperties">The updated properties of the node.</param>
        protected override void DoBeforeUpdate(IMansionContext context, Node node, IPropertyBag modifiedProperties)
        {
            // if the name has not changed we are not interested
            string newName;
            if (!modifiedProperties.TryGet(context, "name", out newName))
                return;

            // if the name has not changed after normalization we are not interested
            newName = TagUtilities.Normalize(newName);
            if (node.Pointer.Name.Equals(newName))
            {
                modifiedProperties.Remove("name");
                return;
            }
            modifiedProperties.Set("name", newName);

            // if the tag is renamed to another already existing tag, move all content to that existing tag and delete this one
            Node existingTag;
            var tagIndexNode = TagUtilities.RetrieveTagIndexNode(context);
            if (TagUtilities.TryRetrieveTagNode(context, tagIndexNode, newName, out existingTag))
            {
                // TODO: move all content to the existing tag

                // TODO: delete this tag
            }
        }
 public void RemoveKeyFromPropertyBag(string key, IPropertyBag propertyBag)
 {
     if (propertyBag == null)
     {
         throw new ArgumentNullException("propertyBag");
     }
     propertyBag.Remove(key);
     propertyBag.Update();
 }
예제 #3
0
        public void RemoveKeyFromPropertyBag(string key, IPropertyBag propertyBag)
        {
            Validation.ArgumentNotNullOrEmpty(key, "key");
            Validation.ArgumentNotNull(propertyBag, "propertyBag");

            string fullKey = GetNamespacedKey(key);

            bool      savedConfig    = false;
            Exception savedException = null;

            for (int retryCnt = 0; retryCnt < maxRetryCount && !savedConfig; retryCnt++)
            {
                // if multiple writes occur concurrently to the property bag for an object at the same time, SharePoint will throw.
                // catch that exception and retry saving the configuration a few times before giving up.
                try
                {
                    propertyBag.Remove(fullKey);
                    savedConfig = true;
                    if (retryCnt > 0)
                    {
                        this.Logger.TraceToDeveloper(string.Format("ConfigManager: Remove to config after retry to '{0}' level, retry count: '{1}', key: '{2}'", propertyBag.Level, retryCnt, key),
                                                     SandboxTraceSeverity.High);
                    }
                }
                catch (Exception ex)
                {
                    if (ExceptionManaged(ex))
                    {
                        savedException = ex;
                        this.Logger.TraceToDeveloper(string.Format("ConfigManager: Remove saving config to '{0}' level, retry count: '{1}', key: '{2}'", propertyBag.Level, retryCnt, key),
                                                     SandboxTraceSeverity.High);
                    }
                    else
                    {
                        throw;
                    }
                }
            }

            if (savedConfig == false)
            {
                throw savedException;
            }
            this.Logger.TraceToDeveloper(string.Format("ConfigManager: Removed config setting for key: '{0}'", key), SandboxTraceSeverity.Medium);
        }
예제 #4
0
        /// <summary>
        /// Manages the tags.
        /// </summary>
        /// <param name="context">The <see cref="IMansionContext"/>.</param>
        /// <param name="properties">The new properties.</param>
        public static void ToGuids(IMansionContext context, IPropertyBag properties)
        {
            // validate arguments
            if (context == null)
                throw new ArgumentNullException("context");
            if (properties == null)
                throw new ArgumentNullException("properties");

            // get the tag name string
            string tagNameString;
            if (!properties.TryGet(context, "_tags", out tagNameString))
                return;

            // normalize the tag names
            var tagNames = NormalizeNames(tagNameString).ToList();

            // retrieve the tag index node
            var tagIndexNode = RetrieveTagIndexNode(context);

            // loop over all the tag names
            var tagNodes = tagNames.Select(tagName => RetrieveTagNode(context, tagIndexNode, tagName));

            // set the new tag guids
            properties.Set("tagGuids", string.Join(",", tagNodes.Select(x => x.PermanentId)));
            properties.Remove("_tags");
        }