Esempio n. 1
0
        /// <summary>
        /// Connect to a CMIS server and get a CMIS session that can be used for further CMIS operations.
        /// </summary>
        public static ISession GetCmisSession(Uri url, UserCredentials credentials, string repositoryId)
        {
            Dictionary<string, string> parameters = GetParameters();
            parameters[SessionParameter.AtomPubUrl] = url.ToString();
            parameters[SessionParameter.User] = credentials.UserName;
            parameters[SessionParameter.Password] = (string)credentials.Password;
            parameters[SessionParameter.RepositoryId] = repositoryId;

            // Create session factory.
            SessionFactory factory = SessionFactory.NewInstance();

            // Create session.
            ISession session = factory.CreateSession(parameters);
            Logger.Info("VendorName: " + session.RepositoryInfo.VendorName);
            Logger.Info("ProductName: " + session.RepositoryInfo.ProductName);
            Logger.Info("ProductVersion: " + session.RepositoryInfo.ProductVersion);
            Logger.Info("CmisVersionSupported: " + session.RepositoryInfo.CmisVersionSupported);
            Logger.Info("Name: " + session.RepositoryInfo.Name);
            Logger.Info("Description: " + session.RepositoryInfo.Description);
            return session;
        }
Esempio n. 2
0
        /// <summary>
        /// Get the sub-folders of a particular CMIS folder.
        /// </summary>
        /// <returns>Full path of each sub-folder, including leading slash.</returns>
        public static string[] GetSubfolders(string repositoryId, string path,
            Uri url, UserCredentials credentials)
        {
            if (string.IsNullOrEmpty(path))
            {
                throw new ArgumentException("path");
            }

            List<string> result = new List<string>();

            // Connect to the CMIS repository.
            ISession session = Auth.Auth.GetCmisSession(url, credentials, repositoryId);

            // Get the folder.
            IFolder folder;
            try
            {
                folder = (IFolder)session.GetObjectByPath(path);
            }
            catch (Exception ex)
            {
                Logger.Warn(String.Format("CmisUtils | exception when session GetObjectByPath for {0}", path), ex);
                return result.ToArray();
            }

            // Debug the properties count, which allows to check whether a particular CMIS implementation is compliant or not.
            // For instance, IBM Connections is known to send an illegal count.
            Logger.Info("CmisUtils | folder.Properties.Count:" + folder.Properties.Count.ToString());

            // Get the folder's sub-folders.
            IItemEnumerable<ICmisObject> children = folder.GetChildren();

            // Return the full path of each of the sub-folders.
            foreach (var subfolder in children.OfType<IFolder>())
            {
                result.Add(subfolder.Path);
            }
            return result.ToArray();
        }