protected override bool FileExists(ControllerContext controllerContext, string virtualPath) { try { var passedController = controllerContext.Controller as BaseMultiTenantController; if (passedController != null) { return(base.FileExists(controllerContext, virtualPath.Replace("%1", passedController.CurrentTenant.FolderName))); } var newEx = new Exception("PassedController is null, Controller must inherit MultiTenantController"); ElmahLogger.LogError(newEx); return(base.FileExists(controllerContext, virtualPath)); } catch (HttpException exception) { ElmahLogger.LogError(exception); if (exception.GetHttpCode() != 0x194) { throw; } return(false); } catch (Exception exception) { var newEx = new Exception((controllerContext == null).ToString(), exception); ElmahLogger.LogError(newEx); return(false); } }
private static async Task SeedCollectionAsync(string seedList, string indexName) { var result = new SearchInitResponse(); try { var commandRepository = new SeachCommandRepository <TDocument>(); { await commandRepository.AzureSearchService.LoadIndexesAsync(); var seeds = JsonConvert.DeserializeObject <List <TDocument> >(seedList); var del = await commandRepository.DeleteIndex(indexName); var insert = await commandRepository.CreateDocumentsInIndex(seeds, indexName); if (!del) { result.MessageList.Add("Delete failed"); } if (!insert) { result.MessageList.Add("Insert failed"); } } } catch (Exception ex) { ElmahLogger.LogError(ex); } }
public async Task <QueryReply <TDocument> > QueryAsync(string indexName, QueryParameters parameters) { QueryReply <TDocument> result = null; if (this.GetIndexByName(indexName) != null) { result = await this.AzureSearchService.Indexes[indexName].QueryAsync <TDocument>(parameters); } else { ElmahLogger.LogError(new Exception("QueryAsync against non existent index")); } return(result); }
public async Task <TDocument> Lookup(string indexName, string key, IEnumerable <string> fields = null) { TDocument result = null; if (this.GetIndexByName(indexName) != null) { result = await this.AzureSearchService.Indexes[indexName].Lookup <TDocument>(key, fields); } else { ElmahLogger.LogError(new Exception("Lookup against non existent index")); } return(result); }
public async Task <SuggestionReply <TSuggestion> > Suggest <TSuggestion>(string indexName, TSuggestion suggest, SuggestionParameters parameters) where TSuggestion : Suggestion { SuggestionReply <TSuggestion> result = null; if (this.GetIndexByName(indexName) != null) { result = await this.AzureSearchService.Indexes[indexName].SuggestAsync <TSuggestion>(parameters); } else { ElmahLogger.LogError(new Exception("QueryAsync against non existent index")); } return(result); }
protected virtual SingleResult <TDocument> Lookup(string id) { try { return(this.DocumentQueryService.Lookup(id)); } catch (HttpResponseException ex) { ElmahLogger.LogError(ex); throw; } catch (Exception ex) { ElmahLogger.LogError(ex); throw new HttpResponseException(HttpStatusCode.InternalServerError); } }
protected virtual List <TDocument> GetAll() { try { return(this.DocumentQueryService.GetAll()); } catch (HttpResponseException ex) { ElmahLogger.LogError(ex); throw; } catch (Exception ex) { ElmahLogger.LogError(ex); throw new HttpResponseException(HttpStatusCode.InternalServerError); } }
protected virtual T GetById <T>(string id) where T : SerializableResource { try { var service = new DocumentQueryService <T>(); return(service.GetById(id)); } catch (HttpResponseException ex) { ElmahLogger.LogError(ex); throw; } catch (Exception ex) { ElmahLogger.LogError(ex); throw new HttpResponseException(HttpStatusCode.InternalServerError); } }
private static async Task SeedCollectionAsync(string seedList, string collection, string database, string deleteCacheKey) { try { var repository = new DocumentCommandRepository <TDocument>(collection, database); { var seeds = JsonConvert.DeserializeObject <List <TDocument> >(seedList); foreach (var seed in seeds) { await repository.InsertAsync(seed); } } } catch (Exception ex) { ElmahLogger.LogError(ex); } }
protected virtual async Task DeleteAsync(string id) { try { ICommand command = new DeleteGenericObjectCommand <TDocument>(this.CurrentTenant.Name, id); await QueueService.AddMessageAsync(command); } catch (HttpResponseException ex) { ElmahLogger.LogError(ex); throw; } catch (Exception ex) { ElmahLogger.LogError(ex); throw new HttpResponseException(HttpStatusCode.InternalServerError); } }
public static async Task Initialize(string seed, string indexName) { SearchInitResponse result = null; try { await SeedCollectionAsync(seed, indexName.ToLower()); } catch (AzureSearchException de) { var baseException = de.GetBaseException(); ElmahLogger.LogError(baseException); } catch (Exception e) { var baseException = e.GetBaseException(); ElmahLogger.LogError(baseException); } }
private static async Task <SearchInitResponse> SeedCollectionAsync(string seedList, string indexName) { var result = new SearchInitResponse(); try { var queryRepository = new SearchQueryRepository <TDocument>(); var commandRepository = new SeachCommandRepository <TDocument>(); { await queryRepository.LoadIndexesAsync(); var seeds = JsonConvert.DeserializeObject <List <TDocument> >(seedList); var del = await commandRepository.DeleteIndex(indexName); var insert = await commandRepository.CreateDocumentsInIndex(seeds, indexName); var stats = await queryRepository.GetIndexStatistics(indexName); var indexes = await queryRepository.GetIndexes(); if (!del) { result.MessageList.Add("Delete failed"); } if (!insert) { result.MessageList.Add("Insert failed"); } result.StorageSize = stats.StorageSize.ToString(CultureInfo.InvariantCulture); result.DocumentCount = stats.DocumentCount.ToString(CultureInfo.InvariantCulture); result.Indexes = indexes.ToList().Select(x => x.Name).ToList(); } } catch (Exception ex) { ElmahLogger.LogError(ex); } return(result); }
protected virtual IQueryable <TDocument> Query() { IQueryable <TDocument> result = null; try { result = this.DocumentQueryService.Query(); } catch (HttpResponseException ex) { ElmahLogger.LogError(ex); } catch (Exception ex) { ElmahLogger.LogError(ex); throw new HttpResponseException(HttpStatusCode.InternalServerError); } return(result); }
public static async Task <bool> Initialize(string seed, string collection = "DemoCollection", string database = "DemoDB", string deleteCacheKey = "DocumentService.GetAll()") { var success = false; try { await SeedCollectionAsync(seed, collection, database, deleteCacheKey); success = true; } catch (DocumentClientException de) { var baseException = de.GetBaseException(); ElmahLogger.LogError(baseException); } catch (Exception e) { var baseException = e.GetBaseException(); ElmahLogger.LogError(baseException); } return(success); }
protected virtual async Task ReplaceAsync(string id, TDocument item) { if (item == null || !this.ModelState.IsValid) { throw new HttpResponseException(HttpStatusCode.BadRequest); } try { ICommand command = new ReplaceGenericObjectCommand <TDocument>(this.CurrentTenant.Name, item); await QueueService.AddMessageAsync(command); } catch (HttpResponseException ex) { ElmahLogger.LogError(ex); throw; } catch (Exception ex) { ElmahLogger.LogError(ex); throw new HttpResponseException(HttpStatusCode.InternalServerError); } }
public Index GetIndexByName(string name) { Index result = null; try { result = this.AzureSearchService.Indexes.FirstOrDefault(x => x.Name == name); } catch (AzureSearchException ex) { if (ex.InnerException != null) { ElmahLogger.LogError(ex.InnerException); } ElmahLogger.LogError(ex); } catch (Exception ex) { ElmahLogger.LogError(ex); } return(result); }
public async Task <IndexStatisticsReply> GetIndexStatistics(string indexName) { IndexStatisticsReply result = null; try { result = await this.AzureSearchService.Indexes[indexName].GetStatisticsAsync(); } catch (AzureSearchException ex) { if (ex.InnerException != null) { ElmahLogger.LogError(ex.InnerException); } ElmahLogger.LogError(ex); } catch (Exception ex) { ElmahLogger.LogError(ex); } return(result); }
public BookDBController() : base() { booksDB = BooksDatabase.getDatabase(); errorlogContainer = ElmahLogger.GetErrorLogContainer(); }