/// <summary> /// Ensures indexes of an entity in No SQL database /// </summary> /// <param name="definition"></param> /// <param name="dataSource"></param> /// <param name="tracker"></param> /// <param name="cancellationToken"></param> /// <returns></returns> public static async Task EnsureNoSqlIndexesAsync(EntityDefinition definition, DataSource dataSource, Action <string, Exception> tracker = null, CancellationToken cancellationToken = default) { if (definition != null && dataSource != null && dataSource.Mode.Equals(RepositoryMode.NoSQL)) { try { tracker?.Invoke($"Ensure indexes of No SQL: {definition.Type} [{dataSource.Name} @ {dataSource.Mode} => {definition.CollectionName}]", null); if (tracker == null && RepositoryMediator.IsDebugEnabled) { RepositoryMediator.WriteLogs($"Ensure indexes of No SQL: {definition.Type} [{dataSource.Name} @ {dataSource.Mode} => {definition.CollectionName}]", null); } await definition.EnsureIndexesAsync(dataSource, tracker, cancellationToken).ConfigureAwait(false); } catch (Exception ex) { tracker?.Invoke($"Error occurred while ensuring indexes of No SQL: {definition.Type} [{dataSource.Name} @ {dataSource.Mode} => {definition.CollectionName}]", ex); if (tracker == null) { RepositoryMediator.WriteLogs($"Cannot ensure indexes of No SQL: {definition.Type} [{dataSource.Name} @ {dataSource.Mode} => {definition.CollectionName}]", ex); } } } }