本文整理汇总了C#中IFileSystem.FileExists方法的典型用法代码示例。如果您正苦于以下问题:C# IFileSystem.FileExists方法的具体用法?C# IFileSystem.FileExists怎么用?C# IFileSystem.FileExists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IFileSystem
的用法示例。
在下文中一共展示了IFileSystem.FileExists方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetUp
public void SetUp()
{
string nestedDependencyFilename = Path.Combine("a", "b", "variables.less");
string nestedDependencyText = "@import \"dependency.less\";";
dependencyFilename = Path.Combine("a", "b", "dependency.less");
var dependencyText = "@color: #4D926F;";
source = "@import \"variables.less\";#header {color: @color;}h2 {color: @color;}";
expected = "#header{color:#4d926f}h2{color:#4d926f}";
arguments = new Dictionary<string, object> {
{
"item",
new Dictionary<string, object> {
{ "filename", Path.Combine("a", "b", "c.less") }
}
}
};
fileSystem = Substitute.For<IFileSystem>();
fileSystem.FileExists(nestedDependencyFilename).Returns(true);
fileSystem.ReadStringFromFile(nestedDependencyFilename).Returns(nestedDependencyText);
fileSystem.FileExists(dependencyFilename).Returns(true);
fileSystem.ReadStringFromFile(dependencyFilename).Returns(dependencyText);
lessFilter = new LessFilter(fileSystem);
}
示例2: Execute
public static string Execute(string fileParameterValue, IFileSystem fileSystem)
{
if (string.IsNullOrEmpty(fileParameterValue))
{
throw new ArgumentException(Resources.FileParameterMustBeSpecified);
}
if (!fileParameterValue.EndsWith(".ps1", StringComparison.OrdinalIgnoreCase))
{
var error = string.Format(CultureInfo.CurrentCulture,
Resources.PowerShellScriptFileMustBeSpecifiedFormat,
fileParameterValue);
throw new ArgumentException(error);
}
var filePath = fileSystem.GetFullPath(fileParameterValue);
if (!fileSystem.FileExists(filePath))
{
var error = string.Format(CultureInfo.CurrentCulture,
Resources.PowerShellScriptFileDoesNotExistFormat,
fileParameterValue);
throw new ArgumentException(error);
}
return filePath;
}
示例3: GetReizedUrl
private string GetReizedUrl(IFileSystem fs, string imageSize)
{
string resizedUrl = ImagesUtility.GetResizedPath(ImageUrl, imageSize);
if (fs.FileExists(resizedUrl))
return resizedUrl;
return ImageUrl;
}
示例4: PackageReferenceFile
/// <summary>
/// Create a new instance of PackageReferenceFile, taking into account the project name.
/// </summary>
/// <remarks>
/// If projectName is not empty and the file packages.<projectName>.config
/// exists, use it. Otherwise, use the value specified by 'path' for the config file name.
/// </remarks>
public PackageReferenceFile(IFileSystem fileSystem, string path, string projectName)
{
if (fileSystem == null)
{
throw new ArgumentNullException("fileSystem");
}
if (String.IsNullOrEmpty(path))
{
throw new ArgumentException(CommonResources.Argument_Cannot_Be_Null_Or_Empty, "path");
}
_fileSystem = fileSystem;
if (!String.IsNullOrEmpty(projectName))
{
string pathWithProjectName = ConstructPackagesConfigFromProjectName(projectName);
if (_fileSystem.FileExists(pathWithProjectName))
{
_path = pathWithProjectName;
}
}
if (_path == null)
{
_path = path;
}
}
示例5: AddMediaPath
/// <summary>
/// Adds an additional mediaPath to an existing 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="path">The path.</param>
/// <param name="appPaths">The app paths.</param>
public static void AddMediaPath(IFileSystem fileSystem, string virtualFolderName, string path, IServerApplicationPaths appPaths)
{
if (string.IsNullOrWhiteSpace(path))
{
throw new ArgumentNullException("path");
}
if (!fileSystem.DirectoryExists(path))
{
throw new DirectoryNotFoundException("The path does not exist.");
}
var rootFolderPath = appPaths.DefaultUserViewsPath;
var virtualFolderPath = Path.Combine(rootFolderPath, virtualFolderName);
var shortcutFilename = fileSystem.GetFileNameWithoutExtension(path);
var lnk = Path.Combine(virtualFolderPath, shortcutFilename + ShortcutFileExtension);
while (fileSystem.FileExists(lnk))
{
shortcutFilename += "1";
lnk = Path.Combine(virtualFolderPath, shortcutFilename + ShortcutFileExtension);
}
fileSystem.CreateShortcut(lnk, path);
}
示例6: WriteSolution
public string WriteSolution(IFileSystem fs, string script, IVisualStudioSolution solution, IList<ProjectItem> nestedItems = null)
{
if (nestedItems == null)
{
nestedItems = new List<ProjectItem>();
}
var launcher = Path.Combine(fs.TempPath, "launcher-" + Guid.NewGuid().ToString() + ".sln");
if (fs.FileExists(launcher))
{
fs.FileDelete(launcher);
}
var currentDir = fs.CurrentDirectory;
var scriptcsPath = Path.Combine(fs.HostBin, "scriptcs.exe");
var scriptcsArgs = string.Format("{0} -debug -loglevel info", script);
_root = new DirectoryInfo { Name = "Solution Items", FullPath = currentDir};
var projectGuid = Guid.NewGuid();
solution.AddScriptcsProject(scriptcsPath, currentDir, scriptcsArgs, false, projectGuid);
GetDirectoryInfo(fs, currentDir, _root);
AddDirectoryProject(solution, fs, _root, _nullGuid, nestedItems);
solution.AddGlobal(projectGuid, nestedItems);
fs.WriteToFile(launcher, solution.ToString());
return launcher;
}
示例7: ExtractFont
internal static string ExtractFont(string name, IApplicationPaths paths, IFileSystem fileSystem)
{
var filePath = Path.Combine(paths.ProgramDataPath, "fonts", name);
if (fileSystem.FileExists(filePath))
{
return filePath;
}
var namespacePath = typeof(PlayedIndicatorDrawer).Namespace + ".fonts." + name;
var tempPath = Path.Combine(paths.TempDirectory, Guid.NewGuid().ToString("N") + ".ttf");
fileSystem.CreateDirectory(Path.GetDirectoryName(tempPath));
using (var stream = typeof(PlayedIndicatorDrawer).Assembly.GetManifestResourceStream(namespacePath))
{
using (var fileStream = new FileStream(tempPath, FileMode.Create, FileAccess.Write, FileShare.Read))
{
stream.CopyTo(fileStream);
}
}
fileSystem.CreateDirectory(Path.GetDirectoryName(filePath));
try
{
fileSystem.CopyFile(tempPath, filePath, false);
}
catch (IOException)
{
}
return tempPath;
}
示例8: StreamFile
public StreamFile(IFileSystem fileSystem, string path, bool readOnly)
{
file = fileSystem.FileExists(path) ? fileSystem.OpenFile(path, readOnly) : fileSystem.CreateFile(path);
endPointer = file.Length;
fileStream = new StreamFileStream(this);
ownsFile = true;
}
示例9: StartUp
public void StartUp()
{
if (FileSystem == null)
{
FileSystem = IsolatedStorageFileSystem.GetForApplication();
if (FileSystem.FileExists(_LOG_FILE_PATH))
FileSystem.DeleteFile(_LOG_FILE_PATH);
}
}
示例10: FillAssignmentDetailsFromXml
public static Assignment FillAssignmentDetailsFromXml(Assignment a, IFileSystem fileSystem, bool includeServerFiles)
{
if (a == null)
{
return null; //no active assignment
}
string path = Path.Combine(a.Path, "assignment.xml");
if (fileSystem.FileExists(path))
{
XmlDocument doc = fileSystem.LoadXml(path);
a.FriendlyName = GetNodeValue(doc, "Assignment/DisplayName");
//a.Tagline = GetNodeValue(doc, "Assignment/Hint");
a.Difficulty = int.Parse(GetNodeValue(doc, "Assignment/Difficulty"));
a.Author = GetNodeValue(doc, "Assignment/Author");
a.Category = GetNodeValue(doc, "Assignment/Category");
a.InterfaceNameToImplement = GetNodeValue(doc, "Assignment/Rules/InterfaceNameToImplement");
a.ClassNameToImplement = GetNodeValue(doc, "Assignment/Rules/ClassNameToImplement");
//a.ClassFileName = GetNodeValue(doc, "Assignment/Files/ClassFile");
//a.InterfaceFileName = GetNodeValue(doc, "Assignment/Files/InterfaceFile");
//a.UnitTestClientFileName = GetNodeValue(doc, "Assignment/Files/NunitTestFileClient");
//a.UnitTestServerFileName = GetNodeValue(doc, "Assignment/Files/NunitTestFileServer");
//a.CaseFileName = GetNodeValue(doc, "Assignment/Files/Case");
a.AssignmentFiles = new List<AssignmentFile>();
XmlNode fileNode = doc.SelectSingleNode("Assignment/Files");
foreach (XmlNode fileChildNode in fileNode.ChildNodes)
{
string nodeName = fileChildNode.Name;
string fileName = fileChildNode.InnerText;
string filepath = Path.Combine(a.Path, fileName);
if (File.Exists(filepath))
{
if (includeServerFiles || (nodeName != "NunitTestFileServer" && nodeName != "ServerFileToCopy"))
{
AssignmentFile assignmentFile = new AssignmentFile();
assignmentFile.Name = nodeName;
assignmentFile.FileName = fileName;
assignmentFile.Data = FacadeHelpers.ReadByteArrayFromFile(filepath);
a.AssignmentFiles.Add(assignmentFile);
}
}
}
}
else
{
throw new ApplicationException("Details for the assignment could not be found");
}
return a;
}
示例11: FileTaskResult
/// <summary>
/// Initializes a new instance of the <see cref="FileTaskResult"/> class from a <see cref="FileInfo"/>.
/// </summary>
/// <param name="file">The <see cref="FileInfo"/>.</param>
/// <param name="deleteAfterMerge">Delete file after merging.</param>
/// <param name="fileSystem">IFileSystem instance, allows this task to interact with the file system in a testable way.</param>
public FileTaskResult(FileInfo file, bool deleteAfterMerge, IFileSystem fileSystem)
{
this.deleteAfterMerge = deleteAfterMerge;
this.dataSource = file;
this.fileSystem = fileSystem;
if (!fileSystem.FileExists(file.FullName))
{
throw new CruiseControlException("File not found: " + file.FullName);
}
}
示例12: Delete
public static IFileInfo Delete(IFileSystem fileSystem, string path) {
var fi = Substitute.For<IFileInfo>();
fi.FullName.Returns(path);
fi.Exists.Returns(false);
fi.Directory.Returns((IDirectoryInfo)null);
fileSystem.FileExists(path).Returns(false);
try {
fileSystem.GetFileAttributes(path).Throws<FileNotFoundException>();
} catch (IOException) { }
return fi;
}
示例13: DefaultPackagePathResolver
public DefaultPackagePathResolver(IFileSystem fileSystem, bool useSideBySidePaths)
{
if (fileSystem == null) {
throw new ArgumentNullException("fileSystem");
}
_fileSystem = fileSystem;
bool excludeVersionMarkerDoesntExist = !_fileSystem.FileExists("ExcludeVersion");
_useSideBySidePaths = excludeVersionMarkerDoesntExist && useSideBySidePaths;
if (!useSideBySidePaths)
_fileSystem.AddFileWithCheck("ExcludeVersion", (Stream st) => { st.WriteByte(49); st.Flush(); });
}
示例14: RepositoryManager
/// <summary>
/// Initializes a new instance of the <see cref="RepositoryManager"/> class.
/// </summary>
/// <param name="repositoryConfig">The repository.config file to parse.</param>
/// <param name="repositoryEnumerator">The repository enumerator.</param>
/// <param name="fileSystem"> </param>
/// <example>Can be a direct path to a repository.config file</example>
///
/// <example>Can be a path to a directory, which will recursively locate all contained repository.config files</example>
public RepositoryManager(string repositoryConfig, IRepositoryEnumerator repositoryEnumerator, IFileSystem fileSystem)
{
Contract.Requires(fileSystem != null);
this.fileSystem = fileSystem;
if (fileSystem.FileExists(repositoryConfig) && repositoryConfig.EndsWith("repositories.config"))
RepositoryConfig = new FileInfo(fileSystem.GetFullPath(repositoryConfig));
else
throw new ArgumentOutOfRangeException("repository");
PackageReferenceFiles = repositoryEnumerator.GetPackageReferenceFiles(RepositoryConfig);// GetPackageReferenceFiles();
}
示例15: WritableXapFile
protected WritableXapFile(string inputPath, string outputPath, IFileSystem fileSystem)
: base(inputPath, fileSystem)
{
FileSystem = fileSystem;
OutputPath = outputPath;
if (fileSystem.FileExists(outputPath))
fileSystem.FileDelete(outputPath);
OutputArchive = fileSystem.OpenArchive(OutputPath, ZipArchiveMode.Create);
Debug.Assert(OutputArchive != null);
}