Example #1
0
        public TestRules()
        {
            _attributesDb    = new InMemoryEntityRepository <Campaigns.Model.Attribute>();
            _contributionsDb = new InMemoryEntityRepository <AttributeContribution>();
            _contributionsDb.AddForeignStore(_attributesDb);

            _contributingAttributes = new HashSet <Campaigns.Model.Attribute>();

            //
            // create attributes
            //

            _races = new Dictionary <string, Campaigns.Model.Attribute>
            {
                { "human", CreateAttribute("human", "races", isStandard: false) },
                { "gnome", CreateAttribute("gnome", "races", isStandard: false) }
            };

            _abilities = new Dictionary <string, Campaigns.Model.Attribute>
            {
                { "str", CreateAttribute("str", "abilities", isStandard: true) },
                { "int", CreateAttribute("int", "abilities", isStandard: true) }
            };

            _abilityMods =
                _abilities.Values
                .Select(attrib => CreateAttribute(attrib.Name, "ability-modifiers", isStandard: true))
                .ToDictionary(m => m.Name);

            _skills = new Dictionary <string, Campaigns.Model.Attribute>
            {
                { "athletics", CreateAttribute("athletics", "skills", isStandard: true) },
                { "arcana", CreateAttribute("arcana", "skills", isStandard: true) }
            };

            // TODO: this should be standard behaviour
            // ensure all standard attributes are contributing
            foreach (var attrib in AllAttributes.Where(a => a.IsStandard))
            {
                SetInitialValue(attrib, 0);
            }

            //
            // create attribute contribution links
            //

            foreach (var mod in _abilities.Keys)
            {
                var contribution = _abilities[mod].ContributionTo(_abilityMods[mod], srcVal => (srcVal / 2) - 5);
                _contributionsDb.Add(contribution);
            }

            // TODO:
            //  - only one contributing link between src and target allowed (overwrite)

            _contributionsDb.Add(_races["gnome"].ConstantContributionTo(_abilities["int"], 2));

            _contributionsDb.Add(_skills["athletics"].CopyContributionFrom(_abilityMods["str"]));
            _contributionsDb.Add(_skills["arcana"].CopyContributionFrom(_abilityMods["int"]));
        }
Example #2
0
        private CloudEventsSpecVersion(
            string versionId,
            CloudEventAttribute idAttribute,
            CloudEventAttribute sourceAttribute,
            CloudEventAttribute typeAttribute,
            CloudEventAttribute dataContentTypeAttribute,
            CloudEventAttribute dataSchemaAttribute,
            CloudEventAttribute subjectAttribute,
            CloudEventAttribute timeAttribute)
        {
            VersionId                = versionId;
            IdAttribute              = idAttribute;
            SourceAttribute          = sourceAttribute;
            TypeAttribute            = typeAttribute;
            DataContentTypeAttribute = dataContentTypeAttribute;
            DataSchemaAttribute      = dataSchemaAttribute;
            SubjectAttribute         = subjectAttribute;
            TimeAttribute            = timeAttribute;

            var allAttributes = new[]
            {
                idAttribute, sourceAttribute, typeAttribute, dataContentTypeAttribute,
                dataSchemaAttribute, subjectAttribute, timeAttribute
            };

            RequiredAttributes = allAttributes.Where(a => a.IsRequired).ToList().AsReadOnly();
            OptionalAttributes = allAttributes.Where(a => !a.IsRequired).ToList().AsReadOnly();
            AllAttributes      = RequiredAttributes.Concat(OptionalAttributes).ToList().AsReadOnly();
            attributesByName   = AllAttributes.ToDictionary(attr => attr.Name);
            allVersions.Add(this);
        }
Example #3
0
 /// <summary>
 /// 设置属性
 /// </summary>
 /// <param name="name">属性名</param>
 /// <param name="value">值</param>
 /// <param name="replaceExisting">是否替换已存在的属性</param>
 public void SetAttribute(string name, object value, bool replaceExisting = true)
 {
     if (replaceExisting == false && Contains(name))
     {
         return;
     }
     AllAttributes.SetAttribute(new TagHelperAttribute(name, value));
 }
 protected int GetAttributeGlobalOrder(Attribute attribute)
 {
     if (attribute is DerivedAttribute)
     {
         return(0);
     }
     return(AllAttributes.IndexOf(attribute) + 1);
 }
Example #5
0
        /// <summary>
        /// Tracks the <see cref="ITagHelper"/> bound attribute in <see cref="AllAttributes"/>.
        /// </summary>
        /// <param name="name">The bound attribute name.</param>
        /// <param name="value">The attribute value.</param>
        public void AddTagHelperAttribute(string name, object value)
        {
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }

            AllAttributes.Add(name, value);
        }
Example #6
0
        private void EnsureProperNumberOfConcurrencyProperties(ValidationContext context)
        {
            int tokenCount = AllAttributes.Count(x => x.IsConcurrencyToken);
            int shouldHave = EffectiveConcurrency == ConcurrencyOverride.Optimistic ? 1 : 0;

            if (tokenCount != shouldHave)
            {
                context.LogError($"{Name}: Should have {shouldHave} concurrency properties but has {tokenCount}", "MCEConcurrencyCount", this);
            }
        }
Example #7
0
 public override AttributesHelper.AddAttributesResponse AddAllFound()
 {
     TempData = AllAttributes.Where(x => x.Attribute.AttributeType.Name == nameof(UniversalUnityHooks.HookAttribute)).ToList();
     if (TempData == null || TempData.Count == 0)
     {
         Program.Chalker.WriteWarning($"No hook attributes were found. Without hook attributes it cannot inject anything. ({Timer.GetElapsedMs}ms)");
         return(AttributesHelper.AddAttributesResponse.Info);
     }
     return(base.AddAllFound());
 }
Example #8
0
 public override AddAttributesResponse AddAllFound()
 {
     TempData = AllAttributes.Where(x => x.Attribute.AttributeType.Name == nameof(HookAttribute.AddMethodAttribute)).ToList();
     if (TempData == null || TempData.Count == 0)
     {
         ConsoleHelper.WriteMessage(ConsoleHelper.MessageType.Warning, $"No add method attributes were found. ({Timer.GetElapsedMs}ms)");
         return(AddAttributesResponse.Info);
     }
     return(base.AddAllFound());
 }
Example #9
0
 /// <summary>
 /// Tracks the minimized HTML attribute in <see cref="AllAttributes"/> and <see cref="HTMLAttributes"/>.
 /// </summary>
 /// <param name="name">The minimized HTML attribute name.</param>
 public void AddMinimizedHtmlAttribute([NotNull] string name)
 {
     HTMLAttributes.Add(
         new TagHelperAttribute
     {
         Name      = name,
         Minimized = true
     });
     AllAttributes.Add(
         new TagHelperAttribute
     {
         Name      = name,
         Minimized = true
     });
 }
Example #10
0
        /// <summary>
        /// Tracks the minimized HTML attribute in <see cref="AllAttributes"/> and <see cref="HTMLAttributes"/>.
        /// </summary>
        /// <param name="name">The minimized HTML attribute name.</param>
        public void AddMinimizedHtmlAttribute(string name)
        {
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }

            HTMLAttributes.Add(
                new TagHelperAttribute
            {
                Name      = name,
                Minimized = true
            });
            AllAttributes.Add(
                new TagHelperAttribute
            {
                Name      = name,
                Minimized = true
            });
        }
Example #11
0
        /// <summary>
        /// Populates the attributes.
        /// </summary>
        /// <param name="line">The line.</param>
        /// <param name="isSampleData">if set to <c>true</c> [is sample data].</param>
        public static void PopulateAttributes(string line, bool isSampleData)
        {
            if (!string.IsNullOrEmpty(line))
            {
                var attribute = new Attribute();

                //Parsing the attributes by removing the {} and then split by comma.
                var firstSpaceIndex      = line.IndexOf(" ", StringComparison.Ordinal);
                var firstOpenParentIndex = line.IndexOf("{", StringComparison.Ordinal);
                var lastCloseParentIndex = line.LastIndexOf("}", StringComparison.Ordinal);

                attribute.AttributeName = line.Substring(firstSpaceIndex + 1, firstOpenParentIndex - firstSpaceIndex - 2).RemoveSingleQuoteIfAny();

                var valueParts = line.Substring(firstOpenParentIndex + 1,
                                                lastCloseParentIndex - 1 - firstOpenParentIndex).Split(',');
                attribute.PossibleValues.AddRange(valueParts.Select(value => value.RemoveSingleQuoteIfAny()).ToList());

                if (isSampleData)
                {
                    AllAttributes.Add(attribute);
                    RemainingAttributes.Add(attribute);
                }
            }
        }
Example #12
0
 /// <summary>
 /// 移除属性
 /// </summary>
 /// <param name="name">属性名</param>
 public void Remove(string name)
 {
     AllAttributes.RemoveAll(name);
 }
Example #13
0
 /// <summary>
 /// 属性集合是否包含指定属性
 /// </summary>
 /// <param name="name">属性名</param>
 public bool Contains(string name)
 {
     return(AllAttributes.ContainsName(name));
 }
Example #14
0
 /// <summary>
 /// 设置属性
 /// </summary>
 /// <param name="name">属性名</param>
 /// <param name="value">值</param>
 public void SetAttribute(string name, object value)
 {
     AllAttributes.SetAttribute(new TagHelperAttribute(name, value));
 }
Example #15
0
 public ModelAttribute FindAttributeNamed(string identifier) => AllAttributes.FirstOrDefault(x => x.Name == identifier);
Example #16
0
 /// <summary>
 /// Tracks the <see cref="ITagHelper"/> bound attribute in <see cref="AllAttributes"/>.
 /// </summary>
 /// <param name="name">The bound attribute name.</param>
 /// <param name="value">The attribute value.</param>
 public void AddTagHelperAttribute([NotNull] string name, object value)
 {
     AllAttributes.Add(name, value);
 }
Example #17
0
 /// <summary>
 /// Tracks the HTML attribute in <see cref="AllAttributes"/> and <see cref="HTMLAttributes"/>.
 /// </summary>
 /// <param name="name">The HTML attribute name.</param>
 /// <param name="value">The HTML attribute value.</param>
 public void AddHtmlAttribute([NotNull] string name, object value)
 {
     HTMLAttributes.Add(name, value);
     AllAttributes.Add(name, value);
 }