Ejemplo n.º 1
0
 protected override void OnExit(ExitEventArgs e)
 {
     controller.Shutdown();
     container.Dispose();
     catalog.Dispose();
     base.OnExit(e);
 }
Ejemplo n.º 2
0
        /// <summary>
        ///  When disposed - likely will never get called
        /// </summary>
        /// <param name="disposing">True when disposing</param>
        protected virtual void Dispose(bool disposing)
        {
            if (_disposed)
            {
                return;
            }

            if (!disposing)
            {
                return;
            }

            if (_mainCatalog != null)
            {
                _mainCatalog.Dispose();
                _mainCatalog = null;
            }

            if (_container != null)
            {
                _container.Dispose();
                _container = null;
            }

            _mefDebugger = null;

            _disposed = true;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Loads all CustomClasses from CustomClasses folder
        /// </summary>
        public void Refresh()
        {
            if (_customClasses != null)
            {
                foreach (var x in _customClasses)
                {
                    $"CustomClasses: Disposing CC {x.Name}".Log(LogFiles.InjectedLog, true);
                    x.Dispose();
                }
            }
            if (_catalog != null)
            {
                $"CustomClasses: Disposing old catalog".Log(LogFiles.InjectedLog, true);
                _catalog.Catalogs.Clear();
                _catalog?.Dispose();
            }
            _catalog = new AggregateCatalog();
            _customClasses?.Clear();
            _container?.Dispose();
            Action <string> load = item =>
            {
                if (!item.EndsWith(".dll"))
                {
                    return;
                }
                $"CustomClasses: Noting down {item} as possible CustomClass".Log(LogFiles.InjectedLog, true);
                var dir = Path.GetDirectoryName(item);
                DependencyLoader.SetPluginPath(dir);
                var assembly = Assembly.Load(File.ReadAllBytes(item));
                _catalog.Catalogs.Add(new AssemblyCatalog(assembly));
            };

            foreach (var path in Directory.EnumerateDirectories(Paths.CustomClasses, "*", SearchOption.TopDirectoryOnly))
            {
                foreach (var item in Directory.GetFiles(path))
                {
                    load(item);
                }
            }
            foreach (var item in Directory.GetFiles(Paths.CustomClasses))
            {
                load(item);
            }
            _container = new CompositionContainer(_catalog);
            $"CustomClasses: Composing catalogs".Log(LogFiles.InjectedLog, true);
            _container.ComposeParts(this);
            var tmpList = new HashSet <string>();

            foreach (var x in _customClasses)
            {
                var name = x.Name.ToLower();
                $"CustomClasses: Loaded {name} botbase".Log(LogFiles.InjectedLog, true);
                if (tmpList.Contains(name))
                {
                    App.QuitWithMessage(
                        $"Name of CustomClasses must be unique however there are two or more bases with name {x.Name}");
                }
                tmpList.Add(name);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// MEF Bootstrap (MEF comes from System.ComponentModel.Composition in the GAC).
        /// <para>This will return a class containing all the application's aggregate roots.</para>
        /// </summary>
        public static ComposedDemoProgram Configure(params string[] pluginDirectories)
        {
            var catalogues =
                pluginDirectories.Select <string, ComposablePartCatalog>(d => new DirectoryCatalog(d)).
                Concat(new [] { new AssemblyCatalog(Assembly.GetExecutingAssembly()) }).ToList();

            var catalog = new AggregateCatalog(catalogues);

            try
            {
                var container = new CompositionContainer(catalog);

                var composedProgram = new ComposedDemoProgram();
                container.SatisfyImportsOnce(composedProgram);

                return(composedProgram);
            }
            finally
            {
                catalog.Dispose();
                foreach (var cat in catalogues)
                {
                    cat.Dispose();
                }
            }
        }
Ejemplo n.º 5
0
 public void Dispose()
 {
     _catalog.Dispose();
     _catalog = null;
     LoggerList.Clear();
     LoggerList = null;
 }
Ejemplo n.º 6
0
        /// <summary>
        ///     The events_ on close.
        /// </summary>
        /// <param name="sender">
        ///     The sender.
        /// </param>
        /// <param name="e">
        ///     The e.
        /// </param>
        private void Events_OnClose(object sender, EventArgs e)
        {
            if (!this.initialized)
            {
                return;
            }

            this.initialized = false;
            Events.OnClose  -= this.Events_OnClose;

            this.AbilityDataCollector?.Value?.OnClose();

            this.MainMenuManager?.Value?.OnClose();

            this.AbilityUnitManager?.Value?.OnClose();

            this.AbilityFactory?.Value?.OnClose();

            this.AbilityModuleManager?.Value?.OnClose();

            if (this.AbilityServices != null && this.AbilityServices.Any())
            {
                foreach (var abilityService in this.AbilityServices)
                {
                    abilityService?.Value?.OnClose();
                }
            }

            container?.Dispose();
            catalog?.Dispose();
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Disposes of the ModuleHandler
 /// </summary>
 public void Dispose()
 {
     _dataModule = null;
     catalog.Dispose();
     catalog = null;
     ModuleList.Clear();
     ModuleList = null;
 }
Ejemplo n.º 8
0
        protected override void OnCleanup()
        {
            container.Dispose();
            catalog.Dispose();
            context.Dispose();

            base.OnCleanup();
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        /// <remarks>
        /// <para>
        /// <note type="important">
        /// <para>
        /// This method must be called, or the application domain that is created to interrogate assembly types will live until the end of the application. This could lead to memory bloat or worse.
        /// </para>
        /// <para>
        /// Because the application domain is unloaded on a separate thread, it may deadlock with the finalizer thread and thus we cannot count on the finalizer to clean evict the stale app domain on our
        /// behalf.
        /// </para>
        /// </note>
        /// </para>
        /// </remarks>
        public void Dispose()
        {
            Log.Print("Unloading MEF plugin container and catalogs.", LoggingLevel.Intermediate);

            _container?.Dispose();
            _container = null;
            _rootCatalog?.Dispose();
            _rootCatalog = null;
        }
Ejemplo n.º 10
0
 public void Dispose()
 {
     foreach (IExport export in Exports)
     {
         IDisposable dispExport = export as IDisposable;
         dispExport?.Dispose();
     }
     catalog.Dispose();
 }
Ejemplo n.º 11
0
        protected override void OnExit(ExitEventArgs e)
        {
            //Shutdown application Controller
            controller.Shutdown();

            //Dispose All parts
            container.Dispose();
            catalog.Dispose();
        }
Ejemplo n.º 12
0
 protected override void OnExit(ExitEventArgs e)
 {
     foreach (var moduleController in moduleControllers.Reverse())
     {
         moduleController.Shutdown();
     }
     container.Dispose();
     catalog.Dispose();
     base.OnExit(e);
 }
Ejemplo n.º 13
0
        protected override void OnExit(ExitEventArgs e)
        {
            Console.WriteLine("Shutting down gracefully");

            controller.Shutdown();
            container.Dispose();
            catalog.Dispose();

            base.OnExit(e);
        }
Ejemplo n.º 14
0
 public void Dispose()
 {
     if (!_disposed && _aggregateCatalog != null)
     {
         _aggregateCatalog.Dispose();
         _container.Dispose();
         _disposed = true;
         GC.SuppressFinalize(this);
     }
 }
Ejemplo n.º 15
0
 protected override void OnExit(ExitEventArgs e)
 {
     foreach (var moduleController in moduleControllers.Reverse())
     {
         moduleController.Shutdown();
     }
     container?.Dispose();
     catalog?.Dispose();
     Log.App.Info("{0} closed", ApplicationInfo.ProductName);
     base.OnExit(e);
 }
Ejemplo n.º 16
0
        public void Dispose()
        {
            if (container != null)
            {
                container.Dispose();
            }

            if (catalog != null)
            {
                catalog.Dispose();
            }
        }
Ejemplo n.º 17
0
        protected override void OnExit(ExitEventArgs e)
        {
            // Shutdown the module controllers in reverse order
            foreach (var moduleController in moduleControllers.Reverse())
            {
                moduleController.Shutdown();
            }

            // Dispose
            container.Dispose();
            catalog.Dispose();
            base.OnExit(e);
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing,
        /// or resetting unmanaged resources.
        /// </summary>
        public void Dispose()
        {
            if (compositionContainer != null)
            {
                compositionContainer.Dispose();
            }

            if (aggregateCatalog != null)
            {
                aggregateCatalog.Dispose();
            }

            compositionContainer = null;
            aggregateCatalog     = null;
            providers            = null;
        }
        public void Dispose()
        {
            if (m_CompositionContainer != null)
            {
                m_CompositionContainer.Dispose();
            }

            if (m_AggregateCatalog != null)
            {
                m_AggregateCatalog.Dispose();
            }

            m_CompositionContainer = null;
            m_AggregateCatalog     = null;
            m_Providers            = null;
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Disposes of the instance.
        /// </summary>
        /// <param name="disposing"></param>
        protected override void Dispose(bool disposing)
        {
            base.Dispose(disposing);

            if (filter != null)
            {
                filter.Dispose();
                filter = null;
            }

            if (aggregate != null)
            {
                aggregate.Dispose();
                aggregate = null;
            }
        }
Ejemplo n.º 21
0
        /// <summary>
        ///   Releases unmanaged and - optionally - managed resources
        /// </summary>
        /// <param name = "disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
        protected override void Dispose(bool disposing)
        {
            base.Dispose(disposing);
            if (_compositionContainer != null)
            {
                _compositionContainer.Dispose();
            }

            if (_aggregateCatalog != null)
            {
                _aggregateCatalog.Dispose();
            }

            _compositionContainer = null;
            _aggregateCatalog     = null;
            _providers            = null;
        }
Ejemplo n.º 22
0
        protected virtual void Dispose(bool disposing)
        {
            if (!_disposed)
            {
                if (disposing)
                {
                    foreach (var catalog in _aggreagateCatalog.Catalogs)
                    {
                        catalog.Dispose();
                    }

                    _aggreagateCatalog.Dispose();
                }

                _disposed = true;
            }
        }
        /// <summary>
        ///     The events_ on close.
        /// </summary>
        /// <param name="sender">
        ///     The sender.
        /// </param>
        /// <param name="e">
        ///     The e.
        /// </param>
        private void Events_OnClose(object sender, EventArgs e)
        {
            if (!this.initialized)
            {
                return;
            }

            this.initialized = false;
            this.MainMenuManager.Value?.OnClose();
            this.AbilityUnitManager.Value?.OnClose();

            foreach (var abilityService in this.AbilityServices)
            {
                abilityService.Value?.OnClose();
            }

            container?.Dispose();
            catalog?.Dispose();
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Releases the unmanaged resources used by the <see cref="T:System.ComponentModel.Composition.Primitives.ComposablePartCatalog"/> and optionally releases the managed resources.
        /// </summary>
        /// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param>
        protected override void Dispose(bool disposing)
        {
            try
            {
                if (disposing)
                {
                    if (!_isDisposed)
                    {
                        AggregateCatalog catalogs    = null;
                        bool             disposeLock = false;
                        try
                        {
                            using (new WriteLock(_lock))
                            {
                                if (!_isDisposed)
                                {
                                    disposeLock        = true;
                                    catalogs           = _catalogCollection;
                                    _catalogCollection = null;
                                    _isDisposed        = true;
                                }
                            }
                        }
                        finally
                        {
                            if (catalogs != null)
                            {
                                catalogs.Dispose();
                            }

                            if (disposeLock)
                            {
                                _lock.Dispose();
                            }
                        }
                    }
                }
            }
            finally
            {
                base.Dispose(disposing);
            }
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        public void Dispose()
        {
            try
            {
                foreach (var plugin in Plugins)
                {
                    plugin.Dispose();
                }

                if (_container != null)
                {
                    _container.Dispose();
                }

                if (_catalog != null)
                {
                    _catalog.Dispose();
                }
            }
            catch (Exception)
            { }
        }
Ejemplo n.º 26
0
        /// <summary>
        ///     This method can be used to initialize the global container in the case where the default container doesn't provide
        ///     enough flexibility.
        ///
        ///     If this method is needed it should be called exactly once and as early as possible in the application host.
        /// </summary>
        /// <param name="catalogs">
        ///     An array of <see cref="ComposablePartCatalog"/> that should be used to initialize the
        ///     <see cref="CompositionContainer"/> with.
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///     <paramref name="catalogs"/> is <see langword="null"/>.
        /// </exception>
        /// <exception cref="InvalidOperationException">
        ///     Either <see cref="Initialize(CompositionContainer)" /> or <see cref="Initialize(ComposablePartCatalog[])" />
        ///     has already been called or someone has already made use of the global container. In either case you need to
        ///		ensure that it  is called only once and that it is called early in the application host startup code.
        /// </exception>
        public static CompositionContainer Initialize(params ComposablePartCatalog[] catalogs)
        {
            AggregateCatalog     aggregateCatalog = new AggregateCatalog(catalogs);
            CompositionContainer container        = new CompositionContainer(aggregateCatalog);

            try
            {
                Initialize(container);
            }
            catch
            {
                container.Dispose();

                // NOTE : this is important, as this prevents the disposal of the catalogs passed as input arguments
                aggregateCatalog.Catalogs.Clear();
                aggregateCatalog.Dispose();

                throw;
            }

            return(container);
        }
Ejemplo n.º 27
0
        protected override void OnExit(ExitEventArgs e)
        {
            // Shutdown the module controllers in reverse order
            foreach (IModuleController moduleController in moduleControllers.Reverse())
            {
                moduleController.Shutdown();
            }

            // Wait until all registered tasks are finished
            var shellService = container.GetExportedValue <IShellService>();

            Task[] tasksToWait = shellService.TasksToCompleteBeforeShutdown.ToArray();
            while (tasksToWait.Any(t => !t.IsCompleted && !t.IsCanceled && !t.IsFaulted))
            {
                DispatcherHelper.DoEvents();
            }

            // Dispose
            container.Dispose();
            catalog.Dispose();
            base.OnExit(e);
        }
Ejemplo n.º 28
0
 public void Dispose()
 {
     _compositionCatalog.Dispose();
     _compositionContainer.Dispose();
 }
Ejemplo n.º 29
0
 public void Dispose()
 {
     _pluginCatalog.Dispose();
 }
Ejemplo n.º 30
0
 public void Dispose()
 {
     catalog.Dispose();
     catalog = null;
     Plugins = null;
 }