예제 #1
0
파일: Settings.cs 프로젝트: anthrax3/NuGet3
        public bool DeleteSection(string section)
        {
            // machine wide settings cannot be changed.
            if (IsMachineWideSettings)
            {
                if (_next == null)
                {
                    throw new InvalidOperationException(Resources.Error_NoWritableConfig);
                }

                return(_next.DeleteSection(section));
            }

            if (String.IsNullOrEmpty(section))
            {
                throw new ArgumentException(Resources.Argument_Cannot_Be_Null_Or_Empty, nameof(section));
            }

            var sectionElement = GetSection(ConfigXDocument.Root, section);

            if (sectionElement == null)
            {
                return(false);
            }

            XElementUtility.RemoveIndented(sectionElement);
            Save();
            return(true);
        }
예제 #2
0
        internal override void Update(SettingItem other)
        {
            var owners = other as OwnersItem;

            if (!owners.Content.Any())
            {
                throw new InvalidOperationException(Resources.OwnersItemMustHaveAtLeastOneOwner);
            }

            base.Update(other);

            if (!Equals(owners))
            {
                XElementUtility.RemoveIndented(_content.Node);
                Content = owners.Content;

                _content = new SettingText(string.Join(OwnersListSeparator.ToString(), Content));

                if (Origin != null)
                {
                    _content.SetOrigin(Origin);

                    if (Node != null)
                    {
                        _content.SetNode(_content.AsXNode());
                        (Node as XElement).Add(_content.Node);
                        Origin.IsDirty = true;
                    }
                }
            }
        }
예제 #3
0
파일: Settings.cs 프로젝트: anthrax3/NuGet3
        public void UpdateSections(string section, IReadOnlyList <SettingValue> values)
        {
            // machine wide settings cannot be changed.
            if (IsMachineWideSettings)
            {
                if (_next == null)
                {
                    throw new InvalidOperationException(Resources.Error_NoWritableConfig);
                }

                _next.UpdateSections(section, values);
                return;
            }

            if (string.IsNullOrEmpty(section))
            {
                throw new ArgumentException(Resources.Argument_Cannot_Be_Null_Or_Empty, nameof(section));
            }

            if (values == null)
            {
                throw new ArgumentNullException(nameof(values));
            }

            var sectionElement = GetSection(ConfigXDocument.Root, section);

            if (sectionElement != null)
            {
                XElementUtility.RemoveIndented(sectionElement);
            }

            var valuesToWrite = _next == null ? values : values.Where(v => v.Priority < _next._priority);

            if (valuesToWrite.Any())
            {
                sectionElement = GetOrCreateSection(ConfigXDocument.Root, section);
            }

            foreach (var value in valuesToWrite)
            {
                var element = new XElement("add");
                SetElementValues(element, value.Key, value.Value, value.AdditionalData);
                XElementUtility.AddIndented(sectionElement, element);
            }

            Save();

            if (_next != null)
            {
                _next.UpdateSections(section, values.Where(v => v.Priority >= _next._priority).ToList());
            }
        }
예제 #4
0
        /// <summary>
        /// Convenience method to remove an element from it's origin and convert to abstract
        /// </summary>
        /// <remarks>Each setting can override this method to remove any descendants from their origin</remarks>
        internal virtual void RemoveFromSettings()
        {
            if (!IsCopy() && !IsAbstract())
            {
                XElementUtility.RemoveIndented(Node);
                Origin.IsDirty = true;

                Node = null;
            }

            Origin = null;
            Parent = null;
        }
예제 #5
0
        public bool DeleteValue(string section, string key)
        {
            // machine wide settings cannot be changed.
            if (IsMachineWideSettings)
            {
                if (_next == null)
                {
                    throw new InvalidOperationException(NuGet_Configuration_Resources.Error_NoWritableConfig);
                }

                return(_next.DeleteValue(section, key));
            }

            if (String.IsNullOrEmpty(section))
            {
                throw new ArgumentException(NuGet_Configuration_Resources.Argument_Cannot_Be_Null_Or_Empty, "section");
            }
            if (String.IsNullOrEmpty(key))
            {
                throw new ArgumentException(NuGet_Configuration_Resources.Argument_Cannot_Be_Null_Or_Empty, "key");
            }

            var sectionElement = GetSection(ConfigXDocument.Root, section);

            if (sectionElement == null)
            {
                return(false);
            }

            var elementToDelete = FindElementByKey(sectionElement, key, null);

            if (elementToDelete == null)
            {
                return(false);
            }
            XElementUtility.RemoveIndented(elementToDelete);
            Save();
            return(true);
        }