/// <summary> /// 根据名称获取SQL(或视图)语句 (已经处理过注释,和参数替换的内容) /// </summary> /// <param name="key"></param> /// <param name="stringFormatValues">如果需要格式化大括号参数</param> /// <returns></returns> public static string GetCode(string key, params object[] stringFormatValues) { if (!string.IsNullOrEmpty(key)) { Dictionary <string, string> fileList = FileList; if (fileList.ContainsKey(key)) { string text = fileList[key]; if (text.Contains(":\\")) { text = FileExtend.ReadAllText(text); int index = text.LastIndexOf("/*"); if (index > -1)//去掉注释 { text = Regex.Replace(text, @"/\*[.\s\S]*?\*/", string.Empty, RegexOptions.IgnoreCase); } } text = text.Trim(); if (stringFormatValues.Length > 0) { text = string.Format(text, stringFormatValues); } text = FormatPara(text.Trim()); //去掉空格 if (key[0] == 'V' && text[0] != '(') //补充语法 { text = "(" + text + ") " + key; } //参数化格式 return(text); } } return(key); }
/// <summary> /// Store the specified images locally if they do not exist. /// </summary> public static IEnumerable <Image> Store(this IEnumerable <Image> images) { WebClient client = null; Directory.CreateDirectory(Settings.Current.LocalDirectoryPath); foreach (Image image in images) { if (FileExtend.NotExists(image.FileName)) { DownloadImage(image); } yield return(image); } void DownloadImage(Image image) { // Lazy loading of WebClient component if (client == null) { client = new WebClient(); } string url = $"{Bing.BaseImageUrl}{image.RelativeUrl}"; client.TryDownloadFileAsync(url, image.FileName); } }
public static T CreateScriptable <T> (string p_path) where T : ScriptableObject { T _asset = ScriptableObject.CreateInstance <T> (); FileExtend.PrepareDirectory(Application.dataPath.Substring(0, Application.dataPath.Length - 7) + "/" + p_path); AssetDatabase.CreateAsset(_asset, p_path); RefreshProject(_asset); return(_asset); }
public static void GetScreenShot(Action <Sprite> sprite) { DebugMode.Log(" GetScreenShot"); string path = "file://" + screenshotPath; #if UNITY_EDITOR path = "file:///" + screenshotPath; #endif instance.StartCoroutine(FileExtend.DOLoadSprite(path, sprite)); }
/// <summary> /// 根据名称获取原始的SQL(或视图)语句 /// </summary> /// <param name="key"></param> /// <returns></returns> internal static string GetSourceCode(string key) { if (!string.IsNullOrEmpty(key)) { if (FileList != null && FileList.ContainsKey(key)) { string path = FileList[key]; return(FileExtend.ReadAllText(path)); } } return(string.Empty); }
/// <summary> /// 根据名称获取SQL(或视图)语句 (已经处理过注释,和参数替换的内容) /// </summary> /// <param name="key"></param> /// <param name="stringFormatValues">如果需要格式化大括号参数</param> /// <returns></returns> public static string GetCode(string key, params object[] stringFormatValues) { if (!string.IsNullOrEmpty(key)) { if (key[0] == '_') { key = key.Substring(1); } Dictionary <string, string> fileList = FileList; if (fileList.ContainsKey(key)) { string text = fileList[key]; string folder = null; if (text.Contains(":\\")) { folder = text; text = FileExtend.ReadAllText(text); int index = text.LastIndexOf("/*"); if (index > -1)//去掉注释 { text = Regex.Replace(text, @"/\*[.\s\S]*?\*/", string.Empty, RegexOptions.IgnoreCase); } } text = text.Trim(); if (stringFormatValues.Length > 0) { text = string.Format(text, stringFormatValues); } text = FormatPara(text.Trim()); //去掉空格 if (key[0] == 'V' && text[0] != '(' && !string.IsNullOrEmpty(folder)) //补充语法 { //如果文件夹名包含数据库名,则补充数据库前缀。 foreach (string name in CrossDb.DbTables.Keys) { if (folder.IndexOf("\\" + name + "\\", StringComparison.OrdinalIgnoreCase) > -1) { text = "(" + text + ") " + name + "." + key;//补充数据库前缀。 break; } } } //参数化格式 return(text); } } return(key); }
/// <summary> /// 根据名称获取原始的SQL(或视图)语句 /// </summary> /// <param name="key"></param> /// <returns></returns> public static string Get(string key) { if (!string.IsNullOrEmpty(key)) { string file = key.Replace(".sql", "") + ".sql"; string[] files = Directory.GetFiles(SqlCode.path, file, SearchOption.AllDirectories); if (files != null && files.Length > 0) { return(FileExtend.ReadAllText(files[0])); } if (FileList != null && FileList.ContainsKey(key)) { string path = FileList[key]; return(FileExtend.ReadAllText(path)); } } return(string.Empty); }