本文整理汇总了C#中IFileSystem.DeleteFile方法的典型用法代码示例。如果您正苦于以下问题:C# IFileSystem.DeleteFile方法的具体用法?C# IFileSystem.DeleteFile怎么用?C# IFileSystem.DeleteFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IFileSystem
的用法示例。
在下文中一共展示了IFileSystem.DeleteFile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Configure
/// <summary>
/// Configures the specified autorun.
/// </summary>
/// <param name="autorun">if set to <c>true</c> [autorun].</param>
/// <param name="fileSystem">The file system.</param>
public static void Configure(bool autorun, IFileSystem fileSystem)
{
var shortcutPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.StartMenu), "Media Browser 3", "Media Browser Server.lnk");
if (!Directory.Exists(Path.GetDirectoryName(shortcutPath)))
{
shortcutPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.StartMenu), "Emby", "Emby Server.lnk");
}
var startupPath = Environment.GetFolderPath(Environment.SpecialFolder.Startup);
// Remove lnk from old name
try
{
fileSystem.DeleteFile(Path.Combine(startupPath, Path.GetFileName(shortcutPath) ?? "Media Browser Server.lnk"));
}
catch
{
}
if (autorun)
{
//Copy our shortut into the startup folder for this user
File.Copy(shortcutPath, Path.Combine(startupPath, Path.GetFileName(shortcutPath) ?? "Emby Server.lnk"), true);
}
else
{
//Remove our shortcut from the startup folder for this user
fileSystem.DeleteFile(Path.Combine(startupPath, Path.GetFileName(shortcutPath) ?? "Emby Server.lnk"));
}
}
示例2: DeleteImages
public static void DeleteImages(GalleryImage image, IFileSystem fileSystem, string virtualRoot)
{
string imageVirtualPath = virtualRoot + "FullSizeImages/" + image.ImageFile;
fileSystem.DeleteFile(imageVirtualPath);
imageVirtualPath = virtualRoot + "WebImages/" + image.WebImageFile;
fileSystem.DeleteFile(imageVirtualPath);
imageVirtualPath = virtualRoot + "Thumbnails/" + image.ThumbnailFile;
fileSystem.DeleteFile(imageVirtualPath);
}
示例3: MongoDbRunner
/// <summary>
/// usage: local debugging
/// </summary>
private MongoDbRunner(IProcessWatcher processWatcher, IPortWatcher portWatcher, IFileSystem fileSystem, IMongoDbProcessStarter processStarter, IMongoBinaryLocator mongoBin, string dataDirectory)
{
_fileSystem = fileSystem;
_port = MongoDbDefaults.DefaultPort;
_mongoBin = mongoBin;
MakeMongoBinarysExecutable();
ConnectionString = "mongodb://localhost:{0}/".Formatted(_port);
if (processWatcher.IsProcessRunning(MongoDbDefaults.ProcessName) && !portWatcher.IsPortAvailable(_port))
{
State = State.AlreadyRunning;
return;
}
if (!portWatcher.IsPortAvailable(_port))
{
throw new MongoDbPortAlreadyTakenException("MongoDB can't be started. The TCP port {0} is already taken.".Formatted(_port));
}
_fileSystem.CreateFolder(dataDirectory);
_fileSystem.DeleteFile(@"{0}{1}{2}".Formatted(dataDirectory, System.IO.Path.DirectorySeparatorChar.ToString(), MongoDbDefaults.Lockfile));
_mongoDbProcess = processStarter.Start(_mongoBin.Directory, dataDirectory, _port, true);
State = State.Running;
}
示例4: StartUp
public void StartUp()
{
if (FileSystem == null)
{
FileSystem = IsolatedStorageFileSystem.GetForApplication();
if (FileSystem.FileExists(_LOG_FILE_PATH))
FileSystem.DeleteFile(_LOG_FILE_PATH);
}
}
示例5: MongoDbRunner
/// <summary>
/// usage: integration tests
/// </summary>
private MongoDbRunner(IPortPool portPool, IFileSystem fileSystem, IMongoDbProcessStarter processStarter, string dataDirectory)
{
_fileSystem = fileSystem;
_port = portPool.GetNextOpenPort();
ConnectionString = "mongodb://localhost:{0}/".Formatted(_port);
_dataDirectoryWithPort = "{0}_{1}".Formatted(dataDirectory, _port);
_fileSystem.CreateFolder(_dataDirectoryWithPort);
_fileSystem.DeleteFile(@"{0}\{1}".Formatted(_dataDirectoryWithPort, MongoDbDefaults.Lockfile));
_mongoDbProcess = processStarter.Start(BinariesDirectory, _dataDirectoryWithPort, _port);
State = State.Running;
}
示例6: Configure
/// <summary>
/// Configures the specified autorun.
/// </summary>
/// <param name="autorun">if set to <c>true</c> [autorun].</param>
/// <param name="fileSystem">The file system.</param>
public static void Configure(bool autorun, IFileSystem fileSystem)
{
var shortcutPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.StartMenu), "Emby", "Emby Server.lnk");
var startupPath = Environment.GetFolderPath(Environment.SpecialFolder.Startup);
if (autorun)
{
//Copy our shortut into the startup folder for this user
File.Copy(shortcutPath, Path.Combine(startupPath, Path.GetFileName(shortcutPath) ?? "Emby Server.lnk"), true);
}
else
{
//Remove our shortcut from the startup folder for this user
fileSystem.DeleteFile(Path.Combine(startupPath, Path.GetFileName(shortcutPath) ?? "Emby Server.lnk"));
}
}
示例7: RemoveMediaPath
/// <summary>
/// Deletes a shortcut from within a virtual folder, within either the default view or a user view
/// </summary>
/// <param name="fileSystem">The file system.</param>
/// <param name="virtualFolderName">Name of the virtual folder.</param>
/// <param name="mediaPath">The media path.</param>
/// <param name="appPaths">The app paths.</param>
/// <exception cref="System.IO.DirectoryNotFoundException">The media folder does not exist</exception>
public static void RemoveMediaPath(IFileSystem fileSystem, string virtualFolderName, string mediaPath, IServerApplicationPaths appPaths)
{
var rootFolderPath = appPaths.DefaultUserViewsPath;
var path = Path.Combine(rootFolderPath, virtualFolderName);
if (!Directory.Exists(path))
{
throw new DirectoryNotFoundException(string.Format("The media collection {0} does not exist", virtualFolderName));
}
var shortcut = Directory.EnumerateFiles(path, ShortcutFileSearch, SearchOption.AllDirectories).FirstOrDefault(f => fileSystem.ResolveShortcut(f).Equals(mediaPath, StringComparison.OrdinalIgnoreCase));
if (!string.IsNullOrEmpty(shortcut))
{
fileSystem.DeleteFile(shortcut);
}
}
示例8: MongoDbRunner
/// <summary>
/// usage: local debugging
/// </summary>
private MongoDbRunner(IProcessWatcher processWatcher, IPortWatcher portWatcher, IFileSystem fileSystem, IMongoDbProcessStarter processStarter)
{
_fileSystem = fileSystem;
_port = MongoDbDefaults.DefaultPort;
ConnectionString = "mongodb://localhost:{0}/".Formatted(_port);
if (processWatcher.IsProcessRunning(MongoDbDefaults.ProcessName) && !portWatcher.IsPortAvailable(_port))
{
State = State.AlreadyRunning;
return;
}
if (!portWatcher.IsPortAvailable(_port))
{
throw new MongoDbPortAlreadyTakenException("MongoDB can't be started. The TCP port {0} is already taken.".Formatted(_port));
}
_fileSystem.CreateFolder(MongoDbDefaults.DataDirectory);
_fileSystem.DeleteFile(@"{0}\{1}".Formatted(MongoDbDefaults.DataDirectory, MongoDbDefaults.Lockfile));
_mongoDbProcess = processStarter.Start(BinariesDirectory, MongoDbDefaults.DataDirectory, _port, true);
State = State.Running;
}
示例9: PerformFileDeletionOperation
/// <summary>
/// Performs a file deletion.
/// </summary>
/// <param name="fileSystem">The file system.</param>
/// <param name="file">The file to delete.</param>
/// <param name="execute">if set to true, the operation gets executed.</param>
private void PerformFileDeletionOperation(IFileSystem fileSystem, IFileInfo file, bool execute)
{
var eventArgs = new FileDeletionEventArgs(file.FullName, file.Length);
this.OnDeletingFile(eventArgs);
if (execute)
{
try
{
fileSystem.DeleteFile(file);
this.OnDeletedFile(eventArgs);
}
catch (AccessException)
{
this.OnFileDeletionError(new FileDeletionErrorEventArgs(file));
}
}
}
示例10: DeleteAttachmentFile
public static void DeleteAttachmentFile(IFileSystem fileSystem, FileAttachment attachment, string basePath)
{
if (attachment == null) { return; }
if (string.IsNullOrEmpty(basePath)) { return; }
if (fileSystem.FileExists(basePath + attachment.ServerFileName))
{
fileSystem.DeleteFile(basePath + attachment.ServerFileName);
}
}
示例11: DeleteOldFiles
/// <summary>
/// Deletes all but the most recent files.
/// </summary>
/// <param name="fileSystem">The abstract file system to search the root directory of.</param>
/// <param name="maxFileAge">The maximum age of the files to keep, or <c>null</c>.</param>
/// <param name="maxAppInstanceCount">The maximum number of app instances to keep, or <c>null</c>.</param>
/// <param name="maxTotalFileSize">The maximum total file size to keep, or <c>null</c>.</param>
public static void DeleteOldFiles( IFileSystem fileSystem, TimeSpan? maxFileAge, int? maxAppInstanceCount, long? maxTotalFileSize )
{
var allFiles = FindAllFiles(fileSystem);
var filesToKeep = FindLatestFiles(fileSystem, maxFileAge, maxAppInstanceCount, maxTotalFileSize);
foreach( var file in allFiles )
{
bool keepFile = false;
foreach( var f in filesToKeep )
{
if( DataStore.Comparer.Equals(file.DataStoreName, f.DataStoreName) )
{
keepFile = true;
break;
}
}
if( keepFile )
continue;
else
fileSystem.DeleteFile(file.DataStoreName);
}
}
示例12: DeleteAllFiles
public static void DeleteAllFiles(SharedFileFolder folder, IFileSystem fileSystem, string fileVirtualBasePath, SharedFilesConfiguration config)
{
// method implemented by Jean-Michel 2008-07-31
// TODO: implement check whether versioning is enabled before calling this method
// if we are keeping versions we should not delete the files
if (folder == null) { return; }
if (fileSystem == null) { return; }
if (string.IsNullOrEmpty(fileVirtualBasePath)) { return; }
if (folder.FolderId == -1) { return; }
ArrayList folders = new ArrayList();
ArrayList files = new ArrayList();
using (IDataReader reader = SharedFile.GetSharedFiles(folder.ModuleId, folder.FolderId))
{
while (reader.Read())
{
files.Add(Convert.ToInt32(reader["ItemID"]));
}
}
using (IDataReader reader = SharedFileFolder.GetSharedFolders(folder.ModuleId, folder.FolderId))
{
while (reader.Read())
{
folders.Add(Convert.ToInt32(reader["FolderID"]));
}
}
foreach (int id in files)
{
SharedFile sharedFile = new SharedFile(folder.ModuleId, id);
sharedFile.Delete();
if (!config.EnableVersioning)
{
fileSystem.DeleteFile(VirtualPathUtility.Combine(fileVirtualBasePath, sharedFile.ServerFileName));
}
}
foreach (int id in folders)
{
SharedFileFolder subFolder = new SharedFileFolder(folder.ModuleId, id);
DeleteAllFiles(subFolder, fileSystem, fileVirtualBasePath, config);
SharedFileFolder.DeleteSharedFileFolder(id);
}
}
示例13: RestoreHistoryFile
public static bool RestoreHistoryFile(
int historyId,
IFileSystem fileSystem,
string virtualSourcePath,
string virtualHistoryPath)
{
bool historyRestored = false;
if (string.IsNullOrEmpty(virtualSourcePath)) { return historyRestored; }
if (string.IsNullOrEmpty(virtualHistoryPath)) { return historyRestored; }
if (fileSystem == null) { return historyRestored; }
int itemId = 0;
int moduleId = 0;
string historyFriendlyName = string.Empty;
string historyOriginalName = string.Empty;
string historyServerName = string.Empty;
DateTime historyUploadDate = DateTime.Now;
int historyUploadUserID = 0;
int historyFileSize = 0;
using (IDataReader reader = SharedFile.GetHistoryFileAsIDataReader(historyId))
{
if (reader.Read())
{
itemId = Convert.ToInt32(reader["ItemID"]);
moduleId = Convert.ToInt32(reader["ModuleID"]);
historyFriendlyName = reader["FriendlyName"].ToString();
historyOriginalName = reader["OriginalFileName"].ToString();
historyServerName = reader["ServerFileName"].ToString();
historyFileSize = Convert.ToInt32(reader["SizeInKB"]);
historyUploadUserID = Convert.ToInt32(reader["UploadUserID"]);
historyUploadDate = DateTime.Parse(reader["UploadDate"].ToString());
}
}
SharedFile sharedFile = new SharedFile(moduleId, itemId);
CreateHistory(sharedFile, fileSystem, virtualSourcePath, virtualHistoryPath);
//File.Move(Path.Combine(historyPath, Path.GetFileName(historyServerName)), Path.Combine(sourcePath, Path.GetFileName(historyServerName)));
fileSystem.MoveFile(
VirtualPathUtility.Combine(virtualHistoryPath, historyServerName),
VirtualPathUtility.Combine(virtualSourcePath, historyServerName),
true);
sharedFile.ServerFileName = historyServerName;
sharedFile.OriginalFileName = historyOriginalName;
sharedFile.FriendlyName = historyFriendlyName;
sharedFile.SizeInKB = historyFileSize;
sharedFile.UploadDate = historyUploadDate;
sharedFile.UploadUserId = historyUploadUserID;
historyRestored = sharedFile.Save();
SharedFile.DeleteHistory(historyId);
fileSystem.DeleteFile(VirtualPathUtility.Combine(virtualHistoryPath, historyServerName));
return historyRestored;
}
示例14: DeleteHistoryFile
public static void DeleteHistoryFile(int id, IFileSystem fileSystem, string virtualHistoryPath)
{
string historyServerName = string.Empty;
using (IDataReader reader = SharedFile.GetHistoryFileAsIDataReader(id))
{
if (reader.Read())
{
historyServerName = reader["ServerFileName"].ToString();
}
}
if (historyServerName.Length > 0)
{
//File.Delete(Path.Combine(historyPath, Path.GetFileName(historyServerName)));
string fullPath = VirtualPathUtility.Combine(virtualHistoryPath, historyServerName);
fileSystem.DeleteFile(fullPath);
}
}
示例15: RemoveOldFile
internal static void RemoveOldFile(IFileSystem fileSystem)
{
string oldFile = typeof(Program).Assembly.Location + ".old";
try
{
if (fileSystem.FileExists(oldFile))
{
fileSystem.DeleteFile(oldFile);
}
}
catch
{
// We don't want to block the exe from usage if anything failed
}
}