Beispiel #1
0
        public PluginRepository(IDatabase database, bool newlyCreated)
        {
            _database = database;
            _users    = _database.GetOrCreateDictionary <string, User>("Users");
            _usernamesByAccessToken = _database.GetOrCreateDictionary <Guid, string>("UsersByAccessToken");
            _plugins            = _database.GetOrCreateDictionary <PluginIdentifier, byte[]>("Plugins");
            _pluginIcons        = _database.GetOrCreateDictionary <PluginIdentifier, byte[]>("PluginIcons");
            _pluginDescriptions = _database.GetOrCreateDictionary <PluginIdentifier, PublishedPlugin>("PluginDescriptions");

            if (newlyCreated)
            {
                AddUser("root", "root@home", null);
            }
        }
Beispiel #2
0
        public Task OpenAsync()
        {
            return(_scheduler.StartNew(() =>
            {
                try
                {
                    var databasePath = Path.Combine(Constants.ApplicationData, "Storage.db");
                    Log.InfoFormat("Opening alarm database '{0}'...", databasePath);

                    Directory.CreateDirectory(Constants.ApplicationData);
                    _database = Database.OpenOrCreate(databasePath, new[] { typeof(Alarm), typeof(Device2) });
                    _alarms = _database.GetDictionary <Guid, Alarm>("Alarms");
                    _devices = _database.GetDictionary <Guid, Device2>("Devices");

                    Log.InfoFormat("Alarm database opened!");
                }
                catch (Exception e)
                {
                    Log.FatalFormat("Unable to open alarm database: {0}", e);
                }
            }));
        }