本文整理汇总了C#中FileMode.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# FileMode.ToString方法的具体用法?C# FileMode.ToString怎么用?C# FileMode.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileMode
的用法示例。
在下文中一共展示了FileMode.ToString方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DoGetOutputStream
internal static Stream DoGetOutputStream(INode node, string contentName, string encoding, FileMode mode, FileShare sharing)
{
if (contentName != null)
{
throw new NotSupportedException();
}
if (mode == FileMode.Append)
{
throw new NotSupportedException("FileMode: " + mode.ToString());
}
return WebRequest.Create(node.Address.Uri).GetRequestStream();
}
示例2: TestMethod
private MFTestResults TestMethod(FileMode fm, FileAccess fa)
{
Log.Comment("Starting tests in FileMode: " + fm.ToString() + " with FileAccess: " + fa.ToString());
int iCountErrors = 0;
String fileName = "TestFile";
StreamWriter sw2;
FileStream fs2;
String str2;
if (File.Exists(fileName))
File.Delete(fileName);
Log.Comment("File does not exist");
//------------------------------------------------------------------
switch (fm)
{
case FileMode.CreateNew:
case FileMode.Create:
case FileMode.OpenOrCreate:
try
{
Log.Comment("null path");
fs2 = File.Open(null, fm, fa);
if (!File.Exists(fileName))
{
iCountErrors++;
Log.Exception("File not created, FileMode==" + fm.ToString());
}
fs2.Close();
}
catch (ArgumentException aexc)
{
Log.Comment("Caught expected exception, aexc==" + aexc.Message);
}
catch (Exception exc)
{
iCountErrors++;
Log.Exception("Incorrect exception thrown, exc==" + exc);
}
try
{
Log.Comment("string empty path");
fs2 = File.Open("", fm, fa);
if (!File.Exists(fileName))
{
iCountErrors++;
Log.Exception("File not created, FileMode==" + fm.ToString());
}
fs2.Close();
}
catch (ArgumentException aexc)
{
Log.Comment("Caught expected exception, aexc==" + aexc.Message);
}
catch (Exception exc)
{
iCountErrors++;
Log.Exception("Incorrect exception thrown, exc==" + exc);
}
try
{
Log.Comment("string:" + fileName);
fs2 = File.Open(fileName, fm, fa);
if (!File.Exists(fileName))
{
iCountErrors++;
Log.Exception("File not created, FileMode==" + fm.ToString());
}
fs2.Close();
}
catch (ArgumentException aexc)
{
if ((fm == FileMode.Create && fa == FileAccess.Read) || (fm == FileMode.CreateNew && fa == FileAccess.Read))
{
Log.Comment("Caught expected exception, aexc==" + aexc.Message);
}
else
{
iCountErrors++;
Log.Exception("Unexpected exception, aexc==" + aexc);
}
}
catch (Exception exc)
{
iCountErrors++;
Log.Exception("Incorrect exception thrown, exc==" + exc);
}
break;
case FileMode.Open:
case FileMode.Truncate:
try
{
Log.Comment("null path");
fs2 = File.Open(null, fm, fa);
iCountErrors++;
Log.Exception("Expected exception not thrown");
fs2.Close();
}
//.........这里部分代码省略.........
示例3: TestMethod
public static void TestMethod(FileMode fm, FileAccess fa)
{
String fileName = Path.Combine(TestInfo.CurrentDirectory, Path.GetRandomFileName());
StreamWriter sw2;
FileStream fs2;
String str2;
if (File.Exists(fileName))
File.Delete(fileName);
// File does not exist
//------------------------------------------------------------------
s_strLoc = "Loc_234yg";
switch (fm)
{
case FileMode.CreateNew:
case FileMode.Create:
case FileMode.OpenOrCreate:
try
{
fs2 = File.Open(null, fm, fa);
s_iCountTestcases++;
if (!File.Exists(fileName))
{
s_iCountErrors++;
printerr("Error_0001! File not created, FileMode==" + fm.ToString("G"));
}
fs2.Dispose();
}
catch (ArgumentException)
{
}
catch (Exception exc)
{
s_iCountErrors++;
printerr("Error_0004! Incorrect exception thrown, exc==" + exc);
}
try
{
fs2 = File.Open("", fm, fa);
s_iCountTestcases++;
if (!File.Exists(fileName))
{
s_iCountErrors++;
printerr("Error_0005! File not created, FileMode==" + fm.ToString("G"));
}
fs2.Dispose();
}
catch (ArgumentException)
{
}
catch (Exception exc)
{
s_iCountErrors++;
printerr("Error_0008! Incorrect exception thrown, exc==" + exc);
}
try
{
fs2 = File.Open(fileName, fm, fa);
s_iCountTestcases++;
if (!File.Exists(fileName))
{
s_iCountErrors++;
printerr("Error_48gb7! File not created, FileMode==" + fm.ToString("G"));
}
fs2.Dispose();
}
catch (ArgumentException aexc)
{
if (!((fm == FileMode.Create && fa == FileAccess.Read) || (fm == FileMode.CreateNew && fa == FileAccess.Read)))
{
s_iCountErrors++;
printerr("Error_478v8! Unexpected exception, aexc==" + aexc);
}
}
catch (Exception exc)
{
s_iCountErrors++;
printerr("Error_4879v! Incorrect exception thrown, exc==" + exc);
}
break;
case FileMode.Open:
case FileMode.Truncate:
s_iCountTestcases++;
try
{
fs2 = File.Open(null, fm, fa);
s_iCountErrors++;
printerr("Error_1001! Expected exception not thrown");
fs2.Dispose();
}
catch (IOException)
{
}
catch (ArgumentException)
{
}
catch (Exception exc)
{
//.........这里部分代码省略.........
示例4: TestMethod
private MFTestResults TestMethod(FileMode fm)
{
Log.Comment("Starting tests in FileMode: " + fm.ToString());
FileInfo fil2;
StreamWriter sw2;
Stream fs2 = null;
String str2;
int iCountErrors = 0;
if (File.Exists(fileName))
File.Delete(fileName);
Log.Comment("File does not exist");
//------------------------------------------------------------------
fil2 = new FileInfo(fileName);
switch (fm)
{
case FileMode.CreateNew:
case FileMode.Create:
case FileMode.OpenOrCreate:
Log.Comment("With a null string");
try
{
fs2 = File.Open(null, fm);
if (!File.Exists(fileName))
{
iCountErrors++;
Log.Exception("File not created, FileMode==" + fm.ToString());
}
}
catch (ArgumentException ex)
{
Log.Comment("Expected exception thrown :: " + ex.Message);
}
catch (Exception ex)
{
iCountErrors++;
Log.Exception("Unexpected exception thrown :: " + ex.ToString());
}
Log.Comment("with an empty string");
try
{
fs2 = File.Open("", fm);
if (!File.Exists(fileName))
{
iCountErrors++;
Log.Exception("File not created, FileMode==" + fm.ToString());
}
}
catch (ArgumentException ex)
{
Log.Comment("Expected exception thrown :: " + ex.Message);
}
catch (Exception ex)
{
iCountErrors++;
Log.Exception("Unexpected exception thrown :: " + ex.ToString());
}
fs2 = File.Open(fileName, fm);
if (!File.Exists(fileName))
{
iCountErrors++;
Log.Exception("File not created, FileMode==" + fm.ToString());
}
fs2.Close();
break;
case FileMode.Open:
case FileMode.Truncate:
try
{
fs2 = File.Open(fileName, fm);
iCountErrors++;
Log.Exception("Expected exception not thrown");
fs2.Close();
}
catch (IOException fexc)
{
Log.Comment("Caught expected exception, fexc==" + fexc.Message);
}
catch (Exception exc)
{
iCountErrors++;
Log.Exception("Incorrect exception thrown, exc==" + exc.ToString());
}
break;
case FileMode.Append:
try
{
fs2 = File.Open(fileName, fm);
fs2.Write(new Byte[] { 54, 65, 54, 90 }, 0, 4);
if (fs2.Length != 4)
{
iCountErrors++;
Log.Exception("Unexpected file length .... " + fs2.Length);
}
//.........这里部分代码省略.........
示例5: TestMethod
public void TestMethod(FileMode fm)
{
String fileName = s_strTFAbbrev+"TestFile";
FileInfo fil2;
StreamWriter sw2;
Stream fs2 = null;
String str2;
if(File.Exists(fileName))
File.Delete(fileName);
strLoc = "Loc_0001";
fil2 = new FileInfo(fileName);
switch(fm) {
case FileMode.CreateNew:
case FileMode.Create:
case FileMode.OpenOrCreate:
iCountTestcases++;
try{
fs2 = File.Open( null , fm);
if(!File.Exists(fileName)) {
iCountErrors++;
printerr( "Error_0002! File not created, FileMode=="+ fm.ToString());
}
} catch(ArgumentNullException ex ){
printinfo("Expected exception thrown :: " + ex.Message );
} catch ( Exception ex ){
iCountErrors++ ;
printerr("Error_0003! Unexpected exception thrown :: " + ex.ToString() );
}
iCountTestcases++;
try{
fs2 = File.Open( "", fm);
if(!File.Exists(fileName)) {
iCountErrors++;
printerr( "Error_0004! File not created, FileMode=="+ fm.ToString());
}
} catch(ArgumentException ex ){
printinfo("Expected exception thrown :: " + ex.Message );
} catch ( Exception ex ){
iCountErrors++ ;
printerr("Error_0005! Unexpected exception thrown :: " + ex.ToString() );
}
fs2 = File.Open(fileName, fm);
iCountTestcases++;
if(!File.Exists(fileName)) {
iCountErrors++;
printerr( "Error_0006! File not created, FileMode=="+ fm.ToString());
}
fs2.Close();
break;
case FileMode.Open:
case FileMode.Truncate:
iCountTestcases++;
try {
fs2 = File.Open(fileName, fm);
iCountErrors++;
printerr( "Error_0007! Expected exception not thrown");
fs2.Close();
} catch (FileNotFoundException fexc) {
printinfo( "Info_0008! Caught expected exception, fexc=="+fexc.Message);
} catch (Exception exc) {
iCountErrors++;
printerr( "Error_0009! Incorrect exception thrown, exc=="+exc.ToString());
}
break;
case FileMode.Append:
iCountTestcases++;
try {
fs2 = File.Open(fileName , fm);
fs2.Write(new Byte[]{54,65,54,90}, 0 , 4 );
if ( fs2.Length != 4) {
iCountErrors++ ;
Console.WriteLine( "Unexpected file length .... " + fs2.Length );
}
fs2.Close();
} catch (Exception exc) {
iCountErrors++;
printerr( "Error_0012! Incorrect exception thrown, exc=="+exc.ToString());
}
break;
default:
iCountErrors++;
printerr( "Error_27tbv! This should not be....");
break;
}
if(File.Exists(fileName))
File.Delete(fileName);
strLoc = "Loc_4yg7b";
sw2 = new StreamWriter(fileName);
str2 = "Du er en ape";
sw2.Write(str2);
sw2.Close();
switch(fm) {
case FileMode.CreateNew:
iCountTestcases++;
try {
fs2 = File.Open(fileName , fm);
iCountErrors++;
printerr( "Error_27b98! Expected exception not thrown");
fs2.Close();
} catch (IOException aexc) {
//.........这里部分代码省略.........
示例6: TestMethod
public void TestMethod(FileMode fm, FileAccess fa)
{
String fileName = s_strTFAbbrev+"TestFile";
StreamWriter sw2;
FileStream fs2;
String str2;
if(File.Exists(fileName))
File.Delete(fileName);
strLoc = "Loc_234yg";
switch(fm) {
case FileMode.CreateNew:
case FileMode.Create:
case FileMode.OpenOrCreate:
try {
fs2 = File.Open( null, fm, fa);
iCountTestcases++;
if(!File.Exists(fileName)) {
iCountErrors++;
printerr( "Error_0001! File not created, FileMode=="+fm.ToString("G"));
}
fs2.Close();
} catch (ArgumentException aexc) {
printinfo( "Info_0002! Caught expected exception, aexc=="+aexc.Message);
} catch (Exception exc) {
iCountErrors++;
printerr( "Error_0004! Incorrect exception thrown, exc=="+exc);
}
try {
fs2 = File.Open( "", fm, fa);
iCountTestcases++;
if(!File.Exists(fileName)) {
iCountErrors++;
printerr( "Error_0005! File not created, FileMode=="+fm.ToString("G"));
}
fs2.Close();
} catch (ArgumentException aexc) {
printinfo( "Info_0006! Caught expected exception, aexc=="+aexc.Message);
} catch (Exception exc) {
iCountErrors++;
printerr( "Error_0008! Incorrect exception thrown, exc=="+exc);
}
try {
fs2 = File.Open( fileName, fm, fa);
iCountTestcases++;
if(!File.Exists(fileName)) {
iCountErrors++;
printerr( "Error_48gb7! File not created, FileMode=="+fm.ToString("G"));
}
fs2.Close();
} catch (ArgumentException aexc) {
if((fm == FileMode.Create && fa == FileAccess.Read) || (fm == FileMode.CreateNew && fa == FileAccess.Read)) {
printinfo( "Info_4987v! Caught expected exception, aexc=="+aexc.Message);
}
else {
iCountErrors++;
printerr( "Error_478v8! Unexpected exception, aexc=="+aexc);
}
} catch (Exception exc) {
iCountErrors++;
printerr( "Error_4879v! Incorrect exception thrown, exc=="+exc);
}
break;
case FileMode.Open:
case FileMode.Truncate:
iCountTestcases++;
try {
fs2 = File.Open(null, fm, fa);
iCountErrors++;
printerr( "Error_1001! Expected exception not thrown");
fs2.Close();
} catch (IOException fexc) {
printinfo( "Info_1002! Caught expected exception, fexc=="+fexc.Message);
} catch (ArgumentException aexc) {
printinfo( "Info_1003! Caught expected exception, aexc=="+aexc.Message);
} catch (Exception exc) {
iCountErrors++;
printerr( "Error_1005! Incorrect exception thrown, exc=="+exc.ToString());
}
iCountTestcases++;
try {
fs2 = File.Open("", fm, fa);
iCountErrors++;
printerr( "Error_1006! Expected exception not thrown");
fs2.Close();
} catch (IOException fexc) {
printinfo( "Info_1007! Caught expected exception, fexc=="+fexc.Message);
} catch (ArgumentException aexc) {
printinfo( "Info_1008! Caught expected exception, aexc=="+aexc.Message);
} catch (Exception exc) {
iCountErrors++;
printerr( "Error_1010! Incorrect exception thrown, exc=="+exc.ToString());
}
iCountTestcases++;
try {
fs2 = File.Open(fileName, fm,fa);
iCountErrors++;
printerr( "Error_2yg8b! Expected exception not thrown");
fs2.Close();
} catch (IOException fexc) {
printinfo( "Info_49y7b! Caught expected exception, fexc=="+fexc.Message);
//.........这里部分代码省略.........
示例7: CreateFile
public int CreateFile(String filename, FileAccess access, FileShare share, FileMode mode, FileOptions options, DokanFileInfo info)
{
String userName = GetProcessOwner((int)info.ProcessId);
string path = GetPath(filename);
info.Context = count_++;
logger.WriteLine("CreateFile: " + path + " //// " + mode.ToString(), Logger.MessagePriority.Debug);
if (!(Directory.Exists(path)) && (mode == FileMode.Create || mode == FileMode.CreateNew || mode == FileMode.OpenOrCreate))
{
if (File.Exists(path))
{
return 0;
}
RamFile fs = null;
logger.WriteLine("Creating " + path, Logger.MessagePriority.Debug);
if (!userFSList.ContainsKey(userName))
{
//fs = new OpenedRamFile(root_ + filename);
UserFS ufs = new UserFS();
ufs.userName = userName;
ufs.files = new System.Collections.Generic.LinkedList<RamFile>();
//ufs.files.AddLast(fs);
lock (userFSLock)
{
userFSList.Add(userName, ufs);
}
AddUserFSRamFile(userName, filename);
}
else
{
fs = GetUserFSFile(userName, filename);
if (fs == null)
{
lock (userFSLock)
{
fs = GetUserFSFile(userName, filename);
if (fs == null)
{
fs = AddUserFSRamFile(userName, filename);
}
}
}
}
return 0;
}
else if (File.Exists(path))
{
return 0;
}
else if (Directory.Exists(path))
{
info.IsDirectory = true;
return 0;
}
else
{
UserFS ufs;
if (userFSList.TryGetValue(userName, out ufs))
{
foreach (RamFile f in ufs.files)
{
if (f.Name.ToLower().Equals(path.ToLower()))
{
return 0;
}
}
}
return -DokanNet.ERROR_FILE_NOT_FOUND;
}
}
示例8: CreateFile
public NtStatus CreateFile(string fileName, FileAccess access, FileShare share, FileMode mode, FileOptions options, FileAttributes attributes, DokanFileInfo info)
{
Debug.WriteLine(@"{0} : {1} {2}", fileName, mode.ToString(), access.ToString());
fileName = ToUnixStylePath(fileName);
if (fileName.EndsWith("desktop.ini", StringComparison.OrdinalIgnoreCase) ||
fileName.EndsWith("autorun.inf", StringComparison.OrdinalIgnoreCase))
{
return DokanResult.FileNotFound;
}
// todo : add to memory cache
bool exists = sftpClient.Exists(fileName);
SftpFileAttributes attr = sftpClient.GetAttributes(fileName);
bool readWriteAttributes = (access & DataAccess) == 0;
bool readAccess = (access & DataWriteAccess) == 0;
System.IO.FileAccess acs = readAccess ? System.IO.FileAccess.Read : System.IO.FileAccess.ReadWrite;
switch(mode)
{
case FileMode.Open:
if (!exists)
return DokanResult.FileNotFound;
if (((uint)access & 0xe0000027) == 0 || attr.IsDirectory)
{
info.IsDirectory = attr.IsDirectory;
info.Context = new object();
return DokanResult.Success;
}
break;
case FileMode.CreateNew:
if (exists)
return DokanResult.AlreadyExists;
// cache invalidate
break;
case FileMode.Truncate:
if (!exists)
return DokanResult.FileNotFound;
// cache invalidate
break;
default:
// cache invalidate
break;
}
try
{
info.Context = sftpClient.Open(fileName, mode, acs) as SftpFileStream;
}
catch(Renci.SshNet.Common.SshException)
{
return DokanResult.AccessDenied;
}
return DokanResult.Success;
}
示例9: TestMethod
public static void TestMethod(FileMode fm)
{
String fileName = Path.Combine(TestInfo.CurrentDirectory, Path.GetRandomFileName());
FileInfo fil2;
StreamWriter sw2;
Stream fs2 = null;
String str2;
if (File.Exists(fileName))
File.Delete(fileName);
// [] File does not exist
//------------------------------------------------------------------
s_strLoc = "Loc_0001";
fil2 = new FileInfo(fileName);
switch (fm)
{
case FileMode.CreateNew:
case FileMode.Create:
case FileMode.OpenOrCreate:
//With a null string
s_iCountTestcases++;
try
{
fs2 = File.Open(null, fm);
if (!File.Exists(fileName))
{
s_iCountErrors++;
printerr("Error_0002! File not created, FileMode==" + fm.ToString());
}
}
catch (ArgumentNullException)
{
}
catch (Exception ex)
{
s_iCountErrors++;
printerr("Error_0003! Unexpected exception thrown :: " + ex.ToString());
}
//with anempty string
s_iCountTestcases++;
try
{
fs2 = File.Open("", fm);
if (!File.Exists(fileName))
{
s_iCountErrors++;
printerr("Error_0004! File not created, FileMode==" + fm.ToString());
}
}
catch (ArgumentException)
{
}
catch (Exception ex)
{
s_iCountErrors++;
printerr("Error_0005! Unexpected exception thrown :: " + ex.ToString());
}
fs2 = File.Open(fileName, fm);
s_iCountTestcases++;
if (!File.Exists(fileName))
{
s_iCountErrors++;
printerr("Error_0006! File not created, FileMode==" + fm.ToString());
}
fs2.Dispose();
break;
case FileMode.Open:
case FileMode.Truncate:
s_iCountTestcases++;
try
{
fs2 = File.Open(fileName, fm);
s_iCountErrors++;
printerr("Error_0007! Expected exception not thrown");
fs2.Dispose();
}
catch (FileNotFoundException)
{
}
catch (Exception exc)
{
s_iCountErrors++;
printerr("Error_0009! Incorrect exception thrown, exc==" + exc.ToString());
}
break;
case FileMode.Append:
s_iCountTestcases++;
try
{
fs2 = File.Open(fileName, fm);
fs2.Write(new Byte[] { 54, 65, 54, 90 }, 0, 4);
if (fs2.Length != 4)
{
s_iCountErrors++;
//.........这里部分代码省略.........