コード例 #1
0
ファイル: WritersCache.cs プロジェクト: lanicon/iExportEngine
        /// <summary>
        /// Initializes a new instance of the <see cref="T:iTin.Export.ComponentModel.Writer.WritersCache" /> class.
        /// </summary>
        /// <param name="settings">A reference to cache settings object.</param>
        private WritersCache(WritersCacheSettings settings)
        {
            SentinelHelper.ArgumentNull(settings);
            SentinelHelper.ArgumentNull(settings.Items);

            _watchers  = new List <FileSystemWatcher>();
            _container = GetCompositionContainer(settings);
        }
コード例 #2
0
ファイル: WritersCache.cs プロジェクト: lanicon/iExportEngine
        /// <summary>
        /// Gets writers repository.
        /// </summary>
        /// <param name="settings">Writer cache settings.</param>
        /// <returns>
        /// Writer repository.
        /// </returns>
        private CompositionContainer GetCompositionContainer(WritersCacheSettings settings)
        {
            CompositionContainer container;

            using (var catalog = new AggregateCatalog())
            {
                foreach (var path in settings.Items)
                {
                    var item = new SafeDirectoryCatalog(path);
                    catalog.Catalogs.Add(item);
                    using (var writerWatcher = GetWriterWatcher(path))
                    {
                        var addWatcher = _watchers.All(watch => watch.Path != path);
                        if (addWatcher)
                        {
                            _watchers.Add(writerWatcher);
                        }
                    }
                }

                CompositionContainer tempContainer = null;
                try
                {
                    tempContainer = new CompositionContainer(catalog);
                    try
                    {
                        tempContainer.ComposeParts(this);
                        container     = tempContainer;
                        tempContainer = null;
                    }
                    catch (CompositionException)
                    {
                        throw;
                    }
                }
                finally
                {
                    tempContainer?.Dispose();
                }
            }

            return(container);
        }
コード例 #3
0
ファイル: WritersCache.cs プロジェクト: lanicon/iExportEngine
        /// <summary>
        /// Gets a reference to the cache of available writers.
        /// </summary>
        /// <param name="settings">Writer cache settings.</param>
        /// <returns>
        /// A <see cref="T:iTin.Export.ComponentModel.Writer.WritersCache" /> object than represents the available writers-cache.
        /// </returns>
        public static WritersCache Instance(WritersCacheSettings settings)
        {
            SentinelHelper.ArgumentNull(settings);

            if (_instance != null)
            {
                return(_instance);
            }

            lock (SyncLock)
            {
                if (_instance == null)
                {
                    _instance = new WritersCache(settings);
                }
            }

            return(_instance);
        }