Esempio n. 1
0
        private IDocumentIndex CreateDocumentIndex(IPluginContext context, DocumentIndexTypeToken documentIndexTypeToken, int?version = null)
        {
            DocumentIndexType charactersIndexType = null;
            DocumentIndexType digitsIndexType     = null;

            if (_documentIndexMetadata.Contains(documentIndexTypeToken, DocumentIndexDataTypeToken.Characters))
            {
                charactersIndexType = _documentIndexMetadata.GetDocumentIndexType(documentIndexTypeToken, DocumentIndexDataTypeToken.Characters);
            }
            if (_documentIndexMetadata.Contains(documentIndexTypeToken, DocumentIndexDataTypeToken.Digits))
            {
                digitsIndexType = _documentIndexMetadata.GetDocumentIndexType(documentIndexTypeToken, DocumentIndexDataTypeToken.Digits);
            }
            if (version != null)
            {
                if (charactersIndexType != null)
                {
                    charactersIndexType = charactersIndexType.CreateVersion(version.Value);
                }
                if (digitsIndexType != null)
                {
                    digitsIndexType = digitsIndexType.CreateVersion(version.Value);
                }
            }
            DocumentIndexMonitor monitor = null;
            Action detachIndex           = () =>
            {
                if (monitor != null)
                {
                    monitor.DetachIndex();
                }
            };
            IActivityLogger logger = _loggerFactory.Create(new PluginContextSnapshot(context));

            monitor = new DocumentIndexMonitor(charactersIndexType ?? digitsIndexType, () =>
            {
                if (charactersIndexType != null)
                {
                    return(digitsIndexType != null
                                                                   ? (IDocumentIndex) new DocumentIndex(charactersIndexType, digitsIndexType, context, detachIndex, _documentIndexSetup, _loggerFactory, _optimizeHintFactory)
                                                                   : new DocumentIndexTyped(charactersIndexType, context, detachIndex, _documentIndexSetup, _loggerFactory, _optimizeHintFactory));
                }
                throw new ApplicationException("Characters index for {0} type is not supported.".Fmt(documentIndexTypeToken));
            }, logger);
            return(monitor);
        }
 public LockRegion(DocumentIndexMonitor monitor)
 {
     _monitor = monitor;
     Monitor.Enter(_monitor._gate);
 }