private static void DescrambleScript(Options options) { if (options.Input == null) { throw new NullReferenceException("No input file was specified."); } if (File.Exists(options.Input)) { string output = options.Output ?? options.Input; DescrambleFile(options.Input, output); } if (Directory.Exists(options.Input)) { string pattern = options.Filter ?? "*"; string[] filenames = Directory.GetFiles(options.Input, pattern); foreach (string filename in filenames) { DescrambleFile(filename, filename); } } void DescrambleFile(string input, string output) { var script = new DataBuffer(File.ReadAllBytes(input), options.Game, 0); ScriptTools.DescrambleScript(script); File.WriteAllBytes(output, script.ToArray()); } }
public Task <object> GetResult(object[] parameters, InterpretationData data) { return(Task.Run(() => { return meth.Invoke(ScriptTools.GetParametersFromArray(parameters)); })); }
public void LargestExponential() { string content = ScriptTools.Cat(@"c:\euler\p099_base_exp.txt"); var original = content.Lines().ToArray(); var lines = content.Lines() .Map <string, double>( str => { var numbers = str.Split(new char[] { ',' }); var a = int.Parse(numbers[0]); var b = int.Parse(numbers[1]); return(Math.Log10((double)a) * (double)b); } ); double max = 0.0; int index = 1; int max_idx = 1; foreach (var line in lines) { if (max < line) { max = line; max_idx = index; } index++; } Console.WriteLine("Max line {0}: {1}", max_idx, original[max_idx]); }
public void CreateTables(string ddl) { var statements = ScriptTools.SplitScript(ddl); using (var con = CreateConnection()) { using (var cmd = con.CreateCommand()) { cmd.Connection = con; con.Open(); //break dll into separate statements and execute them. foreach (var batch in statements) { foreach (var statement in ScriptTools.SplitBySemicolon(batch)) { //ignore the drop table bit, which has no useful commands if (statement.StartsWith("-- DROP TABLE", StringComparison.OrdinalIgnoreCase)) { continue; } if (statement.StartsWith("-- ALTER TABLE", StringComparison.OrdinalIgnoreCase)) { continue; } cmd.CommandText = statement; cmd.ExecuteNonQuery(); } } } } }
/// <summary> /// 绘制窗口时调用 /// </summary> private void OnGUI() { //输入框控件 text = EditorGUILayout.TextField("输入系统名(必要):", text); EditorGUILayout.Space(); if (GUILayout.Button("生成Dialog", GUILayout.Width(200))) { if (!string.IsNullOrEmpty(text)) { ScriptTools.CreateLuaDialogFile(text + "Dialog"); } } if (GUILayout.Button("生成DialogSkin", GUILayout.Width(200))) { if (!string.IsNullOrEmpty(text)) { ScriptTools.CreateLuaDialogSkinFile(text + "DialogSkin"); } } if (GUILayout.Button("生成DialogConfig", GUILayout.Width(200))) { if (!string.IsNullOrEmpty(text)) { ScriptTools.CreateLuaDialogConfigFile(text + "DialogConfig"); } } EditorGUILayout.Space(); EditorGUILayout.LabelField("Dialog、DialogConfig、DialogSkin"); if (GUILayout.Button("一键生成Dialog", GUILayout.Width(200))) { if (!string.IsNullOrEmpty(text)) { ScriptTools.CreateLuaDialogFile(text + "Dialog"); ScriptTools.CreateLuaDialogSkinFile(text + "DialogSkin"); ScriptTools.CreateLuaDialogConfigFile(text + "DialogConfig"); } } EditorGUILayout.Space(); EditorGUILayout.LabelField("仅限第一次创建时使用Dialog、DialogConfig、DialogSkin、Data、Manager..."); if (GUILayout.Button("一键生成全部目录及文件", GUILayout.Width(300))) { if (!string.IsNullOrEmpty(text)) { ScriptTools.CreateLuaDialogFile(text + "Dialog"); ScriptTools.CreateLuaDialogSkinFile(text + "DialogSkin"); ScriptTools.CreateLuaDialogConfigFile(text + "DialogConfig"); ScriptTools.CreateLuaManagerFile(text + "Manager"); ScriptTools.CreateDataFile(); ScriptTools.CreateFrameFile(); } } EditorGUILayout.Space(); EditorGUILayout.LabelField("1、输入系统名称,如A"); EditorGUILayout.LabelField("2、生成文件:ADialog、ADialogConfig、ADialogSkin"); EditorGUILayout.LabelField("3、Dialog目录主要写窗体文件"); EditorGUILayout.LabelField("4、Frame可写除Dialog相关的面板"); EditorGUILayout.LabelField("5、Data主要写数据结构"); EditorGUILayout.LabelField("6、通信写Manager目录"); }
private static void Execute(DbCommand cmd, string statements) { foreach (var statement in ScriptTools.SplitScript(statements)) { Console.WriteLine("Executing " + statement); cmd.CommandText = statement; cmd.ExecuteNonQuery(); } }
private static void Execute(DbCommand cmd, string sql) { //we need to strip out the "GO" parts from these scripts AND by ; foreach (var batch in ScriptTools.SplitScript(sql)) { foreach (var statement in ScriptTools.SplitBySemicolon(batch)) { Console.WriteLine("Executing " + statement); cmd.CommandText = statement; cmd.ExecuteNonQuery(); } } }
private Task <object> Execute(CommandModel cmd, InterpretationData data) { return(Task.Run(new Func <object>(() => { string script = cmd.Command; int assignmentIndex = ScriptTools.GetCharIndexOutsideBrackets(script, '='); string varName = script.Substring(0, assignmentIndex).Trim(); string valueString = script.Substring(assignmentIndex + 1, (script.Length - 1) - assignmentIndex).Trim(); object value = Interpreter.ExecuteCommand(valueString, data); data.Vars[varName] = value; return value; }))); }
private bool IsValidConstruction(CommandModel cmd, InterpretationData data) { int index = ScriptTools.GetCharIndexOutsideBrackets(cmd.Command, '='); if (index == 0 || index == cmd.Command.Length - 1 || index == -1) { return(false); } if (cmd.Command[index - 1] == '=' || cmd.Command[index + 1] == '=' || cmd.Command[index - 1] == '!') { return(false); } return(ScriptTools.GetCharIndexOutsideBrackets(cmd.Command, '.') == -1); }
public void CodedTriangleNumbers() { string content = ScriptTools.Cat(@"C:\euler\p042_words.txt"); var words = content.Replace("\"", "").Split(new char[] { ',' }); var numbers = words.Map <string, int>(word => word.Map <char, int>(c => c - 'A' + 1).Sum()); var triangles = Itertools.Range(1, 1000).Map <int, int>(i => i * (i + 1) / 2); var result = 0; foreach (var number in numbers) { if (triangles.Contains(number)) { result++; } } Console.WriteLine("result is {0}", result); }
private bool ParseFuncData(string cmd) { int bracketIndex = cmd.IndexOf('('); if (bracketIndex == -1) { return(false); } KeyWord = cmd.Substring(0, bracketIndex).Trim(); //берём ключевое слово: всё до параметров if (KeyWord.Contains(' ')) //если ключевое слово состоит более чем из 1 слова { return(false); } int startParsIndex = bracketIndex + 1;//Начинаем с символа после первой скобки int lastParsIndex = startParsIndex; int bracketsCount = 1; int marksCount = 0; for (; lastParsIndex < cmd.Length; lastParsIndex++) { if (cmd[lastParsIndex] == '\"') { marksCount++; } if (marksCount % 2 == 0) { if (cmd[lastParsIndex] == '(') { bracketsCount++; } if (cmd[lastParsIndex] == ')') { bracketsCount--; } } if (bracketsCount == 0) { break; } } var stringPars = cmd.Substring(startParsIndex, lastParsIndex - startParsIndex); parameters = ScriptTools.GetParameters(stringPars); return(true); }
/// <summary> /// 获取所有的api /// </summary> private void queryApis() { try { List <ScriptMethAttribute> scriptMethAttributes = JsonConvert.DeserializeObject <List <ScriptMethAttribute> >(scriptClient.GetStringAsync(GetApisUrl)); TreeData treeData = new TreeData("脚本函数"); foreach (var item in scriptMethAttributes) { ScriptTools.GetIItemboxByScriptMeth <ItemBox, ParatItem>(treeData, item); } ObservableCollection <TreeData> treeDatas = new ObservableCollection <TreeData>(); treeDatas.Add(treeData); scriptContent.RestFunctionData(); scriptContent.SetFunctionData(treeDatas); MessageBox.Show("请求成功, 更新测试块列表成功!"); } catch (Exception ex) { Log.Write(ex); MessageBox.Show("请求失败, 请确认填写的url是否正确!"); } }
public static void ExecuteScript(string script, InterpretationData data) { try { data.Stopper.RegisterStopper(stopSender); string[] commands = ScriptTools.GetCommands(script); foreach (var cmd in commands) { ExecuteCommand(cmd, data); } } catch (Exception e) when(!(e is ReturnException) && !(e is BreakException)) { if (!data.Stopper.IsStopped) { MessageBox.Show(e.ToString(), "Ошибка"); } } finally { data.Stopper.UnRegisterStopper(stopSender); } }
public void TestMigration() { //arrange var tableName = MigrationCommon.FindFreeTableName(ProviderName, _connectionString); var migration = new DdlGeneratorFactory(SqlType.SqlServer).MigrationGenerator(); var table = MigrationCommon.CreateTestTable(tableName); var newColumn = MigrationCommon.CreateNewColumn(); //this creates a nullable column with no default. Normally we automatically create a default. //ensure it is nullable, as we don't want to create a default which we can't delete newColumn.Nullable = true; var unqiueConstraint = MigrationCommon.CreateUniqueConstraint(newColumn); var fk = MigrationCommon.CreateForeignKey(table); var index = MigrationCommon.CreateUniqueIndex(newColumn, tableName); var createTable = migration.AddTable(table); var addColumn = migration.AddColumn(table, newColumn); var addUniqueConstraint = migration.AddConstraint(table, unqiueConstraint); var addForeignKey = migration.AddConstraint(table, fk); var addUniqueIndex = migration.AddIndex(table, index); var dropUniqueIndex = migration.DropIndex(table, index); var dropForeignKey = migration.DropConstraint(table, fk); var dropUniqueConstraint = migration.DropConstraint(table, unqiueConstraint); var dropColumn = migration.DropColumn(table, newColumn); var dropTable = migration.DropTable(table); var statements = ScriptTools.SplitScript(createTable); //we need to strip out the "GO" parts from these scripts using (new TransactionScope()) { using (var con = _factory.CreateConnection()) { con.ConnectionString = _connectionString; using (var cmd = con.CreateCommand()) { con.Open(); foreach (var statement in statements) { //ignore the drop table bit, which has no useful commands if (statement.Contains(Environment.NewLine + "-- DROP TABLE")) { continue; } Console.WriteLine("Executing " + statement); cmd.CommandText = statement; cmd.ExecuteNonQuery(); } Execute(cmd, addColumn); Execute(cmd, addUniqueConstraint); Execute(cmd, addForeignKey); Execute(cmd, dropForeignKey); Execute(cmd, dropUniqueConstraint); Execute(cmd, addUniqueIndex); Execute(cmd, dropUniqueIndex); Execute(cmd, dropColumn); Execute(cmd, dropTable); } } } }