private void InsertLog(RethinkDb.Driver.Net.Connection conn, string categoryName, string logLevel, int eventId, string eventName, string message, Exception exception) { string exceptionId = null; if (exception != null) { // insert exception var result = R.Db(_dbName).Table(ExceptionTable) .Insert(exception) .RunResult(conn); exceptionId = result.GeneratedKeys.First().ToString(); } var logEntry = new LogEntry { Application = _connectionFactory.GetOptions().Application, Category = categoryName, Event = eventName, EventId = eventId, ExceptionId = exceptionId, Host = Environment.MachineName, Level = logLevel, Message = message, Timestamp = DateTime.UtcNow }; R.Db(_dbName).Table(LogTable) .Insert(logEntry) .RunResult(conn); }
public RethinkDbSingletonProvider(IOptions <RethinkDbOptions> options) { if (options == null) { throw new ArgumentNullException(nameof(options)); } if (String.IsNullOrWhiteSpace(options.Value.HostnameOrIp)) { throw new ArgumentNullException(nameof(RethinkDbOptions.HostnameOrIp)); } var rethinkDbSingleton = RethinkDb.Driver.RethinkDB.R; var rethinkDbConnection = rethinkDbSingleton.Connection().Hostname(options.Value.HostnameOrIp); if (options.Value.DriverPort.HasValue) { rethinkDbConnection.Port(options.Value.DriverPort.Value); } if (options.Value.Timeout.HasValue) { rethinkDbConnection.Timeout(options.Value.Timeout.Value); } RethinkDbConnection = rethinkDbConnection.Connect(); RethinkDbSingleton = rethinkDbSingleton; }
public void Init() { if (Settings == null) { Settings = new Dictionary <string, string>(); } try { if (!File.Exists(Assembly.GetExecutingAssembly().Location.Replace(".dll", ".json"))) { File.WriteAllText(Assembly.GetExecutingAssembly().Location.Replace(".dll", ".json"), Properties.Resources.Plugin_RethinkDB); } if (File.Exists(Assembly.GetExecutingAssembly().Location.Replace(".dll", ".json"))) { JConfig = JObject.Parse(File.ReadAllText(Assembly.GetExecutingAssembly().Location.Replace(".dll", ".json"))); bReadOnly = JConfig["ReadOnly"].Value <bool>(); ContinueAfterWrite = JConfig["ContinueAfterWrite"].Value <bool>(); CacheFull = JConfig["CacheFull"].Value <bool>(); CacheKeys = JConfig["CacheKeys"].Value <bool>(); RethinkDBServer = JConfig["RethinkDBServer"].Value <string>(); Port = JConfig["Port"].Value <int>(); Database = JConfig["Database"].Value <string>(); } else { JConfig = new JObject(); } try { conn = R.Connection() .Hostname(RethinkDBServer) .Port(Port) .Timeout(60) .Db(Database) .Connect(); //Create DB if missing if (!((string[])R.DbList().Run <string[]>(conn)).Contains(Database)) { R.DbCreate(Database).Run(conn); } //Get Tables RethinkTables = ((string[])R.TableList().Run <string[]>(conn)).ToList(); } catch (Exception ex) { Debug.WriteLine(ex.Message); } } catch { } }