Example #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SPDirectory" /> class with the specified cache directory.
        /// </summary>
        /// <param name="folder"></param>
        /// <param name="lockFactory"></param>
        /// <param name="cacheDirectory"></param>
        public SPDirectory(SPFolder folder, LockFactory lockFactory, Lucene.Net.Store.Directory cacheDirectory)
        {
            if (folder == null)
            {
                throw new ArgumentNullException("folder");
            }

            if (folder.Exists == false)
            {
                throw new ArgumentException("A folder was specified, however, the specified folder indicates that it does not exist.");
            }

            m_folderUrl = SPUtility.ConcatUrls(folder.ParentWeb.Url, folder.ServerRelativeUrl);

            m_site   = folder.ParentWeb.Site;
            m_web    = folder.ParentWeb;
            m_folder = new Lazy <SPFolder>(() => folder);

            if (lockFactory == null)
            {
                lockFactory = new SPLockFactory(m_folderUrl);
            }

            SetLockFactory(lockFactory);
            InitCacheDirectory(cacheDirectory);
            m_disposeOfSiteAndWeb = false;
        }
Example #2
0
        /// <summary>
        /// Initialize a new instance of the <see cref="SPDirectory"/> class with the specified cache directory.
        /// </summary>
        /// <param name="folderUrl"></param>
        /// <param name="lockFactory"></param>
        /// <param name="cacheDirectory"></param>
        public SPDirectory(string folderUrl, LockFactory lockFactory, Lucene.Net.Store.Directory cacheDirectory)
        {
            if (String.IsNullOrEmpty(folderUrl))
            {
                throw new ArgumentNullException("folderUrl");
            }

            m_folderUrl = folderUrl;

            m_folder = new Lazy <SPFolder>(() =>
            {
                lock (m_syncRoot)
                {
                    m_site = new SPSite(m_folderUrl, SPBaristaContext.Current.Site.UserToken);
                    m_web  = m_site.OpenWeb();
                    m_web.AllowUnsafeUpdates = true;
                    var folder = m_web.GetFolder(m_folderUrl);
                    if (folder.Exists == false)
                    {
                        throw new InvalidOperationException("The specified folder does not exist: " + folder.Url);
                    }
                    return(folder);
                }
            });

            if (lockFactory == null)
            {
                lockFactory = new SPLockFactory(m_folderUrl);
            }

            SetLockFactory(lockFactory);
            InitCacheDirectory(cacheDirectory);
            m_disposeOfSiteAndWeb = true;
        }