Esempio n. 1
0
        /// <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);
        }
Esempio n. 2
0
        /// <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);
        }
Esempio n. 3
0
        /// <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);
        }