public async Task <int> TryPushMoreThan1000(List <T> thisSet, IAzureSearch <T> myClient, ILog log, CancellationToken cancellationToken, bool removeOldValues = false) { int numberToTakeEachTime = 1000; int currentIndex = 0; bool thisIsTheEnd = false; while (!thisIsTheEnd && !cancellationToken.IsCancellationRequested) { thisIsTheEnd = thisSet.Count < currentIndex + numberToTakeEachTime; var batch = thisIsTheEnd ? thisSet.Skip(currentIndex).ToArray() : thisSet.Skip(currentIndex).Take(numberToTakeEachTime).ToArray(); if (!batch.Any()) { break; } currentIndex += batch.Length; if (!await TryPush1000(batch, myClient, log, removeOldValues)) { log.Error("Failed to upload, could only upload " + currentIndex + "number of items"); return(0); } } return(currentIndex); }
public AppHost(IAzureSearch azureSearchService, IInsightsReader <T> insightsReaderService, IDocumentWriter documentWriterService, ILog logger) { _azureSearchService = azureSearchService; _insightsReaderService = insightsReaderService; _documentWriterService = documentWriterService; _logger = logger; }
public AppHost(IVideoIndexer videoIndexerService, IAzureSearch azureSearchService, IInsightsReader insightsReaderService, IDocumentWriter documentWriterService, ILog logger) { _videoIndexerService = videoIndexerService; _azureSearchService = azureSearchService; _insightsReaderService = insightsReaderService; _documentWriterService = documentWriterService; _logger = logger; }
public TriggerAllSurveillanceItems(IJsonStorage <TModel> backupDb, IAzureSearch <TModel> index, ITableStorageDb <SurveilledItem> suvItemDb, IEnumerable <ISurveillanceAction> allRegisteredSurvAction, IQueue queueToPutSingleSurveillances) { _backupDb = backupDb; _index = index; _suvItemDb = suvItemDb; _allRegisteredSurvAction = allRegisteredSurvAction; _queueToPutSingleSurveillances = queueToPutSingleSurveillances; }
public SearchController(IDependencyInjector di, IAzureSearch <TPersonIndexEntity> personIndex, IAzureSearch <TBusinessIndexEntity> busIndex, IPersonFilterManager personFilterManager, IBusinessFilterManager businessFilterManager, IFamilyProvider familyProvider, string minimumCriteriaForPerson = null, string[] freetextPropertiesForPerson = null, string minimumCriteriaForBusiness = "", string[] freetextPropertiesForBusiness = null, string[] surveillanceSearchOrderBy = null) : base(di) { _personIndex = personIndex; _busIndex = busIndex; _personFilterManager = personFilterManager; _businessFilterManager = businessFilterManager; _familyProvider = familyProvider; _minimumCriteriaForPerson = minimumCriteriaForPerson; _freetextPropertiesForPerson = freetextPropertiesForPerson; _minimumCriteriaForBusiness = minimumCriteriaForBusiness; _freetextPropertiesForBusiness = freetextPropertiesForBusiness; _surveillanceSearchOrderBy = surveillanceSearchOrderBy; }
public async Task <bool> TryPush1000(T[] thisSet, IAzureSearch <T> myClient, ILog log, bool removeOldValues = false) { bool uploaded = false; int retries = 10; while (!uploaded) { var st = Stopwatch.StartNew(); retries--; try { await(removeOldValues ? myClient.UploadBatch(thisSet) : myClient.MergeOrUploadBatch(thisSet)); await Task.Delay(200); uploaded = true; } catch (Exception e) { st.Stop(); var str = $"While uploading, got exception after {st.Elapsed.Minutes} minutes: {e.Message} Stack {e.StackTrace}"; if (e.InnerException != null) { str += ". InnerException.message=" + e.InnerException.Message + ", InnerException.StackTrace=" + e.InnerException.StackTrace; } log?.Error(str); if (retries == 0) { log.Error("Exiting after 10 tries"); Quit = true; return(false); } log?.Info("Retrying"); myClient = GetAzureSearch(); await Task.Delay(3000); } } return(true); }
protected SurveillanceController(IDependencyInjector di, IAzureSearch <TPersonIndexEntity> personIndex, IJsonStorage <BuildIndexComplete> buildIndexStorage) : base(di) { _personIndex = personIndex; _buildIndexStorage = buildIndexStorage; }
protected TagController(IDependencyInjector di, IAzureSearch <TPersonIndexEntity> personIndex, IAzureSearch <TBusinessIndexEntity> busIndex) : base(di) { _personIndex = personIndex; _busIndex = busIndex; }
private static async Task <SearchResult <IIndexEntity> > Search <T>(Models.DTO.Search search, string environment, IFilterManager fm, IAzureSearch <T> client, string minimumCriteria, string[] freetextFields) where T : class, IIndexEntity { fm.Init(search.SearchQuery.Filters); var selected = fm.GetSelectedFilters(); var query = search.SearchQuery.SearchTerm; if (IsAllDigits(query)) { query = RemoveWhiteSpaces(query); } var filters = CreateAndFilter(selected, minimumCriteria); var result = await client.SearchWithFullResult(query, filters, true, search.SearchParameters.OrderBy?.ToArray(), search.SearchParameters.NumberPerPage, search.SearchParameters.GetSkipCount(), searchFields : freetextFields); var resultObject = new SearchResult <IIndexEntity>() { SearchParameters = search.SearchParameters, Documents = result.Results.Select(x => x.Document) }; resultObject.SearchParameters.TotalCount = (int)result.Count; return(resultObject); }