Esempio n. 1
0
        /// <summary>
        /// 确认插件是否已激活
        /// </summary>
        /// <param name="bundles"></param>
        private void EnsureBundlesActive(IBundle[] bundles)
        {
            IServiceReference reference = context.GetServiceReference(typeof(IStartLevel).FullName);
            var startService            = context.GetService <IStartLevel>(reference);

            try
            {
                for (int i = 0; i < bundles.Length; i++)
                {
                    if (bundles[i].State != BundleState.Active)
                    {
                        if (bundles[i].State == BundleState.Installed)
                        {
                            // Log that the bundle is not resolved
                            continue;
                        }
                        //// check that the startlevel allows the bundle to be active (111550
                        //if (startService != null && (startService.GetBundleStartLevel(bundles[i]) <= startService.StartLevel))
                        //{
                        //    // Log that the bundle's level
                        //}
                    }
                }
            }
            finally
            {
                context.UngetService(reference);
            }
        }
Esempio n. 2
0
 /// <summary>
 /// 停止
 /// </summary>
 internal void Stop()
 {
     //移除服务监听器
     foreach (IServiceListener listener in serviceListenerList)
     {
         ((IFrameworkListener)framework).RemoveServiceListener(listener);
     }
     serviceListenerList.Clear();
     //移除Bundle监听器
     foreach (IBundleListener listener in bundleListenerList)
     {
         ((IFrameworkListener)framework).RemoveBundleListener(listener);
     }
     bundleListenerList.Clear();
     //移除Extension监听器
     foreach (IExtensionListener listener in extensionListenerList)
     {
         ((IFrameworkListener)framework).RemoveExtensionListener(listener);
     }
     extensionListenerList.Clear();
     //移除已注册的服务
     foreach (IServiceReference reference in serviceReferenceList)
     {
         ((IFrameworkService)framework).UnRegisterService(reference);
     }
     serviceReferenceList.Clear();
     //取消使用正在使用的服务
     IServiceReference[] bundleUsingServiceReferences = new IServiceReference[bundleUsingServiceReferenceList.Count];
     bundleUsingServiceReferenceList.CopyTo(bundleUsingServiceReferences, 0);
     foreach (IServiceReference reference in bundleUsingServiceReferences)
     {
         UnGetService(reference);
     }
     bundleUsingServiceReferenceList.Clear();
 }
Esempio n. 3
0
        /// <summary>
        /// Lookups the service references.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <returns>IServiceReference[].</returns>
        /// Performs a lookup for ServiceReferences that are bound to this
        /// ServiceRegistry using the specified BundleContext.
        /// @param context The BundleContext to lookup the ServiceReferences on.
        /// @return An array of all matching ServiceReferences or null if none
        /// exist.
        public IServiceReference[] LookupServiceReferences(IBundleContext context)
        {
            int size;
            List <IServiceReference>    references;
            List <IServiceRegistration> serviceRegs = (List <IServiceRegistration>)PublishedServicesByContext[context];

            if (serviceRegs == null)
            {
                return(null);
            }

            size = serviceRegs.Count;

            if (size == 0)
            {
                return(null);
            }

            references = new List <IServiceReference>();
            for (int i = 0; i < size; i++)
            {
                IServiceRegistration registration = (IServiceRegistration)serviceRegs[i];

                IServiceReference reference = registration.GetReference();
                references.Add(reference);
            }

            if (references.Count == 0)
            {
                return(null);
            }

            return((IServiceReference[])references.ToArray());
        }
Esempio n. 4
0
        public override bool SetInstance(IServiceReference serviceReference)
        {
            //
            // Ha nincs factory akkor amugy sem lehet peldanyositani a szervizt tok mind1 mi az.
            //

            if (Factory is null)
            {
                throw new InvalidOperationException(Resources.NOT_PRODUCIBLE);
            }

            //
            // Peldanyositas utan ellenorizzuk a tipust (Factory, Proxy, stb visszaadhat vicces dolgokat).
            //
            // TBD: Vajon fel kene szabaditani a szervizpeldanyt ha gond vt?
            //

            object instance = Factory(serviceReference.RelatedInjector !, Interface);

            if (!Interface.IsInstanceOfType(instance))
            {
                throw new InvalidCastException(string.Format(Resources.Culture, Resources.INVALID_INSTANCE, Interface));
            }

            serviceReference.Value = instance;

            SaveReference(serviceReference);
            State |= ServiceEntryStates.Instantiated;

            return(true);
        }
Esempio n. 5
0
        public static DotGraph AsDotGraph(this IServiceReference serviceReference)
        {
            DotGraph graph = new();

            Process(serviceReference);
            return(graph);

            void Process(IServiceReference serviceReference)
            {
                DotGraphNode from = serviceReference.AsDotGraphNode();

                graph.Nodes.Add(from);

                foreach (IServiceReference dep in serviceReference.Dependencies)
                {
                    DotGraphNode to = dep.AsDotGraphNode();

                    DotGraphEdge edge = new(from, to);

                    //
                    // Korkoros referencia eseten ne legyen S.O.E.
                    //

                    if (!graph.Edges.Add(edge))
                    {
                        continue;
                    }

                    graph.Nodes.Add(to);

                    Process(dep);
                }
            }
        }
Esempio n. 6
0
 /// <summary>
 /// 取消调用指定服务引用的服务实例
 /// </summary>
 /// <param name="reference">服务引用</param>
 /// <param name="bundle">调用服务的Bundle</param>
 /// <returns>是否成功</returns>
 public bool UnGetService(IServiceReference reference, IBundle bundle)
 {
     if (usingServiceBundleDict.ContainsKey(reference))
     {
         return(usingServiceBundleDict[reference].Remove(bundle));
     }
     return(false);
 }
Esempio n. 7
0
 /// <summary>
 /// 取消调用指定服务引用的服务实例
 /// </summary>
 /// <param name="reference">服务引用</param>
 /// <returns>是否成功</returns>
 public bool UnGetService(IServiceReference reference)
 {
     if (reference != null && bundleUsingServiceReferenceList.Contains(reference))
     {
         bundleUsingServiceReferenceList.Remove(reference);
     }
     return(((IFrameworkService)framework).UnGetService(reference, GetBundle()));
 }
Esempio n. 8
0
 public ServiceRegistration(IBundle b, object s, IDictionary props)
 {
     bundle     = b;
     service    = s;
     properties = props;
     reference  = new ServiceReference(this);
     available  = true;
 }
Esempio n. 9
0
        public static object GetInstance(this IServiceReference svc)
        {
            if (svc is null)
            {
                throw new ArgumentNullException(nameof(svc));
            }

            return(svc.RelatedServiceEntry.GetInstance(svc));
        }
Esempio n. 10
0
        public object GetRegisterService(string clazz)
        {
            IServiceReference reference = GetServiceReference(clazz);

            if (reference != null)
            {
                return(GetRegisterService(reference));
            }

            return(null);
        }
Esempio n. 11
0
 /// <summary>
 /// 启动Word应程序管理器
 /// </summary>
 public void Start()
 {
     if (!_isActive)
     {
         string type = "Microsoft.Office.Tools.CustomTaskPaneCollection";
         _customTaskPaneReference = _context.GetServiceReference(type);
         if (_customTaskPaneReference != null)
         {
             _isActive = true;
         }
     }
 }
Esempio n. 12
0
        /// <summary>
        /// 设置启动级别
        /// </summary>
        /// <param name="value"></param>
        private void SetStartLevel(int value)
        {
            IServiceReference reference = context.GetServiceReference(typeof(IStartLevel).FullName);
            var startService            = context.GetService <IStartLevel>(reference);

            if (startService == null)
            {
                return;
            }

            startService.StartLevel = (value);
            context.UngetService(reference);
        }
        //////////////////////////////////////////////////////////////////////////
        // Internals
        //////////////////////////////////////////////////////////////////////////

        public IServiceReference[] getRegisteredServices()
        {
            m_checker.Check();
            lock (m_lock)
            {
                IServiceReference[] ret = new IServiceReference[m_publishedServices.Count];
                for (int i = 0; i != m_publishedServices.Count; ++i)
                {
                    m_publishedServices[i].getReference();
                }
                return(ret);
            }
        }
Esempio n. 14
0
        /// <summary>
        /// 获取用户指定的类型的服务
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public T GetService <T>()
        {
            string            clazz     = typeof(T).FullName;
            IServiceReference reference = context.GetServiceReference(clazz);

            if (reference == null)
            {
                return(default(T));
            }
            T service = context.GetService <T>(reference);

            context.UngetService(reference);
            return(service);
        }
Esempio n. 15
0
        /// <summary>
        /// Returns the effective service instance from the given <paramref name="reference"/>. The <paramref name="reference"/> must be taken from this entry.
        /// </summary>
        public virtual object GetInstance(IServiceReference reference)
        {
            if (reference is null)
            {
                throw new ArgumentNullException(nameof(reference));
            }

            if (reference.RelatedServiceEntry != this)
            {
                throw new ArgumentException(Resources.INCOMPATIBLE_REFERENCE);
            }

            return(reference.Value !);
        }
Esempio n. 16
0
 /// <summary>
 /// 匹配
 /// </summary>
 /// <param name="reference">服务引用</param>
 /// <returns>bool</returns>
 public bool IsAssignableTo(IServiceReference reference)
 {
     //if (!scopeEvents)
     //    return true;
     string[] clazzes = reference.GetClasses();
     for (int i = 0; i < clazzes.Length; i++)
     {
         if (!reference.IsAssignableTo(bundle, clazzes[i]))
         {
             return(false);
         }
     }
     return(true);
 }
Esempio n. 17
0
 /// <summary>
 /// 获取正在使用指定服务的所有Bundle模块
 /// </summary>
 /// <param name="reference">服务引用</param>
 /// <returns>正在使用服务的Bundle列表</returns>
 public IList <IBundle> GetUsingBundles(IServiceReference reference)
 {
     if (usingServiceBundleDict.ContainsKey(reference))
     {
         IList <IBundle> usingBundleList = usingServiceBundleDict[reference];
         var             usingBundles    = new IBundle[usingBundleList.Count];
         usingBundleList.CopyTo(usingBundles, 0);
         return(usingBundles);
     }
     else
     {
         return(new IBundle[0]);
     }
 }
Esempio n. 18
0
        /// <summary>
        /// Lookups the service references.
        /// </summary>
        /// <param name="clazz">The clazz.</param>
        /// <param name="filter">The filter.</param>
        /// <returns>IServiceReference[].</returns>
        /// Performs a lookup for ServiceReferences that are bound to this
        /// ServiceRegistry. If both clazz and filter are null then all bound
        /// ServiceReferences are returned.
        /// @param clazz A fully qualified class name.  All ServiceReferences that
        /// reference an object that implement this class are returned.  May be
        /// null.
        /// @param filter Used to match against published Services.  All
        /// ServiceReferences that match the filter are returned.  If a clazz is
        /// specified then all ServiceReferences that match the clazz and the
        /// filter parameter are returned. May be null.
        /// @return An array of all matching ServiceReferences or null
        /// if none exist.
        public IServiceReference[] LookupServiceReferences(string clazz, IFilter filter)
        {
            int size;
            List <IServiceReference>    references  = null;
            List <IServiceRegistration> serviceRegs = null;

            if (clazz == null) /* all services */
            {
                serviceRegs = AllPublishedServices;
            }
            else
            {
                /* services registered under the class name */
                if (PublishedServicesByClass.ContainsKey(clazz))
                {
                    serviceRegs = (List <IServiceRegistration>)PublishedServicesByClass[clazz];
                }
            }

            if (serviceRegs == null)
            {
                return(null);
            }

            size = serviceRegs.Count;

            if (size == 0)
            {
                return(null);
            }

            references = new List <IServiceReference>();
            for (int i = 0; i < size; i++)
            {
                IServiceRegistration registration = (IServiceRegistration)serviceRegs[i];

                IServiceReference reference = registration.GetReference();
                if ((filter == null) || filter.Match(reference))
                {
                    references.Add(reference);
                }
            }

            if (references.Count == 0)
            {
                return(null);
            }

            return((IServiceReference[])references.ToArray());
        }
Esempio n. 19
0
 /// <summary>
 /// 使用服务的属性进行匹配
 /// </summary>
 /// <param name="reference"></param>
 /// <returns></returns>
 public bool Match(IServiceReference reference)
 {
     try
     {
         if (reference is ServiceReferenceImpl)
         {
             return(Match0(((ServiceReferenceImpl)reference).Registration.GetProperties()));
         }
         return(Match0(new ServiceReferenceDictionary(reference)));
     }
     catch (Exception e)
     {
         Log.Debug(e);
         return(false);
     }
 }
Esempio n. 20
0
        /// <summary>
        /// 取消注册公开的服务对象
        /// </summary>
        /// <param name="serviceReference">服务引用</param>
        public void UnRegisterService(IServiceReference serviceReference)
        {
            FireServiceEvent(new ServiceEventArgs(ServiceEventArgs.UNREGISTERING, serviceReference.GetSercieContracts(), serviceReference));

            foreach (string contract in serviceReferenceDictionary.Keys)
            {
                IList <IServiceReference> serviceReferenceList = serviceReferenceDictionary[contract];
                if (serviceReferenceList.Contains(serviceReference))
                {
                    serviceReferenceList.Remove(serviceReference);
                }
            }
            if (usingServiceBundleDict.ContainsKey(serviceReference))
            {
                usingServiceBundleDict.Remove(serviceReference);
            }
        }
Esempio n. 21
0
        public static DotGraphNode AsDotGraphNode(this IServiceReference serviceReference)
        {
            string friendlyName = serviceReference.RelatedServiceEntry.FriendlyName();

            return(new DotGraphNode
                   (
                       friendlyName.GetHashCode
                       (
#if !NETSTANDARD2_0
                           System.StringComparison.OrdinalIgnoreCase
#endif
                       )
                   )
            {
                Label = $"<u>{friendlyName}</u><br/><br/><i>{serviceReference.RelatedServiceEntry.Lifetime}</i>"
            });
        }
Esempio n. 22
0
        public static void SetInstance(this IServiceReference svc)
        {
            if (svc is null)
            {
                throw new ArgumentNullException(nameof(svc));
            }

            //
            // Elmeletileg a SetInstance() csak akkor lehet hivva ha szukseges is letrehozni a
            // szervizpeldanyt.
            //

            if (!svc.RelatedServiceEntry.SetInstance(svc))
            {
                throw new InvalidOperationException(); // TODO: error message
            }
        }
Esempio n. 23
0
        public void OnRoutineStart(
            IServiceReference serviceRef,
            IMethodReference methodRef,
            PersistedMethodId methodId,
            object serviceInstance,
            IAsyncStateMachine routineStateMachine,
            CallerDescriptor caller)
        {
            Context.ServiceRef          = serviceRef;
            Context.MethodRef           = methodRef;
            Context.MethodId            = methodId;
            Context.ServiceInstance     = serviceInstance;
            Context.RoutineStateMachine = routineStateMachine;
            Context.Caller = caller;

            _intrinsicFlowController.OnRoutineStart(this);
        }
Esempio n. 24
0
        /// <summary>
        /// 根据服务引用获取对应的服务实例
        /// </summary>
        /// <param name="reference">服务引用</param>
        /// <param name="bundle">调用服务的Bundle</param>
        /// <returns>服务实例</returns>
        public object GetService(IServiceReference reference, IBundle bundle)
        {
            ServiceReference sri = reference as ServiceReference;

            if (sri == null)
            {
                return(null);
            }

            if (!usingServiceBundleDict.ContainsKey(reference))
            {
                usingServiceBundleDict.Add(reference, new List <IBundle>());
            }

            usingServiceBundleDict[reference].Add(bundle);

            return(sri.GetService());
        }
Esempio n. 25
0
        /// <summary>
        /// 根据服务引用获取服务对象
        /// </summary>
        /// <param name="reference"></param>
        /// <returns></returns>
        public object GetService(IServiceReference reference)
        {
            CheckValid();
            if (reference == null)
            {
                throw new ArgumentNullException("A null service reference is not allowed."); //$NON-NLS-1$
            }
            lock (contextLock)
            {
                if (servicesInUse == null)
                {
                    // Cannot predict how many services a bundle will use, start with a small table.
                    servicesInUse = new Hashtable();
                }
            }

            return(framework.ServiceRegistry.GetService(this, (ServiceReferenceImpl)reference));
        }
Esempio n. 26
0
        /// <summary>
        /// 取消注册公开的服务对象
        /// </summary>
        /// <param name="serviceReference">服务引用</param>
        public void UnRegisterService(IServiceReference serviceReference)
        {
            if (!serviceReferenceList.Contains(serviceReference))
            {
                return;
            }

            //触发服变更事件
            foreach (var bundleObj in this.framework.GetBundles())
            {
                var fireContext = (IContextFireEvent)bundleObj.GetBundleContext();
                fireContext.FireServiceChanged(this.bundle, new ServiceEventArgs(ServiceEventArgs.UNREGISTERING, serviceReference.GetSercieContracts(), serviceReference));
            }

            ((IFrameworkService)framework).UnRegisterService(serviceReference);

            serviceReferenceList.Remove(serviceReference);
        }
Esempio n. 27
0
        /// <summary>
        /// 启动列表中所有的插件
        /// </summary>
        /// <param name="bundles"></param>
        private void StartBundles(IBundle[] bundles)
        {
            IServiceReference reference    = context.GetServiceReference(typeof(IStartLevel).FullName);
            IStartLevel       startService = null;

            if (reference != null)
            {
                startService = context.GetService <IStartLevel>(reference);
            }
            try
            {
                foreach (AbstractBundle bundle in bundles)
                {
                    if (bundle == null)
                    {
                        break;
                    }
                    if (bundle.BundleData.Policy == ActivatorPolicy.Lazy)
                    {
                        StartBundle(bundle, BundleOptions.Transient);
                    }
                    else
                    {
                        // always set the startlevel incase it has changed (bug 111549)
                        // this is a no-op if the level is the same as previous launch.
                        if (bundle.StartLevel == 0 && startService != null)
                        {
                            startService.SetBundleStartLevel(bundle, GetStartLevel());
                        }
                        StartBundle(bundle, BundleOptions.General);
                    }
                }
            }
            finally
            {
                if (reference != null)
                {
                    context.UngetService(reference);
                }
            }
        }
Esempio n. 28
0
        /// <summary>
        /// 解析插件
        /// </summary>
        /// <param name="bundles"></param>
        /// <returns></returns>
        private bool ResolvePackages(IBundle[] bundles)
        {
            IServiceReference packageAdminRef = context.GetServiceReference(typeof(IPackageAdmin).FullName);
            PackageAdminImpl  packageAdmin    = null;

            if (packageAdminRef != null)
            {
                packageAdmin = (PackageAdminImpl)context.GetService(packageAdminRef);
            }
            if (packageAdmin == null)
            {
                return(false);
            }
            // TODO this is such a hack it is silly.  There are still cases for race conditions etc
            // but this should allow for some progress...

            bool isResolved = packageAdmin.ResolveBundles(bundles);

            context.UngetService(packageAdminRef);

            return(isResolved);
        }
Esempio n. 29
0
 /// <summary>
 /// 启动Word应程序管理器
 /// </summary>
 public void Start()
 {
     if (!isActive)
     {
         string type = "Microsoft.Office.Interop.Word.Application";
         wordApplicationReference = context.GetServiceReference(type);
         if (wordApplicationReference != null)
         {
             OfficeWord.Application app = this.GetApp();
             if (app != null)
             {
                 app.DocumentOpen          += OnDocumentOpen;
                 app.DocumentChange        += OnDocumentChange;
                 app.DocumentBeforeSave    += OnDocumentBeforeSave;
                 app.DocumentBeforeClose   += OnDocumentBeforeClose;
                 app.WindowActivate        += OnWindowActivate;
                 app.WindowSelectionChange += OnSelectionChange;
             }
             isActive = true;
         }
     }
 }
Esempio n. 30
0
        public bool TryResolve(ServiceId serviceId, out IServiceReference serviceReference)
        {
            IServiceDefinition serviceDefinition;

            if (string.Equals(serviceId.Name, IntrinsicCommunicationModel.IntrinsicRoutinesServiceDefinition.Name, StringComparison.OrdinalIgnoreCase))
            {
                serviceDefinition = IntrinsicCommunicationModel.IntrinsicRoutinesServiceDefinition;
            }
            else
            {
                serviceDefinition = _communicationModel.FindServiceByName(serviceId.Name);

                // Convenience resolution if a person typed the "Service" suffix where the full service name matches the class name.
                if (serviceDefinition == null && serviceId.Name.EndsWith("Service", StringComparison.OrdinalIgnoreCase))
                {
                    var candidateServiceName = serviceId.Name.Substring(0, serviceId.Name.Length - 7);
                    serviceDefinition = _communicationModel.FindServiceByName(candidateServiceName);
                    if (serviceDefinition != null && serviceDefinition.Implementation != null &&
                        serviceDefinition.Implementation.Name.Equals(serviceId.Name, StringComparison.OrdinalIgnoreCase))
                    {
                        serviceId      = serviceId.Clone();
                        serviceId.Name = candidateServiceName;
                    }
                    else
                    {
                        serviceDefinition = null;
                    }
                }
            }

            if (serviceDefinition == null)
            {
                serviceReference = null;
                return(false);
            }

            serviceReference = new ServiceReference(_domainServiceProvider, serviceId, serviceDefinition);
            return(true);
        }
 //////////////////////////////////////////////////////////////////////////
 public bool ungetService(IServiceReference reference)
 {
     m_checker.Check();
     throw new NotImplementedException();
 }
 //////////////////////////////////////////////////////////////////////////
 // Internals
 //////////////////////////////////////////////////////////////////////////
 public IServiceReference[] getRegisteredServices()
 {
     m_checker.Check();
     lock (m_lock)
     {
         IServiceReference[] ret = new IServiceReference[m_publishedServices.Count];
         for (int i = 0; i != m_publishedServices.Count; ++i)
             m_publishedServices[i].getReference();
         return ret;
     }
 }
Esempio n. 33
0
 public bool Match(IServiceReference reference)
 {
     return true;
 }
Esempio n. 34
0
		//////////////////////////////////////////////////////////////////////////

		public int CompareTo(IServiceReference other)
		{
			throw new NotImplementedException();
		}
 /// <summary>
 /// Creates a new service event object.
 /// </summary>
 public ServiceEvent(ServiceEvent.Type type, IServiceReference reference)
 {
     m_type = type;
     m_reference = reference;
 }
Esempio n. 36
0
 public ServiceEventArgs(ServiceState state, IServiceReference reference)
 {
     this.reference = reference;
     this.state = state;
 }