public static Boolean IsDirectoryEmpty(String path) { path.Name("path").NotNullEmptyOrOnlyWhitespace(); return IsDirectoryEmpty(new DirectoryInfo(path)); }
public static void SafelyCreateEmptyFile(String filename) { filename.Name("filename").NotNullEmptyOrOnlyWhitespace(); CreateEmptyFile(filename, Overwrite.No); }
public static void DeleteEmptyDirectories(String path) { path.Name("path").NotNullEmptyOrOnlyWhitespace(); DeleteEmptyDirectories(new DirectoryInfo(path)); }
public static String GetMD5Checksum(String filename) { filename.Name("filename").NotNullEmptyOrOnlyWhitespace(); using (var fs = new FileStream(filename, FileMode.Open, FileAccess.Read)) return GetMD5Checksum(fs); }
"Unicode", "Until", "Where" }; private static Configuration _configuration; private static Boolean _isInitialized = false; private static List<String> _targetLanguageKeywords; #endregion Fields #region Methods /// <summary> /// Given a T-SQL identifier, return the same identifier with all of its /// constituent parts wrapped in square brackets. /// </summary> public static String GetBracketedSqlIdentifier(String identifier) { identifier.Name("identifier").NotNullEmptyOrOnlyWhitespace(); Func<String, String> wrap = s => s.Any() ? String.Concat("[", s.Trim(_brackets), "]") : ""; return identifier /* Keep empty array elements, because parts of a multi-part T-SQL identifier can be empty (e.g. "server.database..object", where the schema name is omitted). */ .Split(".".ToCharArray(), StringSplitOptions.None) .Select(element => wrap(element)) .Join("."); } public static String GetStrippedSqlIdentifier(String identifier) { return identifier.Replace("[", "").Replace("]", ""); } /// <summary> /// Convert an SQL identifier, like a database name or column name, into a valid /// identifier for the target language (C#, F#, etc.) that was set in /// the configuration. /// <para>NOTE: IdentifierHelper.Init() must be called before this method is called for the first time, otherwise an exception will be thrown.</para> /// <para>System.dll has code providers for both C# (Microsoft.CSharp.CSharpCodeProvider) and /// Visual Basic (Microsoft.VisualBasic.VBCodeProvider). Why not use code from those classes /// to determine if a given string is a valid identifier?</para> /// <para>There are several reasons. One is that .Net does not provide a corresponding F# code provider. /// The second reason is that the code providers' CreateValidIdentifier() method
public static void CreateEmptyFile(String filename, Overwrite overwrite) { filename.Name("filename").NotNullEmptyOrOnlyWhitespace(); if ((overwrite == Overwrite.Yes) || !File.Exists(filename)) { using (var fs = File.Create(filename)) { /* Create an empty file. */ } } }
public static ImageFormat GetImageFormatFromFileExtension(String filename) { filename.Name("filename").NotNullEmptyOrOnlyWhitespace(); var fileExtension = GetFileExtension(filename); switch (fileExtension) { case "bmp": return ImageFormat.Bmp; case "emf": return ImageFormat.Emf; case "exif": return ImageFormat.Exif; case "gif": return ImageFormat.Gif; case "icon": return ImageFormat.Icon; case "jpg": case "jpeg": return ImageFormat.Jpeg; case "png": return ImageFormat.Png; case "tif": case "tiff": return ImageFormat.Tiff; case "wmf": return ImageFormat.Wmf; default: throw new Exception(String.Format(Properties.Resources.Graphics_BadFileExtension, fileExtension)); } }
public static void WriteMemoryStreamToFile(String filename, MemoryStream ms) { filename.Name("filename").NotNullEmptyOrOnlyWhitespace(); ms.Name("ms").NotNull(); using (var fs = File.Create(filename)) ms.WriteTo(fs); }
public Item(String pathname) : this() { pathname.Name("pathname").NotNullEmptyOrOnlyWhitespace().FileExists(); var fileContents = File.ReadAllText(pathname); this.Filename = Path.GetFileName(pathname); this.Pathname = pathname; this.SchemaName = ""; this.ObjectName = ""; this.FileContentsMD5Hash = fileContents.MD5Checksum(); this.Type = _userDefinedTableTypeRegex.IsMatch(fileContents) ? "TT" : " "; this.NeedsToBeCompiled = true; this.IsPresentOnServer = false; this.DropOrder = 0; this.NeedsToBeDropped = false; }
public static String GetContentTypeFromFileExtension(String filename) { filename.Name("filename").NotNullEmptyOrOnlyWhitespace(); var fileExtension = GetFileExtension(filename); if (String.IsNullOrWhiteSpace(fileExtension)) throw new Exception(String.Format(Properties.Resources.Graphics_EmptyFileExtension, filename)); else return "image/" + fileExtension; }
public void AddFolder(String folder, String filemask = "*.*", SearchOption searchOption = SearchOption.TopDirectoryOnly) { folder.Name("folder").NotNullEmptyOrOnlyWhitespace().DirectoryExists(); filemask.Name("filemask").NotNullEmptyOrOnlyWhitespace(); filemask = filemask.Trim(); var pathnames = Directory.EnumerateFiles(folder, "*", searchOption); if ((filemask == "*") || (filemask == "*.*")) { this.AddFiles(pathnames); } else { /* Directory.EnumerateFiles()'s searchPattern parameter has an odd behavior when matching pathname extensions. (Read the "Remarks" section at https://msdn.microsoft.com/en-us/library/dd413233%28v=vs.110%29.aspx). That odd (IMO buggy) behavior is avoided by converting the filemask to an equivalent regular expression. */ var filemaskRegexPattern = filemask /* Escape all regex-related characters except '*' and '?'. */ .RegexEscape('*', '?') /* Convert '*' and '?' to their regex equivalents. */ .Replace('?', '.') .Replace("*", ".*?"); var _saneFilemaskRegex = new Regex(filemaskRegexPattern, RegexOptions.IgnoreCase | RegexOptions.Singleline); this.AddFiles(pathnames.Where(f => _saneFilemaskRegex.IsMatch(Path.GetFileName(f)))); } }
public void AddFile(String pathname) { pathname.Name("pathname").NotNullEmptyOrOnlyWhitespace().FileExists(); this._pathnames.Add(Path.GetFullPath(pathname)); }
public static String GetUrlAsRoot(String url) { url.Name("url").NotNull(); if (url.StartsWith("~/")) return url; else if (url.StartsWith("/")) return "~" + url; else return "~/" + url; }
public static void Touch(String filename) { filename.Name("filename").NotNullEmptyOrOnlyWhitespace(); Touch(filename, DateTime.Now); }
/// <summary> /// Passes the given command to the shell and executes it. /// </summary> /// <param name="command"> /// String containing a valid shell command. /// </param> /// <exception cref="System.ArgumentException"> /// Thrown if the command parameter is null or empty. /// </exception> public static void ShellExecute(String command) { command.Name("command").NotNullEmptyOrOnlyWhitespace(); var browser = new Process(); browser.StartInfo.FileName = command; browser.Start(); }
public static void Touch(String filename, DateTime timestamp) { filename.Name("filename").NotNullEmptyOrOnlyWhitespace(); Touch(new FileInfo(filename), timestamp); }
public StoredProcedure AddStoredProcedure(String name, Int32 versionNumber, params SqlParameter[] sqlParameters) { name.Name("name").NotNullEmptyOrOnlyWhitespace(); versionNumber.Name("versionNumber").GreaterThan(0); name = IdentifierHelper.GetBracketedSqlIdentifier(name); if (name.Contains(".")) throw new ArgumentExceptionFmt(Properties.Resources.InvalidStoredProcedureNameForSchema, name); if (this.StoredProcedures.GetByName(name, versionNumber) == null) { var sp = new StoredProcedure(this, name, versionNumber, sqlParameters); this.StoredProcedures.Add(sp); return sp; } else { throw new ExceptionFmt(Properties.Resources.StoredProcedureAlreadyExists, name, versionNumber); } }
/// <summary> /// Create and add a StoredProcedure instance to this Database. /// <para>The name parameter must be a valid one-part or two-part T-SQL identifier. Square brackets around the name parts are optional.</para> /// <para>E.g. "my_stored_proc", "[my_stored_proc]", "my_schema.my_stored_proc", and "[my_schema].[my_stored_proc]" are all valid name identifiers.</para> /// <para>Names with more than two parts, or missing parts, are considered errors.</para> /// </summary> public StoredProcedure AddStoredProcedure(String name, Int32 versionNumber, params SqlParameter[] sqlParameters) { name.Name("name").NotNullEmptyOrOnlyWhitespace(); versionNumber.Name("versionNumber").GreaterThan(0); name = IdentifierHelper.GetStrippedSqlIdentifier(name); var nameParts = name.Split(".".ToCharArray(), StringSplitOptions.None); /* It's an error if any of the name parts are empty, and this method only accepts one-part ([object name]) or two-part ([schema name].[object name]) T-SQL identifiers. */ if (nameParts.Any(s => s.IsEmpty()) || (nameParts.Length > 2)) throw new ArgumentExceptionFmt(Properties.Resources.InvalidStoredProcedureName, name); /* At this point, all of the name parts have been validated for correct form. */ if (nameParts.Length == 1) { return this.Schemas.GetDefaultSchema().AddStoredProcedure(name, versionNumber, sqlParameters); } else { var schemaName = nameParts[0]; var schema = this.Schemas.GetByName(schemaName); if (schema == null) throw new ExceptionFmt(Properties.Resources.SchemaNameNotFound, schemaName); var storedProcedureName = nameParts[1]; return schema.AddStoredProcedure(storedProcedureName, versionNumber, sqlParameters); } }
"Compare", "Custom", "Distinct", "Equals", "From", "Group", "Infer", "Into", "IsFalse", "IsTrue", "Iterator", "Join", "Let", "Mid", "Off", "Order", "Out", "PM",