示例#1
0
        static void Main(string[] args)
        {
            IIndex index = new RedisIndex("localhost", 6379, 0);
            IService service = new IndexingService(index);
            service.Start();

            while (true)
            {
                Console.WriteLine("{0} files indexed.", (service as IndexingService).FilesIndexed);
                Console.Write("> ");
                string term = Console.ReadLine().ToLower();

                if (String.IsNullOrEmpty(term))
                {
                    continue;
                }

                int resultsFound = 0;
                foreach (string file in index.Get(term))
                {
                    Console.ForegroundColor = resultsFound%2 == 0 ? ConsoleColor.Gray : ConsoleColor.DarkGray;
                    Console.WriteLine("{0}: {1}", resultsFound++, file);
                }
                Console.ResetColor();
            }
        }
示例#2
0
        public void IndexService_WithNotPublishedPost_DoesntAddsPostToIndex()
        {
            var context      = new Mock <ISubtextContext>();
            var searchEngine = new Mock <ISearchEngineService>();

            searchEngine.Setup(s => s.AddPost(It.IsAny <SearchEngineEntry>())).Never();

            var indexService = new IndexingService(context.Object, searchEngine.Object);

            var entry = new Entry(PostType.BlogPost)
            {
                Title = "Sample Post",
                Blog  = new Blog()
                {
                    Title = "My Blog"
                },
                IsActive = false,
            };

            indexService.AddPost(entry);
        }
示例#3
0
        public virtual ActionResult PublishPackage(string id, string version)
        {
            var package = PackageService.FindPackageByIdAndVersion(id, version);

            if (package == null)
            {
                return(new HttpStatusCodeWithBodyResult(
                           HttpStatusCode.NotFound, String.Format(CultureInfo.CurrentCulture, Strings.PackageWithIdAndVersionNotFound, id, version)));
            }

            User user = GetCurrentUser();

            if (!package.IsOwner(user))
            {
                return(new HttpStatusCodeWithBodyResult(HttpStatusCode.Forbidden, String.Format(CultureInfo.CurrentCulture, Strings.ApiKeyNotAuthorized, "publish")));
            }

            PackageService.MarkPackageListed(package);
            IndexingService.UpdatePackage(package);
            return(new EmptyResult());
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldFailOnExistingOwnedConstraintIndex() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldFailOnExistingOwnedConstraintIndex()
        {
            // given
            IndexingService indexingService = mock(typeof(IndexingService));
            StubKernel      kernel          = new StubKernel(this);

            long constraintIndexId      = 111;
            long constraintIndexOwnerId = 222;

            when(_schemaRead.indexGetCommittedId(_indexReference)).thenReturn(constraintIndexId);
            IndexProxy indexProxy = mock(typeof(IndexProxy));

            when(indexingService.GetIndexProxy(constraintIndexId)).thenReturn(indexProxy);
            NodePropertyAccessor nodePropertyAccessor = mock(typeof(NodePropertyAccessor));

            when(_schemaRead.index(_descriptor)).thenReturn(_indexReference);
            when(_schemaRead.indexGetOwningUniquenessConstraintId(_indexReference)).thenReturn(constraintIndexOwnerId);                     // which means there's an owner
            when(_tokenRead.nodeLabelName(LABEL_ID)).thenReturn("MyLabel");
            when(_tokenRead.propertyKeyName(PROPERTY_KEY_ID)).thenReturn("MyKey");
            ConstraintIndexCreator creator = new ConstraintIndexCreator(() => kernel, indexingService, nodePropertyAccessor, _logProvider);

            // when
            try
            {
                KernelTransactionImplementation transaction = CreateTransaction();
                creator.CreateUniquenessConstraintIndex(transaction, _descriptor, DefaultProvider);
                fail("Should've failed");
            }
            catch (AlreadyConstrainedException)
            {
                // THEN good
            }

            // then
            assertEquals("There should have been no need to acquire a statement to create the constraint index", 0, kernel.Transactions.Count);
            verify(_schemaRead).index(_descriptor);
            verify(_schemaRead).indexGetOwningUniquenessConstraintId(_indexReference);
            verifyNoMoreInteractions(_schemaRead);
        }
示例#5
0
        private void PrepareDatabase(Label label)
        {
            GenerateData(label);

            using (Transaction transaction = Database.beginTx())
            {
                for (int i = 0; i < 10; i++)
                {
                    Database.schema().indexFor(label).on(PROPERTY_PREFIX + i).create();
                }
                transaction.Success();
            }

            using (Transaction ignored = Database.beginTx())
            {
                Database.schema().awaitIndexesOnline(1, TimeUnit.MINUTES);
            }

            _checkPointer    = ResolveDependency(typeof(CheckPointer));
            _indexingService = ResolveDependency(typeof(IndexingService));
            _fileSystem      = ResolveDependency(typeof(FileSystemAbstraction));
        }
示例#6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testManualRelationshipIndexPopulation() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void TestManualRelationshipIndexPopulation()
        {
            RelationTypeSchemaDescriptor descriptor;

            using ([email protected] tx = (( GraphDatabaseAPI )_database).DependencyResolver.resolveDependency(typeof(Kernel)).beginTransaction(@explicit, AUTH_DISABLED))
            {
                int foodId     = tx.TokenWrite().relationshipTypeGetOrCreateForName(FOOD_LABEL);
                int propertyId = tx.TokenWrite().propertyKeyGetOrCreateForName(PROPERTY_NAME);
                descriptor = forRelType(foodId, propertyId);
                tx.SchemaWrite().indexCreate(descriptor);
                tx.Success();
            }

            IndexingService indexingService = GetIndexingService(_database);
            IndexProxy      indexProxy      = indexingService.getIndexProxy(descriptor);

            WaitIndexOnline(indexProxy);
            assertEquals(InternalIndexState.ONLINE, indexProxy.State);
            PopulationProgress progress = indexProxy.IndexPopulationProgress;

            assertEquals(progress.Completed, progress.Total);
        }
示例#7
0
 public KernelTransactions(Config config, StatementLocksFactory statementLocksFactory, ConstraintIndexCreator constraintIndexCreator, StatementOperationParts statementOperations, SchemaWriteGuard schemaWriteGuard, TransactionHeaderInformationFactory txHeaderFactory, TransactionCommitProcess transactionCommitProcess, AuxiliaryTransactionStateManager auxTxStateManager, TransactionHooks hooks, TransactionMonitor transactionMonitor, AvailabilityGuard databaseAvailabilityGuard, Tracers tracers, StorageEngine storageEngine, Procedures procedures, TransactionIdStore transactionIdStore, SystemNanoClock clock, AtomicReference <CpuClock> cpuClockRef, AtomicReference <HeapAllocation> heapAllocationRef, AccessCapability accessCapability, AutoIndexing autoIndexing, ExplicitIndexStore explicitIndexStore, VersionContextSupplier versionContextSupplier, CollectionsFactorySupplier collectionsFactorySupplier, ConstraintSemantics constraintSemantics, SchemaState schemaState, IndexingService indexingService, TokenHolders tokenHolders, string currentDatabaseName, Dependencies dataSourceDependencies)
 {
     if (!InstanceFieldsInitialized)
     {
         InitializeInstanceFields();
         InstanceFieldsInitialized = true;
     }
     this._config = config;
     this._statementLocksFactory  = statementLocksFactory;
     this._constraintIndexCreator = constraintIndexCreator;
     this._statementOperations    = statementOperations;
     this._schemaWriteGuard       = schemaWriteGuard;
     this._transactionHeaderInformationFactory = txHeaderFactory;
     this._transactionCommitProcess            = transactionCommitProcess;
     this._auxTxStateManager         = auxTxStateManager;
     this._hooks                     = hooks;
     this._transactionMonitor        = transactionMonitor;
     this._databaseAvailabilityGuard = databaseAvailabilityGuard;
     this._tracers                   = tracers;
     this._storageEngine             = storageEngine;
     this._procedures                = procedures;
     this._transactionIdStore        = transactionIdStore;
     this._cpuClockRef               = cpuClockRef;
     this._heapAllocationRef         = heapAllocationRef;
     this._accessCapability          = accessCapability;
     this._autoIndexing              = autoIndexing;
     this._explicitIndexStore        = explicitIndexStore;
     this._indexingService           = indexingService;
     this._tokenHolders              = tokenHolders;
     this._currentDatabaseName       = currentDatabaseName;
     this._dataSourceDependencies    = dataSourceDependencies;
     this._versionContextSupplier    = versionContextSupplier;
     this._clock                     = clock;
     DoBlockNewTransactions();
     this._collectionsFactorySupplier = collectionsFactorySupplier;
     this._constraintSemantics        = constraintSemantics;
     this._schemaState = schemaState;
 }
示例#8
0
        public virtual async Task <ActionResult> PublishPackage(string id, string version)
        {
            var package = PackageService.FindPackageByIdAndVersionStrict(id, version);

            if (package == null)
            {
                return(new HttpStatusCodeWithBodyResult(
                           HttpStatusCode.NotFound, String.Format(CultureInfo.CurrentCulture, Strings.PackageWithIdAndVersionNotFound, id, version)));
            }

            // Check if API key allows listing/unlisting the current package id
            User user = GetCurrentUser();

            if (!HasAnyScopeThatAllows(package.PackageRegistration, NuGetScopes.PackageUnlist))
            {
                return(new HttpStatusCodeWithBodyResult(HttpStatusCode.Forbidden, Strings.ApiKeyNotAuthorized));
            }

            await PackageService.MarkPackageListedAsync(package);

            IndexingService.UpdatePackage(package);
            return(new EmptyResult());
        }
示例#9
0
        public void IndexService_WithPublishedPost_AddsPostToIndex()
        {
            var context             = new Mock <ISubtextContext>();
            var searchEngine        = new Mock <ISearchEngineService>();
            SearchEngineEntry entry = null;

            searchEngine.Setup(s => s.AddPost(It.IsAny <SearchEngineEntry>())).Callback <SearchEngineEntry>(e => entry = e);

            var indexService = new IndexingService(context.Object, searchEngine.Object);

            var blogEntry = new Entry(PostType.BlogPost)
            {
                Title = "Sample Post",
                Blog  = new Blog()
                {
                    Title = "My Blog"
                },
                IsActive = true,
            };

            indexService.AddPost(blogEntry);
            Assert.IsNotNull(entry);
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldCreateIndexInAnotherTransaction() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldCreateIndexInAnotherTransaction()
        {
            // given
            StubKernel      kernel          = new StubKernel(this);
            IndexProxy      indexProxy      = mock(typeof(IndexProxy));
            IndexingService indexingService = mock(typeof(IndexingService));

            when(indexingService.GetIndexProxy(INDEX_ID)).thenReturn(indexProxy);
            when(indexingService.getIndexProxy(_descriptor)).thenReturn(indexProxy);
            when(indexProxy.Descriptor).thenReturn(_index.withId(INDEX_ID).withoutCapabilities());
            NodePropertyAccessor   nodePropertyAccessor = mock(typeof(NodePropertyAccessor));
            ConstraintIndexCreator creator = new ConstraintIndexCreator(() => kernel, indexingService, nodePropertyAccessor, _logProvider);

            // when
            long indexId = creator.CreateUniquenessConstraintIndex(CreateTransaction(), _descriptor, DefaultProvider);

            // then
            assertEquals(INDEX_ID, indexId);
            verify(_schemaRead).indexGetCommittedId(_indexReference);
            verify(_schemaRead).index(_descriptor);
            verifyNoMoreInteractions(_schemaRead);
            verify(indexProxy).awaitStoreScanCompleted(anyLong(), any());
        }
示例#11
0
        private async Task <LuceneInfoModel> GetLuceneInfo()
        {
            var model = new LuceneInfoModel
            {
                Directory = IndexingService.IndexPath,
                IsLocal   = IndexingService.IsLocal,
                Location  = Config.LuceneIndexLocation
            };

            try
            {
                model.LastUpdated = await IndexingService.GetLastWriteTime();

                model.DocumentCount = await IndexingService.GetDocumentCount();

                model.IndexSize = await IndexingService.GetIndexSizeInBytes();
            }
            catch (FileNotFoundException)
            {
                model.LastUpdated = null;
            }
            return(model);
        }
示例#12
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldValidateUniquenessIndexes() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
		 public virtual void ShouldValidateUniquenessIndexes()
		 {
			  // Given
			  NeoStores store = mock( typeof( NeoStores ) );
			  IndexingService indexes = mock( typeof( IndexingService ) );
			  IntegrityValidator validator = new IntegrityValidator( store, indexes );
			  UniquenessConstraintDescriptor constraint = ConstraintDescriptorFactory.uniqueForLabel( 1, 1 );

			  doThrow( new UniquePropertyValueValidationException( constraint, ConstraintValidationException.Phase.VERIFICATION, new Exception() ) ).when(indexes).validateIndex(2L);

			  ConstraintRule record = ConstraintRule.constraintRule( 1L, constraint, 2L );

			  // When
			  try
			  {
					validator.ValidateSchemaRule( record );
					fail( "Should have thrown integrity error." );
			  }
			  catch ( Exception )
			  {
					// good
			  }
		 }
示例#13
0
        public void IndexService_WithNotPublishedPost_RemovesPostFromIndex()
        {
            var  context      = new Mock <ISubtextContext>();
            var  searchEngine = new Mock <ISearchEngineService>();
            bool deleted      = false;

            searchEngine.Setup(s => s.RemovePost(It.IsAny <int>())).Callback(() => deleted = true);

            var indexService = new IndexingService(context.Object, searchEngine.Object);

            var entry = new Entry(PostType.BlogPost)
            {
                Title = "Sample Post",
                Blog  = new Blog()
                {
                    Title = "My Blog"
                },
                IsActive = false,
            };

            indexService.AddPost(entry);
            Assert.IsTrue(deleted);
        }
        public virtual async Task <ActionResult> DeletePackage(string id, string version)
        {
            var package = PackageService.FindPackageByIdAndVersion(id, version);

            if (package == null)
            {
                return(new HttpStatusCodeWithBodyResult(
                           HttpStatusCode.NotFound, String.Format(CultureInfo.CurrentCulture, Strings.PackageWithIdAndVersionNotFound, id, version)));
            }

            var user = GetCurrentUser();

            if (!package.IsOwner(user))
            {
                return(new HttpStatusCodeWithBodyResult(HttpStatusCode.Forbidden, Strings.ApiKeyNotAuthorized));
            }

            // Check if API key allows listing/unlisting the current package id
            if (!ApiKeyScopeAllows(
                    subject: id,
                    requestedActions: NuGetScopes.PackageUnlist))
            {
                return(new HttpStatusCodeWithBodyResult(HttpStatusCode.Forbidden, Strings.ApiKeyNotAuthorized));
            }

            await PackageService.MarkPackageUnlistedAsync(package);

            // Handle in separate transaction because of concurrency check with retry. Due to using
            // separate transactions, we must always call UpdateIsLatest on delete/unlist. This is
            // because a concurrent thread could be marking the package as latest before this thread
            // is able to commit the delete /unlist.
            await PackageService.UpdateIsLatestAsync(package.PackageRegistration);

            IndexingService.UpdatePackage(package);
            return(new EmptyResult());
        }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void launchCustomIndexPopulation(java.util.Map<String,int> labelNameIdMap, int propertyId, Runnable customAction) throws Exception
        private void LaunchCustomIndexPopulation(IDictionary <string, int> labelNameIdMap, int propertyId, ThreadStart customAction)
        {
            NeoStores      neoStores      = NeoStores;
            LabelScanStore labelScanStore = LabelScanStore;
            ThreadToStatementContextBridge transactionStatementContextBridge = TransactionStatementContextBridge;

            using (Transaction transaction = EmbeddedDatabase.beginTx(), KernelTransaction ktx = transactionStatementContextBridge.GetKernelTransactionBoundToThisThread(true))
            {
                DynamicIndexStoreView storeView = DynamicIndexStoreViewWrapper(customAction, neoStores, labelScanStore);

                IndexProviderMap providerMap     = IndexProviderMap;
                JobScheduler     scheduler       = JobScheduler;
                TokenNameLookup  tokenNameLookup = new SilentTokenNameLookup(ktx.TokenRead());

                NullLogProvider nullLogProvider = NullLogProvider.Instance;
                _indexService = IndexingServiceFactory.createIndexingService(Config.defaults(), scheduler, providerMap, storeView, tokenNameLookup, GetIndexRules(neoStores), nullLogProvider, nullLogProvider, IndexingService.NO_MONITOR, SchemaState, false);
                _indexService.start();

                _rules = CreateIndexRules(labelNameIdMap, propertyId);

                _indexService.createIndexes(_rules);
                transaction.Success();
            }
        }
示例#16
0
        private async Task <ActionResult> CreatePackageInternal()
        {
            // Get the user
            var user = GetCurrentUser();

            using (var packageStream = ReadPackageFromRequest())
            {
                try
                {
                    using (var archive = new ZipArchive(packageStream, ZipArchiveMode.Read, leaveOpen: true))
                    {
                        var reference = DateTime.UtcNow.AddDays(1); // allow "some" clock skew

                        var entryInTheFuture = archive.Entries.FirstOrDefault(
                            e => e.LastWriteTime.UtcDateTime > reference);

                        if (entryInTheFuture != null)
                        {
                            return(new HttpStatusCodeWithBodyResult(HttpStatusCode.BadRequest, string.Format(
                                                                        CultureInfo.CurrentCulture,
                                                                        Strings.PackageEntryFromTheFuture,
                                                                        entryInTheFuture.Name)));
                        }
                    }

                    using (var packageToPush = new PackageArchiveReader(packageStream, leaveStreamOpen: false))
                    {
                        NuspecReader nuspec = null;
                        try
                        {
                            nuspec = packageToPush.GetNuspecReader();
                        }
                        catch (Exception ex)
                        {
                            return(new HttpStatusCodeWithBodyResult(HttpStatusCode.BadRequest, string.Format(
                                                                        CultureInfo.CurrentCulture,
                                                                        Strings.UploadPackage_InvalidNuspec,
                                                                        ex.Message)));
                        }

                        if (nuspec.GetMinClientVersion() > Constants.MaxSupportedMinClientVersion)
                        {
                            return(new HttpStatusCodeWithBodyResult(HttpStatusCode.BadRequest, string.Format(
                                                                        CultureInfo.CurrentCulture,
                                                                        Strings.UploadPackage_MinClientVersionOutOfRange,
                                                                        nuspec.GetMinClientVersion())));
                        }

                        // Ensure that the user can push packages for this partialId.
                        var packageRegistration = PackageService.FindPackageRegistrationById(nuspec.GetId());
                        if (packageRegistration != null)
                        {
                            if (!packageRegistration.IsOwner(user))
                            {
                                return(new HttpStatusCodeWithBodyResult(HttpStatusCode.Forbidden,
                                                                        Strings.ApiKeyNotAuthorized));
                            }

                            // Check if a particular Id-Version combination already exists. We eventually need to remove this check.
                            string normalizedVersion = nuspec.GetVersion().ToNormalizedString();
                            bool   packageExists     =
                                packageRegistration.Packages.Any(
                                    p => String.Equals(
                                        p.NormalizedVersion,
                                        normalizedVersion,
                                        StringComparison.OrdinalIgnoreCase));

                            if (packageExists)
                            {
                                return(new HttpStatusCodeWithBodyResult(
                                           HttpStatusCode.Conflict,
                                           String.Format(CultureInfo.CurrentCulture, Strings.PackageExistsAndCannotBeModified,
                                                         nuspec.GetId(), nuspec.GetVersion().ToNormalizedStringSafe())));
                            }
                        }

                        var packageStreamMetadata = new PackageStreamMetadata
                        {
                            HashAlgorithm = Constants.Sha512HashAlgorithmId,
                            Hash          = CryptographyService.GenerateHash(packageStream.AsSeekableStream()),
                            Size          = packageStream.Length,
                        };

                        var package = await PackageService.CreatePackageAsync(
                            packageToPush,
                            packageStreamMetadata,
                            user,
                            commitChanges : false);

                        await AutoCuratePackage.ExecuteAsync(package, packageToPush, commitChanges : false);

                        await EntitiesContext.SaveChangesAsync();

                        using (Stream uploadStream = packageStream)
                        {
                            uploadStream.Position = 0;
                            await PackageFileService.SavePackageFileAsync(package, uploadStream.AsSeekableStream());

                            IndexingService.UpdatePackage(package);
                        }

                        MessageService.SendPackageAddedNotice(package,
                                                              Url.Action("DisplayPackage", "Packages", routeValues: new { id = package.PackageRegistration.Id, version = package.Version }, protocol: Request.Url.Scheme),
                                                              Url.Action("ReportMyPackage", "Packages", routeValues: new { id = package.PackageRegistration.Id, version = package.Version }, protocol: Request.Url.Scheme),
                                                              Url.Action("Account", "Users", routeValues: null, protocol: Request.Url.Scheme));

                        return(new HttpStatusCodeResult(HttpStatusCode.Created));
                    }
                }
                catch (InvalidPackageException ex)
                {
                    return(BadRequestForExceptionMessage(ex));
                }
                catch (InvalidDataException ex)
                {
                    return(BadRequestForExceptionMessage(ex));
                }
                catch (EntityException ex)
                {
                    return(BadRequestForExceptionMessage(ex));
                }
                catch (FrameworkException ex)
                {
                    return(BadRequestForExceptionMessage(ex));
                }
            }
        }
示例#17
0
        private async Task <ActionResult> CreatePackageInternal()
        {
            // Get the user
            var user = GetCurrentUser();

            using (var packageStream = ReadPackageFromRequest())
            {
                try
                {
                    using (var packageToPush = new PackageArchiveReader(packageStream, leaveStreamOpen: false))
                    {
                        NuspecReader nuspec = null;
                        try
                        {
                            nuspec = packageToPush.GetNuspecReader();
                        }
                        catch (Exception ex)
                        {
                            return(new HttpStatusCodeWithBodyResult(HttpStatusCode.BadRequest, string.Format(
                                                                        CultureInfo.CurrentCulture,
                                                                        Strings.UploadPackage_InvalidNuspec,
                                                                        ex.Message)));
                        }

                        if (nuspec.GetMinClientVersion() > Constants.MaxSupportedMinClientVersion)
                        {
                            return(new HttpStatusCodeWithBodyResult(HttpStatusCode.BadRequest, string.Format(
                                                                        CultureInfo.CurrentCulture,
                                                                        Strings.UploadPackage_MinClientVersionOutOfRange,
                                                                        nuspec.GetMinClientVersion())));
                        }

                        // Ensure that the user can push packages for this partialId.
                        var packageRegistration = PackageService.FindPackageRegistrationById(nuspec.GetId());
                        if (packageRegistration != null)
                        {
                            if (!packageRegistration.IsOwner(user))
                            {
                                return(new HttpStatusCodeWithBodyResult(HttpStatusCode.Forbidden, Strings.ApiKeyNotAuthorized));
                            }

                            // Check if a particular Id-Version combination already exists. We eventually need to remove this check.
                            string normalizedVersion = nuspec.GetVersion().ToNormalizedString();
                            bool   packageExists     =
                                packageRegistration.Packages.Any(
                                    p => String.Equals(
                                        p.NormalizedVersion,
                                        normalizedVersion,
                                        StringComparison.OrdinalIgnoreCase));

                            if (packageExists)
                            {
                                return(new HttpStatusCodeWithBodyResult(
                                           HttpStatusCode.Conflict,
                                           String.Format(CultureInfo.CurrentCulture, Strings.PackageExistsAndCannotBeModified,
                                                         nuspec.GetId(), nuspec.GetVersion().ToNormalizedStringSafe())));
                            }
                        }

                        var packageStreamMetadata = new PackageStreamMetadata
                        {
                            HashAlgorithm = Constants.Sha512HashAlgorithmId,
                            Hash          = CryptographyService.GenerateHash(packageStream.AsSeekableStream()),
                            Size          = packageStream.Length,
                        };

                        var package = await PackageService.CreatePackageAsync(packageToPush, packageStreamMetadata, user, commitChanges : false);

                        await AutoCuratePackage.ExecuteAsync(package, packageToPush, commitChanges : false);

                        await EntitiesContext.SaveChangesAsync();

                        using (Stream uploadStream = packageStream)
                        {
                            uploadStream.Position = 0;
                            await PackageFileService.SavePackageFileAsync(package, uploadStream.AsSeekableStream());

                            IndexingService.UpdatePackage(package);
                        }

                        return(new HttpStatusCodeResult(HttpStatusCode.Created));
                    }
                }
                catch (InvalidDataException ex)
                {
                    return(new HttpStatusCodeWithBodyResult(
                               HttpStatusCode.BadRequest,
                               string.Format(CultureInfo.CurrentCulture, Strings.UploadPackage_InvalidPackage, ex.Message)));
                }
            }
        }
示例#18
0
        private async Task <ActionResult> CreatePackageInternal()
        {
            // Get the user
            var user = GetCurrentUser();

            using (var packageStream = ReadPackageFromRequest())
            {
                try
                {
                    using (var archive = new ZipArchive(packageStream, ZipArchiveMode.Read, leaveOpen: true))
                    {
                        var reference = DateTime.UtcNow.AddDays(1); // allow "some" clock skew

                        var entryInTheFuture = archive.Entries.FirstOrDefault(
                            e => e.LastWriteTime.UtcDateTime > reference);

                        if (entryInTheFuture != null)
                        {
                            return(new HttpStatusCodeWithBodyResult(HttpStatusCode.BadRequest, string.Format(
                                                                        CultureInfo.CurrentCulture,
                                                                        Strings.PackageEntryFromTheFuture,
                                                                        entryInTheFuture.Name)));
                        }
                    }

                    using (var packageToPush = new PackageArchiveReader(packageStream, leaveStreamOpen: false))
                    {
                        try
                        {
                            PackageService.EnsureValid(packageToPush);
                        }
                        catch (Exception ex)
                        {
                            ex.Log();

                            var message = Strings.FailedToReadUploadFile;
                            if (ex is InvalidPackageException || ex is InvalidDataException || ex is EntityException)
                            {
                                message = ex.Message;
                            }

                            return(new HttpStatusCodeWithBodyResult(HttpStatusCode.BadRequest, message));
                        }

                        NuspecReader nuspec;
                        var          errors = ManifestValidator.Validate(packageToPush.GetNuspec(), out nuspec).ToArray();
                        if (errors.Length > 0)
                        {
                            var errorsString = string.Join("', '", errors.Select(error => error.ErrorMessage));
                            return(new HttpStatusCodeWithBodyResult(HttpStatusCode.BadRequest, string.Format(
                                                                        CultureInfo.CurrentCulture,
                                                                        errors.Length > 1 ? Strings.UploadPackage_InvalidNuspecMultiple : Strings.UploadPackage_InvalidNuspec,
                                                                        errorsString)));
                        }

                        if (nuspec.GetMinClientVersion() > Constants.MaxSupportedMinClientVersion)
                        {
                            return(new HttpStatusCodeWithBodyResult(HttpStatusCode.BadRequest, string.Format(
                                                                        CultureInfo.CurrentCulture,
                                                                        Strings.UploadPackage_MinClientVersionOutOfRange,
                                                                        nuspec.GetMinClientVersion())));
                        }

                        // Ensure that the user can push packages for this partialId.
                        var packageRegistration = PackageService.FindPackageRegistrationById(nuspec.GetId());
                        if (packageRegistration == null)
                        {
                            // Check if API key allows pushing a new package id
                            if (!ApiKeyScopeAllows(
                                    subject: nuspec.GetId(),
                                    requestedActions: NuGetScopes.PackagePush))
                            {
                                // User cannot push a new package ID as the API key scope does not allow it
                                return(new HttpStatusCodeWithBodyResult(HttpStatusCode.Unauthorized, Strings.ApiKeyNotAuthorized));
                            }
                        }
                        else
                        {
                            // Is the user allowed to push this Id?
                            if (!packageRegistration.IsOwner(user))
                            {
                                // Audit that a non-owner tried to push the package
                                await AuditingService.SaveAuditRecord(
                                    new FailedAuthenticatedOperationAuditRecord(
                                        user.Username,
                                        AuditedAuthenticatedOperationAction.PackagePushAttemptByNonOwner,
                                        attemptedPackage : new AuditedPackageIdentifier(
                                            nuspec.GetId(), nuspec.GetVersion().ToNormalizedStringSafe())));

                                // User cannot push a package to an ID owned by another user.
                                return(new HttpStatusCodeWithBodyResult(HttpStatusCode.Conflict,
                                                                        string.Format(CultureInfo.CurrentCulture, Strings.PackageIdNotAvailable,
                                                                                      nuspec.GetId())));
                            }

                            // Check if API key allows pushing the current package id
                            if (!ApiKeyScopeAllows(
                                    packageRegistration.Id,
                                    NuGetScopes.PackagePushVersion, NuGetScopes.PackagePush))
                            {
                                // User cannot push a package as the API key scope does not allow it
                                return(new HttpStatusCodeWithBodyResult(HttpStatusCode.Unauthorized, Strings.ApiKeyNotAuthorized));
                            }

                            // Check if a particular Id-Version combination already exists. We eventually need to remove this check.
                            string normalizedVersion = nuspec.GetVersion().ToNormalizedString();
                            bool   packageExists     =
                                packageRegistration.Packages.Any(
                                    p => string.Equals(
                                        p.NormalizedVersion,
                                        normalizedVersion,
                                        StringComparison.OrdinalIgnoreCase));

                            if (packageExists)
                            {
                                return(new HttpStatusCodeWithBodyResult(
                                           HttpStatusCode.Conflict,
                                           string.Format(CultureInfo.CurrentCulture, Strings.PackageExistsAndCannotBeModified,
                                                         nuspec.GetId(), nuspec.GetVersion().ToNormalizedStringSafe())));
                            }
                        }

                        var packageStreamMetadata = new PackageStreamMetadata
                        {
                            HashAlgorithm = Constants.Sha512HashAlgorithmId,
                            Hash          = CryptographyService.GenerateHash(packageStream.AsSeekableStream()),
                            Size          = packageStream.Length
                        };

                        var package = await PackageService.CreatePackageAsync(
                            packageToPush,
                            packageStreamMetadata,
                            user,
                            commitChanges : false);

                        await AutoCuratePackage.ExecuteAsync(package, packageToPush, commitChanges : false);

                        using (Stream uploadStream = packageStream)
                        {
                            uploadStream.Position = 0;

                            try
                            {
                                await PackageFileService.SavePackageFileAsync(package, uploadStream.AsSeekableStream());
                            }
                            catch (InvalidOperationException ex)
                            {
                                ex.Log();

                                return(new HttpStatusCodeWithBodyResult(HttpStatusCode.Conflict, Strings.UploadPackage_IdVersionConflict));
                            }
                        }

                        try
                        {
                            await EntitiesContext.SaveChangesAsync();
                        }
                        catch
                        {
                            // If saving to the DB fails for any reason, we need to delete the package we just saved.
                            await PackageFileService.DeletePackageFileAsync(nuspec.GetId(), nuspec.GetVersion().ToNormalizedString());

                            throw;
                        }

                        IndexingService.UpdatePackage(package);

                        // Write an audit record
                        await AuditingService.SaveAuditRecord(
                            new PackageAuditRecord(package, AuditedPackageAction.Create, PackageCreatedVia.Api));

                        // Notify user of push
                        MessageService.SendPackageAddedNotice(package,
                                                              Url.Action("DisplayPackage", "Packages", routeValues: new { id = package.PackageRegistration.Id, version = package.Version }, protocol: Request.Url.Scheme),
                                                              Url.Action("ReportMyPackage", "Packages", routeValues: new { id = package.PackageRegistration.Id, version = package.Version }, protocol: Request.Url.Scheme),
                                                              Url.Action("Account", "Users", routeValues: null, protocol: Request.Url.Scheme));

                        return(new HttpStatusCodeResult(HttpStatusCode.Created));
                    }
                }
                catch (InvalidPackageException ex)
                {
                    return(BadRequestForExceptionMessage(ex));
                }
                catch (InvalidDataException ex)
                {
                    return(BadRequestForExceptionMessage(ex));
                }
                catch (EntityException ex)
                {
                    return(BadRequestForExceptionMessage(ex));
                }
                catch (FrameworkException ex)
                {
                    return(BadRequestForExceptionMessage(ex));
                }
            }
        }
示例#19
0
 public IndexActivator(IndexingService indexingService)
 {
     this._indexingService = indexingService;
 }
示例#20
0
 public SettingsVM(SettingsService s, IndexingService index)
 {
     S            = s;
     IndexService = index;
     ApplyBase(S.Settings.DarkTheme);
 }
示例#21
0
 public IndexProcedures(KernelTransaction tx, IndexingService indexingService)
 {
     this._ktx             = tx;
     _statement            = tx.AcquireStatement();
     this._indexingService = indexingService;
 }
示例#22
0
 public NeoStoreFileListing(DatabaseLayout databaseLayout, LogFiles logFiles, LabelScanStore labelScanStore, IndexingService indexingService, ExplicitIndexProvider explicitIndexProviders, StorageEngine storageEngine)
 {
     this._databaseLayout           = databaseLayout;
     this._logFiles                 = logFiles;
     this._storageEngine            = storageEngine;
     this._neoStoreFileIndexListing = new NeoStoreFileIndexListing(labelScanStore, indexingService, explicitIndexProviders);
     this._additionalProviders      = new CopyOnWriteArraySet <StoreFileProvider>();
 }
 public virtual ActionResult Rebuild()
 {
     IndexingService.UpdateIndex(forceRefresh: true);
     return(Index());
 }
示例#24
0
 public void LinkIndexingServiceInstance(IndexingService indexingService)
 {
     _indexingService = indexingService;
 }
示例#25
0
        /// <summary>
        /// Called by the Blazor runtime - this is where we setup the HTTP request pipeline and
        /// initialise all the bits and pieces we need to run.
        /// </summary>
        /// <param name="app"></param>
        /// <param name="env"></param>
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env,
                              DownloadService download, ThemeService themes, TaskService tasks,
                              ExifService exifService, ThumbnailService thumbService,
                              IndexingService indexService, ImageProcessService imageProcessing,
                              AzureFaceService azureFace, ImageRecognitionService aiService,
                              UserService userService, ConfigService configService, WorkService workService,
                              ImageCache imageCache, MetaDataService metaDataService, ObjectDetector objectDetector)
        {
            SyncfusionLicenseProvider.RegisterLicense("NTUxMzEwQDMxMzkyZTM0MmUzMGFRSFpzQUhjdUE2M2V4S1BmYSs5bk13dkpGbkhvam5Wb1VRbGVURkRsOHM9");

            var logLevel = configService.Get(ConfigSettings.LogLevel, Serilog.Events.LogEventLevel.Information);

            Logging.ChangeLogLevel(logLevel);

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Error");
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }

            if (Logging.Verbose)
            {
                app.UseSerilogRequestLogging();
            }

            app.UseResponseCompression();
            app.UseRouting();
            app.UseResponseCaching();

            // Disable this for now
            // app.UseHttpsRedirection();

            // TODO: Do we need this if we serve all the images via the controller?
            app.UseStaticFiles();
            app.UseStaticFiles(new StaticFileOptions
            {
                FileProvider = new PhysicalFileProvider(ThumbnailService.PicturesRoot),
                RequestPath  = ThumbnailService.RequestRoot
            });

            // Enable auth
            app.UseAuthentication();
            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                //endpoints.MapControllerRoute(name: "default", pattern: "{controller}/{action}");
                endpoints.MapControllers();
                endpoints.MapBlazorHub();
                endpoints.MapFallbackToPage("/_Host");
            });

            // Prime the cache
            imageCache.WarmUp().Wait();

            // TODO: Save this in ConfigService
            string contentRootPath = Path.Combine(env.ContentRootPath, "wwwroot");

            // TODO: Fix this, or not if Skia doesn't need it
            imageProcessing.SetContentPath(contentRootPath);
            download.SetDownloadPath(contentRootPath);
            themes.SetContentPath(contentRootPath);

            // Start the work processing queue for AI, Thumbs, etc
            workService.StartService();

            // Start the face service before the thumbnail service
            azureFace.StartService().Wait();
            metaDataService.StartService();
            indexService.StartService();
            aiService.StartService();

            // ObjectDetector can throw a segmentation fault if the docker container is pinned
            // to a single CPU, so for now, to aid debugging, let's not even try and initialise
            // it if AI is disabled. See https://github.com/Webreaper/Damselfly/issues/334
            if (!configService.GetBool(ConfigSettings.DisableObjectDetector, false))
            {
                objectDetector.InitScorer();
            }

            // Validation check to ensure at least one user is an Admin
            userService.CheckAdminUser().Wait();

            StartTaskScheduler(tasks, download, thumbService, exifService);

            Logging.StartupCompleted();
            Logging.Log("Starting Damselfly webserver...");
        }
示例#26
0
 public IntegrityValidator(NeoStores neoStores, IndexingService indexes)
 {
     this._neoStores = neoStores;
     this._indexes   = indexes;
 }
示例#27
0
 internal RecordStorageReader(TokenHolders tokenHolders, SchemaStorage schemaStorage, NeoStores neoStores, IndexingService indexService, SchemaCache schemaCache, System.Func <IndexReaderFactory> indexReaderFactory, System.Func <LabelScanReader> labelScanReaderSupplier, RecordStorageCommandCreationContext commandCreationContext)
 {
     this._tokenHolders           = tokenHolders;
     this._neoStores              = neoStores;
     this._schemaStorage          = schemaStorage;
     this._indexService           = indexService;
     this._nodeStore              = neoStores.NodeStore;
     this._relationshipStore      = neoStores.RelationshipStore;
     this._relationshipGroupStore = neoStores.RelationshipGroupStore;
     this._propertyStore          = neoStores.PropertyStore;
     this._counts      = neoStores.Counts;
     this._schemaCache = schemaCache;
     this._indexReaderFactorySupplier = indexReaderFactory;
     this._labelScanReaderSupplier    = labelScanReaderSupplier;
     this._commandCreationContext     = commandCreationContext;
 }
示例#28
0
        private async Task <ActionResult> CreatePackageInternal()
        {
            var policyResult = await SecurityPolicyService.EvaluateAsync(SecurityPolicyAction.PackagePush, HttpContext);

            if (!policyResult.Success)
            {
                return(new HttpStatusCodeWithBodyResult(HttpStatusCode.BadRequest, policyResult.ErrorMessage));
            }

            // Get the user
            var currentUser = GetCurrentUser();

            using (var packageStream = ReadPackageFromRequest())
            {
                try
                {
                    using (var archive = new ZipArchive(packageStream, ZipArchiveMode.Read, leaveOpen: true))
                    {
                        var reference = DateTime.UtcNow.AddDays(1); // allow "some" clock skew

                        var entryInTheFuture = archive.Entries.FirstOrDefault(
                            e => e.LastWriteTime.UtcDateTime > reference);

                        if (entryInTheFuture != null)
                        {
                            return(new HttpStatusCodeWithBodyResult(HttpStatusCode.BadRequest, string.Format(
                                                                        CultureInfo.CurrentCulture,
                                                                        Strings.PackageEntryFromTheFuture,
                                                                        entryInTheFuture.Name)));
                        }
                    }

                    using (var packageToPush = new PackageArchiveReader(packageStream, leaveStreamOpen: false))
                    {
                        try
                        {
                            PackageService.EnsureValid(packageToPush);
                        }
                        catch (Exception ex)
                        {
                            ex.Log();

                            var message = Strings.FailedToReadUploadFile;
                            if (ex is InvalidPackageException || ex is InvalidDataException || ex is EntityException)
                            {
                                message = ex.Message;
                            }

                            return(new HttpStatusCodeWithBodyResult(HttpStatusCode.BadRequest, message));
                        }

                        NuspecReader nuspec;
                        var          errors = ManifestValidator.Validate(packageToPush.GetNuspec(), out nuspec).ToArray();
                        if (errors.Length > 0)
                        {
                            var errorsString = string.Join("', '", errors.Select(error => error.ErrorMessage));
                            return(new HttpStatusCodeWithBodyResult(HttpStatusCode.BadRequest, string.Format(
                                                                        CultureInfo.CurrentCulture,
                                                                        errors.Length > 1 ? Strings.UploadPackage_InvalidNuspecMultiple : Strings.UploadPackage_InvalidNuspec,
                                                                        errorsString)));
                        }

                        if (nuspec.GetMinClientVersion() > Constants.MaxSupportedMinClientVersion)
                        {
                            return(new HttpStatusCodeWithBodyResult(HttpStatusCode.BadRequest, string.Format(
                                                                        CultureInfo.CurrentCulture,
                                                                        Strings.UploadPackage_MinClientVersionOutOfRange,
                                                                        nuspec.GetMinClientVersion())));
                        }

                        User owner;

                        // Ensure that the user can push packages for this partialId.
                        var id                  = nuspec.GetId();
                        var version             = nuspec.GetVersion();
                        var packageRegistration = PackageService.FindPackageRegistrationById(id);
                        if (packageRegistration == null)
                        {
                            // Check if the current user's scopes allow pushing a new package ID
                            var apiScopeEvaluationResult = EvaluateApiScope(ActionsRequiringPermissions.UploadNewPackageId, new ActionOnNewPackageContext(id, ReservedNamespaceService), NuGetScopes.PackagePush);
                            owner = apiScopeEvaluationResult.Owner;
                            if (!apiScopeEvaluationResult.IsSuccessful())
                            {
                                // User cannot push a new package ID as the current user's scopes does not allow it
                                return(GetHttpResultFromFailedApiScopeEvaluationForPush(apiScopeEvaluationResult, id, version));
                            }
                        }
                        else
                        {
                            // Check if the current user's scopes allow pushing a new version of an existing package ID
                            var apiScopeEvaluationResult = EvaluateApiScope(ActionsRequiringPermissions.UploadNewPackageVersion, packageRegistration, NuGetScopes.PackagePushVersion, NuGetScopes.PackagePush);
                            owner = apiScopeEvaluationResult.Owner;
                            if (!apiScopeEvaluationResult.IsSuccessful())
                            {
                                // User cannot push a package as the current user's scopes does not allow it
                                await AuditingService.SaveAuditRecordAsync(
                                    new FailedAuthenticatedOperationAuditRecord(
                                        currentUser.Username,
                                        AuditedAuthenticatedOperationAction.PackagePushAttemptByNonOwner,
                                        attemptedPackage : new AuditedPackageIdentifier(
                                            id, version.ToNormalizedStringSafe())));

                                return(GetHttpResultFromFailedApiScopeEvaluationForPush(apiScopeEvaluationResult, id, version));
                            }

                            if (packageRegistration.IsLocked)
                            {
                                return(new HttpStatusCodeWithBodyResult(
                                           HttpStatusCode.Forbidden,
                                           string.Format(CultureInfo.CurrentCulture, Strings.PackageIsLocked, packageRegistration.Id)));
                            }

                            // Check if a particular Id-Version combination already exists. We eventually need to remove this check.
                            string normalizedVersion = version.ToNormalizedString();
                            bool   packageExists     =
                                packageRegistration.Packages.Any(
                                    p => string.Equals(
                                        p.NormalizedVersion,
                                        normalizedVersion,
                                        StringComparison.OrdinalIgnoreCase));

                            if (packageExists)
                            {
                                return(new HttpStatusCodeWithBodyResult(
                                           HttpStatusCode.Conflict,
                                           string.Format(CultureInfo.CurrentCulture, Strings.PackageExistsAndCannotBeModified,
                                                         id, nuspec.GetVersion().ToNormalizedStringSafe())));
                            }
                        }

                        var packageStreamMetadata = new PackageStreamMetadata
                        {
                            HashAlgorithm = Constants.Sha512HashAlgorithmId,
                            Hash          = CryptographyService.GenerateHash(packageStream.AsSeekableStream()),
                            Size          = packageStream.Length
                        };

                        var package = await PackageUploadService.GeneratePackageAsync(
                            id,
                            packageToPush,
                            packageStreamMetadata,
                            owner,
                            currentUser);

                        await AutoCuratePackage.ExecuteAsync(package, packageToPush, commitChanges : false);

                        PackageCommitResult commitResult;
                        using (Stream uploadStream = packageStream)
                        {
                            uploadStream.Position = 0;
                            commitResult          = await PackageUploadService.CommitPackageAsync(
                                package,
                                uploadStream.AsSeekableStream());
                        }

                        switch (commitResult)
                        {
                        case PackageCommitResult.Success:
                            break;

                        case PackageCommitResult.Conflict:
                            return(new HttpStatusCodeWithBodyResult(
                                       HttpStatusCode.Conflict,
                                       Strings.UploadPackage_IdVersionConflict));

                        default:
                            throw new NotImplementedException($"The package commit result {commitResult} is not supported.");
                        }

                        IndexingService.UpdatePackage(package);

                        // Write an audit record
                        await AuditingService.SaveAuditRecordAsync(
                            new PackageAuditRecord(package, AuditedPackageAction.Create, PackageCreatedVia.Api));

                        if (!(ConfigurationService.Current.AsynchronousPackageValidationEnabled && ConfigurationService.Current.BlockingAsynchronousPackageValidationEnabled))
                        {
                            // Notify user of push unless async validation in blocking mode is used
                            MessageService.SendPackageAddedNotice(package,
                                                                  Url.Package(package.PackageRegistration.Id, package.NormalizedVersion, relativeUrl: false),
                                                                  Url.ReportPackage(package.PackageRegistration.Id, package.NormalizedVersion, relativeUrl: false),
                                                                  Url.AccountSettings(relativeUrl: false));
                        }

                        TelemetryService.TrackPackagePushEvent(package, currentUser, User.Identity);

                        if (package.SemVerLevelKey == SemVerLevelKey.SemVer2)
                        {
                            return(new HttpStatusCodeWithServerWarningResult(HttpStatusCode.Created, Strings.WarningSemVer2PackagePushed));
                        }

                        return(new HttpStatusCodeResult(HttpStatusCode.Created));
                    }
                }
                catch (InvalidPackageException ex)
                {
                    return(BadRequestForExceptionMessage(ex));
                }
                catch (InvalidDataException ex)
                {
                    return(BadRequestForExceptionMessage(ex));
                }
                catch (EntityException ex)
                {
                    return(BadRequestForExceptionMessage(ex));
                }
                catch (FrameworkException ex)
                {
                    return(BadRequestForExceptionMessage(ex));
                }
            }
        }
示例#29
0
 public IndexReaderFactory_Caching(IndexingService indexingService)
 {
     this.IndexingService = indexingService;
 }
示例#30
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Before public void setup() throws org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void Setup()
        {
            _txState = mock(typeof(TransactionState));

            Dictionary <int, Value> map = new Dictionary <int, Value>();

            map[PROP_ID1] = Values.of("hi1");
            map[PROP_ID2] = Values.of("hi2");
            map[PROP_ID3] = Values.of("hi3");
            _node         = (new StubNodeCursor()).withNode(0, new long[] { LABEL_ID1, LABEL_ID2 }, map);
            _node.next();

            _propertyCursor = new StubPropertyCursor();

            Read readOps = mock(typeof(Read));

            when(readOps.TxState()).thenReturn(_txState);

            IndexingService indexingService = mock(typeof(IndexingService));
            IndexProxy      indexProxy      = mock(typeof(IndexProxy));

            when(indexingService.getIndexProxy(any(typeof(SchemaDescriptor)))).thenReturn(indexProxy);
            when(indexingService.getRelatedIndexes(any(), anyInt(), any())).thenAnswer(invocationOnMock =>
            {
                long[] labels     = invocationOnMock.getArgument(0);
                int propertyKeyId = invocationOnMock.getArgument(1);
                ISet <SchemaDescriptor> descriptors = new HashSet <SchemaDescriptor>();
                foreach (IndexDescriptor index in _indexes)
                {
                    if (contains(labels, index.schema().keyId()) && contains(index.schema().PropertyIds, propertyKeyId))
                    {
                        descriptors.add(index.schema());
                    }
                }
                return(descriptors);
            });
            when(indexingService.getRelatedIndexes(any(), any(typeof(int[])), any())).thenAnswer(invocationOnMock =>
            {
                long[] labels        = invocationOnMock.getArgument(0);
                int[] propertyKeyIds = invocationOnMock.getArgument(1);
                ISet <SchemaDescriptor> descriptors = new HashSet <SchemaDescriptor>();
                foreach (IndexDescriptor index in _indexes)
                {
                    if (contains(labels, index.schema().keyId()))
                    {
                        bool containsAll = true;
                        foreach (int propertyId in index.schema().PropertyIds)
                        {
                            containsAll &= contains(propertyKeyIds, propertyId);
                        }
                        if (containsAll)
                        {
                            descriptors.add(index.schema());
                        }
                    }
                }
                return(descriptors);
            });

            _indexTxUpdater = new IndexTxStateUpdater(readOps, indexingService);
        }
示例#31
0
 public IndexingController(IndexingService indexingService)
 {
     _indexingService = indexingService;
 }