Exemplo n.º 1
0
 public static bool IsBlobOrClob(INakedObjectSpecificationSurface spec)
 {
     if (spec.IsParseable() || spec.IsCollection())
     {
         Type           underlyingType = spec.GetUnderlyingType();
         PredefinedType pdt            = TypeToPredefinedType(underlyingType);
         return(pdt == PredefinedType.Blob || pdt == PredefinedType.Clob);
     }
     return(false);
 }
Exemplo n.º 2
0
        public void AddActionResultRepresentationParameter(MediaTypeHeaderValue mediaType, RestControlFlags flags)
        {
            INakedObjectSpecificationSurface resultSpec = action.ReturnType;
            bool isCollection = resultSpec.IsCollection() && !resultSpec.IsParseable();
            INakedObjectSpecificationSurface parameterValueSpec = isCollection ? action.ElementType : resultSpec;
            string parameterValue = GetParameterValue(flags, parameterValueSpec);

            if (parameterValue != null)
            {
                string parameterType = isCollection ? RestControlFlags.ElementTypeReserved : RestControlFlags.DomainTypeReserved;
                mediaType.Parameters.Add(new NameValueHeaderValue(parameterType, string.Format("\"{0}\"", parameterValue)));
            }
        }
Exemplo n.º 3
0
        public static PredefinedType?SpecToPredefinedType(INakedObjectSpecificationSurface spec)
        {
            if (spec.IsFileAttachment() || spec.IsImage())
            {
                return(PredefinedType.Blob);
            }

            if (spec.IsParseable() || spec.IsCollection() || spec.IsVoid())
            {
                Type underlyingType = spec.GetUnderlyingType();
                return(TypeToPredefinedType(underlyingType));
            }
            return(null);
        }
Exemplo n.º 4
0
        public static MapRepresentation GetExtensions(string friendlyname,
                                                      string description,
                                                      string pluralName,
                                                      string domainType,
                                                      bool? isService,
                                                      bool? hasParams,
                                                      bool? optional,
                                                      int? maxLength,
                                                      string pattern,
                                                      int? memberOrder,
                                                      IDictionary<string, object> customExtensions,
                                                      INakedObjectSpecificationSurface returnType) {
            var exts = new Dictionary<string, object> {
                {JsonPropertyNames.FriendlyName, friendlyname},
                {JsonPropertyNames.Description, description}
            };

            if (pluralName != null) {
                exts.Add(JsonPropertyNames.PluralName, pluralName);
            }

            if (domainType != null) {
                exts.Add(JsonPropertyNames.DomainType, domainType);
            }

            if (hasParams != null) {
                exts.Add(JsonPropertyNames.HasParams, hasParams);
            }

            if (isService != null) {
                exts.Add(JsonPropertyNames.IsService, isService);
            }

            if (optional != null) {
                exts.Add(JsonPropertyNames.Optional, optional);
            }

            if (memberOrder != null) {
                exts.Add(JsonPropertyNames.MemberOrder, memberOrder);
            }

            if (returnType != null && !returnType.IsVoid()) {
                Tuple<string, string> jsonDataType = SpecToTypeAndFormatString(returnType);
                exts.Add(JsonPropertyNames.ReturnType, jsonDataType.Item1);

                // blob and clobs are arrays so do this check first so they are not caught be the collection test after. 
                if (jsonDataType.Item1 == PredefinedType.Number.ToRoString()) {
                    exts.Add(JsonPropertyNames.Format, jsonDataType.Item2);
                }
                else if (jsonDataType.Item1 == PredefinedType.String.ToRoString()) {
                    exts.Add(JsonPropertyNames.Format, jsonDataType.Item2);
                    exts.Add(JsonPropertyNames.MaxLength, maxLength ?? 0);
                    exts.Add(JsonPropertyNames.Pattern, pattern ?? "");
                }
                else if (returnType.IsCollection()) {
                    exts.Add(JsonPropertyNames.ElementType, SpecToTypeAndFormatString(returnType.ElementType).Item1);
                    exts.Add(JsonPropertyNames.PluralName, returnType.ElementType.PluralName());
                }
            }

            if (customExtensions != null) {
                foreach (var kvp in customExtensions) {
                    exts.Add(kvp.Key, kvp.Value);
                }
            }

            return CreateMap(exts);
        }
Exemplo n.º 5
0
 public static bool IsBlobOrClob(INakedObjectSpecificationSurface spec) {
     if (spec.IsParseable() || spec.IsCollection()) {
         Type underlyingType = spec.GetUnderlyingType();
         PredefinedType pdt = TypeToPredefinedType(underlyingType);
         return pdt == PredefinedType.Blob || pdt == PredefinedType.Clob;
     }
     return false;
 }
Exemplo n.º 6
0
        public static PredefinedType? SpecToPredefinedType(INakedObjectSpecificationSurface spec) {
            if (spec.IsFileAttachment() || spec.IsImage()) {
                return PredefinedType.Blob;
            }

            if (spec.IsParseable() || spec.IsCollection() || spec.IsVoid()) {
                Type underlyingType = spec.GetUnderlyingType();
                return TypeToPredefinedType(underlyingType);
            }
            return null;
        }
Exemplo n.º 7
0
        public static MapRepresentation GetExtensions(string friendlyname,
                                                      string description,
                                                      string pluralName,
                                                      string domainType,
                                                      bool?isService,
                                                      bool?hasParams,
                                                      bool?optional,
                                                      int?maxLength,
                                                      string pattern,
                                                      int?memberOrder,
                                                      IDictionary <string, object> customExtensions,
                                                      INakedObjectSpecificationSurface returnType,
                                                      INakedObjectSpecificationSurface elementType)
        {
            var exts = new Dictionary <string, object> {
                { JsonPropertyNames.FriendlyName, friendlyname },
                { JsonPropertyNames.Description, description }
            };

            if (pluralName != null)
            {
                exts.Add(JsonPropertyNames.PluralName, pluralName);
            }

            if (domainType != null)
            {
                exts.Add(JsonPropertyNames.DomainType, domainType);
            }

            if (hasParams != null)
            {
                exts.Add(JsonPropertyNames.HasParams, hasParams);
            }

            if (isService != null)
            {
                exts.Add(JsonPropertyNames.IsService, isService);
            }

            if (optional != null)
            {
                exts.Add(JsonPropertyNames.Optional, optional);
            }

            if (memberOrder != null)
            {
                exts.Add(JsonPropertyNames.MemberOrder, memberOrder);
            }

            if (returnType != null && !returnType.IsVoid())
            {
                Tuple <string, string> jsonDataType = SpecToTypeAndFormatString(returnType);
                exts.Add(JsonPropertyNames.ReturnType, jsonDataType.Item1);

                // blob and clobs are arrays so do this check first so they are not caught be the collection test after.
                if (jsonDataType.Item1 == PredefinedType.Number.ToRoString())
                {
                    exts.Add(JsonPropertyNames.Format, jsonDataType.Item2);
                }
                else if (jsonDataType.Item1 == PredefinedType.String.ToRoString())
                {
                    exts.Add(JsonPropertyNames.Format, jsonDataType.Item2);
                    exts.Add(JsonPropertyNames.MaxLength, maxLength ?? 0);
                    exts.Add(JsonPropertyNames.Pattern, pattern ?? "");
                }
                else if (returnType.IsCollection())
                {
                    exts.Add(JsonPropertyNames.ElementType, SpecToTypeAndFormatString(elementType).Item1);
                    exts.Add(JsonPropertyNames.PluralName, elementType.PluralName());
                }
            }

            if (customExtensions != null)
            {
                foreach (var kvp in customExtensions)
                {
                    exts.Add(kvp.Key, kvp.Value);
                }
            }

            return(CreateMap(exts));
        }