예제 #1
0
        public SPFileOutputStream(SPDirectory directory, SPFile file)
        {
            if (directory == null)
            {
                throw new ArgumentNullException("directory");
            }

            if (file == null)
            {
                throw new ArgumentNullException("file");
            }

            if (file.Exists == false)
            {
                throw new ArgumentException("A file object was passed, but the file does not exist. " + file.Url);
            }

            m_directory = directory;
            m_fileName  = file.Name;
            m_fileUrl   = SPUtility.ConcatUrls(file.Web.Url, file.ServerRelativeUrl);

            m_mutex = SPFileMutexManager.GrabMutex(m_fileUrl);
            m_mutex.WaitOne();
            try
            {
                m_indexOutput = m_directory.CacheDirectory.CreateOutput(file.Name);
            }
            finally
            {
                m_mutex.ReleaseMutex();
            }
        }
        public SPFileInputStream(SPDirectory directory, SPFile file)
        {
            if (directory == null)
            {
                throw new ArgumentNullException("directory");
            }

            if (file == null)
            {
                throw new ArgumentNullException("file");
            }

            var fileUrl = SPUtility.ConcatUrls(file.Web.Url, file.ServerRelativeUrl);

            m_directory = directory;

            m_mutex = SPFileMutexManager.GrabMutex(fileUrl);
            m_mutex.WaitOne();

            try
            {
                if (!m_directory.CacheDirectory.FileExists(file.Name))
                {
                    CreateOrUpdateCachedFile(file, directory);
                }
                else
                {
                    //Check the eTag.
                    var cachedETag = m_directory.ReadCachedFileETag(file.Name);

                    //If it doesn't match, re-retrieve the file from SharePoint.
                    if (cachedETag != file.ETag)
                    {
                        CreateOrUpdateCachedFile(file, directory);
                    }
                }

                m_indexInput = m_directory.CacheDirectory.OpenInput(file.Name);
            }
            finally
            {
                m_mutex.ReleaseMutex();
            }
        }