/// <summary> /// Deletes and de-indexes a file. /// </summary> /// <param name="provider">The provider.</param> /// <param name="fullName">The full name of the file to delete.</param> /// <returns><c>true</c> if the file was deleted, <c>false</c> otherwise.</returns> public static bool DeleteFile(IFilesStorageProviderV40 provider, string fullName) { if (provider == null) { throw new ArgumentNullException("provider"); } if (fullName == null) { throw new ArgumentNullException("fullName"); } if (fullName.Length == 0) { throw new ArgumentException("Full Name cannot be empty", "fullName"); } fullName = NormalizeFullName(fullName); bool done = provider.DeleteFile(fullName); if (!done) { return(false); } SearchClass.UnindexFile(provider.GetType().FullName + "|" + fullName, provider.CurrentWiki); Host.Instance.OnFileActivity(provider.GetType().FullName, fullName, null, FileActivity.FileDeleted); return(true); }
/// <summary> /// Stores and indexes a file. /// </summary> /// <param name="provider">The destination provider.</param> /// <param name="fullName">The full name.</param> /// <param name="source">The source stream.</param> /// <param name="overwrite"><c>true</c> to overwrite the existing file, <c>false</c> otherwise.</param> /// <returns><c>true</c> if the file was stored, <c>false</c> otherwise.</returns> public static bool StoreFile(IFilesStorageProviderV30 provider, string fullName, Stream source, bool overwrite) { if (provider == null) { throw new ArgumentNullException("provider"); } if (fullName == null) { throw new ArgumentNullException("fullName"); } if (fullName.Length == 0) { throw new ArgumentException("Full Name cannot be empty", "fullName"); } if (source == null) { throw new ArgumentNullException("source"); } fullName = NormalizeFullName(fullName); bool done = provider.StoreFile(fullName, source, overwrite); if (!done) { return(false); } if (overwrite) { SearchClass.UnindexFile(provider.GetType().FullName + "|" + fullName); } // Index the attached file string tempDir = Path.Combine(Environment.GetEnvironmentVariable("TEMP"), Guid.NewGuid().ToString()); if (!Directory.Exists(tempDir)) { Directory.CreateDirectory(tempDir); } string tempFile = Path.Combine(tempDir, Path.GetFileName(fullName)); source.Seek(0, SeekOrigin.Begin); using (FileStream temp = File.Create(tempFile)) { source.CopyTo(temp); } SearchClass.IndexFile(provider.GetType().FullName + "|" + fullName, tempFile); Directory.Delete(tempDir, true); Host.Instance.OnFileActivity(provider.GetType().FullName, fullName, null, FileActivity.FileUploaded); return(true); }
/// <summary> /// De-indexes all contents of a directory. /// </summary> /// <param name="provider">The provider.</param> /// <param name="directory">The directory.</param> private static void DeindexDirectory(IFilesStorageProviderV30 provider, string directory) { directory = NormalizeFullPath(directory); foreach (string sub in provider.ListDirectories(directory)) { DeindexDirectory(provider, sub); } foreach (string file in provider.ListFiles(directory)) { SearchClass.UnindexFile(provider.GetType().FullName + "|" + file); } }