static public Dictionary<string, string> GetRepositories(Credentials.ServerCredentials credentials)
{
Dictionary<string, string> result = new Dictionary<string, string>();
// If no URL was provided, return empty result.
if (credentials.Address == null)
{
return result;
}
// Create session factory.
SessionFactory factory = SessionFactory.NewInstance();
Dictionary<string, string> cmisParameters = new Dictionary<string, string>();
cmisParameters[SessionParameter.BindingType] = BindingType.AtomPub;
cmisParameters[SessionParameter.AtomPubUrl] = credentials.Address.ToString();
cmisParameters[SessionParameter.User] = credentials.UserName;
cmisParameters[SessionParameter.Password] = credentials.Password.ToString();
IList<IRepository> repositories;
try
{
repositories = factory.GetRepositories(cmisParameters);
}
catch (DotCMIS.Exceptions.CmisPermissionDeniedException e)
{
Logger.Debug("CMIS server found, but permission denied. Please check username/password. " + Utils.ToLogString(e));
throw;
}
catch (CmisRuntimeException e)
{
Logger.Debug("No CMIS server at this address, or no connection. " + Utils.ToLogString(e));
throw;
}
catch (CmisObjectNotFoundException e)
{
Logger.Debug("No CMIS server at this address, or no connection. " + Utils.ToLogString(e));
throw;
}
catch (CmisConnectionException e)
{
Logger.Debug("No CMIS server at this address, or no connection. " + Utils.ToLogString(e));
throw;
}
catch (CmisInvalidArgumentException e)
{
Logger.Debug("Invalid URL, maybe Alfresco Cloud? " + Utils.ToLogString(e));
throw;
}
// Populate the result list with identifier and name of each repository.
foreach (IRepository repo in repositories)
{
if(!Utils.IsRepoNameHidden(repo.Name, ConfigManager.CurrentConfig.HiddenRepoNames))
{
result.Add(repo.Id, repo.Name);
}
}
return result;
}