public LuceneIndexingJob(TimeSpan frequence, Func<EntitiesContext> contextThunk, TimeSpan timeout, LuceneIndexLocation location)
            : base("Lucene", frequence, timeout)
        {
            _updateIndex = () =>
            {
                using (var context = contextThunk())
                {
                    var indexingService = new LuceneIndexingService(
                        new EntityRepository<Package>(context),
                        new EntityRepository<CuratedPackageVersion>(context),
                        LuceneCommon.GetDirectory(location),
                        null);
                    indexingService.UpdateIndex();
                }
            };

            // Updates the index synchronously first time job is created.
            // For startup code resiliency, we should handle exceptions for the database being down.
            try
            {
                _updateIndex();
            }
            catch (SqlException e)
            {
                QuietLog.LogHandledException(e);
            }
            catch (DataException e)
            {
                QuietLog.LogHandledException(e);
            }
        }
示例#2
0
 private static string GetIndexLocation(LuceneIndexLocation location)
 {
     switch (location)
     {
         case LuceneIndexLocation.Temp:
             return Path.Combine(Path.GetTempPath(), "NuGetGallery", "Lucene");
         default:
             return HostingEnvironment.MapPath("~/App_Data/Lucene");
     }
 }
示例#3
0
        private static string GetIndexLocation(LuceneIndexLocation location)
        {
            switch (location)
            {
            case LuceneIndexLocation.Temp:
                return(Path.Combine(Path.GetTempPath(), "NuGetGallery", "Lucene"));

            default:
                return(HostingEnvironment.MapPath("~/App_Data/Lucene"));
            }
        }
示例#4
0
        internal static Lucene.Net.Store.Directory GetDirectory(LuceneIndexLocation location)
        {
            if (_directorySingleton == null)
            {
                var index = GetIndexLocation(location);
                if (!System.IO.Directory.Exists(index))
                {
                    System.IO.Directory.CreateDirectory(index);
                }

                var directoryInfo = new DirectoryInfo(index);
                _directorySingleton = new SimpleFSDirectory(directoryInfo, LuceneLock);
            }

            return _directorySingleton;
        }
示例#5
0
        internal static Lucene.Net.Store.Directory GetDirectory(LuceneIndexLocation location)
        {
            if (_directorySingleton == null)
            {
                var index = GetIndexLocation(location);
                if (!System.IO.Directory.Exists(index))
                {
                    System.IO.Directory.CreateDirectory(index);
                }

                var directoryInfo = new DirectoryInfo(index);
                _directorySingleton = new SimpleFSDirectory(directoryInfo, LuceneLock);
            }

            return(_directorySingleton);
        }
        public LuceneIndexingJob(TimeSpan frequence, Func <EntitiesContext> contextThunk, TimeSpan timeout, LuceneIndexLocation location)
            : base("Lucene", frequence, timeout)
        {
            _updateIndex = () =>
            {
                using (var context = contextThunk())
                {
                    var indexingService = new LuceneIndexingService(
                        new EntityRepository <Package>(context),
                        new EntityRepository <CuratedPackageVersion>(context),
                        LuceneCommon.GetDirectory(location),
                        null);
                    indexingService.UpdateIndex();
                }
            };

            // Updates the index synchronously first time job is created.
            // For startup code resiliency, we should handle exceptions for the database being down.
            try
            {
                _updateIndex();
            }
            catch (SqlException e)
            {
                QuietLog.LogHandledException(e);
            }
            catch (DataException e)
            {
                QuietLog.LogHandledException(e);
            }
        }