Пример #1
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);
        }
Пример #2
0
        private Dictionary <string, string> GetRequiredAttributes(XmlReader reader, RequiredAttributes attribs)
        {
            Dictionary <string, string> result = new Dictionary <string, string>();

            foreach (RequiredAttribute attrib in attribs.Attributes)
            {
                string value;
                if (attrib.UseTemplate)
                {
                    value = GetTemplateAttribute(reader, attrib.Name);
                }
                else
                {
                    value = reader.GetAttribute(attrib.Name);
                }

                if (attrib.Required && (value == null || (!attrib.AllowBlank && value.Length == 0)))
                {
                    throw new Exception(string.Format("Missing required attribute '{0}' in '{1}' tag", attrib.Name, reader.LocalName));
                }

                result.Add(attrib.Name, value);
            }

            return(result);
        }
Пример #3
0
        public WonkaRegistryItem(WonkaEth.Extensions.RuleTreeRegistryIndex poIndex, string psHostContractABI)
        {
            Init();


            RuleTreeId  = poIndex.RuleTreeId;
            Description = poIndex.RuleTreeDesc;

            HostContractAddress = poIndex.RuleTreeHostEngineAddr;
            HostContractABI     = psHostContractABI;

            OwnerId      = poIndex.RuleTreeOwner;
            MaxGasCost   = poIndex.MaxGasCost;
            creationTime = poIndex.CreationEpochTime;

            RequiredAttributes.UnionWith(poIndex.RequiredAttributes);
        }
Пример #4
0
        private bool IsAttributeValid(string attributeName, string value)
        {
            if (AllowedAttributes != null)
            {
                // No attributes are allowed
                if (!AllowedAttributes.Any())
                {
                    return(false);
                }

                if (!AllowedAttributes.Contains(attributeName))
                {
                    return(false);
                }
            }

            if (RequiredAttributes != null)
            {
                if (value == null && RequiredAttributes.Contains(attributeName))
                {
                    // Don't delete any required attributes
                    return(false);
                }
            }

            if (AllowedValues != null)
            {
                if (AllowedValues.TryGetValue(attributeName, out var allowed) && !allowed.Contains(value.Trim()))
                {
                    return(false);
                }
            }

            if (DisallowedValues != null)
            {
                if (DisallowedValues.TryGetValue(attributeName, out var disallowed) && disallowed.Contains(value.Trim()))
                {
                    return(false);
                }
            }

            return(true);
        }
Пример #5
0
        private Dictionary<string, string> GetRequiredAttributes(XmlReader reader, RequiredAttributes attribs)
        {
            Dictionary<string, string> result = new Dictionary<string, string>();

            foreach (RequiredAttribute attrib in attribs.Attributes)
            {
                string value;
                if (attrib.UseTemplate)
                {
                    value = GetTemplateAttribute(reader, attrib.Name);
                }
                else
                {
                    value = reader.GetAttribute(attrib.Name);
                }

                if (attrib.Required && (value == null || (!attrib.AllowBlank && value.Length == 0)))
                {
                    throw new Exception(string.Format("Missing required attribute '{0}' in '{1}' tag", attrib.Name, reader.LocalName));
                }

                result.Add(attrib.Name, value);
            }

            return result;
        }