Exemplo n.º 1
0
        private static IEnumerator <Connect.Model.ServiceDescriptor.Request.HeaderParameter> FormHeaderParameters(IService service)
        {
            ServiceDescriptor serviceDescriptor = service.GetServiceDescriptor();

            String requestName = service.GetRequest();

            Connect.Model.ServiceDescriptor.Request request = serviceDescriptor.GetRequest(requestName);

            return(request.GetHeaderParameters());
        }
Exemplo n.º 2
0
        /// <summary>
        /// It resolve service descriptor instance
        /// </summary>
        /// <param name="service">Service instance</param>
        /// <exception cref="Siminov.Connect.Exception.ServiceException">If any exception occur while resolving dynamic resources</exception>
        public static void Resolve(IService service)
        {
            /*
             * Resolve Service Descriptor Properties
             */
            ServiceDescriptor serviceDescriptor = service.GetServiceDescriptor();

            IEnumerator <String> resources = service.GetResources();

            while (resources.MoveNext())
            {
                String resourceName  = resources.Current;
                Object resourceValue = service.GetResource(resourceName);

                if (resourceValue is String)
                {
                    serviceDescriptor.AddProperty(resourceName, (String)resourceValue);
                }
            }


            IEnumerator <String>         serviceDescriptorProperties        = serviceDescriptor.GetProperties();
            IDictionary <String, String> changedServiceDescriptorProperties = new Dictionary <String, String>();

            while (serviceDescriptorProperties.MoveNext())
            {
                String serviceDescriptorProperty = serviceDescriptorProperties.Current;
                String serviceDescriptorValue    = serviceDescriptor.GetProperty(serviceDescriptorProperty);

                var serviceDescriptors = new List <IDescriptor>();
                serviceDescriptors.Add(serviceDescriptor);

                serviceDescriptorValue = ResourceUtils.Resolve(serviceDescriptorValue, serviceDescriptors.ToArray());

                changedServiceDescriptorProperties.Add(serviceDescriptorProperty, serviceDescriptorValue);
            }

            foreach (String changedServiceDescriptorProperty in changedServiceDescriptorProperties.Keys)
            {
                serviceDescriptor.AddProperty(changedServiceDescriptorProperty, changedServiceDescriptorProperties[changedServiceDescriptorProperty]);
            }


            /*
             * Resolve API Properties
             */
            Connect.Model.ServiceDescriptor.Request request   = serviceDescriptor.GetRequest(service.GetRequest());
            IEnumerator <String>         apiProperties        = request.GetProperties();
            IDictionary <String, String> changedApiProperties = new Dictionary <String, String>();

            while (apiProperties.MoveNext())
            {
                String apiProperty = apiProperties.Current;
                String apiValue    = request.GetProperty(apiProperty);

                var serviceDescriptors = new List <IDescriptor>();
                serviceDescriptors.Add(serviceDescriptor);

                apiValue = ResourceUtils.Resolve(apiValue, serviceDescriptors.ToArray());

                changedApiProperties.Add(apiProperty, apiValue);
            }

            foreach (String changedApiProperty in changedApiProperties.Keys)
            {
                request.AddProperty(changedApiProperty, changedApiProperties[changedApiProperty]);
            }

            /*
             * Resolve API Query Parameters
             */
            IEnumerator <Connect.Model.ServiceDescriptor.Request.QueryParameter> queryParameters = request.GetQueryParameters();

            while (queryParameters.MoveNext())
            {
                Connect.Model.ServiceDescriptor.Request.QueryParameter queryParameter = queryParameters.Current;

                String queryValue = queryParameter.GetValue();

                var serviceDescriptors = new List <IDescriptor>();
                serviceDescriptors.Add(serviceDescriptor);

                queryValue = ResourceUtils.Resolve(queryValue, serviceDescriptors.ToArray());

                queryParameter.SetValue(queryValue);
            }


            /*
             * Resolve API Query Parameters
             */
            IEnumerator <Connect.Model.ServiceDescriptor.Request.HeaderParameter> headerParameters = request.GetHeaderParameters();

            while (headerParameters.MoveNext())
            {
                Connect.Model.ServiceDescriptor.Request.HeaderParameter headerParameter = headerParameters.Current;

                String headerValue = headerParameter.GetValue();

                var serviceDescriptors = new List <IDescriptor>();
                serviceDescriptors.Add(serviceDescriptor);

                headerValue = ResourceUtils.Resolve(headerValue, serviceDescriptors.ToArray());

                headerParameter.SetValue(headerValue);
            }
        }