Example #1
0
        public void SeedDatabase()
        {
            // Create the database if it does not exist
            List <string> dbList = rethinkDB.DbList().Run <List <string> >(connection);

            if (dbList.Contains(this._dbName))
            {
                rethinkDB.DbDrop(this._dbName).Run(connection);
                rethinkDB.DbCreate(this._dbName).Run(connection);
            }
            else if (!dbList.Contains(this._dbName))
            {
                rethinkDB.DbCreate(this._dbName).Run(connection);
            }
            // Load the tables from the database
            List <string> tableList    = rethinkDB.Db(this._dbName).TableList().Run <List <string> >(connection);
            List <string> createTables = new List <string>()
            {
                "Users", "UserSession", "SessionState", "PolicyHolders", "UserQuotation"
            };

            // Create the tables if they do not exist
            foreach (var tableName in createTables)
            {
                // Check if the table exists in the database
                if (!tableList.Contains(tableName))
                {
                    rethinkDB.Db(this._dbName).TableCreate(tableName).Run(connection);
                }
            }
        }
Example #2
0
        private void CheckAndPopulateIfNeeded()
        {
            if (Initalized)
            {
                return;
            }
            var list = R.DbList().Run <List <string> >(_connection);

            if (!list.Contains(DatabaseName))
            {
                R.DbCreate(DatabaseName).Run(_connection);
            }
            var tables = R.Db(DatabaseName).TableList().RunResult <List <string> >(_connection);

            foreach (var tableInfo in TableInfos)
            {
                if (!tables.Contains(tableInfo.TableName))
                {
                    R.Db(DatabaseName).TableCreate(tableInfo.TableName).Run(_connection);
                    foreach (var secondaryIndex in tableInfo.SecondaryIndexes)
                    {
                        var secondaryIndexResult = R.Db(DatabaseName).Table(tableInfo.TableName).IndexCreate(secondaryIndex).Run(_connection);
                    }
                }
            }

            Initalized = true;
        }
Example #3
0
        protected void CreateDatabase(string dbName)
        {
            try
            {
                var exists = _rethinkDb.DbList().Contains(db => db == dbName).Run(_rethinkCon);
                if (!exists)
                {
                    _rethinkDb.DbCreate(dbName).Run(_rethinkCon);
                    _rethinkDb.Db(dbName).Wait_().Run(_rethinkCon);

                    foreach (string tname in new List <string> {
                        "RtBoardAnnotation", "RtLibraryThumb"
                    })
                    {
                        _rethinkDb.Db(dbName).TableCreate(tname).Run(_rethinkCon);
                        _rethinkDb.Db(dbName).Table(tname).Wait_().Run(_rethinkCon);

                        _rethinkDb.Db(dbName).Table(tname).IndexCreate("MeetingId").Run(_rethinkCon);
                        _rethinkDb.Db(dbName).Table(tname).IndexWait("MeetingId").Run(_rethinkCon);
                    }
                }
            }
            catch (Exception ex)
            {
                App.InsertException(ex);
            }
        }
Example #4
0
    public void OnGUI()
    {
        //var obj = new ShieldData() {ID = Guid.NewGuid(), Name = "Bar" , HeatPerformanceCurve = new []{float4(0,0,0,0), float4(1,1,1,1)}} as DatabaseEntry;
        //var obj = new GalaxyRequestMessage() as Message;
        var obj   = new Gradient();
        var times = Enumerable.Range(0, 5).Select(i => (float)i / 4).ToArray();

        obj.alphaKeys = times.Select(f => new GradientAlphaKey(1, f)).ToArray();
        obj.colorKeys = times.Select(f => new GradientColorKey(UnityEngine.Random.ColorHSV(), f)).ToArray();
        // JsonSerializer serializer = new JsonSerializer();
        // serializer.Converters.Add(new MathJsonConverter());
        // serializer.Converters.Add(Converter.DateTimeConverter);
        // serializer.Converters.Add(Converter.BinaryConverter);
        // serializer.Converters.Add(Converter.GroupingConverter);
        // serializer.Converters.Add(Converter.PocoExprConverter);

        JsonConvert.DefaultSettings = () => new JsonSerializerSettings
        {
            Converters = new List <JsonConverter>
            {
                new MathJsonConverter(),
                Converter.DateTimeConverter,
                Converter.BinaryConverter,
                Converter.GroupingConverter,
                Converter.PocoExprConverter
            }
        };

        Converter.Serializer.Converters.Add(new MathJsonConverter());

        RegisterResolver.Register();

        if (GUILayout.Button("Print MsgPack JSON"))
        {
            Debug.Log(MessagePackSerializer.SerializeToJson(obj));
        }

        //var writer = new StringWriter();
        if (GUILayout.Button("Print Newtonsoft JSON"))
        {
            //serializer.Serialize(writer, obj);
            Debug.Log(JsonConvert.SerializeObject(obj));
        }

        if (GUILayout.Button("Create Database"))
        {
            R.DbCreate("Aetheria").Run(_connection);
        }

        if (GUILayout.Button("Create Table"))
        {
            R.Db("Aetheria").TableCreate("Items").Run(_connection);
        }

        if (GUILayout.Button("Send to RethinkDB"))
        {
            R.Db("Aetheria").Table("Items").Insert(obj).Run(_connection);
        }
    }
Example #5
0
        private void CreateDb()
        {
            var exists = R.DbList().Contains(db => db == _dbName).Run(_connection);

            if (!exists)
            {
                R.DbCreate(_dbName).Run(_connection);
                R.Db(_dbName).Wait_().Run(_connection);
            }
        }
        protected void CreateDb(string dbName)
        {
            var conn   = _connectionFactory.CreateConnection();
            var exists = R.DbList().Contains(db => db == dbName).Run(conn);

            if (!exists)
            {
                R.DbCreate(dbName).Run(conn);
                R.Db(dbName).Wait_().Run(conn);
            }
        }
Example #7
0
 private RethinkDb.Driver.Ast.Db EnsureDatabaseExists(string dbName, Connection c)
 {
     List<string> dbs = R.DbList().Run<List<string>>(c);
     if (!dbs.Contains(dbName))
     {
         logger.LogInformation("Db does not exist. Creating...");
         R.DbCreate(dbName).Run(c);
         logger.LogInformation("Db created");
     }
     var db = R.Db(dbName);
     return db;
 }
Example #8
0
        /// <summary>
        /// Create the database if it does not exist
        /// </summary>
        /// <param name="configuration">The session store configuration</param>
        /// <exception cref="InvalidOperationException">If there is a problem creating the database</exception>
        private static async Task DatabaseCheck(RethinkDbSessionConfiguration configuration)
        {
            var databases = await R.DbList().RunAtomAsync <List <string> >(configuration.Connection);

            if (!databases.Contains(configuration.Database))
            {
                var result = await R.DbCreate(configuration.Database).RunResultAsync(configuration.Connection);

                if (0 != result.Errors)
                {
                    throw new InvalidOperationException(String.Format(
                                                            "Could not create RethinkDB session store database {0}: {1}", configuration.Database,
                                                            result.FirstError));
                }
            }
        }
Example #9
0
        void InitData()
        {
            var c = GetConnection();

            if (!R.DbList().Contains(Configuration.DatabaseName).RunAtom <bool>(c))
            {
                Logger.Warn("DatabaseManager", $"Database {Configuration.DatabaseName} not found. Creating it...");
                var x = R.DbCreate(Configuration.DatabaseName).Run(c);
            }
            UpdateConnectionsDatabase(Configuration.DatabaseName);

            Logger.Log("DatabaseManager", "Searching for database table definitions");
            Assembly a = Assembly.GetExecutingAssembly();

            string[] namespaces = a.GetTypes().Select(x => x.Namespace).Distinct().ToArray();
            foreach (string n in namespaces)
            {
                if (n.StartsWith("RemoteSigner.Database", StringComparison.InvariantCultureIgnoreCase))
                {
                    Logger.Log("DatabaseManager", $"Loading DB Data for namespace {n}");
                    InitTables(c, a, n);
                }
            }
        }
Example #10
0
 public static void dbinit()
 {
     Connection.Builder builder = r.Connection().Hostname("localhost").Port(28015);
     // connect
     Console.WriteLine("Floatzel is now loading EzioSoft RethinkDB Driver V2...");
     thonk = builder.Connect();
     // check if the database exists
     if (!(bool)r.DbList().Contains("FloatzelSharp").Run(thonk))
     {
         // it doesnt exist! make that database!
         Console.WriteLine("Database not detected! creating new database...");
         r.DbCreate("FloatzelSharp").Run(thonk);
         thonk.Use("FloatzelSharp");
         Console.WriteLine("Creating tables...");
         makeTables();
         Console.WriteLine("Database created!");
     }
     else
     {
         thonk.Use("FloatzelSharp");
         Console.WriteLine("Driver loaded!");
     }
     // check for legacy database stuff
     Console.WriteLine("Floatzel is now checking for 2.x database...");
     if ((bool)r.DbList().Contains("floatzel").Run(thonk))
     {
         oldthonk = builder.Connect();
         oldthonk.Use("floatzel");
         Console.WriteLine("Floatzel found 2.x database! Will convert data as its accessed");
         hasOld = true;
     }
     else
     {
         Console.WriteLine("Floatzel did not find 2.x databse!");
     }
 }
Example #11
0
 protected void CreateDb(string dbName)
 {
     R.DbCreate(dbName).Run(conn);
     R.Db(dbName).Wait_().Run(conn);
 }
Example #12
0
        public static int Main(string[] args)
        {
            const string rethinkHost = "localhost";
            const string redisHost   = "localhost";
            const string dbName      = "doc_stack_db";
            const string tableName   = "documents";

            //indexes
            const string name_client_user_index = "name_client_user";

            var ip = GetIp(rethinkHost);

            var c = R.Connection()
                    .Hostname(ip)
                    .Port(RethinkDBConstants.DefaultPort)
                    .Timeout(60)
                    .Connect();

            List <string> dbs = R.DbList().Run <List <string> >(c);

            if (!dbs.Contains(dbName))
            {
                R.DbCreate(dbName).Run(c);
            }
            var db = R.Db(dbName);

            List <string> tables = db.TableList().Run <List <string> >(c);

            if (!tables.Contains(tableName))
            {
                db.TableCreate(tableName).Run(c);
            }
            var documentTable = db.Table(tableName);

            List <string> indexes = documentTable.IndexList().Run(c);

            if (!indexes.Contains(name_client_user_index))
            {
                RethinkDb.Driver.Ast.ReqlFunction1 pathIx = row => { return(R.Array(row["name"], row["client"], row["user"])); };
                documentTable.IndexCreate("name_client_user", pathIx).Run(c);
                documentTable.IndexWait("name_client_user").Run(c);
            }

            try
            {
                var redis = OpenRedisConnection(redisHost).GetDatabase();

                var definition = new { id = "", name = "", size = 0, user = "", client = "", content = "" };

                while (true)
                {
                    string json = redis.ListLeftPopAsync("documents:process:0").Result;
                    if (json != null)
                    {
                        var document = JsonConvert.DeserializeAnonymousType(json, definition);
                        Console.WriteLine($"Document '{document.name}/{document.id}/{document.user}/{document.client}' will be persisted");
                        var now    = DateTime.UtcNow;
                        var toSave = new { id = document.id, user = document.user, client = document.client, name = document.name, document = document, inserted = now, updated = now, state = new[] { "persisted" } };

                        //first check if the document maybe already exists - right now we will just override
                        var x = new[] { "ocr-test2.png", "dummyClient", "dummyUser" };
                        //documentTable.GetAll(x).OptArg("index", "name_client_user");
                        //
                        documentTable.Insert(toSave).Run(c);
                    }
                    else
                    {
                        Thread.Sleep(500);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(ex.ToString());
                return(1);
            }
        }