Пример #1
0
        public static void run()
        {
            ConfigurationDB db = new ConfigurationDB("myStuff.db");

            Console.WriteLine($"Database is at {db.DatabaseFileName}");

            var guid = Guid.NewGuid();

            showExample <Guid>(db, "Guid", "MyGuid", "General.UI", guid, Guid.Empty);

            var name = "MyNameText";

            showExample <string>(db, "String", "MyName", "General.UI", name, string.Empty);

            var myFloat = 3.14f;

            showExample <float>(db, "Float", "MyName", "General.UI", myFloat, 0);

            var myDate = DateTime.Now;

            showExample <DateTime>(db, "DateTime", "myDate", "General.UI", myDate, DateTime.MinValue);

            var myColor = System.Drawing.Color.FromArgb(101, 102, 103, 104);

            showExample <System.Drawing.Color>(db, "Color", "myColor", "General.UI", myColor, System.Drawing.Color.FromArgb(0, 0, 0, 0));

            var myTimespan = TimeSpan.FromSeconds(1234);

            showExample <TimeSpan>(db, "TimeSpan", "myTimespan", "General.UI", myTimespan, TimeSpan.Zero);

            var mByteArray = new byte[] { 101, 102, 103, 104 };

            showExample <byte[]>(db, "Byte[]", "mByteArray", "General.UI", mByteArray, new byte[0]);
        }
Пример #2
0
        public static void run()
        {
            var db  = new NoSqliteStorage("robops_servidores.db");
            var cfg = new ConfigurationDB("robops_servidores.db");

            int comecarPagina = cfg.GetConfig("LastPage", "", 1440);

            // catalogar todos os servidores
            for (int i = comecarPagina; ; i++)
            {
                var resultado = FetchHelper.FetchResourceJson <ConsultaServidores>(buildJsonUri(i));

                Console.WriteLine($"{DateTime.Now.ToLongTimeString()} Pagina {i} - {resultado.data.Length} lidos");
                db.Store(resultado.data, d => d.id);
                cfg.SetConfig("LastPage", "", i);

                //foreach (var d in resultado.data)
                //{
                //    db.Store(d.id, d);
                //}

                if (resultado.data.Length < 50)
                {
                    break; // terminou
                }
            }
        }
Пример #3
0
 private static void showExample <T>(ConfigurationDB db, string typeName, string key, string category, T valueToInsert, T defaultValue)
 {
     // force delete due to multiple executions
     db.RemoveConfig(key, category);
     Console.WriteLine($"---{typeName} example---");
     Console.WriteLine($"Current {typeName}: {db.GetConfig(key, category, defaultValue)}");
     Console.WriteLine($"Saving a new {typeName}: {valueToInsert}");
     db.SetConfig(key, category, valueToInsert);
     Console.WriteLine($"Current {typeName}: {db.GetConfig(key, category, defaultValue)}");
 }
Пример #4
0
        public void Config_InMemory_BaseTests()
        {
            var memDb = SqliteDB.CreateInMemory();
            var cfg   = ConfigurationDB.FromDB(memDb);

            Assert.Equal(":Empty:", cfg.GetConfig("test", "cat", ":Empty:"));

            cfg.SetConfig("test", "cat", "myValue");
            Assert.Equal("myValue", cfg.GetConfig("test", "cat", ":Empty:"));
        }
Пример #5
0
        public void Config_InMemory_Nulls()
        {
            var memDb = SqliteDB.CreateInMemory();
            var cfg   = ConfigurationDB.FromDB(memDb);

            Assert.Equal(":Empty:", cfg.GetConfig("null", "cat", ":Empty:"));

            cfg.SetConfig <string>("null", "cat", null);
            Assert.Null(cfg.GetConfig("null", "cat", ":Empty:"));
        }