Example #1
0
        /// <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);
            }
        }