public override void EndElement(String localName) { if (localName.Equals(Constants.SERVICE_DESCRIPTOR_PROPERTY, StringComparison.OrdinalIgnoreCase)) { ProcessProperty(); } else if (localName.Equals(Constants.SERVICE_DESCRIPTOR_REQUEST, StringComparison.OrdinalIgnoreCase)) { serviceDescriptor.AddRequest(request); request = null; isRequest = false; } else if (localName.Equals(Constants.SERVICE_DESCRIPTOR_REQUEST_QUERY_PARAMETER, StringComparison.OrdinalIgnoreCase)) { request.AddQueryParameter(queryParameter); queryParameter = null; isQueryParameter = false; } else if (localName.Equals(Constants.SERVICE_DESCRIPTOR_REQUEST_HEADER_PARAMETER, StringComparison.OrdinalIgnoreCase)) { request.AddHeaderParameter(headerParameter); headerParameter = null; isHeaderParameter = false; } else if (localName.Equals(Constants.SERVICE_DESCRIPTOR_REQUEST_DATA_STREAM, StringComparison.OrdinalIgnoreCase)) { request.SetDataStream(tempValue.ToString()); } }
public override void StartElement(XmlReader reader, IDictionary <String, String> attributes) { String localName = reader.Name; tempValue = new StringBuilder(); if (localName.Equals(Constants.SERVICE_DESCRIPTOR_PROPERTY, StringComparison.OrdinalIgnoreCase)) { propertyName = attributes[Constants.SERVICE_DESCRIPTOR_PROPERTY_NAME]; } else if (localName.Equals(Constants.SERVICE_DESCRIPTOR_REQUEST, StringComparison.OrdinalIgnoreCase)) { request = new ServiceDescriptor.Request(); isRequest = true; } else if (localName.Equals(Constants.SERVICE_DESCRIPTOR_REQUEST_QUERY_PARAMETER, StringComparison.OrdinalIgnoreCase)) { queryParameter = new Connect.Model.ServiceDescriptor.Request.QueryParameter(); isQueryParameter = true; } else if (localName.Equals(Constants.SERVICE_DESCRIPTOR_REQUEST_HEADER_PARAMETER, StringComparison.OrdinalIgnoreCase)) { headerParameter = new Connect.Model.ServiceDescriptor.Request.HeaderParameter(); isHeaderParameter = true; } }
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()); }
private static String FormUrl(IService service) { ServiceDescriptor serviceDescriptor = service.GetServiceDescriptor(); String requestName = service.GetRequest(); Connect.Model.ServiceDescriptor.Request request = serviceDescriptor.GetRequest(requestName); String protocol = serviceDescriptor.GetProtocol(); String instance = serviceDescriptor.GetInstance(); String port = serviceDescriptor.GetPort(); String context = serviceDescriptor.GetContext(); String apiPath = request.GetApi(); StringBuilder url = new StringBuilder(); if (protocol != null) { if (protocol.Equals(Constants.SERVICE_DESCRIPTOR_HTTP_PROTOCOL, StringComparison.OrdinalIgnoreCase)) { url.Append(Constants.CONNECTION_HTTP); } else if (protocol.Equals(Constants.SERVICE_DESCRIPTOR_HTTPS_PROTOCOL, StringComparison.OrdinalIgnoreCase)) { url.Append(Constants.CONNECTION_HTTPS); } url.Append("://"); } url.Append(instance); if (port != null && port.Length > 0) { url.Append(":" + port); } if (context != null && context.Length > 0) { url.Append("/" + context); } if (apiPath != null && apiPath.Length > 0) { url.Append("/" + apiPath); } return(url.ToString()); }
private static byte[] FormDataStream(IService service) { ServiceDescriptor serviceDescriptor = service.GetServiceDescriptor(); String requestName = service.GetRequest(); Connect.Model.ServiceDescriptor.Request request = serviceDescriptor.GetRequest(requestName); if (request.GetDataStream() == null) { return(new byte[0]); } return(System.Text.Encoding.UTF8.GetBytes(request.GetDataStream())); }
/// <summary> /// It handles the service request /// </summary> /// <param name="service">Service instance</param> /// <exception cref="Siminov.Connect.Exception.ServiceException">If any exception occur while handling the service request</exception> public void Handle(IService service) { ServiceDescriptor serviceDescriptor = service.GetServiceDescriptor(); if (serviceDescriptor == null) { serviceDescriptor = resourceManager.RequiredServiceDescriptorBasedOnName(service.GetService()); service.SetServiceDescriptor(serviceDescriptor); } 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); } } Connect.Model.ServiceDescriptor.Request request = serviceDescriptor.GetRequest(service.GetRequest()); var serviceDescriptors = new List <Core.Model.IDescriptor>(); serviceDescriptors.Add(serviceDescriptor); String mode = ResourceUtils.Resolve(request.GetMode(), serviceDescriptors.ToArray()); if (mode.Equals(Constants.SERVICE_DESCRIPTOR_REQUEST_SYNC_REQUEST_MODE, StringComparison.OrdinalIgnoreCase)) { ResourceUtils.Resolve(service); syncServiceWorker.Process(service); } else if (mode.Equals(Constants.SERVICE_DESCRIPTOR_REQUEST_ASYNC_REQUEST_MODE, StringComparison.OrdinalIgnoreCase)) { asyncServiceWorker.AddRequest(service); } }
/// <summary> /// It build connection request instance based on the service descriptor object /// </summary> /// <param name="service">Instance of IService</param> /// <returns>IConnectionRequest instance</returns> public static IConnectionRequest PrepareConnectionRequest(IService service) { /* * Resolve All Referring Resources */ ServiceDescriptor serviceDescriptor = service.GetServiceDescriptor(); Connect.Model.ServiceDescriptor.Request request = serviceDescriptor.GetRequest(service.GetRequest()); String url = FormUrl(service); IEnumerator <Connect.Model.ServiceDescriptor.Request.QueryParameter> queryParameters = FormQueryParameters(service); IEnumerator <Connect.Model.ServiceDescriptor.Request.HeaderParameter> headerParameters = FormHeaderParameters(service); byte[] dataStream = FormDataStream(service); IConnectionRequest connectionRequest = new ConnectionRequest(); connectionRequest.SetUrl(url); connectionRequest.SetProtocol(serviceDescriptor.GetProtocol()); connectionRequest.SetType(request.GetType()); while (queryParameters.MoveNext()) { connectionRequest.AddQueryParameter(queryParameters.Current); } while (headerParameters.MoveNext()) { connectionRequest.AddHeaderParameter(headerParameters.Current); } connectionRequest.SetDataStream(dataStream); return(connectionRequest); }
/// <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); } }
public override void EndElement(String localName) { if(localName.Equals(Constants.SERVICE_DESCRIPTOR_PROPERTY, StringComparison.OrdinalIgnoreCase)) { ProcessProperty(); } else if(localName.Equals(Constants.SERVICE_DESCRIPTOR_REQUEST, StringComparison.OrdinalIgnoreCase)) { serviceDescriptor.AddRequest(request); request = null; isRequest = false; } else if(localName.Equals(Constants.SERVICE_DESCRIPTOR_REQUEST_QUERY_PARAMETER, StringComparison.OrdinalIgnoreCase)) { request.AddQueryParameter(queryParameter); queryParameter = null; isQueryParameter = false; } else if(localName.Equals(Constants.SERVICE_DESCRIPTOR_REQUEST_HEADER_PARAMETER, StringComparison.OrdinalIgnoreCase)) { request.AddHeaderParameter(headerParameter); headerParameter = null; isHeaderParameter = false; } else if(localName.Equals(Constants.SERVICE_DESCRIPTOR_REQUEST_DATA_STREAM, StringComparison.OrdinalIgnoreCase)) { request.SetDataStream(tempValue.ToString()); } }
public override void StartElement(XmlReader reader, IDictionary<String, String> attributes) { String localName = reader.Name; tempValue = new StringBuilder(); if(localName.Equals(Constants.SERVICE_DESCRIPTOR_PROPERTY, StringComparison.OrdinalIgnoreCase)) { propertyName = attributes[Constants.SERVICE_DESCRIPTOR_PROPERTY_NAME]; } else if(localName.Equals(Constants.SERVICE_DESCRIPTOR_REQUEST, StringComparison.OrdinalIgnoreCase)) { request = new ServiceDescriptor.Request(); isRequest = true; } else if(localName.Equals(Constants.SERVICE_DESCRIPTOR_REQUEST_QUERY_PARAMETER, StringComparison.OrdinalIgnoreCase)) { queryParameter = new Connect.Model.ServiceDescriptor.Request.QueryParameter(); isQueryParameter = true; } else if(localName.Equals(Constants.SERVICE_DESCRIPTOR_REQUEST_HEADER_PARAMETER, StringComparison.OrdinalIgnoreCase)) { headerParameter = new Connect.Model.ServiceDescriptor.Request.HeaderParameter(); isHeaderParameter = true; } }