本文整理汇总了C#中FileSystem.FileExists方法的典型用法代码示例。如果您正苦于以下问题:C# FileSystem.FileExists方法的具体用法?C# FileSystem.FileExists怎么用?C# FileSystem.FileExists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileSystem
的用法示例。
在下文中一共展示了FileSystem.FileExists方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FileExists
public void FileExists()
{
var curDirectory = Directory.GetCurrentDirectory();
var existingFile = Path.Combine(curDirectory, "../../" + fileName);
var fileSystem = new FileSystem();
Assert.IsTrue(fileSystem.FileExists(existingFile));
var notExistingFile = Path.Combine(curDirectory, "../../" + notExisting);
Assert.IsFalse(fileSystem.FileExists(notExistingFile));
}
示例2: Correctly_Reports_File_Exists
public void Correctly_Reports_File_Exists()
{
writeSampleFile();
IFileSystem fileSystem = new FileSystem(null);
Assert.AreEqual(true, fileSystem.FileExists("test.txt"));
Assert.AreEqual(false, fileSystem.FileExists("nonExistentFile.txt"));
}
示例3: Test_FileSystem_That_File_Delete_Removes_File
public void Test_FileSystem_That_File_Delete_Removes_File()
{
var fileSystem = new FileSystem();
var path = Path.Combine(TestContext.DeploymentDirectory, @"IO\1.txt");
fileSystem.DeleteFile(path);
Assert.IsFalse(fileSystem.FileExists(path));
// cleanup
using(fileSystem.OpenFile(path, FileMode.OpenOrCreate)) {; }
Assert.IsTrue(fileSystem.FileExists(path));
}
示例4: ForSolution
public static PersistenceExpression<Solution> ForSolution(Solution target)
{
var file = "{0}-{1}.config".ToFormat(typeof(Solution).Name, Guid.NewGuid());
var fileSystem = new FileSystem();
if (fileSystem.FileExists(file))
{
fileSystem.DeleteFile(file);
}
var writer = ObjectBlockWriter.Basic(new RippleBlockRegistry());
var contents = writer.Write(target);
Debug.WriteLine(contents);
fileSystem.WriteStringToFile(file, contents);
var reader = SolutionLoader.Reader();
var specification = new PersistenceSpecification<Solution>(x =>
{
var fileContents = fileSystem.ReadStringFromFile(file);
var readValue = Solution.Empty();
reader.Read(readValue, fileContents);
fileSystem.DeleteFile(file);
return readValue;
});
specification.Original = target;
return new PersistenceExpression<Solution>(specification);
}
示例5: LoadFrom
public static SolutionConfig LoadFrom(string directory)
{
var fileSystem = new FileSystem();
var file = directory.AppendPath(FileName);
return fileSystem.FileExists(file)
? fileSystem.LoadFromFile<SolutionConfig>(file)
: null;
}
示例6: buildDriver
protected override IWebDriver buildDriver()
{
var fileSystem = new FileSystem();
var settings = StoryTellerEnvironment.Get<SerenityEnvironment>();
return fileSystem.FileExists(settings.WorkingDir, File)
? new ChromeDriver(settings.WorkingDir)
: new ChromeDriver();
}
示例7: CompressingJpgResultsInSmallerFile
public void CompressingJpgResultsInSmallerFile()
{
// Arrange
var fileSystem = new FileSystem();
const string fileToCompress = TestConstants.ExistingJpgFullFileName;
var compressor = new JpgCompressor();
const string newFileName = "CompressedResult.jpg";
// Act
compressor.Compress(fileToCompress, newFileName);
// Assert
Assert.IsTrue(fileSystem.FileExists(fileToCompress));
Assert.IsTrue(fileSystem.FileExists(newFileName));
Assert.IsTrue(fileSystem.GetFileLength(fileToCompress) > 0);
Assert.IsTrue(fileSystem.GetFileLength(newFileName) > 0);
Assert.IsTrue(fileSystem.GetFileLength(fileToCompress) > fileSystem.GetFileLength(newFileName));
}
示例8: ReadFrom
public static IEnumerable<Input> ReadFrom(string directory)
{
var fileSystem = new FileSystem();
string file = directory.AppendPath(File);
if (!fileSystem.FileExists(file))
{
return Enumerable.Empty<Input>();
}
return ReadFromFile(file);
}
示例9: buildDriver
protected override IWebDriver buildDriver()
{
var fileSystem = new FileSystem();
var settings = StoryTellerEnvironment.Get<SerenityEnvironment>();
if (fileSystem.FileExists(settings.WorkingDir, File))
{
return new PhantomJSDriver(settings.WorkingDir);
}
return new PhantomJSDriver(AppDomain.CurrentDomain.BaseDirectory);
}
示例10: TryHandleCommandAsync
public async Task<bool> TryHandleCommandAsync(IImmutableSet<IProjectTree> nodes, long commandId, bool focused, long commandExecuteOptions, IntPtr variantArgIn, IntPtr variantArgOut) {
if (commandId == RPackageCommandId.icmdSourceSelectedFiles || commandId == RPackageCommandId.icmdSourceSelectedFilesWithEcho) {
bool echo = commandId == RPackageCommandId.icmdSourceSelectedFilesWithEcho;
IFileSystem fs = new FileSystem();
IEnumerable<string> rFiles = Enumerable.Empty<string>();
var workflow = _interactiveWorkflowProvider.GetOrCreate();
try {
var session = workflow.RSession;
if (session.IsRemote) {
var files = nodes.GetSelectedNodesPaths().Where(x =>
Path.GetExtension(x).EqualsIgnoreCase(RContentTypeDefinition.FileExtension) &&
fs.FileExists(x));
var properties = _configuredProject.Services.ExportProvider.GetExportedValue<ProjectProperties>();
string projectDir = Path.GetDirectoryName(_configuredProject.UnconfiguredProject.FullPath);
string projectName = properties.GetProjectName();
string remotePath = await properties.GetRemoteProjectPathAsync();
await SendToRemoteAsync(files, projectDir, projectName, remotePath, CancellationToken.None);
rFiles = files.Select(p => p.MakeRelativePath(projectDir).ProjectRelativePathToRemoteProjectPath(remotePath, projectName));
} else {
rFiles = nodes.GetSelectedNodesPaths().Where(x =>
Path.GetExtension(x).EqualsIgnoreCase(RContentTypeDefinition.FileExtension) &&
fs.FileExists(x));
}
workflow.Operations.SourceFiles(rFiles, echo);
} catch (IOException ex) {
_appShell.ShowErrorMessage(string.Format(CultureInfo.InvariantCulture, Resources.Error_CannotTransferFile, ex.Message));
}
catch (RHostDisconnectedException) {
workflow.ActiveWindow.InteractiveWindow.WriteErrorLine(Resources.Error_CannotTransferNoRSession);
}
return true;
}
return false;
}
示例11: writes_both_the_update_and_rollback_files
public void writes_both_the_update_and_rollback_files()
{
StoreOptions(_ =>
{
// This is enough to tell Marten that the User
// document is persisted and needs schema objects
_.Schema.For<User>();
// Lets Marten know that the event store is active
_.Events.AddEventType(typeof(MembersJoined));
});
var fileSystem = new FileSystem();
fileSystem.DeleteDirectory(@"bin\patches");
fileSystem.CreateDirectory(@"bin\patches");
// SAMPLE: write-patch
// Write the patch SQL file to the @"bin\patches" directory
theStore.Schema.WritePatch(@"bin\patches".AppendPath("1.initial.sql"));
// ENDSAMPLE
fileSystem.FileExists(@"bin\patches".AppendPath("1.initial.sql"));
fileSystem.FileExists(@"bin\patches".AppendPath("1.initial.drop.sql"));
}
示例12: TestSubscription
public async Task TestSubscription()
{
var fileSystem = new FileSystem(TestContext.TestRunDirectory);
fileSystem.RemoveFile(TestFileName);
Assert.AreEqual(false, fileSystem.FileExists(TestFileName));
var c = new TaskCompletionSource<IFileInfo>();
using (await fileSystem.SubscribeAsync(TestFilePattern, s => c.TrySetResult(s)).ConfigureAwait(false))
{
using (var writer = new StreamWriter(fileSystem.OpenWrite(TestFileName)))
{
writer.BaseStream.SetLength(0);
writer.Write("123456789");
}
var result = await c.Task.ConfigureAwait(false);
Assert.AreEqual(TestFileName.ToString(), Path.GetFileName(result.FilePath.ToString()));
}
}
示例13: TestSubscription
public async Task TestSubscription()
{
var fileSystem = new FileSystem(PathUtility.GetDirectory());
fileSystem.RemoveFile(TestFileName);
Assert.Equal(false, fileSystem.FileExists(TestFileName));
var c = new TaskCompletionSource<FileChangeEventArgs>();
using (fileSystem.Subscribe(GlobPattern.All, s => c.TrySetResult(s)))
{
using (var writer = new StreamWriter(fileSystem.OpenWrite(TestFileName)))
{
writer.BaseStream.SetLength(0);
writer.Write("123456789");
}
var result = await c.Task.ConfigureAwait(false);
Assert.Equal(TestFileName.ToString(), Path.GetFileName(result.FileInfo.FilePath.ToString()));
}
}
示例14: ReadFrom
public static Profile ReadFrom(DeploymentSettings settings, string profileName, string settingsProfileName = null)
{
var profile = new Profile(profileName);
var profileFile = settings.ProfileFileNameFor(profileName);
var fileSystem = new FileSystem();
if (!fileSystem.FileExists(profileFile))
{
var sb = new StringBuilder();
sb.AppendFormat("Couldn't find the profile '{0}'", profileFile);
sb.AppendLine();
sb.AppendLine("Looked in:");
settings.Directories.Each(d => sb.AppendLine(" {0}".ToFormat(d)));
throw new Exception(sb.ToString());
}
// Settings profile goes first
if (settingsProfileName != null)
{
profile.AddProfileDependency(settingsProfileName);
}
fileSystem.ReadTextFile(profileFile, profile.ReadText);
profile._childProfileNames.Each(childName =>
{
var childProfile = ReadFrom(settings, childName);
profile._childProfiles.Add(childProfile);
childProfile.Data.AllKeys.Each(childKey =>
{
// do not override main profile settings from dependencies.
// NOTE: Has(childKey) doesn't work here because SettingsData has a weird inner dictionary with a special key structure
if (profile.Data.AllKeys.Any(k => k == childKey)) return;
profile.Data[childKey] = childProfile.Data[childKey];
});
});
return profile;
}
示例15: ReadFrom
public static Profile ReadFrom(DeploymentSettings settings, string profileName)
{
var profile = new Profile(profileName);
var profileFile = settings.ProfileFileNameFor(profileName);
var fileSystem = new FileSystem();
if (!fileSystem.FileExists(profileFile))
{
var sb = new StringBuilder();
sb.AppendFormat("Couldn't find the profile '{0}'", profileFile);
sb.AppendLine();
sb.AppendLine("Looked in:");
settings.Directories.Each(d => sb.AppendLine(" {0}".ToFormat(d)));
throw new Exception(sb.ToString());
}
fileSystem.ReadTextFile(profileFile, profile.ReadText);
return profile;
}