public static string ToCreateConnectorStatement(this ConnectorMetadata connectorMetadata, string connectorName, bool ifNotExists = false) { var stringBuilder = new StringBuilder(); string connectorType = connectorMetadata.ConnectorType switch { ConnectorType.Source => "SOURCE", ConnectorType.Sink => "SINK", _ => throw new ArgumentOutOfRangeException() }; string existsCondition = ifNotExists ? "IF NOT EXISTS " : string.Empty; string createConnector = $"CREATE {connectorType} CONNECTOR {existsCondition}{connectorName} WITH ({Environment.NewLine}"; stringBuilder.Append(createConnector); var keyValuePairs = connectorMetadata.Properties.Select(c => $"\t'{c.Key}'= '{c.Value}'"); var properties = string.Join($", {Environment.NewLine}", keyValuePairs); stringBuilder.AppendLine(properties); stringBuilder.AppendLine(");"); return(stringBuilder.ToString()); }
/// <summary> /// Create a new connector. /// </summary> /// <param name="connectorMetadata">Configuration parameters for the connector.</param> /// <param name="connectorName">Name of the connector to create</param> /// <param name="cancellationToken"></param> /// <returns></returns> public async Task <HttpResponseMessage> PostConnectorAsync(ConnectorMetadata connectorMetadata, string connectorName, CancellationToken cancellationToken = default) { if (connectorMetadata == null) { throw new ArgumentNullException(nameof(connectorMetadata)); } if (string.IsNullOrWhiteSpace(connectorName)) { throw new ArgumentException("Cannot be null, empty, or contain only whitespace.", nameof(connectorName)); } using var httpClient = httpClientFactory.CreateClient(); var connector = new Connector { Name = connectorName, Config = connectorMetadata.Properties }; var httpRequestMessage = CreateHttpRequestMessage(connector, HttpMethod.Post, @"/connectors"); httpClient.DefaultRequestHeaders.Accept.Add( new MediaTypeWithQualityHeaderValue(MediaType)); var httpResponseMessage = await httpClient.SendAsync(httpRequestMessage, cancellationToken) .ConfigureAwait(false); return(httpResponseMessage); }
public static ConnectorMetadata ToModel(this ConnectorMetadataEntity entity) { var metadata = new ConnectorMetadata(); metadata.ConnectorName = entity.Provider; metadata.ConnectorUri = entity.ServiceUri; metadata.BatchSize = entity.BatchSize; return(metadata); }
public static int CalculateBillingUnits(string message, ConnectorMetadata connectorMetadata) { // By default take as single report and charge once if (connectorMetadata == null || !connectorMetadata.SingleReportForLongMessage) { return(1); } // Calculate units by message length return(GetTotalSegments(message)); }
public static ConnectorMetadata ToModel(this ConnectorMetadataEntity entity) { var metadata = new ConnectorMetadata(); metadata.ConnectorName = entity.Provider; metadata.ConnectorUri = entity.ServiceUri; metadata.BatchSize = entity.BatchSize; metadata.SingleReportForLongMessage = entity.SingleReportForLongMessage; if (Enum.TryParse(entity.ReportType, out ConnectorMetadata.ConnectorInboundType reportType)) { metadata.ReportType = reportType; } if (Enum.TryParse(entity.ReportType, out ConnectorMetadata.ConnectorInboundType moType)) { metadata.InboundMessageType = moType; } return(metadata); }
public static string ToStatement(this ConnectorMetadata connectorMetadata, string connectorName, bool ifNotExists = false) { return(connectorMetadata.ToCreateConnectorStatement(connectorName, ifNotExists)); }