Example #1
0
        // this function will generate an api dictionary with apiName/versionsetName (if exist one) as key, list of apiNames as value
        public static async Task <Dictionary <string, List <string> > > GetAllAPIsDictionary(string sourceApim, string resourceGroup, FileWriter fileWriter)
        {
            APIExtractor apiExtractor = new APIExtractor(fileWriter);

            // pull all apis from service
            JToken[] apis = await apiExtractor.GetAllAPIObjsAsync(sourceApim, resourceGroup);

            // Generate folders based on all apiversionset
            var apiDictionary = new Dictionary <string, List <string> >();

            foreach (JToken oApi in apis)
            {
                string apiDisplayName = ((JValue)oApi["properties"]["displayName"]).Value.ToString();
                if (!apiDictionary.ContainsKey(apiDisplayName))
                {
                    List <string> apiVersionSet = new List <string>();
                    apiVersionSet.Add(((JValue)oApi["name"]).Value.ToString());
                    apiDictionary[apiDisplayName] = apiVersionSet;
                }
                else
                {
                    apiDictionary[apiDisplayName].Add(((JValue)oApi["name"]).Value.ToString());
                }
            }
            return(apiDictionary);
        }
Example #2
0
        public async Task <Template> CreateMasterTemplateParameterValues(string singleApiName, List <string> multipleApiNames, Extractor exc)
        {
            // used to create the parameter values for use in parameters file
            // create empty template
            Template masterTemplate = GenerateEmptyTemplate();

            // add parameters with value property
            Dictionary <string, TemplateParameterProperties> parameters = new Dictionary <string, TemplateParameterProperties>();
            TemplateParameterProperties apimServiceNameProperties       = new TemplateParameterProperties()
            {
                value = exc.destinationApimName
            };

            parameters.Add("ApimServiceName", apimServiceNameProperties);
            if (exc.linkedTemplatesBaseUrl != null)
            {
                TemplateParameterProperties linkedTemplatesBaseUrlProperties = new TemplateParameterProperties()
                {
                    value = exc.linkedTemplatesBaseUrl
                };
                parameters.Add("LinkedTemplatesBaseUrl", linkedTemplatesBaseUrlProperties);
                // add linkedTemplatesSasToken parameter if provided and if the user has provided a linkedTemplatesBaseUrl
                if (exc.linkedTemplatesSasToken != null)
                {
                    TemplateParameterProperties linkedTemplatesSasTokenProperties = new TemplateParameterProperties()
                    {
                        value = exc.linkedTemplatesSasToken
                    };
                    parameters.Add("LinkedTemplatesSasToken", linkedTemplatesSasTokenProperties);
                }
                // add linkedTemplatesUrlQueryString parameter if provided and if the user has provided a linkedTemplatesBaseUrl
                if (exc.linkedTemplatesUrlQueryString != null)
                {
                    TemplateParameterProperties linkedTemplatesUrlQueryStringProperties = new TemplateParameterProperties()
                    {
                        value = exc.linkedTemplatesUrlQueryString
                    };
                    parameters.Add("LinkedTemplatesUrlQueryString", linkedTemplatesUrlQueryStringProperties);
                }
            }
            if (exc.policyXMLBaseUrl != null)
            {
                TemplateParameterProperties policyTemplateBaseUrlProperties = new TemplateParameterProperties()
                {
                    value = exc.policyXMLBaseUrl
                };
                parameters.Add("PolicyXMLBaseUrl", policyTemplateBaseUrlProperties);
                // add policyXMLSasToken parameter if provided and if the user has provided a policyXMLBaseUrl
                if (exc.policyXMLSasToken != null)
                {
                    TemplateParameterProperties policyTemplateSasTokenProperties = new TemplateParameterProperties()
                    {
                        value = exc.policyXMLSasToken
                    };
                    parameters.Add("PolicyXMLSasToken", policyTemplateSasTokenProperties);
                }
            }
            if (exc.paramServiceUrl)
            {
                Dictionary <string, string> serviceUrls = new Dictionary <string, string>();
                APIExtractor apiExc = new APIExtractor(new FileWriter());
                if (singleApiName != null)
                {
                    string validApiName = ExtractorUtils.GenValidApiParamName(singleApiName);
                    string serviceUrl   = GetApiServiceUrlFromParameters(singleApiName, exc.serviceUrlParameters);
                    if (serviceUrl == null)
                    {
                        serviceUrl = await apiExc.GetAPIServiceUrl(exc.sourceApimName, exc.resourceGroup, singleApiName);
                    }
                    serviceUrls.Add(validApiName, serviceUrl);
                }
                else if (multipleApiNames != null)
                {
                    foreach (string apiName in multipleApiNames)
                    {
                        string validApiName = ExtractorUtils.GenValidApiParamName(apiName);
                        string serviceUrl   = GetApiServiceUrlFromParameters(apiName, exc.serviceUrlParameters);
                        if (serviceUrl == null)
                        {
                            serviceUrl = await apiExc.GetAPIServiceUrl(exc.sourceApimName, exc.resourceGroup, apiName);
                        }
                        serviceUrls.Add(validApiName, serviceUrl);
                    }
                }
                else
                {
                    JToken[] oApis = await apiExc.GetAllAPIObjsAsync(exc.sourceApimName, exc.resourceGroup);

                    foreach (JToken oApi in oApis)
                    {
                        string apiName      = ((JValue)oApi["name"]).Value.ToString();
                        string validApiName = ExtractorUtils.GenValidApiParamName(apiName);
                        string serviceUrl   = GetApiServiceUrlFromParameters(apiName, exc.serviceUrlParameters);
                        if (serviceUrl == null)
                        {
                            serviceUrl = await apiExc.GetAPIServiceUrl(exc.sourceApimName, exc.resourceGroup, apiName);
                        }
                        serviceUrls.Add(validApiName, serviceUrl);
                    }
                }
                TemplateServiceUrlProperties serviceUrlProperties = new TemplateServiceUrlProperties()
                {
                    value = serviceUrls
                };
                parameters.Add("serviceUrl", serviceUrlProperties);
            }
            masterTemplate.parameters = parameters;
            return(masterTemplate);
        }