コード例 #1
0
ファイル: Program.cs プロジェクト: Uzere/nlctest
        // обработка входного файла
        static void EvalScript(string inputFilename, string outputFilename) {
            RLETree chunk = null;
            var results = new List<string>();

            string[] lines;
            try {
                lines = File.ReadAllLines(inputFilename);
            } catch (FileNotFoundException) {
                ScriptFail(outputFilename, "Input file does not exist");
                return;
            }

            try {
                foreach (var line in lines) {
                    var tokens = line.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                    if(tokens.Length==0) {
                        continue;
                    }

                    switch (tokens[0]) {
                        case "load":
                            chunk = new RLETree(chunks, int.Parse(tokens[1]) * 1024 * 1024);
                            break;
                        case "get":
                            var x = int.Parse(tokens[1]);
                            var y = int.Parse(tokens[2]);
                            var z = int.Parse(tokens[3]);

                            var id = chunk.getBlock(x, y, z);
                            results.Add(id.ToString());
                            break;
                        case "set":
                            x = int.Parse(tokens[1]);
                            y = int.Parse(tokens[2]);
                            z = int.Parse(tokens[3]);
                            id = uint.Parse(tokens[4]);

                            chunk.setBlock(x, y, z, id);
                            break;
                        default:
                            ScriptFail(outputFilename, "Syntax error: unknown command");
                            return;
                    }
                }
            } catch (IndexOutOfRangeException) {
                ScriptFail(outputFilename, "Syntax error: wrong argument count");
                return;
            } catch (NullReferenceException) {
                ScriptFail(outputFilename, "Runtime error: no chunk loaded");
                return;
            } catch (FormatException) {
                ScriptFail(outputFilename, "Syntax error: wrong argument");
                return;
            } catch (OverflowException) {
                ScriptFail(outputFilename, "Syntax error: wrong argument");
                return;
            } catch (Exception e) {
                ScriptFail(outputFilename, "Unknown error: " + e.ToString());
                return;
            }

            File.WriteAllLines(outputFilename, results.ToArray());
            // длинный метод, на самом деле
        }
コード例 #2
0
        // обработка входного файла
        static void EvalScript(string inputFilename, string outputFilename)
        {
            RLETree chunk   = null;
            var     results = new List <string>();

            string[] lines;
            try {
                lines = File.ReadAllLines(inputFilename);
            } catch (FileNotFoundException) {
                ScriptFail(outputFilename, "Input file does not exist");
                return;
            }

            try {
                foreach (var line in lines)
                {
                    var tokens = line.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                    if (tokens.Length == 0)
                    {
                        continue;
                    }

                    switch (tokens[0])
                    {
                    case "load":
                        chunk = new RLETree(chunks, int.Parse(tokens[1]) * 1024 * 1024);
                        break;

                    case "get":
                        var x = int.Parse(tokens[1]);
                        var y = int.Parse(tokens[2]);
                        var z = int.Parse(tokens[3]);

                        var id = chunk.getBlock(x, y, z);
                        results.Add(id.ToString());
                        break;

                    case "set":
                        x  = int.Parse(tokens[1]);
                        y  = int.Parse(tokens[2]);
                        z  = int.Parse(tokens[3]);
                        id = uint.Parse(tokens[4]);

                        chunk.setBlock(x, y, z, id);
                        break;

                    default:
                        ScriptFail(outputFilename, "Syntax error: unknown command");
                        return;
                    }
                }
            } catch (IndexOutOfRangeException) {
                ScriptFail(outputFilename, "Syntax error: wrong argument count");
                return;
            } catch (NullReferenceException) {
                ScriptFail(outputFilename, "Runtime error: no chunk loaded");
                return;
            } catch (FormatException) {
                ScriptFail(outputFilename, "Syntax error: wrong argument");
                return;
            } catch (OverflowException) {
                ScriptFail(outputFilename, "Syntax error: wrong argument");
                return;
            } catch (Exception e) {
                ScriptFail(outputFilename, "Unknown error: " + e.ToString());
                return;
            }

            File.WriteAllLines(outputFilename, results.ToArray());
            // длинный метод, на самом деле
        }