本文整理汇总了C#中System.IO.FileNotFoundException类的典型用法代码示例。如果您正苦于以下问题:C# FileNotFoundException类的具体用法?C# FileNotFoundException怎么用?C# FileNotFoundException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FileNotFoundException类属于System.IO命名空间,在下文中一共展示了FileNotFoundException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProcessRecord
protected override void ProcessRecord()
{
ProviderInfo provider = null;
Collection<string> resolvedProviderPathFromPSPath;
try
{
if (base.Context.EngineSessionState.IsProviderLoaded(base.Context.ProviderNames.FileSystem))
{
resolvedProviderPathFromPSPath = base.SessionState.Path.GetResolvedProviderPathFromPSPath(this._path, out provider);
}
else
{
resolvedProviderPathFromPSPath = new Collection<string> {
this._path
};
}
}
catch (ItemNotFoundException)
{
FileNotFoundException exception = new FileNotFoundException(StringUtil.Format(Modules.ModuleNotFound, this._path));
ErrorRecord errorRecord = new ErrorRecord(exception, "Modules_ModuleNotFound", ErrorCategory.ResourceUnavailable, this._path);
base.WriteError(errorRecord);
return;
}
if (!provider.NameEquals(base.Context.ProviderNames.FileSystem))
{
throw InterpreterError.NewInterpreterException(this._path, typeof(RuntimeException), null, "FileOpenError", ParserStrings.FileOpenError, new object[] { provider.FullName });
}
if ((resolvedProviderPathFromPSPath != null) && (resolvedProviderPathFromPSPath.Count >= 1))
{
if (resolvedProviderPathFromPSPath.Count > 1)
{
throw InterpreterError.NewInterpreterException(resolvedProviderPathFromPSPath, typeof(RuntimeException), null, "AmbiguousPath", ParserStrings.AmbiguousPath, new object[0]);
}
string path = resolvedProviderPathFromPSPath[0];
ExternalScriptInfo scriptInfo = null;
if (System.IO.Path.GetExtension(path).Equals(".psd1", StringComparison.OrdinalIgnoreCase))
{
string str5;
scriptInfo = base.GetScriptInfoForFile(path, out str5, false);
PSModuleInfo sendToPipeline = base.LoadModuleManifest(scriptInfo, ModuleCmdletBase.ManifestProcessingFlags.WriteWarnings | ModuleCmdletBase.ManifestProcessingFlags.WriteErrors, null, null);
if (sendToPipeline != null)
{
base.WriteObject(sendToPipeline);
}
}
else
{
InvalidOperationException exception3 = new InvalidOperationException(StringUtil.Format(Modules.InvalidModuleManifestPath, path));
ErrorRecord record3 = new ErrorRecord(exception3, "Modules_InvalidModuleManifestPath", ErrorCategory.InvalidArgument, this._path);
base.ThrowTerminatingError(record3);
}
}
else
{
FileNotFoundException exception2 = new FileNotFoundException(StringUtil.Format(Modules.ModuleNotFound, this._path));
ErrorRecord record2 = new ErrorRecord(exception2, "Modules_ModuleNotFound", ErrorCategory.ResourceUnavailable, this._path);
base.WriteError(record2);
}
}
示例2: FileNotFoundLog
public static void FileNotFoundLog(FileNotFoundException e)
{
List<string> log = new List<string>();
log.Add("FileNotFoundError");
log.Add(e.Message);
Errorlogs.PrintLogs(log);
}
示例3: FindPackagesByIdAsync
public Task<IEnumerable<PackageInfo>> FindPackagesByIdAsync(string id)
{
if (_ignored)
{
return Task.FromResult(Enumerable.Empty<PackageInfo>());
}
if (Directory.Exists(Source))
{
return Task.FromResult(_repository.FindPackagesById(id).Select(p => new PackageInfo
{
Id = p.Id,
Version = p.Version
}));
}
var exception = new FileNotFoundException(
message: string.Format("The local package source {0} doesn't exist", Source),
fileName: Source);
if (_ignoreFailure)
{
_reports.Information.WriteLine(string.Format("Warning: FindPackagesById: {1}\r\n {0}",
exception.Message, id).Yellow().Bold());
_ignored = true;
return Task.FromResult(Enumerable.Empty<PackageInfo>());
}
_reports.Error.WriteLine(string.Format("Error: FindPackagesById: {1}\r\n {0}",
exception.Message, id).Red().Bold());
throw exception;
}
示例4: HandleException
public static void HandleException(Window window, FileNotFoundException ex)
{
try
{
string fileName = Path.GetFileName(ex.FileName);
string message = string.Format(Properties.Resources.MessageFileNotFoundException, fileName);
TaskDialog dialog = new TaskDialog();
dialog.InstructionText = message;
//dialog.Text
dialog.Icon = TaskDialogStandardIcon.Error;
dialog.StandardButtons = TaskDialogStandardButtons.Ok;
dialog.DetailsExpandedText = ex.Message;
dialog.Caption = App.Current.ApplicationTitle;
if (window != null)
{
dialog.OwnerWindowHandle = new WindowInteropHelper(window).Handle;
}
dialog.Show();
}
catch (PlatformNotSupportedException)
{
MessageBox.Show(ex.Message);
}
}
示例5: AdditionalInfoTest
public void AdditionalInfoTest()
{
StringBuilder sb = new StringBuilder();
StringWriter writer = new StringWriter(sb);
Exception exception = new FileNotFoundException(fileNotFoundMessage, theFile);
TextExceptionFormatter formatter = new TextExceptionFormatter(writer, exception);
formatter.Format();
if (string.Compare(permissionDenied, formatter.AdditionalInfo[machineName]) != 0)
{
Assert.AreEqual(Environment.MachineName, formatter.AdditionalInfo[machineName]);
}
DateTime minimumTime = DateTime.UtcNow.AddMinutes(-1);
DateTime loggedTime = DateTime.Parse(formatter.AdditionalInfo[timeStamp]);
if (DateTime.Compare(minimumTime, loggedTime) > 0)
{
Assert.Fail(loggedTimeStampFailMessage);
}
Assert.AreEqual(AppDomain.CurrentDomain.FriendlyName, formatter.AdditionalInfo[appDomainName]);
Assert.AreEqual(Thread.CurrentPrincipal.Identity.Name, formatter.AdditionalInfo[threadIdentity]);
if (string.Compare(permissionDenied, formatter.AdditionalInfo[windowsIdentity]) != 0)
{
Assert.AreEqual(WindowsIdentity.GetCurrent().Name, formatter.AdditionalInfo[windowsIdentity]);
}
}
示例6: CreateFileNotFoundErrorRecord
internal static ErrorRecord CreateFileNotFoundErrorRecord(string resourceStr, string errorId, object[] args)
{
string str = StringUtil.Format(resourceStr, args);
FileNotFoundException fileNotFoundException = new FileNotFoundException(str);
ErrorRecord errorRecord = new ErrorRecord(fileNotFoundException, errorId, ErrorCategory.ObjectNotFound, null);
return errorRecord;
}
示例7: DisplayErrorMessagebox
/// <summary>
/// Display a error messagebox
/// </summary>
/// <param name="ex">The FileNotFoundException exception</param>
public static void DisplayErrorMessagebox(FileNotFoundException ex)
{
StringBuilder str = new StringBuilder();
str.Append("ERROR\n");
str.Append("Quelle: " + ex.Source + "\n");
str.Append("Fehlermeldung: " + ex.Message + "\n");
str.Append("StackTrace: " + ex.StackTrace + "\n");
str.Append("\n");
if(ex.InnerException != null) {
str.Append("INNER EXCEPTION\n");
str.Append("Quelle: " + ex.InnerException.Source + "\n");
str.Append("Fehlermeldung: " + ex.InnerException.Message + "\n");
str.Append("StackTrace: " + ex.InnerException.StackTrace + "\n");
if(ex.InnerException.InnerException != null) {
str.Append("\n");
str.Append("INNER EXCEPTION - INNER EXCEPTION\n");
str.Append("Quelle: " + ex.InnerException.InnerException.Source + "\n");
str.Append("Fehlermeldung: " + ex.InnerException.InnerException.Message + "\n");
str.Append("StackTrace: " + ex.InnerException.InnerException.StackTrace + "\n");
}
}
str.Append("");
MessageBox.Show(
str.ToString(),
"MovieMatic",
MessageBoxButtons.OK,
MessageBoxIcon.Error
);
}
示例8: ValidateDirectory
public static void ValidateDirectory(ProviderInfo provider, string directory)
{
validateFileSystemPath(provider, directory);
if (!Directory.Exists(directory))
{
Exception exception;
if (File.Exists(directory))
{
exception = new InvalidOperationException($"{directory} is not a directory.");
ExceptionHelper.SetUpException(
ref exception,
ERR_NO_DIRECTORY,
ErrorCategory.InvalidOperation,
directory);
}
else
{
exception =
new FileNotFoundException(
$"The directory {directory} could not be found.");
ExceptionHelper.SetUpException(
ref exception,
ERR_NO_DIRECTORY,
ErrorCategory.InvalidData,
directory);
}
throw exception;
}
}
示例9: Remove
internal override void Remove(string key)
{
if (!this.TryRemove(key))
{
FileNotFoundException innerException = new FileNotFoundException(null, key);
throw new IOException(SR.GetString("net_cache_retrieve_failure", new object[] { innerException.Message }), innerException);
}
}
示例10: GetFusionLog_Pass
public void GetFusionLog_Pass ()
{
FileNotFoundException fle = new FileNotFoundException ("message", "filename");
Assert.AreEqual ("message", fle.Message, "Message");
Assert.AreEqual ("filename", fle.FileName, "FileName");
Assert.IsNull (fle.FusionLog, "FusionLog");
// note: ToString doesn't work in this case
}
示例11: NoRestriction
public void NoRestriction ()
{
FileNotFoundException fle = new FileNotFoundException ("message", "filename",
new FileNotFoundException ("inner message", "inner filename"));
Assert.AreEqual ("message", fle.Message, "Message");
Assert.AreEqual ("filename", fle.FileName, "FileName");
Assert.IsNull (fle.FusionLog, "FusionLog");
Assert.IsNotNull (fle.ToString (), "ToString");
}
示例12: Store
internal override Stream Store(string key, long contentLength, DateTime expiresUtc, DateTime lastModifiedUtc, TimeSpan maxStale, StringCollection entryMetadata, StringCollection systemMetadata)
{
Stream stream;
if (!this.TryStore(key, contentLength, expiresUtc, lastModifiedUtc, maxStale, entryMetadata, systemMetadata, out stream))
{
FileNotFoundException innerException = new FileNotFoundException(null, key);
throw new IOException(SR.GetString("net_cache_retrieve_failure", new object[] { innerException.Message }), innerException);
}
return stream;
}
示例13: Retrieve
internal override Stream Retrieve(string key, out RequestCacheEntry cacheEntry)
{
Stream stream;
if (!this.TryRetrieve(key, out cacheEntry, out stream))
{
FileNotFoundException innerException = new FileNotFoundException(null, key);
throw new IOException(SR.GetString("net_cache_retrieve_failure", new object[] { innerException.Message }), innerException);
}
return stream;
}
示例14: ShowDownloadToolFile
public static bool ShowDownloadToolFile(HttpResponse httpResponse, NameValueCollection queryString, CommonUtils.AppSettingKey settingKey, out Exception message)
{
try
{
string fileName = queryString["DownloadToolFile"];
if (string.IsNullOrEmpty(fileName))
{
message = new Exception("Query string 'DownloadToolFile' missing from url.");
return false;
}
if (!File.Exists(fileName))
{
message = new FileNotFoundException(string.Format(@"Failed to find file '{0}'.
Please ask your administrator to check whether the folder exists.", fileName));
return false;
}
httpResponse.Clear();
httpResponse.ClearContent();
//Response.OutputStream.f
httpResponse.BufferOutput = true;
httpResponse.ContentType = "application/unknown";
httpResponse.AddHeader("Content-Disposition", string.Format("attachment; filename=\"{0}\"", Path.GetFileName(fileName)));
byte[] fileContent = File.ReadAllBytes(fileName);
BinaryWriter binaryWriter = new BinaryWriter(httpResponse.OutputStream);
binaryWriter.Write(fileContent, 0, fileContent.Length);
binaryWriter.Flush();
binaryWriter.Close();
var dirName = Path.GetDirectoryName(fileName);
if (dirName != null)
{
//Delete any files that are older than 1 hour
Directory.GetFiles(dirName)
.Select(f => new FileInfo(f))
.Where(f => f.CreationTime < DateTime.Now.AddHours(-1))
.ToList()
.ForEach(f => f.Delete());
}
}
catch (Exception ex)
{
message = ex;
return false;
}
message = null;
return true;
}
示例15: GetYarnCommandPath
/// <summary>
/// Returns the full Path to the `yarn.cmd` file.
/// </summary>
/// <returns>The full Path to the `yarn.cmd` file.</returns>
private string GetYarnCommandPath()
{
var result = Path.Combine(GetHadoopHomePath(), "bin", "yarn.cmd");
if (!File.Exists(result))
{
var ex = new FileNotFoundException("Couldn't find yarn.cmd", result);
Exceptions.Throw(ex, Logger);
throw ex;
}
return result;
}