/// <summary> /// Setup up the logger /// </summary> public FileLogger() { var dir = ScriptEngine.ConfigurationSettings.Settings.FileLoggerSettings.Folder; var file = ScriptEngine.ConfigurationSettings.Settings.FileLoggerSettings.FileName; var over = ScriptEngine.ConfigurationSettings.Settings.FileLoggerSettings.Overwrite; Path = FilePathBuilder.BuildPath(dir, file, over); }
/// <summary> /// Save a result of a run /// </summary> /// <param name="results"></param> public void SaveResults(ScriptRunResults results) { // get settings from configuration file var dir = ScriptEngine.ConfigurationSettings.Settings.FileResultsStorage.Folder; var file = ScriptEngine.ConfigurationSettings.Settings.FileResultsStorage.FileName; var over = ScriptEngine.ConfigurationSettings.Settings.FileResultsStorage.Overwrite; // generate the path (make it unique if necessary) var fileName = FilePathBuilder.BuildPath(dir, file, over); // save the file data File.WriteAllText(fileName, JsonConvert.SerializeObject(results)); }
/// <summary> /// Масштабировать изображение /// </summary> /// <param name="imagePath">Входное изображение</param> /// <param name="outputPath">Увеличенное изображение</param> public void ScaleImage(string imagePath, string outputPath) { var byteImage = ByteImageFileManager.ReadFile(imagePath); var result = ScaleImage(byteImage); var path = new FilePathBuilder(imagePath) .SetPath(outputPath) .SetAlgorithmName(GetType().Name) .SetScale(Scale) .Build(); ByteImageFileManager.Save(result, path); }
public static (bool status, string desc) Core(string invokePath, InvokeMethod method, string parameter) { var gamePath = Config.Read()["GamePath"]; //decide using internal script or external script if (File.Exists(new FilePathBuilder(invokePath).Enter("internal.script").Path)) { //use internal script //read file var fs = new StreamReader(new FilePathBuilder(invokePath).Enter("internal.script").Path, Encoding.UTF8); var data = fs.ReadToEnd(); fs.Close(); fs.Dispose(); try { return(InternalInvoker(method, (PackageType)Enum.Parse(typeof(PackageType), data), gamePath, invokePath, parameter)); } catch (Exception) { return(false, I18N.Core("ScriptInvoker_IllegalInternalFlagFileContent")); } } else { //use external script var folder_build = new FilePathBuilder(invokePath, Information.OS); folder_build.Enter("setup.cs"); var script_file = folder_build.Path; folder_build.Backtracking(); folder_build.Enter("setup.dll"); var dll_file = folder_build.Path; if (!File.Exists(script_file)) { return(false, I18N.Core("ScriptInvoker_NoScriptFile")); } if (!File.Exists(dll_file)) { //try compile var test = CompileScript(script_file, dll_file); if (!test.status) { return(false, I18N.Core("ScriptInvoker_CompileError", test.desc)); //todo: translation } } return(RealInvoker(dll_file, method, gamePath, invokePath, parameter)); } }
public static (bool status, string desc) Remove(string gamePath, string currentPath) { try { var _gamePath = new FilePathBuilder(gamePath); var _currentPath = new FilePathBuilder(currentPath); var deploy_cache = ScriptCommon.ReadDeploy(_currentPath.Enter("deploy.cfg").Path); if (deploy_cache == "") { return(true, ""); } var int_level = int.Parse(deploy_cache); var target_file = _gamePath.Enter("3D Entities").Enter("Level").Enter($"Level_{(int_level < 10 ? "0" : "")}{deploy_cache}.NMO").Path; ScriptCommon.RemoveWithRestore(target_file); } catch (Exception e) { return(false, "Runtime error:" + Environment.NewLine + e.Message); } return(true, ""); }
public static (bool status, string desc) Deploy(string gamePath, string currentPath, string parameter) { try { var _gamePath = new FilePathBuilder(gamePath, Information.OS); var _currentPath = new FilePathBuilder(currentPath); var cache_file = _currentPath.Enter("deploy.cfg").Path; _currentPath.Backtracking(); var local_map_file = _currentPath.Enter("MapNameInPackage.nmo").Path; var target_map_folder = _gamePath.Enter("3D Entities").Enter("Level").Path; //restore old var deploy_cache = ScriptCommon.ReadDeploy(cache_file); if (deploy_cache != "") { var old_level = int.Parse(deploy_cache); var target_old_file = new FilePathBuilder(target_map_folder).Enter($"Level_{(old_level < 10 ? "0" : "")}{deploy_cache}.NMO").Path; ScriptCommon.RemoveWithRestore(target_old_file); } ScriptCommon.RecordDeploy(cache_file, ""); //deploy new _gamePath = new FilePathBuilder(gamePath); _currentPath = new FilePathBuilder(currentPath); if (parameter == "") { return(true, ""); } var level = int.Parse(parameter); if (!(level >= 1 && level <= 15)) { return(false, "Illegal parameter range"); } var target_file = new FilePathBuilder(target_map_folder).Enter($"Level_{(level < 10 ? "0" : "")}{parameter}.NMO").Path; ScriptCommon.CopyWithBackups(target_file, local_map_file); ScriptCommon.RecordDeploy(cache_file, level.ToString()); } catch (Exception e) { return(false, "Runtime error:" + Environment.NewLine + e.Message); } return(true, ""); }
public static (bool status, string desc) Remove(string gamePath, string currentPath) { try { var _gamePath = new FilePathBuilder(gamePath).Enter("Sounds"); var _currentPath = new FilePathBuilder(currentPath); foreach (var item in file_list) { if (File.Exists(_currentPath.Enter(item).Path)) { ScriptCommon.RemoveWithRestore(_gamePath.Enter(item).Path); _gamePath.Backtracking(); } _currentPath.Backtracking(); } } catch (Exception e) { return(false, "Runtime error:" + Environment.NewLine + e.Message); } return(true, ""); }
private string BuildFilePath() { AtataContext context = AtataContext.Current; if (FilePathBuilder != null) { return(FilePathBuilder.Invoke(context).SanitizeForPath()); } string folderPath = FolderPathBuilder?.Invoke(context) ?? BuildDefaultFolderPath(); folderPath = folderPath.SanitizeForPath(); string fileName = FileNameBuilder?.Invoke(context) ?? BuildDefaultFileName(context); fileName = fileName.SanitizeForFileName(); return(Path.Combine(folderPath, fileName)); }
public static (bool status, string desc) Remove(string gamePath, string currentPath) { try { var _gamePath = new FilePathBuilder(gamePath); var _currentPath = new FilePathBuilder(currentPath); var deploy_cache = ScriptCommon.ReadDeploy(_currentPath.Enter("deploy.cfg").Path); if (deploy_cache == "") { return(true, ""); } var target_file = _gamePath.Enter("Sounds").Enter($"Music_Theme_{deploy_cache}").Path; ScriptCommon.RemoveWithRestore(target_file + "_1.wav"); ScriptCommon.RemoveWithRestore(target_file + "_2.wav"); ScriptCommon.RemoveWithRestore(target_file + "_3.wav"); } catch (Exception e) { return(false, "Runtime error:" + Environment.NewLine + e.Message); } return(true, ""); }
/// <summary> /// 建制 Mail /// </summary> /// <param name="topic">主题</param> /// <param name="stream">附件流</param> /// <returns>mail 管理者</returns> protected virtual MailManager BuildMail(TopicDto topic, Stream stream = null) { this.OnTopicBuilding(topic); var fileName = FilePathBuilder.BuildPath( string.Format("{0}-{1}", topic.TopicName, DateTime.Now.ToString("yyMMddHHmmss")), FileExtension.Excel2007); var subject = topic.Subject; var body = topic.Body; var mailTos = (from subscriber in topic.Subscribers select subscriber.Email).ToArray(); if (stream != null) { var attachmemts = new List <Tuple <Stream, string> > { Tuple.Create(stream, fileName) }; return(new MailManager(subject, body, mailTos, attachmemts)); } return(new MailManager(subject, body, mailTos)); }
public static (bool status, string desc) Remove(string gamePath, string currentPath) { try { var _gamePath = new FilePathBuilder(gamePath); var _currentPath = new FilePathBuilder(currentPath); var deploy_cache = ScriptCommon.ReadDeploy(_currentPath.Enter("deploy.cfg").Path); if (deploy_cache == "") { return(true, ""); } var target_file = _gamePath.Enter("Textures").Enter("Sky").Enter($"Sky_{deploy_cache}").Path; ScriptCommon.RemoveWithRestore(target_file + "_Back.BMP"); ScriptCommon.RemoveWithRestore(target_file + "_Down.BMP"); ScriptCommon.RemoveWithRestore(target_file + "_Front.BMP"); ScriptCommon.RemoveWithRestore(target_file + "_Left.BMP"); ScriptCommon.RemoveWithRestore(target_file + "_Right.BMP"); } catch (Exception e) { return(false, "Runtime error:" + Environment.NewLine + e.Message); } return(true, ""); }
public BenchmarkWorlds() { _filePathBuilder = new FilePathBuilder(); _fileWorldStateSaver = new FileWorldStateSaver(_filePathBuilder); }
public async Task Save(BackingStoreInfo info, string data) { var filePath = FilePathBuilder.Build(info, Constants.NotificationFileNameFormat); await File.WriteAllTextAsync(filePath, data); }
public static (bool status, string desc) Deploy(string gamePath, string currentPath, string parameter) { try { var _gamePath = new FilePathBuilder(gamePath, Information.OS); var _currentPath = new FilePathBuilder(currentPath); var cache_file = _currentPath.Enter("deploy.cfg").Path; _currentPath.Backtracking(); var local_file_folder = _currentPath.Path; var target_folder = _gamePath.Enter("Textures").Enter("Sky").Path; //restore old var deploy_cache = ScriptCommon.ReadDeploy(cache_file); if (deploy_cache != "") { var target_old_file = new FilePathBuilder(target_folder).Enter($"Sky_{deploy_cache}").Path; ScriptCommon.RemoveWithRestore(target_old_file + "_Back.BMP"); ScriptCommon.RemoveWithRestore(target_old_file + "_Down.BMP"); ScriptCommon.RemoveWithRestore(target_old_file + "_Front.BMP"); ScriptCommon.RemoveWithRestore(target_old_file + "_Left.BMP"); ScriptCommon.RemoveWithRestore(target_old_file + "_Right.BMP"); } ScriptCommon.RecordDeploy(cache_file, ""); //deploy new _gamePath = new FilePathBuilder(gamePath); _currentPath = new FilePathBuilder(currentPath); if (parameter == "") { return(true, ""); } var sky = "A"; var sp_param = parameter.Split('_'); if (sp_param[0] == "level") { var level = int.Parse(sp_param[1]); if (!(level >= 1 && level <= 15)) { return(false, "Illegal parameter range"); } sky = level_dict[level]; } else if (sp_param[0] == "sky") { sky = sp_param[1].ToUpper(); } else { return(false, "Illegal formation"); } if (!legal_character_dict.Contains(sky)) { return(false, "Illegal formation"); } var target_file = new FilePathBuilder(target_folder).Enter($"Sky_{sky}").Path; ScriptCommon.CopyWithBackups(target_file + "_Back.BMP", new FilePathBuilder(local_file_folder).Enter("back.bmp").Path); ScriptCommon.CopyWithBackups(target_file + "_Down.BMP", new FilePathBuilder(local_file_folder).Enter("down.bmp").Path); ScriptCommon.CopyWithBackups(target_file + "_Front.BMP", new FilePathBuilder(local_file_folder).Enter("front.bmp").Path); ScriptCommon.CopyWithBackups(target_file + "_Left.BMP", new FilePathBuilder(local_file_folder).Enter("left.bmp").Path); ScriptCommon.CopyWithBackups(target_file + "_Right.BMP", new FilePathBuilder(local_file_folder).Enter("right.bmp").Path); ScriptCommon.RecordDeploy(cache_file, sky); } catch (Exception e) { return(false, "Runtime error:" + Environment.NewLine + e.Message); } return(true, ""); }
public void SetUp() { _sut = new FilePathBuilder(); }
public static (bool status, string desc) Deploy(string gamePath, string currentPath, string parameter) { try { var _gamePath = new FilePathBuilder(gamePath, Information.OS); var _currentPath = new FilePathBuilder(currentPath); var cache_file = _currentPath.Enter("deploy.cfg").Path; _currentPath.Backtracking(); var local_file_folder = _currentPath.Path; var target_folder = _gamePath.Enter("Sounds").Path; //restore old var deploy_cache = ScriptCommon.ReadDeploy(cache_file); if (deploy_cache != "") { var target_old_file = new FilePathBuilder(target_folder).Enter($"Music_Theme_{deploy_cache}").Path; ScriptCommon.RemoveWithRestore(target_old_file + "_1.wav"); ScriptCommon.RemoveWithRestore(target_old_file + "_2.wav"); ScriptCommon.RemoveWithRestore(target_old_file + "_3.wav"); } ScriptCommon.RecordDeploy(cache_file, ""); //deploy new _gamePath = new FilePathBuilder(gamePath); _currentPath = new FilePathBuilder(currentPath); if (parameter == "") { return(true, ""); } var theme = "1"; var sp_param = parameter.Split('_'); if (sp_param[0] == "level") { var level = int.Parse(sp_param[1]); if (!(level >= 1 && level <= 15)) { return(false, "Illegal parameter range"); } theme = level_dict[level]; } else if (sp_param[0] == "theme") { theme = sp_param[1]; } else { return(false, "Illegal formation"); } if (!legal_character_dict.Contains(theme)) { return(false, "Illegal formation"); } var target_file = new FilePathBuilder(target_folder).Enter($"Music_Theme_{theme}").Path; ScriptCommon.CopyWithBackups(target_file + "_1.wav", new FilePathBuilder(local_file_folder).Enter("1.wav").Path); ScriptCommon.CopyWithBackups(target_file + "_2.wav", new FilePathBuilder(local_file_folder).Enter("2.wav").Path); ScriptCommon.CopyWithBackups(target_file + "_3.wav", new FilePathBuilder(local_file_folder).Enter("3.wav").Path); ScriptCommon.RecordDeploy(cache_file, theme); } catch (Exception e) { return(false, "Runtime error:" + Environment.NewLine + e.Message); } return(true, ""); }