Example #1
0
 public static Bioma[] LoadBiomas()
 {
     LoadJson();
     foreach (var bioma in json.biomas)
     {
         RawAttributes.AddAttribute(bioma.specs, bioma.rawSpecs);
     }
     return(json.biomas);
 }
Example #2
0
 public static Plant[] LoadPlants()
 {
     LoadJson();
     foreach (var plant in json.plants)
     {
         RawAttributes.AddAttribute(plant.specs, plant.rawSpecs);
     }
     return(json.plants);
 }
        internal void Validate(bool loading)
        {
            List <string> missing = null;

            foreach (ConfigurationAttributeSchema attribute in Schema.AttributeSchemas)
            {
                if (!attribute.IsRequired)
                {
                    continue;
                }

                if (!RawAttributes.ContainsKey(attribute.Name))
                {
                    if (missing == null)
                    {
                        missing = new List <string>();
                    }

                    missing.Add(attribute.Name);
                }
            }

            if (missing != null)
            {
                string error;
                if (!loading)
                {
                    error = $"required attributes {StringExtensions.Combine(missing, ",")}";
                }
                else if (missing.Count == 1)
                {
                    error = $"required attribute '{missing[0]}'";
                }
                else
                {
                    error = $"required attributes '{StringExtensions.Combine(missing, ",")}'";
                }

                if (loading)
                {
                    var line = (Entity as IXmlLineInfo).LineNumber;
                    throw new COMException(
                              string.Format("Line number: {0}\r\nError: Missing {1}\r\n", line, error));
                }

                throw new FileNotFoundException($"Filename: \r\nError: Element is missing {error}\r\n\r\n");
            }
        }
Example #4
0
        internal object SetAttributeValueInner(string name, object value)
        {
            if (Section.IsLocked)
            {
                throw new FileLoadException("This configuration section cannot be used at this path. This happens when the section is locked at a parent level. Locking is either by default (overrideModeDefault=\"Deny\"), or set explicitly by a location tag with overrideMode=\"Deny\" or the legacy allowOverride=\"false\".\r\n");
            }

            if (!this.SkipCheck)
            {
                this.FileContext.SetDirty();
            }

            var attribute = this.GetAttribute(name);
            var result    = attribute.TypeMatch(value);

            attribute.IsInheritedFromDefaultValue = (attribute.Schema == null || !attribute.Schema.IsRequired) &&
                                                    result.Equals(attribute.ExtractDefaultValue());
            // IMPORTANT: remove attribute if value is equal to default.
            this.Entity.SetAttributeValue(
                name, attribute.IsInheritedFromDefaultValue
                    ? null
                    : attribute.Format(result));

            // IMPORTANT: IIS seems to use the following
            // this.Entity.SetAttributeValue(name, attribute.Format(_value));

            this.CleanEntity();
            if (attribute.IsInheritedFromDefaultValue)
            {
                this.RawAttributes.Remove(name);
            }
            else
            {
                if (RawAttributes.ContainsKey(name))
                {
                    RawAttributes[name] = value.ToString();
                }
                else
                {
                    RawAttributes.Add(name, value.ToString());
                }
            }

            return(result);
        }
        private void ParseAttribute(XAttribute attribute)
        {
            if (attribute.Name.NamespaceName == "http://www.w3.org/2000/xmlns/")
            {
                return;
            }

            var name = attribute.Name.LocalName;

            switch (name)
            {
            case "lockAllAttributesExcept":
                LockAllAttributesExcept.SetFromList(attribute.Value);
                return;

            case "lockAllElementsExcept":
                LockAllElementsExcept.SetFromList(attribute.Value);
                return;

            case "lockAttributes":
                LockAttributes.SetFromList(attribute.Value);
                return;

            case "lockElements":
                LockElements.SetFromList(attribute.Value);
                return;

            case "lockItem":
                IsLocked = attribute.Value;
                return;
            }

            RawAttributes.Add(name, attribute.Value);
            var child = Schema.AttributeSchemas[name];

            if (child == null && !Schema.AllowUnrecognizedAttributes)
            {
                throw new ArgumentException(String.Format("Unrecognized attribute '{0}'", name));
            }

            var item = new ConfigurationAttribute(name, child, attribute.Value, this);

            Attributes.Add(item);
        }