private string GetPagingSetting(Dictionary <string, object> extensions, string valueTypeName)
        {
            var ext = extensions[AzureExtensions.PageableExtension] as Newtonsoft.Json.Linq.JContainer;

            string nextLinkName = (string)ext["nextLinkName"] ?? "nextLink";
            string itemName     = (string)ext["itemName"] ?? "value";
            string className    = (string)ext["className"];

            if (string.IsNullOrEmpty(className))
            {
                className        = valueTypeName + "Paged";
                ext["className"] = className;
            }

            var pageModel = new PageTemplateModel(className, nextLinkName, itemName, valueTypeName);

            if (!pageModels.Contains(pageModel))
            {
                pageModels.Add(pageModel);
            }

            return(className);
        }
예제 #2
0
        private string GetPagingSetting(CompositeType body, Dictionary <string, object> extensions, string valueTypeName, IDictionary <int, string> typePageClasses)
        {
            var ext = extensions[AzureExtensions.PageableExtension] as Newtonsoft.Json.Linq.JContainer;

            bool ignoreNextLink = false;

            if (ext["nextLinkName"] != null && ext["nextLinkName"].Type == Newtonsoft.Json.Linq.JTokenType.Null)
            {
                ignoreNextLink = true;
            }
            string nextLinkName = (string)ext["nextLinkName"] ?? "nextLink";
            string itemName     = (string)ext["itemName"] ?? "value";

            nextLinkName = nextLinkName.Replace(".", "\\\\.");
            itemName     = itemName.Replace(".", "\\\\.");
            bool findNextLink = false;
            bool findItem     = false;

            foreach (var property in body.ComposedProperties)
            {
                if (property.SerializedName == nextLinkName)
                {
                    findNextLink = true;
                }
                else if (property.SerializedName == itemName)
                {
                    findItem = true;
                }
            }

            if (!ignoreNextLink && !findNextLink)
            {
                throw new KeyNotFoundException("Couldn't find the nextLink property specified by extension");
            }
            if (!findItem)
            {
                throw new KeyNotFoundException("Couldn't find the item property specified by extension");
            }

            string className;
            var    hash = (nextLinkName + "#" + itemName).GetHashCode();

            if (!typePageClasses.ContainsKey(hash))
            {
                className = (string)ext["className"];
                if (string.IsNullOrEmpty(className))
                {
                    if (typePageClasses.Count > 0)
                    {
                        className = valueTypeName + String.Format(CultureInfo.InvariantCulture, "Paged{0}", typePageClasses.Count);
                    }
                    else
                    {
                        className = valueTypeName + "Paged";
                    }
                }
                typePageClasses.Add(hash, className);
            }

            className        = typePageClasses[hash];
            ext["className"] = className;

            var pageModel = new PageTemplateModel(className, nextLinkName, itemName, valueTypeName);

            if (!pageModels.Contains(pageModel))
            {
                pageModels.Add(pageModel);
            }

            return(className);
        }