public CouchQueryProvider(IFlurlClient flurlClient, CouchSettings settings, string connectionString, string db) { _flurlClient = flurlClient ?? throw new ArgumentNullException(nameof(flurlClient)); _settings = settings ?? throw new ArgumentNullException(nameof(settings)); _connectionString = connectionString ?? throw new ArgumentNullException(nameof(connectionString)); _db = db ?? throw new ArgumentNullException(nameof(db)); }
public HomeController(IOptions <CouchSettings> couch) { _couch = couch.Options; ClusterHelper.Initialize( new ClientConfiguration { Servers = new List <Uri> { new Uri(_couch.Server) }, UseSsl = false, DefaultOperationLifespan = 2500, EnableTcpKeepAlives = true, TcpKeepAliveTime = 1000 * 60 * 60, TcpKeepAliveInterval = 5000, BucketConfigs = new Dictionary <string, BucketConfiguration> { { _couch.Bucket, new BucketConfiguration { BucketName = _couch.Bucket, UseSsl = false, Password = "", PoolConfiguration = new PoolConfiguration { MaxSize = 50, MinSize = 10 } } } } }); }
public HomeController(IOptions<CouchSettings> couch) { _couch = couch.Options; ClusterHelper.Initialize( new ClientConfiguration { Servers = new List<Uri> { new Uri(_couch.Server) }, UseSsl = false, DefaultOperationLifespan = 2500, EnableTcpKeepAlives = true, TcpKeepAliveTime = 1000 * 60 * 60, TcpKeepAliveInterval = 5000, BucketConfigs = new Dictionary<string, BucketConfiguration> { { _couch.Bucket, new BucketConfiguration { BucketName = _couch.Bucket, UseSsl = false, Password = "", PoolConfiguration = new PoolConfiguration { MaxSize = 50, MinSize = 10 } } } } }); }
/// <summary> /// Creates a new CouchDB client. /// </summary> /// <param name="connectionString">URI to the CouchDB endpoint.</param> /// <param name="couchSettingsFunc">A function to configure the client settings.</param> /// <param name="flurlSettingsFunc">A function to configure the HTTP client.</param> public CouchClient(string connectionString, Action <CouchSettings> couchSettingsFunc = null, Action <ClientFlurlHttpSettings> flurlSettingsFunc = null) { if (string.IsNullOrEmpty(connectionString)) { throw new ArgumentNullException(nameof(connectionString)); } _settings = new CouchSettings(); couchSettingsFunc?.Invoke(_settings); ConnectionString = connectionString; _flurlClient = new FlurlClient(connectionString).Configure(s => { s.JsonSerializer = new NewtonsoftJsonSerializer(new JsonSerializerSettings { ContractResolver = new CouchContractResolver(_settings.PropertiesCase) }); s.BeforeCall = OnBeforeCall; if (_settings.ServerCertificateCustomValidationCallback != null) { s.HttpClientFactory = new CertClientFactory(_settings.ServerCertificateCustomValidationCallback); } flurlSettingsFunc?.Invoke(s); }); }
internal CouchDatabase(IFlurlClient flurlClient, CouchSettings settings, string connectionString, string db) { _flurlClient = flurlClient ?? throw new ArgumentNullException(nameof(flurlClient)); _settings = settings ?? throw new ArgumentNullException(nameof(settings)); _connectionString = connectionString ?? throw new ArgumentNullException(nameof(connectionString)); Database = db ?? throw new ArgumentNullException(nameof(db)); _queryProvider = new CouchQueryProvider(flurlClient, _settings, connectionString, Database); Security = new CouchSecurity(NewRequest); }
public static async Task <TestDocument> CreateTestDocument(string Database) { var testDoc = TestDocument.GenerateTestObject(); var client = CouchSettings.GetTestClient(Database); var result = await client.CreateANewDocumentAsync(testDoc, DatabaseToCreateDocumentIn : Database); //Ensure all needed parts are set by the client Assert.True(result.Ok, "Error during document creation"); Assert.False(string.IsNullOrEmpty(testDoc.ID), "ID was not set for new document"); Assert.False(string.IsNullOrEmpty(testDoc.Rev), "Rev was not set for new document"); return(testDoc); }
internal static string GetName(this Type t, CouchSettings settings) { var jsonObjectAttributes = t.GetCustomAttributes(typeof(JsonObjectAttribute), true); var jsonObject = jsonObjectAttributes.Length > 0 ? jsonObjectAttributes[0] as JsonObjectAttribute : null; if (jsonObject != null) { return(jsonObject.Id); } var typeName = t.Name; if (settings.PluralizeEntitis) { typeName = typeName.Pluralize(); } return(settings.DocumentsCaseType.Convert(typeName)); }
public void PurgeDocuments() { var testDocTask = CreateTestDocument(this.TestDB); testDocTask.Wait(); var testDoc = testDocTask.Result; var client = CouchSettings.GetTestClient(this.TestDB); var result = client.PurgeDocumentsInDatabase(new PurgeRequest() { DocumentsToPurge = new List <PurgeRequestDocument> { new PurgeRequestDocument(testDoc.ID, new List <string> { testDoc.Rev }) } }); Assert.NotNull(result); Assert.True(result.Purged.ContainsKey(testDoc.ID)); //Get document from db -> must fail var allDocs = client.GetAllDocuments(); Assert.Empty(allDocs.Rows); //Purge multi revsions testDocTask = CreateTestDocument(this.TestDB); testDoc = testDocTask.Result; testDoc.StringProp = "Cat's everywhere"; var firstRev = testDoc.Rev; client.UpdateDocument(testDoc); result = client.PurgeDocumentsInDatabase(new PurgeRequest() { DocumentsToPurge = new List <PurgeRequestDocument> { new PurgeRequestDocument(testDoc.ID, new List <string> { testDoc.Rev, firstRev }) } }); Assert.NotNull(result); Assert.True(result.Purged.ContainsKey(testDoc.ID)); allDocs = client.GetAllDocuments(); Assert.Empty(allDocs.Rows); }
internal QueryTranslator(CouchSettings settings) { _settings = settings ?? throw new ArgumentNullException(nameof(settings)); }
public PillowClient GetTestClient(ELoginTypes LoginType = ELoginTypes.BasicAuth) { return(CouchSettings.GetTestClient(TestDB, LoginType)); }