internal static bool IsIoRelatedException(Exception e) { return(!ExceptionHandling.NotExpectedException(e)); }
internal static bool NotExpectedIoOrXmlException(Exception e) { return(!ExceptionHandling.IsXmlException(e) && ExceptionHandling.NotExpectedException(e)); }
internal static string GetItemSpecModifier(string currentDirectory, string itemSpec, string modifier, ref CopyOnWriteDictionary <string, string> cachedModifiers) { ErrorUtilities.VerifyThrow(itemSpec != null, "Need item-spec to modify."); ErrorUtilities.VerifyThrow(modifier != null, "Need modifier to apply to item-spec."); string fullPath = null; if (cachedModifiers != null) { cachedModifiers.TryGetValue(modifier, out fullPath); } if (fullPath == null) { bool flag = true; try { if (string.Compare(modifier, "FullPath", StringComparison.OrdinalIgnoreCase) == 0) { if (currentDirectory == null) { currentDirectory = string.Empty; } fullPath = FileUtilities.GetFullPath(itemSpec, currentDirectory); ThrowForUrl(fullPath, itemSpec, currentDirectory); } else if (string.Compare(modifier, "RootDir", StringComparison.OrdinalIgnoreCase) == 0) { string str2; if (currentDirectory == null) { currentDirectory = string.Empty; } if ((cachedModifiers == null) || !cachedModifiers.TryGetValue("FullPath", out str2)) { str2 = FileUtilities.GetFullPath(itemSpec, currentDirectory); ThrowForUrl(str2, itemSpec, currentDirectory); } fullPath = Path.GetPathRoot(str2); if (!FileUtilities.EndsWithSlash(fullPath)) { ErrorUtilities.VerifyThrow(FileUtilitiesRegex.UNCPattern.IsMatch(fullPath), "Only UNC shares should be missing trailing slashes."); fullPath = fullPath + Path.DirectorySeparatorChar; } } else if (string.Compare(modifier, "Filename", StringComparison.OrdinalIgnoreCase) == 0) { if (Path.GetDirectoryName(itemSpec) == null) { fullPath = string.Empty; } else { fullPath = Path.GetFileNameWithoutExtension(itemSpec); } } else if (string.Compare(modifier, "Extension", StringComparison.OrdinalIgnoreCase) == 0) { if (Path.GetDirectoryName(itemSpec) == null) { fullPath = string.Empty; } else { fullPath = Path.GetExtension(itemSpec); } } else if (string.Compare(modifier, "RelativeDir", StringComparison.OrdinalIgnoreCase) == 0) { fullPath = FileUtilities.GetDirectory(itemSpec); } else if (string.Compare(modifier, "Directory", StringComparison.OrdinalIgnoreCase) == 0) { string str3; if (currentDirectory == null) { currentDirectory = string.Empty; } if ((cachedModifiers == null) || !cachedModifiers.TryGetValue("FullPath", out str3)) { str3 = FileUtilities.GetFullPath(itemSpec, currentDirectory); ThrowForUrl(str3, itemSpec, currentDirectory); } fullPath = FileUtilities.GetDirectory(str3); Match match = FileUtilitiesRegex.DrivePattern.Match(fullPath); if (!match.Success) { match = FileUtilitiesRegex.UNCPattern.Match(fullPath); } if (match.Success) { ErrorUtilities.VerifyThrow((fullPath.Length > match.Length) && FileUtilities.IsSlash(fullPath[match.Length]), "Root directory must have a trailing slash."); fullPath = fullPath.Substring(match.Length + 1); } } else if (string.Compare(modifier, "RecursiveDir", StringComparison.OrdinalIgnoreCase) == 0) { fullPath = string.Empty; } else if (string.Compare(modifier, "Identity", StringComparison.OrdinalIgnoreCase) == 0) { flag = cachedModifiers != null; fullPath = itemSpec; } else if (string.Compare(modifier, "ModifiedTime", StringComparison.OrdinalIgnoreCase) == 0) { flag = false; FileInfo fileInfoNoThrow = FileUtilities.GetFileInfoNoThrow(EscapingUtilities.UnescapeAll(itemSpec)); if (fileInfoNoThrow != null) { fullPath = fileInfoNoThrow.LastWriteTime.ToString("yyyy'-'MM'-'dd HH':'mm':'ss'.'fffffff", null); } else { fullPath = string.Empty; } } else if (string.Compare(modifier, "CreatedTime", StringComparison.OrdinalIgnoreCase) == 0) { flag = false; string path = EscapingUtilities.UnescapeAll(itemSpec); if (File.Exists(path)) { fullPath = File.GetCreationTime(path).ToString("yyyy'-'MM'-'dd HH':'mm':'ss'.'fffffff", null); } else { fullPath = string.Empty; } } else if (string.Compare(modifier, "AccessedTime", StringComparison.OrdinalIgnoreCase) == 0) { flag = false; string str6 = EscapingUtilities.UnescapeAll(itemSpec); if (File.Exists(str6)) { fullPath = File.GetLastAccessTime(str6).ToString("yyyy'-'MM'-'dd HH':'mm':'ss'.'fffffff", null); } else { fullPath = string.Empty; } } else { ErrorUtilities.VerifyThrow(false, "\"{0}\" is not a valid item-spec modifier.", modifier); } } catch (Exception exception) { if (ExceptionHandling.NotExpectedException(exception)) { throw; } ErrorUtilities.VerifyThrowInvalidOperation(false, "Shared.InvalidFilespecForTransform", modifier, itemSpec, exception.Message); } ErrorUtilities.VerifyThrow(fullPath != null, "The item-spec modifier \"{0}\" was not evaluated.", modifier); if (flag) { if (cachedModifiers == null) { cachedModifiers = new CopyOnWriteDictionary <string, string>(StringComparer.OrdinalIgnoreCase); } cachedModifiers[modifier] = fullPath; } } return(fullPath); }