Exemplo n.º 1
0
        private int AvailableRepositories()
        {
            User.RaiseMessage("Listing all (canonical) available CKAN repositories:");
            RepositoryList repositories = new RepositoryList();

            try
            {
                repositories = FetchMasterRepositoryList();
            }
            catch
            {
                User.RaiseError("Couldn't fetch CKAN repositories master list from {0}", Repository.default_repo_master_list.ToString());
                return(Exit.ERROR);
            }

            int maxNameLen = 0;

            foreach (Repository repository in repositories.repositories)
            {
                maxNameLen = Math.Max(maxNameLen, repository.name.Length);
            }

            foreach (Repository repository in repositories.repositories)
            {
                User.RaiseMessage("  {0}: {1}", repository.name.PadRight(maxNameLen), repository.uri);
            }

            return(Exit.OK);
        }
Exemplo n.º 2
0
        private int AddRepository(AddOptions options)
        {
            RegistryManager manager = Manager.CurrentInstance.RegistryManager;

            if (options.name == null)
            {
                User.RaiseMessage("add <name> [ <uri> ] - argument missing, perhaps you forgot it?");
                return(Exit.BADOPT);
            }

            if (options.uri == null)
            {
                RepositoryList repositoryList = new RepositoryList();

                try
                {
                    repositoryList = FetchMasterRepositoryList();
                }
                catch
                {
                    User.RaiseError("Couldn't fetch CKAN repositories master list from {0}", Repository.default_repo_master_list.ToString());
                    return(Exit.ERROR);
                }

                foreach (Repository candidate in repositoryList.repositories)
                {
                    if (String.Equals(candidate.name, options.name, StringComparison.OrdinalIgnoreCase))
                    {
                        options.name = candidate.name;
                        options.uri  = candidate.uri.ToString();
                    }
                }

                // Nothing found in the master list?
                if (options.uri == null)
                {
                    User.RaiseMessage("Name {0} not found in master list, please provide name and uri.", options.name);
                    return(Exit.BADOPT);
                }
            }

            log.DebugFormat("About to add repository '{0}' - '{1}'", options.name, options.uri);
            SortedDictionary <string, Repository> repositories = manager.registry.Repositories;

            if (repositories.ContainsKey(options.name))
            {
                User.RaiseMessage("Repository with name \"{0}\" already exists, aborting..", options.name);
                return(Exit.BADOPT);
            }

            repositories.Add(options.name, new Repository(options.name, options.uri));

            User.RaiseMessage("Added repository '{0}' - '{1}'", options.name, options.uri);
            manager.Save();

            return(Exit.OK);
        }