Example #1
0
        private protected ServiceElementWithAttributesInfo(IEnumerable <ServiceAttributeInfo> attributes, IReadOnlyList <ServicePart> parts)
            : base(parts)
        {
            Attributes = attributes.ToReadOnlyList();

            var obsoleteAttributes = GetAttributes("obsolete");

            if (obsoleteAttributes.Count > 1)
            {
                AddValidationError(ServiceDefinitionUtility.CreateDuplicateAttributeError(obsoleteAttributes[1]));
            }
            var obsoleteAttribute = obsoleteAttributes.Count == 0 ? null : obsoleteAttributes[0];

            if (obsoleteAttribute != null)
            {
                IsObsolete = true;

                foreach (var obsoleteParameter in obsoleteAttribute.Parameters)
                {
                    if (obsoleteParameter.Name == "message")
                    {
                        ObsoleteMessage = obsoleteParameter.Value;
                    }
                    else
                    {
                        AddValidationError(ServiceDefinitionUtility.CreateUnexpectedAttributeParameterError(obsoleteAttribute.Name, obsoleteParameter));
                    }
                }
            }

            var tagNames      = new List <string>();
            var tagAttributes = GetAttributes("tag");

            foreach (var tagAttribute in tagAttributes)
            {
                string tagName = null;
                foreach (var tagParameter in tagAttribute.Parameters)
                {
                    if (tagParameter.Name == "name")
                    {
                        tagName = tagParameter.Value;
                    }
                    else
                    {
                        AddValidationError(ServiceDefinitionUtility.CreateUnexpectedAttributeParameterError(tagParameter.Name, tagParameter));
                    }
                }

                if (tagName != null)
                {
                    tagNames.Add(tagName);
                }
                else
                {
                    AddValidationError(new ServiceDefinitionError("'tag' attribute is missing required 'name' parameter.", tagAttribute.Position));
                }
            }

            TagNames = tagNames;
        }
Example #2
0
        /// <summary>
        /// Creates a field.
        /// </summary>
        public ServiceFieldInfo(string name, string typeName, IEnumerable <ServiceAttributeInfo> attributes = null, string summary = null, params ServicePart[] parts)
            : base(attributes, parts)
        {
            Name     = name ?? throw new ArgumentNullException(nameof(name));
            TypeName = typeName ?? throw new ArgumentNullException(nameof(typeName));
            Summary  = summary ?? "";

            ValidateName();

            var requiredAttributes = GetAttributes("required");

            if (requiredAttributes.Count > 1)
            {
                AddValidationError(ServiceDefinitionUtility.CreateDuplicateAttributeError(requiredAttributes[1]));
            }
            var requiredAttribute = requiredAttributes.Count == 0 ? null : requiredAttributes[0];

            if (requiredAttribute != null)
            {
                IsRequired = true;

                foreach (var requiredParameter in requiredAttribute.Parameters)
                {
                    AddValidationError(ServiceDefinitionUtility.CreateUnexpectedAttributeParameterError(requiredAttribute.Name, requiredParameter));
                }
            }
        }
Example #3
0
        /// <summary>
        /// Creates a service.
        /// </summary>
        public ServiceInfo(string name, IEnumerable <IServiceMemberInfo> members = null, IEnumerable <ServiceAttributeInfo> attributes = null, string summary = null, IEnumerable <string> remarks = null, NamedTextPosition position = null)
        {
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }

            Name       = name;
            Members    = members.ToReadOnlyList();
            Attributes = attributes.ToReadOnlyList();
            Summary    = summary ?? "";
            Remarks    = remarks.ToReadOnlyList();
            Position   = position;

            ServiceDefinitionUtility.ValidateName(Name, Position);

            foreach (var member in Members)
            {
                if (!(member is ServiceMethodInfo) && !(member is ServiceDtoInfo) && !(member is ServiceEnumInfo) && !(member is ServiceErrorSetInfo))
                {
                    throw new ServiceDefinitionException($"Unsupported member type '{member.GetType()}'.");
                }
            }

            ServiceDefinitionUtility.ValidateNoDuplicateNames(Members, "service member");
            m_membersByName = new ReadOnlyDictionary <string, IServiceMemberInfo>(Members.ToDictionary(x => x.Name, x => x));

            foreach (var field in Methods.SelectMany(x => x.RequestFields.Concat(x.ResponseFields)).Concat(Dtos.SelectMany(x => x.Fields)))
            {
                GetFieldType(field);
            }
        }
Example #4
0
        private protected void ValidateName()
        {
            var name = ((IServiceHasName)this).Name;

            if (!ServiceDefinitionUtility.IsValidName(name))
            {
                AddValidationError(new ServiceDefinitionError($"Invalid name '{name}'.", Position));
            }
        }
Example #5
0
        /// <summary>
        /// Creates an attribute.
        /// </summary>
        public ServiceAttributeInfo(string name, IEnumerable <ServiceAttributeParameterInfo> parameters = null, NamedTextPosition position = null)
        {
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }

            Name       = name;
            Parameters = parameters.ToReadOnlyList();
            Position   = position;

            ServiceDefinitionUtility.ValidateName(Name, Position);
            ServiceDefinitionUtility.ValidateNoDuplicateNames(Parameters, "attribute parameter");
        }
Example #6
0
        /// <summary>
        /// Creates an enum value.
        /// </summary>
        public ServiceEnumValueInfo(string name, IEnumerable <ServiceAttributeInfo> attributes = null, string summary = null, NamedTextPosition position = null)
        {
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }

            Name       = name;
            Attributes = attributes.ToReadOnlyList();
            Summary    = summary ?? "";
            Position   = position;

            ServiceDefinitionUtility.ValidateName(Name, Position);
        }
Example #7
0
        /// <summary>
        /// Creates a DTO.
        /// </summary>
        public ServiceDtoInfo(string name, IEnumerable <ServiceFieldInfo> fields = null, IEnumerable <ServiceAttributeInfo> attributes = null, string summary = null, IEnumerable <string> remarks = null, NamedTextPosition position = null)
        {
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }

            Name       = name;
            Fields     = fields.ToReadOnlyList();
            Attributes = attributes.ToReadOnlyList();
            Summary    = summary ?? "";
            Remarks    = remarks.ToReadOnlyList();
            Position   = position;

            ServiceDefinitionUtility.ValidateName(Name, Position);
            ServiceDefinitionUtility.ValidateNoDuplicateNames(Fields, "field");
        }
        /// <summary>
        /// Creates an attribute parameter.
        /// </summary>
        public ServiceAttributeParameterInfo(string name, string value, NamedTextPosition position = null)
        {
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }

            Name     = name;
            Value    = value;
            Position = position;

            ServiceDefinitionUtility.ValidateName(Name, Position);
        }