Exemple #1
0
        public void RemoveUser(string username)
        {
            using (var transaction = _database.BeginTransaction())
            {
                if (!_users.TryGet(username, out var user))
                {
                    throw new CannotRemoveUserException($"The user '{username}' does not exist.");
                }

                _users.Remove(username);
                _usernamesByAccessToken.Remove(user.AccessToken);

                transaction.Commit();
            }
        }
Exemple #2
0
        public void PublishPlugin(byte[] plugin, string accessToken, DateTime publishDate)
        {
            Log.DebugFormat("Adding plugin ({0} bytes) to repository...", plugin.Length);

            IPluginPackageIndex pluginIndex;
            DateTime            builtTime;
            IReadOnlyList <SerializableChange> changes;

            byte[] icon;
            using (var stream = new MemoryStream(plugin))
                using (var archive = OpenPlugin(stream))
                {
                    pluginIndex = archive.Index;
                    changes     = archive.LoadChanges();
                    builtTime   = GetBuildTime(archive.ReadAssembly());
                    icon        = archive.ReadIcon()?.ReadToEnd();
                }
            var id = new PluginIdentifier(pluginIndex.Id, pluginIndex.Version);

            if (!Guid.TryParse(accessToken, out var token))
            {
                throw new InvalidUserTokenException($"'{accessToken}' is not a valid access token.");
            }

            using (var transaction = _database.BeginTransaction())
            {
                if (!_usernamesByAccessToken.TryGet(token, out var userName))
                {
                    throw new InvalidUserTokenException($"'{accessToken}' is not a valid access token.");
                }

                // TODO: Only throw a temper tantrum in case the plugin to be added differs from the plugin stored in this repository
                if (_pluginDescriptions.ContainsKey(id) || _plugins.ContainsKey(id))
                {
                    throw new PluginAlreadyPublishedException($"The plugin '{id}' already exists and cannot be modified.");
                }

                var publishedPlugin = new PublishedPlugin(pluginIndex)
                {
                    Publisher          = userName,
                    Identifier         = id,
                    BuildDate          = builtTime,
                    SizeInBytes        = plugin.Length,
                    PublishDate        = publishDate,
                    RequiredInterfaces = pluginIndex.ImplementedPluginInterfaces
                                         .Select(x => new PluginInterface(x.InterfaceTypename, x.InterfaceVersion)).ToList(),
                };
                _pluginDescriptions.Put(id, publishedPlugin);
                _plugins.Put(id, plugin);
                _pluginIcons.Put(id, icon);

                transaction.Commit();
                Log.InfoFormat("Added plugin '{0}' to repository!", id);
            }
        }