Exemple #1
0
        /// <summary>
        /// Creates a new pageable type for the specified response type.
        /// </summary>
        /// <param name="method">The method that will return a pageable type.</param>
        public PageTypeGo(MethodGo method) : base(CodeNamerGo.Instance.GetPageTypeName(method))
        {
            if (!method.IsPageable)
            {
                throw new InvalidOperationException($"method {method.Owner}.{method.Name} is not a pageable operation");
            }

            CodeModel   = method.CodeModel;
            ContentType = (CompositeTypeGo)method.ReturnType.Body;
            var returnSeq = ContentType.Properties.FirstOrDefault(p => p.ModelType is SequenceTypeGo);

            if (returnSeq == null)
            {
                throw new InvalidOperationException($"pageable return type {ContentType.Name} for method {method.Owner}.{method.Name} does not contain an array");
            }
            ElementType = returnSeq.ModelType.Cast <SequenceTypeGo>().ElementType;

            Documentation  = $"Contains a page of {ReturnTypeName} values.";
            PreparerNeeded = !method.NextMethodExists(CodeModel.Methods.Cast <MethodGo>());

            var pageableExtension = method.Extensions[AzureExtensions.PageableExtension] as Newtonsoft.Json.Linq.JContainer;

            NextLink = CodeNamerGo.Instance.GetPropertyName((string)pageableExtension["nextLinkName"]);
            if (string.IsNullOrWhiteSpace(NextLink))
            {
                throw new InvalidOperationException($"method {method.Owner}.{method.Name} contains a null nextLinkName so it shouldn't be treated as a pageable operation");
            }
            ItemName = CodeNamerGo.Instance.GetPropertyName((string)pageableExtension["itemName"] ?? "value");

            IteratorType = new IteratorTypeGo(this);
            if (method.Deprecated)
            {
                DeprecationMessage = "The method for this type has been deprecated.";
            }
        }
        /// <summary>
        /// Creates a new future type for the specified method using the specified name.
        /// </summary>
        /// <param name="method">The method that will return a future.</param>
        public FutureTypeGo(string methodName, MethodGo method) : base(methodName)
        {
            if (!method.IsLongRunningOperation())
            {
                throw new InvalidOperationException($"method {method.Owner}.{method.Name} is not a long-running operation");
            }

            CodeModel           = method.CodeModel;
            Documentation       = "An abstraction for monitoring and retrieving the results of a long-running operation.";
            ClientTypeName      = method.Owner;
            ResultType          = method.ReturnValue().Body;
            ResponderMethodName = method.ResponderMethodName;
        }
        /// <summary>
        /// Creates a new future type for the specified method.
        /// </summary>
        /// <param name="method">The method that will return a future.</param>
        public FutureTypeGo(MethodGo method) : this(CodeNamerGo.Instance.GetFutureTypeName(method), method)
        {
            if (!method.IsLongRunningOperation())
            {
                throw new InvalidOperationException($"method {method.Owner}.{method.Name} is not a long-running operation");
            }

            CodeModel           = method.CodeModel;
            Documentation       = "An abstraction for monitoring and retrieving the results of a long-running operation.";
            ClientTypeName      = method.Owner;
            ResultType          = method.ReturnValue().Body;
            ResponderMethodName = method.ResponderMethodName;
            if (method.Deprecated)
            {
                DeprecationMessage = "The method for this type has been deprecated.";
            }
        }