예제 #1
0
            /// <summary>
            /// Converts the service request database instance to IService instance
            /// </summary>
            /// <param name="service">ServiceRequest instance</param>
            /// <returns>IService instance</returns>
            /// <exception cref="Siminov.Connect.Exception.ServiceException">ServiceException If any exception occur while converting the instance</exception>
            public IService Convert(Connect.Model.ServiceRequest service)
            {
                IService iService = (IService)ClassUtils.CreateClassInstance(service.GetInstanceOf());

                iService.SetRequestId(service.GetRequestId());
                iService.SetService(service.GetService());
                iService.SetRequest(service.GetRequest());

                IEnumerator <ServiceRequestResource> serviceRequestResources = service.GetServiceRequestResources();

                while (serviceRequestResources.MoveNext())
                {
                    ServiceRequestResource serviceResource = serviceRequestResources.Current;
                    iService.AddResource(serviceResource.GetName(), serviceResource.GetValue());
                }

                ServiceDescriptor serviceDescriptor = resourceManager.RequiredServiceDescriptorBasedOnName(service.GetService());

                iService.SetServiceDescriptor(serviceDescriptor);

                ResourceUtils.Resolve(iService);

                return(iService);
            }
예제 #2
0
            /**
             * Check whether it contains the requested service or not
             * @param service Service
             * @return (true/false) TRUE: If service request already exists | FALSE: If service does not exists
             * @throws ServiceException If there is any exception while checking for request
             */
            public bool ContainService(Connect.Model.ServiceRequest service)
            {
                Connect.Model.ServiceRequest[] services = null;
                try
                {
                    services = (Connect.Model.ServiceRequest[]) new Connect.Model.ServiceRequest().Select().Execute();
                }
                catch (DatabaseException de)
                {
                    Log.Error(typeof(AsyncServiceWorker).Name, "ContainService", "DatabaseException caught while getting services from database, " + de.GetMessage());
                    throw new ServiceException(typeof(AsyncServiceWorker).Name, "ContainService", de.GetMessage());
                }


                if (services == null || services.Length <= 0)
                {
                    return(false);
                }

                for (int i = 0; i < services.Length; i++)
                {
                    Connect.Model.ServiceRequest savedService = services[i];
                    if (service.GetService().Equals(savedService.GetService(), StringComparison.OrdinalIgnoreCase))
                    {
                        if (service.GetRequest().Equals(savedService.GetRequest(), StringComparison.OrdinalIgnoreCase))
                        {
                            bool contain = true;

                            IEnumerator <ServiceRequestResource> serviceRequestResources = service.GetServiceRequestResources();
                            while (serviceRequestResources.MoveNext())
                            {
                                ServiceRequestResource serviceResource      = serviceRequestResources.Current;
                                ServiceRequestResource savedRequestResource = savedService.GetServiceRequestResource(serviceResource.GetName());

                                if (savedRequestResource == null)
                                {
                                    contain = false;
                                    break;
                                }

                                if (!serviceResource.GetName().Equals(savedRequestResource.GetName(), StringComparison.OrdinalIgnoreCase))
                                {
                                    contain = false;
                                    break;
                                }
                                else if (!serviceResource.GetValue().Equals(savedRequestResource.GetValue(), StringComparison.OrdinalIgnoreCase))
                                {
                                    contain = false;
                                    break;
                                }
                            }

                            if (contain)
                            {
                                return(true);
                            }
                        }
                    }
                }


                return(false);
            }