/// <summary> /// Configures replication writebacks to File /// </summary> /// <param name="request"></param> /// <param name="context"></param> /// <returns></returns> public override Task <ConfigureReplicationResponse> ConfigureReplication(ConfigureReplicationRequest request, ServerCallContext context) { Logger.SetLogPrefix("configure_replication"); Logger.Info($"Configuring write for schema name {request?.Schema?.Name}..."); var schemaJson = Replication.GetSchemaJson(); var uiJson = Replication.GetUIJson(); try { if (!string.IsNullOrWhiteSpace(request.Form.DataJson)) { // check for config errors var replicationFormData = JsonConvert.DeserializeObject <ConfigureReplicationFormData>(request.Form.DataJson); replicationFormData.ConvertLegacyConfiguration(); var errors = replicationFormData.ValidateReplicationFormData(_server.Settings); return(Task.FromResult(new ConfigureReplicationResponse { Form = new ConfigurationFormResponse { DataJson = JsonConvert.SerializeObject(replicationFormData), Errors = { errors }, SchemaJson = schemaJson, UiJson = uiJson, StateJson = request.Form.StateJson } })); } return(Task.FromResult(new ConfigureReplicationResponse { Form = new ConfigurationFormResponse { DataJson = request.Form.DataJson, Errors = { }, SchemaJson = schemaJson, UiJson = uiJson, StateJson = request.Form.StateJson } })); } catch (Exception e) { Logger.Error(e, e.Message, context); return(Task.FromResult(new ConfigureReplicationResponse { Form = new ConfigurationFormResponse { DataJson = request.Form.DataJson, Errors = { e.Message }, SchemaJson = schemaJson, UiJson = uiJson, StateJson = request.Form.StateJson } })); } }
/// <summary> /// Configures replication writebacks to CouchDB /// </summary> /// <param name="request"></param> /// <param name="context"></param> /// <returns></returns> public override Task <ConfigureReplicationResponse> ConfigureReplication(ConfigureReplicationRequest request, ServerCallContext context) { Logger.SetLogPrefix("configure_replication"); Logger.Info($"Configuring write for schema name {request.Schema.Name}..."); var schemaProperties = request.Schema.Properties.Select(property => property.Name).ToList(); schemaProperties.Insert(0, "auto generate unique id"); var schemaJson = Replication.GetSchemaJson(schemaProperties); var uiJson = Replication.GetUIJson(); //user provided database name should only lowercase characters, digits and mush start with a letter try { //fetch and validate database name var dataJson = JObject.Parse(request.Form.DataJson); var databaseName = dataJson.Count != 0 ? (string)dataJson.SelectToken("DatabaseName") : ""; if (!IsValidDatabaseName(databaseName) && !string.IsNullOrEmpty(databaseName)) { throw new System.Exception("Not a valid database name!"); } return(Task.FromResult(new ConfigureReplicationResponse { Form = new ConfigurationFormResponse { DataJson = request.Form.DataJson, Errors = { }, SchemaJson = schemaJson, UiJson = uiJson, StateJson = request.Form.StateJson } })); } catch (Exception e) { Logger.Error(e, e.Message, context); return(Task.FromResult(new ConfigureReplicationResponse { Form = new ConfigurationFormResponse { DataJson = request.Form.DataJson, Errors = { e.Message }, SchemaJson = schemaJson, UiJson = uiJson, StateJson = request.Form.StateJson } })); } }
/// <summary> /// Configures replication writebacks to Couchbase /// </summary> /// <param name="request"></param> /// <param name="context"></param> /// <returns></returns> public override Task <ConfigureReplicationResponse> ConfigureReplication(ConfigureReplicationRequest request, ServerCallContext context) { Logger.Info("Configuring write..."); var schemaJson = Replication.GetSchemaJson(); var uiJson = Replication.GetUIJson(); try { var errors = new List <string>(); if (!string.IsNullOrWhiteSpace(request.Form.DataJson)) { // check for config errors var replicationFormData = JsonConvert.DeserializeObject <ConfigureReplicationFormData>(request.Form.DataJson); errors = replicationFormData.ValidateReplicationFormData(); } return(Task.FromResult(new ConfigureReplicationResponse { Form = new ConfigurationFormResponse { DataJson = request.Form.DataJson, Errors = { errors }, SchemaJson = schemaJson, UiJson = uiJson, StateJson = request.Form.StateJson } })); } catch (Exception e) { Logger.Error(e, e.Message, context); return(Task.FromResult(new ConfigureReplicationResponse { Form = new ConfigurationFormResponse { DataJson = request.Form.DataJson, Errors = { e.Message }, SchemaJson = schemaJson, UiJson = uiJson, StateJson = request.Form.StateJson } })); } }
/// <summary> /// Configures replication writebacks to Sisense /// </summary> /// <param name="request"></param> /// <param name="context"></param> /// <returns></returns> public override Task <ConfigureReplicationResponse> ConfigureReplication(ConfigureReplicationRequest request, ServerCallContext context) { Logger.Info("Configuring write..."); var schemaJson = Replication.GetSchemaJson(); var uiJson = Replication.GetUIJson(); try { return(Task.FromResult(new ConfigureReplicationResponse { Form = new ConfigurationFormResponse { DataJson = request.Form.DataJson, Errors = { }, SchemaJson = schemaJson, UiJson = uiJson, StateJson = request.Form.StateJson } })); } catch (Exception e) { Logger.Error(e.Message); return(Task.FromResult(new ConfigureReplicationResponse { Form = new ConfigurationFormResponse { DataJson = request.Form.DataJson, Errors = { e.Message }, SchemaJson = schemaJson, UiJson = uiJson, StateJson = request.Form.StateJson } })); } }