public override async Task EmptyContainer(ExecutionContext executionContext, Guid providerDefinitionId, string id) { var config = await base.GetAuthenticationDetails(executionContext, providerDefinitionId); async Task EmptyTable(string name, string context) { var sql = BuildEmptyContainerSql(name); _logger.LogDebug("Sql Server Connector - Empty Container[{Context}] - Generated query: {sql}", context, sql); try { await _client.ExecuteCommandAsync(config, sql); } catch (Exception e) { var message = $"Could not empty Container {name}"; _logger.LogError(e, message); throw new CreateContainerException(message); } } var tasks = new List <Task> { EmptyTable(id, "Data") }; var edgeTableName = EdgeContainerHelper.GetName(id); if (await CheckTableExists(executionContext, providerDefinitionId, edgeTableName)) { tasks.Add(EmptyTable(edgeTableName, "Edges")); } await Task.WhenAll(tasks); }
public override async Task CreateContainer(ExecutionContext executionContext, Guid providerDefinitionId, CreateContainerModel model) { var config = await base.GetAuthenticationDetails(executionContext, providerDefinitionId); async Task CreateTable(string name, IEnumerable <ConnectionDataType> columns, string context) { var sql = BuildCreateContainerSql(name, columns); _logger.LogDebug("Sql Server Connector - Create Container[{Context}] - Generated query: {sql}", context, sql); try { await _client.ExecuteCommandAsync(config, sql); } catch (Exception e) { var message = $"Could not create Container {name} for Connector {providerDefinitionId}"; _logger.LogError(e, message); throw new CreateContainerException(message); } } var tasks = new List <Task> { CreateTable(model.Name, model.DataTypes, "Data") }; if (model.CreateEdgeTable) { tasks.Add(CreateTable(EdgeContainerHelper.GetName(model.Name), new List <ConnectionDataType> { new ConnectionDataType { Name = Sanitize("OriginEntityCode"), Type = VocabularyKeyDataType.Text }, new ConnectionDataType { Name = Sanitize("Code"), Type = VocabularyKeyDataType.Text }, }, "Edges")); } await Task.WhenAll(tasks); }
public override async Task StoreEdgeData(ExecutionContext executionContext, Guid providerDefinitionId, string containerName, string originEntityCode, IEnumerable <string> edges) { try { var edgeTableName = EdgeContainerHelper.GetName(containerName); if (await CheckTableExists(executionContext, providerDefinitionId, edgeTableName)) { var sql = BuildEdgeStoreDataSql(edgeTableName, originEntityCode, edges, out var param); _logger.LogDebug($"Sql Server Connector - Store Edge Data - Generated query: {sql}"); var config = await base.GetAuthenticationDetails(executionContext, providerDefinitionId); await _client.ExecuteCommandAsync(config, sql, param); } } catch (Exception e) { var message = $"Could not store edge data into Container '{containerName}' for Connector {providerDefinitionId}"; _logger.LogError(e, message); throw new StoreDataException(message); } }
public override async Task RenameContainer(ExecutionContext executionContext, Guid providerDefinitionId, string id, string newName) { var config = await base.GetAuthenticationDetails(executionContext, providerDefinitionId); async Task RenameTable(string currentName, string updatedName, string context) { var tempName = Sanitize(updatedName); var sql = BuildRenameContainerSql(currentName, tempName, out var param); _logger.LogDebug("Sql Server Connector - Rename Container[{Context}] - Generated query: {sql}", context, sql); try { await _client.ExecuteCommandAsync(config, sql, param); } catch (Exception e) { var message = $"Could not Rename Container {currentName} for Connector {providerDefinitionId}"; _logger.LogError(e, message); throw new CreateContainerException(message); } } var tasks = new List <Task> { RenameTable(id, newName, "Data") }; var edgeTableName = EdgeContainerHelper.GetName(id); if (await CheckTableExists(executionContext, providerDefinitionId, edgeTableName)) { tasks.Add(RenameTable(edgeTableName, EdgeContainerHelper.GetName(newName), "Edges")); } await Task.WhenAll(tasks); }
public override async Task ArchiveContainer(ExecutionContext executionContext, Guid providerDefinitionId, string id) { var config = await base.GetAuthenticationDetails(executionContext, providerDefinitionId); async Task ArchiveTable(string name, string context) { var newName = await GetValidContainerName(executionContext, providerDefinitionId, $"{name}{DateTime.Now:yyyyMMddHHmmss}"); var sql = BuildRenameContainerSql(name, newName, out var param); _logger.LogDebug("Sql Server Connector - Archive Container[{Context}] - Generated query: {sql}", context, sql); try { await _client.ExecuteCommandAsync(config, sql, param); } catch (Exception e) { var message = $"Could not Archive Container {name} for Connector {providerDefinitionId}"; _logger.LogError(e, message); throw new CreateContainerException(message); } } var tasks = new List <Task> { ArchiveTable(id, "Data") }; var edgeTableName = EdgeContainerHelper.GetName(id); if (await CheckTableExists(executionContext, providerDefinitionId, edgeTableName)) { tasks.Add(ArchiveTable(edgeTableName, "Edges")); } await Task.WhenAll(tasks); }