Наследование: IServiceReference
        public ServiceRegistration(BundleContext context, string[] classes,
            object serviceObject, Dictionary<string, object> properties)
        {
            this.context = context;
            this.bundle = context.Bundle;
            this.framework = context.Framework;
            this.classes = classes;
            this.serviceObject = serviceObject;
            this.serviceId = framework.GetNextServiceId();
            this.referance = new ServiceReference(this, bundle);
            this.contextsUsing = null;
            this.factory = serviceObject as IServiceFactory;
            available = true;
            InitializeProperties(properties);

            framework.ServiceRegistry.PublishService(context, this);

            EventManager.OnServiceChanged(new ServiceEventArgs(ServiceState.Registered, referance));
        }
        public void Unregister()
        {
            lock (properties)
            {
                if (available)
                {

                    if (null != bundle)
                    {
                        //bundle.Framework.Bundles
                        framework.ServiceRegistry.UnpublishService(context, this);

                        EventManager.OnServiceChanged(new ServiceEventArgs(ServiceState.Unregistering, referance));
                    }
                    available = false;
                }
                else
                {
                   throw new NotSupportedException("Service is unregistered");
                }

                contextsUsing = null;

                referance = null;
                context = null;
            }
        }
Пример #3
0
        public IServiceReference[] GetServiceReferences(string clazz, string filterString,
            IBundleContext context, bool allservices)
        {
            Filter filter = string.IsNullOrEmpty(filterString) ? null : new Filter(filterString);
            IServiceReference[] services = null;

            lock (serviceRegistry)
            {
                services = serviceRegistry.LookupServiceReferences(clazz, filter);
                if (services == null)
                {
                    return null;
                }
                int removed = 0;
                for (int i = services.Length - 1; i >= 0; i--)
                {
                    ServiceReference reference = (ServiceReference)services[i];
                    string[] classes = reference.GetClasses();
                    if (allservices || context.IsAssignableTo((ServiceReference)services[i]))
                    {
                        if (clazz == null)
                            try
                            { /* test for permission to the classes */
                                //checkGetServicePermission(classes);
                            }
                            catch (SecurityException)
                            {
                                services[i] = null;
                                removed++;
                            }
                    }
                    else
                    {
                        services[i] = null;
                        removed++;
                    }
                }
                if (removed > 0)
                {
                    IServiceReference[] temp = services;
                    services = new ServiceReference[temp.Length - removed];
                    for (int i = temp.Length - 1; i >= 0; i--)
                    {
                        if (temp[i] == null)
                            removed--;
                        else
                            services[i - removed] = temp[i];
                    }
                }

            }
            return services == null || services.Length == 0 ? null : services;
        }