/// <summary> /// 服务引用 /// </summary> /// <param name="bundleContext">暴露服务的Bundle上下文</param> /// <param name="contracts">服务约束数组</param> /// <param name="properties">服务属性</param> /// <param name="service">服务对象</param> public ServiceReference(IBundleContext bundleContext, string[] contracts, IDictionary <string, object> properties, object service) { this.bundleContext = bundleContext; this.contracts = contracts; this.properties = properties; this.service = service; }
/// <summary> /// 注册一个公开的服务对象 /// </summary> /// <param name="context">Bundle上下文</param> /// <param name="contracts">服务约束</param> /// <param name="service">服务对象</param> /// <param name="properties">服务属性</param> /// <returns>服务注册信息</returns> public IServiceRegistration RegisterService(IBundleContext context, string[] contracts, object service, IDictionary <string, object> properties) { var bundleContextImpl = context as BundleContext; var reference = new ServiceReference(bundleContextImpl, contracts, properties, service); foreach (string contract in contracts) { IList <IServiceReference> serviceReferenceList = null; if (serviceReferenceDictionary.ContainsKey(contract)) { serviceReferenceList = serviceReferenceDictionary[contract]; } else { serviceReferenceList = new List <IServiceReference>(); serviceReferenceDictionary.Add(contract, serviceReferenceList); } serviceReferenceList.Add(reference); } FireServiceEvent(new ServiceEventArgs(ServiceEventArgs.REGISTERED, contracts, reference)); return(new ServiceRegistration(this, bundleContextImpl, reference)); }
public void Start(IBundleContext context) { TracesProvider.TracesOutput.OutputTrace("The bundle is starting"); TracesProvider.TracesOutput.OutputTrace("Id=" + context.Bundle.Id); TracesProvider.TracesOutput.OutputTrace("State=" + context.Bundle.State); FileSystemInfo file = context.GetDataFile(" "); TracesProvider.TracesOutput.OutputTrace("File is: " + file.GetType().Name); TracesProvider.TracesOutput.OutputTrace("File name: " + file.FullName); if (!file.Exists) { DirectoryInfo dir = file as DirectoryInfo; dir.Create(); } file = context.GetDataFile("bundle_file.txt"); TracesProvider.TracesOutput.OutputTrace("File is: " + file.GetType().Name); TracesProvider.TracesOutput.OutputTrace("File name: " + file.FullName); if (!file.Exists) { FileInfo f = file as FileInfo; StreamWriter stream = f.CreateText(); stream.Write("hello"); stream.Flush(); stream.Close(); } }
/// <summary> /// Unpublishes the services. /// </summary> /// <param name="context">The context.</param> /// Unpublishes all services from this ServiceRegistry that the /// specified BundleContext registered. /// @param context the BundleContext to unpublish all services for. public void UnpublishServices(IBundleContext context) { // Get all the Services published by the BundleContext. List <IServiceRegistration> serviceRegs = (List <IServiceRegistration>)PublishedServicesByContext[context]; if (serviceRegs != null) { // Remove this list for the BundleContext PublishedServicesByContext.Remove(context); int size = serviceRegs.Count(); for (int i = 0; i < size; i++) { IServiceRegistration serviceReg = (IServiceRegistration)serviceRegs[i]; // Remove each service from the list of all published Services AllPublishedServices.Remove(serviceReg); // Remove each service from the list of Services published by Class Name. string[] clazzes = ((ServiceRegistration)serviceReg).Classes; int numclazzes = clazzes.Length; for (int j = 0; j < numclazzes; j++) { string clazz = clazzes[j]; if (PublishedServicesByClass.ContainsKey(clazz)) { List <IServiceRegistration> services = (List <IServiceRegistration>)PublishedServicesByClass[clazz]; services.Remove(serviceReg); } } } } }
/// <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()); }
public void MultipleInits() { IFrameworkFactory factory = new CFrameworkFactory(); IFramework fwk = factory.NewFramework(null); fwk.Init(); IBundleContext ctx = fwk.getBundleContext(); Expect.Exactly(2).On(mock_fwk_listener) .Method("FrameworkEvent") .With(new FrameworkEvent(FrameworkEvent.Type.STARTED, fwk, null)); ctx.AddFrameworkListener(mock_fwk_listener); fwk.Start(); fwk.Stop(); fwk.WaitForStop(0); Assert.AreEqual(fwk.getState(), BundleState.RESOLVED); fwk.Init(); fwk.getBundleContext().AddFrameworkListener(mock_fwk_listener); fwk.Start(); Assert.AreEqual(fwk.getState(), BundleState.ACTIVE); fwk.Stop(); fwk.WaitForStop(0); Assert.AreEqual(fwk.getState(), BundleState.RESOLVED); mocks.VerifyAllExpectationsHaveBeenMet(); }
public void InitShutdown() { IFrameworkFactory factory = new CFrameworkFactory(); IFramework fwk = factory.NewFramework(null); Assert.IsNotNull(fwk); Assert.AreEqual(fwk.getState(), BundleState.INSTALLED); fwk.Init(); Assert.AreEqual(fwk.getState(), BundleState.STARTING); IBundleContext ctx = fwk.getBundleContext(); Assert.IsNotNull(ctx); Assert.AreEqual(ctx.getBundle(), fwk); Expect.Once.On(mock_fwk_listener) .Method("FrameworkEvent") .With(new FrameworkEvent(FrameworkEvent.Type.STARTED, fwk, null)); ctx.AddFrameworkListener(mock_fwk_listener); fwk.Start(); Assert.AreEqual(fwk.getState(), BundleState.ACTIVE); fwk.Stop(); Assert.AreEqual(fwk.getState(), BundleState.STOPPING); fwk.WaitForStop(0); Assert.AreEqual(fwk.getState(), BundleState.RESOLVED); mocks.VerifyAllExpectationsHaveBeenMet(); }
/// <summary> /// Creates the domain. /// </summary> /// <param name="context">The context.</param> /// <returns>AppDomain.</returns> public AppDomain CreateDomain(IBundleContext context) { string binpatch = Path.GetDirectoryName(context.Bundle.Location); AppDomainSetup info = new AppDomainSetup(); if (binpatch != null) { var dirinfo = new DirectoryInfo(binpatch); if (String.Equals(dirinfo.Name.ToLower(), "bin")) { if (dirinfo.Parent != null) { info.ApplicationBase = dirinfo.Parent.FullName; } } else { info.ApplicationBase = binpatch; } } if (!String.IsNullOrEmpty(AppDomain.CurrentDomain.DynamicDirectory)) { info.ShadowCopyDirectories = Path.Combine(info.ApplicationBase, @"cache"); info.ShadowCopyFiles = "true"; info.PrivateBinPath = binpatch; } string domainName = "Bundle-" + context.Bundle.Id.ToString().PadLeft(3, '0'); AppDomain domain = AppDomain.CreateDomain(domainName, AppDomain.CurrentDomain.Evidence, info); Interlocked.Increment(ref this._bundleAppDomains); //Assembly[] asses = domain.GetAssemblies(); return(domain); }
public void Start(IBundleContext context) { BundleContext = context; Bundle = context.Bundle; NavigationServiceTracker = new ServiceTracker <INavigationService>(context); ConfigurationServiceTracker = new ServiceTracker <IConfigurationService>(context); PermissionServiceTracker = new ServiceTracker <IPermissionService>(context); NavigationServiceFactoryTracker = new ServiceTracker <INavigationServiceFactory>(context); MainWindowServiceTracker = new ServiceTracker <IMainWindowService>(context); FirstFloor.ModernUI.Resources.Culture = new CultureInfo("zh-CN"); var app = context.GetFirstOrDefaultService <Application>(); if (app != null) { try { // 注册ModernUI皮肤资源。 ResourceDictionary r = new ResourceDictionary(); r.MergedDictionaries.Add(new ResourceDictionary() { Source = new Uri("/FirstFloor.ModernUI,Version=1.0.6.0;component/Assets/ModernUI.xaml", UriKind.RelativeOrAbsolute) }); r.MergedDictionaries.Add(new ResourceDictionary() { Source = new Uri("/FirstFloor.ModernUI,Version=1.0.6.0;component/Assets/ModernUI.Light.xaml", UriKind.RelativeOrAbsolute) }); app.Resources = r; } catch { } } }
void IBundleActivator.Stop(IBundleContext context) { // 注销Framework监听器 //context.RemoveFrameworkListener(this); base.Stop(context.Bundle.Headers); }
void IBundleActivator.Start(IBundleContext context) { // 注册Framework监听器 context.AddFrameworkListener(this); base.Start(context.Bundle.Headers); }
/// <summary> /// /// </summary> /// <param name="context"></param> public void Start(IBundleContext context) { var serviceRef = context.GetServiceReference <IAttachContent>(); var service = context.GetService <IAttachContent>(serviceRef); service.AttachUcContent(new UserControl1()); }
public void OnFrameworkStopping(IBundleContext context) { foreach (var hook in _hooks) { hook.OnFrameworkStopping(context); } }
private void ShowMainForm(IBundleContext context) { Workbench.PostMessage(() => { try { // 引发OnMainFormShowing事件。 var args = new CancelEventArgs(); OnMainFormShowing(context, args); if (!args.Cancel) { // Show main form Workbench.ShowMainForm(); } } catch (Exception ex) { _log.Error("UI 线程出现异常,主窗口已退出,错误原因:" + ex.Message, ex); } finally { FrameworkFactory.CurrentFramework.Stop(); } }); }
public void Start(IBundleContext context) { Bundle = context.Bundle; BundleManagementServiceTracker = new ServiceTracker <IBundleManagementService>(context); BundleInstallerService = context.GetFirstOrDefaultService <IBundleInstallerService>(); Application firstOrDefaultService = context.GetFirstOrDefaultService <Application>(); if (firstOrDefaultService != null) { try { ResourceDictionary resourceDictionary = new ResourceDictionary(); resourceDictionary.MergedDictionaries.Add(new ResourceDictionary { Source = new Uri("/FirstFloor.ModernUI,Version=1.0.3.0;component/Assets/ModernUI.xaml", UriKind.RelativeOrAbsolute) }); resourceDictionary.MergedDictionaries.Add(new ResourceDictionary { Source = new Uri("/FirstFloor.ModernUI,Version=1.0.3.0;component/Assets/ModernUI.Light.xaml", UriKind.RelativeOrAbsolute) }); firstOrDefaultService.Resources = resourceDictionary; } catch { } } }
protected override void DoStop(BundleStopOptions option) { if (((base.State != BundleState.Starting) && (base.State != BundleState.Stopping)) && base.IsActive) { base.State = BundleState.Stopping; IBundleContext context = base.Context; Exception exception = null; try { if (this.Activator != null) { this.Activator.Stop(context); } } catch (Exception exception2) { FileLogUtility.Error(string.Format(Messages.ExceptionOccursWhenStopping, base.SymbolicName, base.Version)); FileLogUtility.Error(exception2); exception = exception2; } this.CheckValidState(); base.State = BundleState.Resolved; if (option == BundleStopOptions.General) { this.SavePersistent(); } base.Context.Dispose(); base.Context = null; if (exception != null) { throw exception; } } }
public void Start(IBundleContext context) { BundleRuntime runtime = BundleRuntime.Instance; context.BundleStateChanged += context_BundleStateChanged; //注册宿主程序 if (HostingAssemblyFunc != null) { Assembly[] hostingAssemblies = HostingAssemblyFunc(); RegisterAssemblies(hostingAssemblies); } //注册激活的插件的依赖项 foreach (IBundle bundle in context.Framework.Bundles) { if (bundle.State == BundleState.Active) { RegisterBundle(bundle); } } if (runtime.State == BundleRuntimeState.Starting) { context.FrameworkStateChanged += context_FrameworkStateChanged; } else { Complate(); } }
/// <summary> /// /// </summary> /// <param name="context"></param> public void Start(IBundleContext context) { context.ServiceChanged += ContextOnServiceChanged; var serviceReference = context.GetServiceReference <IHelloWord>(); var service = context.GetService <IHelloWord>(serviceReference); log.Info(service.SayHi("BundleDemoB" + ReferenceClass.GetName())); var serviceRef1 = context.GetServiceReferences <IMutilImplement>(new Dictionary <string, object>() { { "id", "1" } }).FirstOrDefault(); var service1 = context.GetService <IMutilImplement>(serviceRef1); log.Info(service1.TestMethod()); var serviceRef2 = context.GetServiceReferences <IMutilImplement>(new Dictionary <string, object>() { { "id", "2" } }).FirstOrDefault(); var service2 = context.GetService <IMutilImplement>(serviceRef2); log.Info(service2.TestMethod()); var serviceRef3 = context.GetServiceReferences <IMutilImplement>(new Dictionary <string, object>() { { "id", "3" } }).FirstOrDefault(); var service3 = context.GetService <IMutilImplement>(serviceRef3); log.Info(service3.TestMethod()); }
public void Start(IBundleContext context) { TracesProvider.TracesOutput.OutputTrace("Application's starting\n"); context.BundleEvent += new BundleEventHandler(OnBundleChanged); IBundle bundle = context.Install(@".\Bundle.dll"); bundle.Start(); }
public static void RefreshAllBundles(IBundleContext context) { // parse each folders to register new bundles foreach (var folderPath in Directory.GetDirectories(Path.GetFullPath(string.Format("Bundles")))) { var bundleName = new DirectoryInfo(folderPath).Name; var bundleInfo = context.GetBundle(bundleName); if (bundleInfo == null) { string path = Path.GetFullPath(string.Format("Bundles\\{0}\\{0}.dll", bundleName)); // the assembly doesn't exist, try the bundle.config? Web.config? if (!File.Exists(path)) { System.Configuration.Configuration configuration = null; if (File.Exists(Path.GetFullPath(string.Format("Bundles\\{0}\\{0}.dll.config", bundleName)))) { configuration = ConfigurationManager.OpenExeConfiguration(path); } else if (File.Exists(Path.GetFullPath(string.Format("Bundles\\{0}\\web.config", bundleName)))) { VirtualDirectoryMapping vdm = new VirtualDirectoryMapping( Path.GetFullPath(string.Format("Bundles\\{0}", bundleName)), true); WebConfigurationFileMap wcfm = new WebConfigurationFileMap(); wcfm.VirtualDirectories.Add("/", vdm); // Get the Web application configuration object. configuration = WebConfigurationManager.OpenMappedWebConfiguration(wcfm, "/"); } else { throw new BundleNotFoundException(bundleName, new Version()); } // TODO : better error handling var section = (BundleConfigurationSection) configuration.GetSection("bundleConfiguration"); path = Path.GetFullPath(string.Format("Bundles\\{0}\\{1}", bundleName, section.BundlePath)); if (!File.Exists(path)) throw new BundleNotFoundException(bundleName, new Version()); } // create the bundle with all information needed var assembly = Assembly.ReflectionOnlyLoadFrom(path); var version = assembly.GetName().Version; bundleInfo = new BundleInfo { Path = path, Name = bundleName, Version = assembly.GetName().Version, State = BundleState.Installed }; // and then, register it context.RegisterBundle(bundleInfo); } } }
public void Start(IBundleContext context) { context.BundleStateChanged += context_BundleStateChanged; //provide the container builder so that each plugin can register the dependancy when starting. var containerBuilder = BundleRuntime.Instance.Initialize(); //Register active bundle assemblies. foreach (var bundle in context.Framework.Bundles) { if (bundle.State == BundleState.Active) { var service = BundleRuntime.Instance.GetFirstOrDefaultService <IRuntimeService>(); var assemblies = service.LoadBundleAssembly(bundle.SymbolicName); RegisterBundleAssemblies(bundle.BundleID, containerBuilder, assemblies); } } if (BundleRuntime.Instance.State == BundleRuntimeState.Started) { BundleRuntime.Instance.Complete(); } else if (BundleRuntime.Instance.State == BundleRuntimeState.Starting) { context.FrameworkStateChanged += context_FrameworkStateChanged; } context.AddService(typeof(IControllerResolver), new ControllerResolver()); }
public void Start(IBundleContext context) { IWindow window = context.GetFirstOrDefaultService <IWindow>(); MenuItem menuItem = new MenuItem(); menuItem.Header = "cs"; menuItem.Click += (sender, e) => { WebBrowser browser = new WebBrowser(); browser.Navigate("https://www.baidu.com/"); //Frame frame = new Frame(); //frame.Source = new Uri("https://www.baidu.com/"); window.AddChildrenToLayoutRootPanel("BCD Reader", browser); }; window.AddMenuItem(menuItem); window.AddChildrenToLeftSide("Text1", new TextBlock() { Text = "Text01" }); window.AddChildrenToRightSide("Text1", new TextBlock() { Text = "Text02" }); }
/// <summary> /// 内核构造 /// </summary> public Framework() { this.bundleContext = new BundleContext(this, this); //读取元数据信息 this.LoadMetaData(); }
public void Start(IBundleContext context) { TracesProvider.TracesOutput.OutputTrace("The bundle is starting"); TracesProvider.TracesOutput.OutputTrace("Id=" + context.Bundle.Id); TracesProvider.TracesOutput.OutputTrace("State=" + context.Bundle.State); FileSystemInfo file = context.GetDataFile(" "); TracesProvider.TracesOutput.OutputTrace("File is: " + file.GetType().Name); TracesProvider.TracesOutput.OutputTrace("File name: " + file.FullName); if(!file.Exists) { DirectoryInfo dir = file as DirectoryInfo; dir.Create(); } file = context.GetDataFile("bundle_file.txt"); TracesProvider.TracesOutput.OutputTrace("File is: " + file.GetType().Name); TracesProvider.TracesOutput.OutputTrace("File name: " + file.FullName); if(!file.Exists) { FileInfo f = file as FileInfo; StreamWriter stream = f.CreateText(); stream.Write("hello"); stream.Flush(); stream.Close(); } }
public void Stop(IBundleContext context) { context.RemoveBundleListener(this); CloseSplashScreen(); ClosProcessMonitor(); }
public void Start(IBundleContext context) { try { context.AddFrameworkListener(this); context.AddBundleListener(this); this.OpenSplashScreen(); var dto = context.Framework.Adapt <FrameworkDto>(); foreach (var key in dto.Properties.Keys) { Workbench.Context.Add(key, dto.Properties[key]); } this.InitProductProperty(context); this.InitializeComponentMetaData(); this.UpdateOptimizeInterval(context); // 更新产品属性 UpdateProductProperty(); } catch (Exception ex) { HandleAppStartError(ex); } }
public ExtensionHandlerBase(IBundleContext bundleContext, string extensionPoint) { BundleContext = bundleContext; ExtensionPoint = extensionPoint; ExtensionDatas = new ThreadSafeDictionary <Extension, List <T> >(); HandleExtensions(); BundleContext.ExtensionChanged += new EventHandler <ExtensionEventArgs>(BundleContextExtensionChanged); }
public void Start(IBundleContext context) { var serviceReference = context.GetServiceReference <ILogService>(); logService = context.GetService <ILogService>(serviceReference); logger = logService.GetLogger(); logger.Debug("CachePlugin Started!"); }
public void Start(IBundleContext context) { LogService logService = new LogService(); serviceRegistration = context.RegisterService <ILogService>(logService); logger = logService.GetLogger(); logger.Debug("LogPlugin Started!"); }
public void Start(IBundleContext context) { TracesProvider.TracesOutput.OutputTrace("Application's starting\n"); context.BundleEvent += new BundleEventHandler(OnBundleChanged); IBundle bundle = context.Install(@".\Bundle.dll"); bundle.Start(); }
/// <summary> /// /// </summary> /// <param name="context"></param> public void Start(IBundleContext context) { var serviceRef = context.GetServiceReference <IAttachContent>(); AttachContentService = context.GetService <IAttachContent>(serviceRef); serviceRegistration = context.RegisterService <IMenuItemEvent>(new MenuItemEvent()); }
public ServiceTracker(IBundleContext context, bool throwsExceptionIfServiceNotFound) { AssertUtility.ArgumentNotNull(context, "BundleContext"); BundleContext = context; _defaultOrFirstService = context.GetFirstOrDefaultService <TServiceInterface>(); _serviceInstances = context.GetService <TServiceInterface>(); context.ServiceChanged += new EventHandler <ServiceEventArgs>(ServiceChanged); }
/// <summary> /// 激活器启动 /// </summary> /// <param name="context"></param> public void Start(IBundleContext context) { // 获取上下文对象 bundleContext = context; bundle = context.Bundle; // 初始化功能区管理器 RibbonExtensionAdmin.Instance.Initialize(context); }
public void Start(IBundleContext context) { Context = context; ExtensionService = context.GetFirstOrDefaultService<IExtensionService>(); WeChatProxyContainer = new WeChatProxyContainer(); WeChatMenuContainer = new WeChatMenuContainer(); WeChatProxyService = new WeChatProxyService(); context.AddService<IWeChatProxyService>(WeChatProxyService); }
public void Stop(IBundleContext context) { context.RemoveService<Form>(_mainForm); CloseFormDelegate closeFormDel = delegate() { _mainForm.Close(); }; }
public void Stop(IBundleContext context) { TracesProvider.TracesOutput.OutputTrace("The bundle is stopping"); TracesProvider.TracesOutput.OutputTrace("Id=" + context.Bundle.Id); TracesProvider.TracesOutput.OutputTrace("State=" + context.Bundle.State); DirectoryInfo folder = (DirectoryInfo) context.GetDataFile(" "); folder.Delete(true); }
public override void Start(IBundleContext context) { TestIBll.IMessage message = new TestBll.MessageBll(); Message = message; TestIBll.ISayYear year = new TestBll.SayYearBll(); SayYear = year; messageReg = context.RegisterService<TestIBll.IMessage>(message, null); sayyear = context.RegisterService<TestIBll.ISayYear>(year, null); mcontext = context; }
////////////////////////////////////////////////////////////////////////// public void Start(IBundleContext context) { Assembly asm = Assembly.GetExecutingAssembly(); Type[] types = asm.GetTypes(); foreach (Type t in types) { object[] attrs = t.GetCustomAttributes(typeof(FrameworkService), false); foreach (object attr in attrs) { FrameworkService svc_attr = (FrameworkService)attr; context.RegisterService(t.FullName, asm.CreateInstance(t.FullName)); } } }
public override void Stop(IBundleContext context) { if (null != sayyear) { sayyear.Unregister(); //context.UngetService(sayyear.); } if (null != messageReg) { messageReg.Unregister(); //context.UngetService(messageReg); } //messageReg.(context.Bundle.Context.); mcontext = context; }
public void PublishService(IBundleContext context, IServiceRegistration serviceRegistration) { // Add the ServiceRegistration to the list of Services published by BundleContext. List<IServiceRegistration> contextServices = null; if (publishedServicesByContext.ContainsKey(context)) { contextServices = (List<IServiceRegistration>)publishedServicesByContext[context]; } if (contextServices == null) { contextServices = new List<IServiceRegistration>(); publishedServicesByContext.Add(context, contextServices); } contextServices.Add(serviceRegistration); // Add the ServiceRegistration to the list of Services published by Class Name. string[] clazzes = ((ServiceRegistration)serviceRegistration).Classes; int size = clazzes.Length; for (int i = 0; i < size; i++) { string clazz = clazzes[i]; List<IServiceRegistration> services = null; if (publishedServicesByClass.ContainsKey(clazz)) { services = (List<IServiceRegistration>)publishedServicesByClass[clazz]; } if (services == null) { services = new List<IServiceRegistration>(); publishedServicesByClass.Add(clazz, services); } services.Add(serviceRegistration); } // Add the ServiceRegistration to the list of all published Services. allPublishedServices.Add(serviceRegistration); }
public void Start(IBundleContext context) { context.AddService<IExtensionService>(new ExtensionService()); ExtensionProviderHandler = new ExtensionProviderHandler(context.Bundle); }
public void Start(IBundleContext context) { //todo: context.AddService<ISqlite3Helper>(new Sqlite3Helper()); }
public void Start(IBundleContext context) { Bundle = context.Bundle; }
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(); }
public void StartActivator(IBundleContext context) { var path = AppDomain.CurrentDomain.SetupInformation.ApplicationName; var name = AssemblyName.GetAssemblyName(path); context.ChangeBundleState(name.Name, BundleState.Starting); // load the assembly in the AppDomain var assembly = AppDomain.CurrentDomain.Load(name); // get the meta-data of the bundle var activatorAttribute = (BundleActivatorAttribute)assembly.GetCustomAttributes(typeof(BundleActivatorAttribute), false).FirstOrDefault(); var dependencyAttributes = assembly.GetCustomAttributes(typeof(BundleDependencyAttribute), false).Cast<BundleDependencyAttribute>(); // if there's some dependencies, load them if (dependencyAttributes != null) { foreach (var bundle in dependencyAttributes) { var existingBundle = context.GetBundle(bundle.Name); if (existingBundle == null) { throw new BundleNotFoundException(bundle.Name, bundle.Version); } else { if (existingBundle.Version != bundle.Version) { throw new InvalidBundleVersionException(bundle.Name, bundle.Version, existingBundle.Version); } else if (existingBundle.State == BundleState.Installed) { BundleController.Start(context, bundle.Name); } else if (existingBundle.State == BundleState.Resolved) { BundleController.Start(context, bundle.Name); } else if (existingBundle.State == BundleState.Starting) { BundleController.WaitFor(context, bundle.Name, BundleState.Active); } else if (existingBundle.State == BundleState.Stopping) { BundleController.WaitFor(context, bundle.Name, BundleState.Resolved); BundleController.Start(context, bundle.Name); } else if (existingBundle.State == BundleState.Uninstalled) throw new BundleIsBeingUninstalledException(existingBundle.Name, existingBundle.Version); logger.InfoFormat("Loading dependency: {0}", bundle); } } } // create a new instance of the activator var activatorType = Type.GetType(activatorAttribute.Activator.AssemblyQualifiedName); var ctor = activatorType.GetConstructor(new Type[0]); this.instance = (IBundleActivator)ctor.Invoke(new object[0]); // start the bundle ThreadPool.QueueUserWorkItem(new WaitCallback((o) => ((IBundleActivator)o).Start()), this.instance); context.ChangeBundleState(name.Name, BundleState.Active); }
public void Stop(IBundleContext context) { context.BundleEvent -= new BundleEventHandler(OnBundleChanged); TracesProvider.TracesOutput.OutputTrace("Application's stopping\n"); context = null; }
public override void Start(IBundleContext context) { mcontext = context; }
public static void Start(IBundleContext context, string bundleName) { // load all installed bundle RefreshAllBundles(context); // TODO : handle installation of new bundle? var bundleInfo = context.GetBundle(bundleName); if(bundleInfo == null) throw new BundleNotFoundException(bundleName, null); if (bundleInfo.State == BundleState.Active) { logger.InfoFormat("Application {0} already loaded", bundleName); return; } AppDomainSetup setup = AppDomain.CurrentDomain.SetupInformation; setup.ApplicationBase = AppDomain.CurrentDomain.SetupInformation.ApplicationBase; ApplicationIdentity identity = new ApplicationIdentity(bundleInfo.Name); //setup.ActivationArguments = new ActivationArguments(identity, new string[] { p }); setup.ApplicationName = bundleInfo.Path; setup.AppDomainInitializer = null; //setup.AppDomainInitializer = new AppDomainInitializer(Initialize); //setup.AppDomainInitializerArguments = new string[]{ path }; List<string> paths = new List<string>(); paths.Add(Path.GetDirectoryName(bundleInfo.Path)); paths.Add(Path.Combine(setup.ApplicationBase, "Libs")); paths.AddRange(Directory.GetDirectories(Path.Combine(setup.ApplicationBase, "Libs"))); setup.PrivateBinPath = string.Join(";", paths.ToArray()); var dom = AppDomain.CreateDomain(bundleInfo.Path, AppDomain.CurrentDomain.Evidence, setup); dom.ProcessExit += new EventHandler(dom_ProcessExit); dom.DomainUnload += new EventHandler(dom_DomainUnload); dom.UnhandledException += new UnhandledExceptionEventHandler(dom_UnhandledException); bundleInfo.Boostrap = (BundleController)dom.CreateInstanceAndUnwrap(typeof(BundleController).Assembly.FullName, typeof(BundleController).FullName); bundleInfo.AppDomain = dom; bundleInfo.State = BundleState.Resolved; context.RegisterBundle(bundleInfo); bundleInfo.Boostrap.StartActivator(context); }
public override void Stop(IBundleContext context) { mybllserver.Unregister(); mcontext = null; }
public override void Start(IBundleContext context) { Log2Service.ITextLog log = new Log2Net.TextLog(); mybllserver = context.RegisterService<Log2Service.ITextLog>(log, null); mcontext = context; }
private static void WaitFor(IBundleContext context, string bundleName, BundleState bundleState) { while(context.GetBundle(bundleName).State != bundleState) Thread.Sleep(1000); }
public void StopActivator(IBundleContext context) { this.instance.Stop(); }
public void UnpublishService(IBundleContext context, IServiceRegistration serviceRegistration) { // Remove the ServiceRegistration from the list of Services published by BundleContext. List<IServiceRegistration> contextServices = (List<IServiceRegistration>)publishedServicesByContext[context]; if (contextServices != null) { contextServices.Remove(serviceRegistration); } // Remove the ServiceRegistration from the list of Services published by Class Name. string[] clazzes = ((ServiceRegistration)serviceRegistration).Classes; int size = clazzes.Length; for (int i = 0; i < size; i++) { string clazz = clazzes[i]; List<IServiceRegistration> services = (List<IServiceRegistration>)publishedServicesByClass[clazz]; services.Remove(serviceRegistration); } // Remove the ServiceRegistration from the list of all published Services. allPublishedServices.Remove(serviceRegistration); }
public override void Stop(IBundleContext context) { throw new NotImplementedException(); }
public void UnpublishServices(IBundleContext context) { // Get all the Services published by the BundleContext. List<IServiceRegistration> serviceRegs = (List<IServiceRegistration>)publishedServicesByContext[context]; if (serviceRegs != null) { // Remove this list for the BundleContext publishedServicesByContext.Remove(context); int size = serviceRegs.Count(); for (int i = 0; i < size; i++) { IServiceRegistration serviceReg = (IServiceRegistration)serviceRegs[i]; // Remove each service from the list of all published Services allPublishedServices.Remove(serviceReg); // Remove each service from the list of Services published by Class Name. string[] clazzes = ((ServiceRegistration)serviceReg).Classes; int numclazzes = clazzes.Length; for (int j = 0; j < numclazzes; j++) { string clazz = clazzes[j]; if (publishedServicesByClass.ContainsKey(clazz)) { List<IServiceRegistration> services = (List<IServiceRegistration>)publishedServicesByClass[clazz]; services.Remove(serviceReg); } } } } }
public void Stop(IBundleContext context) { TracesProvider.TracesOutput.OutputTrace("The bundle is stopping"); TracesProvider.TracesOutput.OutputTrace("Id=" + context.Bundle.Id); TracesProvider.TracesOutput.OutputTrace("State=" + context.Bundle.State); }
public void Start(IBundleContext context) { //todo; }
public static void Stop(IBundleContext context, string bundleName) { var bundle = context.GetBundle(bundleName); if (bundle == null) { logger.InfoFormat("Application {0} not loaded", bundleName); return; } context.ChangeBundleState(bundle.Name, BundleState.Stopping); bundle.Boostrap.StopActivator(context); context.ChangeBundleState(bundle.Name, BundleState.Resolved); AppDomain.Unload(bundle.AppDomain); }
public void Stop(IBundleContext context) { //todo: }
public void Stop(IBundleContext context) { }