public async Task CreateFromResourceFileAsync(Assembly assembly, string resourceFile)
        {
            //logger.Debug($"CreateFromResourceFileAsync():resourceNames={string.Join(",", assembly.GetManifestResourceNames())}");
            string sql = await FileX.LoadResourceAsTextAsync(assembly, resourceFile);

            await this.CreateFromSqlAsync(sql);
        }
Exemplo n.º 2
0
 private FileDao()
 {
     file       = new FileX();
     stocks     = file.GetStocks();
     operations = new Operations();
     logical    = new StocksLogical();
 }
Exemplo n.º 3
0
        public void ParseNotifyMessage()
        {
            var email = FileX.LoadResourceAsText(Assembly.GetExecutingAssembly(), "Butterfly.Notify.Test.email.txt");
            var templateNotifyMessage = NotifyMessage.Parse(email);
            var notifyMessage         = templateNotifyMessage.Evaluate(new {
                first_name = "Bob"
            });

            Assert.IsTrue(notifyMessage.bodyText.Trim().StartsWith("Hello, Bob."));
        }
Exemplo n.º 4
0
        public void ParseSendMessage()
        {
            var email = FileX.LoadResourceAsText(Assembly.GetExecutingAssembly(), "Butterfly.Message.Test.email.txt");
            var sendMessageTemplate = SendMessage.Parse(email, SimpleEvaluator.Evaluate);
            var sendMessage         = sendMessageTemplate.Evaluate(new {
                first_name = "Bob"
            });

            Assert.IsTrue(sendMessage.bodyText.Trim().StartsWith("Hello, Bob."));
        }
Exemplo n.º 5
0
        private void downloadbtn_Click(object sender, EventArgs e)
        {
            int i = listfiles.SelectedIndex;

            if (i != -1)
            {
                if (SelectService != null)
                {
                    tempFile              = SelectService.ListFile[i];
                    progressBar1.Maximum  = tempFile.Capacity;
                    downloadtimer.Enabled = true;
                }
            }
        }
Exemplo n.º 6
0
        public FileX FindFileId(string id)
        {
            FileX result = null;

            foreach (EnemyComp e in X_Enemies)
            {
                foreach (ServiceX s in e.Services)
                {
                    foreach (FileX f in s.ListFile)
                    {
                        if (f.id == id)
                        {
                            return(f);
                        }
                    }
                }
            }
            return(result);
        }
Exemplo n.º 7
0
 private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (isUpload)
     {
         ListBox lb = (ListBox)sender;
         if (lb.SelectedIndex != -1)
         {
             string s = lb.Items[lb.SelectedIndex].ToString();
             foreach (FileX file in listFilePlayer)
             {
                 if (file.Name == s)
                 {
                     tempFile               = file;
                     progressBar1.Maximum   = file.Capacity;
                     progressBar1.Value     = 0;
                     uploadtimer.Enabled    = true;
                     listBox1.SelectedIndex = -1;
                     isUpload               = false;
                 }
             }
         }
     }
 }
Exemplo n.º 8
0
        ResponseData EventedData(GameScript handle)
        {
            ResponseData result = new ResponseData("event");

            switch (this.TypeOutEvent)
            {
            case TypeOutEventX.ENEMY:
            {
                handle.ListEnemy.Add(outEventData as EnemyComp);
                (outEventData as EnemyComp).Initialize();
                break;
            }

            case TypeOutEventX.MAIL:
            {
                handle.player.ListMail.Add(outEventData as MailX);
                break;
            }

            case TypeOutEventX.WANTED:
            {
                handle.player.Wanted += SByte.Parse(this.outEventData.ToString());
                break;
            }

            case TypeOutEventX.FILE:
            {
                FileX file = outEventData as FileX;
                handle.player.Computer.FileList.Add(file);
                break;
            }
            }
            this.isEvented = true;
            result.Data.Add(true);
            return(result);
        }
Exemplo n.º 9
0
        /**
         * Start the Janet-Sudoku Tutorial code.
         * @param args    No arguments are considered.
         */
        public static void Start()
        {
            String tmpDir = FileX.getTmpDir();
            {
                /*
                 * Simple sudoku generation.
                 */
                SudokuStore.consolePrintln("");
                SudokuStore.consolePrintln("Simple sudoku generation.");
                SudokuGenerator sg = new SudokuGenerator();
                int[,] puzzle = sg.generate();
                SudokuStore.consolePrintBoard(puzzle);
            }
            {
                /*
                 * Simple sudoku generation + parameters.
                 */
                SudokuStore.consolePrintln("");
                SudokuStore.consolePrintln("Simple sudoku generation + parameters.");
                SudokuGenerator sg = new SudokuGenerator(SudokuGenerator.PARAM_GEN_RND_BOARD);
                int[,] puzzle = sg.generate();
                SudokuStore.consolePrintBoard(puzzle);
            }
            {
                /*
                 * Simple sudoku generation + puzzle rating.
                 */
                SudokuStore.consolePrintln("");
                SudokuStore.consolePrintln("Simple sudoku generation + puzzle rating.");
                SudokuGenerator sg = new SudokuGenerator();
                int[,] puzzle = sg.generate();
                int rating = SudokuStore.calculatePuzzleRating(puzzle);
                SudokuStore.consolePrintBoard(puzzle);
                SudokuStore.consolePrintln("Puzzle rating: " + rating);
            }
            {
                /*
                 * Solving sudoku example.
                 */
                SudokuStore.consolePrintln("");
                SudokuStore.consolePrintln("Solving sudoku example.");
                SudokuSolver ss = new SudokuSolver(SudokuPuzzles.PUZZLE_EXAMPLE_001);
                SudokuStore.consolePrintBoard(ss.getBoard());
                ss.solve();
                SudokuStore.consolePrintBoard(ss.getSolvedBoard());
            }
            {
                /*
                 * Saving board examples
                 */
                SudokuStore.consolePrintln("");
                SudokuStore.consolePrintln("Saving board examples " + tmpDir);
                SudokuStore.saveBoard(SudokuPuzzles.PUZZLE_EXAMPLE_001, tmpDir + "sudoku-board-ex-1.txt");
                SudokuStore.saveBoard(SudokuPuzzles.PUZZLE_EXAMPLE_001, tmpDir + "sudoku-board-ex-2.txt", "This is a head comment");
                SudokuStore.saveBoard(SudokuPuzzles.PUZZLE_EXAMPLE_001, tmpDir + "sudoku-board-ex-3.txt", "This is a head comment", "And a tail comment");
                SudokuSolver ss = new SudokuSolver(1);
                ss.solve();
                ss.saveSolvedBoard(tmpDir + "sudoku-board-ex-sol.txt", "Solution for the PUZZLE_EXAMPLE_001");
            }

            /*
             * And many other staff provided by the library :-)
             */
        }
Exemplo n.º 10
0
        public void ReadEnemy(string path)
        {
            try
            {
                XDocument xDoc = XDocument.Load(path);
                foreach (XElement enem in xDoc.Root.Elements())
                {
                    EnemyComp x_enemy = new EnemyComp();
                    x_enemy.id   = enem.Attribute("id").Value;
                    x_enemy.Addr = enem.Attribute("address").Value;
                    RePoint r = new RePoint();
                    x_enemy.Position  = r.Point(float.Parse(enem.Element("position").Attribute("x").Value), float.Parse(enem.Element("position").Attribute("y").Value));
                    x_enemy.isScaning = bool.Parse(enem.Element("isscan").Value);
                    x_enemy.isVisible = bool.Parse(enem.Element("isvisible").Value);
                    x_enemy.Money     = int.Parse(enem.Element("money").Value);
                    foreach (XElement sx in enem.Element("services").Elements("service"))
                    {
                        ServiceX service = new ServiceX(int.Parse(sx.Element("timestart").Value), int.Parse(sx.Element("port").Value));
                        service.id   = sx.Attribute("id").Value;
                        service.Desc = sx.Element("name").Value;
                        switch (sx.Element("type").Value)
                        {
                        case "NONE": service.Type = TypeServiceX.NONE;
                            break;

                        case "FTP": service.Type = TypeServiceX.FTP;
                            break;

                        case "FIREWALL": service.Type = TypeServiceX.FIREWALL;
                            break;

                        case "ATM": service.Type = TypeServiceX.ATM;
                            break;

                        case "PROXY": service.Type = TypeServiceX.PROXY;
                            break;

                        case "SSH": service.Type = TypeServiceX.SSH;
                            break;

                        default: service.Type = TypeServiceX.NONE;
                            break;
                        }
                        service.Pass       = sx.Element("pass").Value;
                        service.isHackPass = bool.Parse(sx.Element("ishackpass").Value);
                        foreach (XElement fx in sx.Element("files").Elements("file"))
                        {
                            FileX file = null;
                            switch (fx.Attribute("type").Value)
                            {
                            case "TXT": file = new FileTxtX();
                                break;

                            case "SCRIPT": file = new FileScriptX();
                                break;

                            case "EXPLOIT": file = new FileExploitX();
                                break;

                            case "DATA": file = new FileDataX();
                                break;

                            case "SSHKEY": file = new FileSSHKeyX();
                                break;

                            default: file = new FileX();
                                break;
                            }
                            file.id       = fx.Attribute("id").Value;
                            file.Capacity = int.Parse(fx.Attribute("capacity").Value);
                            file.Name     = fx.Attribute("name").Value;
                            file.AddText(fx.Value);
                            service.AddFile(file);
                        }
                        x_enemy.AddService(service);
                    }
                    X_Enemies.Add(x_enemy);
                }
            }
            catch (Exception ex) { LOG.Error("ERROR LOAD comp.xml: {" + ex.Message + "}"); }
        }
Exemplo n.º 11
0
        public void ReadEvent(string path)
        {
            XDocument  xDoc = XDocument.Load(path);
            GameScript game = new GameScript();

            foreach (XElement ev in xDoc.Root.Elements("outs"))
            {
                EventGame Event = new EventGame(TypeInEventX.None, TypeOutEventX.None);
                foreach (XElement file in ev.Element("files").Elements("file"))
                {
                    FileX f = null;
                    switch (file.Attribute("type").Value)
                    {
                    case "TXT": f = new FileTxtX();
                        break;

                    case "SCRIPT": f = new FileScriptX();
                        break;

                    case "EXPLOIT": f = new FileExploitX();
                        break;

                    case "DATA": f = new FileDataX();
                        break;

                    case "SSHKEY": f = new FileSSHKeyX();
                        break;

                    default: f = new FileX();
                        break;
                    }
                    f.id       = file.Attribute("id").Value;
                    f.Capacity = int.Parse(file.Attribute("capacity").Value);
                    f.Name     = file.Attribute("name").Value;
                    f.AddText(file.Value);
                    Ev_File.Add(f);
                }
                foreach (XElement enem in ev.Element("enemies").Elements("enemy"))
                {
                    EnemyComp x_enemy = new EnemyComp();
                    x_enemy.id   = enem.Attribute("id").Value;
                    x_enemy.Addr = enem.Attribute("address").Value;
                    RePoint r = new RePoint();
                    x_enemy.Position  = r.Point(float.Parse(enem.Element("position").Attribute("x").Value), float.Parse(enem.Element("position").Attribute("y").Value));
                    x_enemy.isScaning = bool.Parse(enem.Element("isscan").Value);
                    x_enemy.isVisible = bool.Parse(enem.Element("isvisible").Value);
                    x_enemy.Money     = int.Parse(enem.Element("money").Value);
                    foreach (XElement sx in enem.Element("services").Elements("service"))
                    {
                        ServiceX service = new ServiceX(int.Parse(sx.Element("timestart").Value), int.Parse(sx.Element("port").Value));
                        service.id   = sx.Attribute("id").Value;
                        service.Desc = sx.Element("name").Value;
                        switch (sx.Element("type").Value)
                        {
                        case "NONE": service.Type = TypeServiceX.NONE;
                            break;

                        case "FTP": service.Type = TypeServiceX.FTP;
                            break;

                        case "FIREWALL": service.Type = TypeServiceX.FIREWALL;
                            break;

                        case "ATM": service.Type = TypeServiceX.ATM;
                            break;

                        case "PROXY": service.Type = TypeServiceX.PROXY;
                            break;

                        case "SSH": service.Type = TypeServiceX.SSH;
                            break;

                        default: service.Type = TypeServiceX.NONE;
                            break;
                        }
                        service.Pass       = sx.Element("pass").Value;
                        service.isHackPass = bool.Parse(sx.Element("ishackpass").Value);
                        foreach (XElement fx in sx.Element("files").Elements("file"))
                        {
                            FileX file = null;
                            switch (fx.Attribute("type").Value)
                            {
                            case "TXT": file = new FileTxtX();
                                break;

                            case "SCRIPT": file = new FileScriptX();
                                break;

                            case "EXPLOIT": file = new FileExploitX();
                                break;

                            case "DATA": file = new FileDataX();
                                break;

                            case "SSHKEY": file = new FileSSHKeyX();
                                break;

                            default: file = new FileX();
                                break;
                            }
                            file.id       = fx.Attribute("id").Value;
                            file.Capacity = int.Parse(fx.Attribute("capacity").Value);
                            file.Name     = fx.Attribute("name").Value;
                            file.AddText(fx.Value);
                            service.AddFile(file);
                        }
                        x_enemy.AddService(service);
                    }
                    Ev_Enemy.Add(x_enemy);
                }
                foreach (XElement m in ev.Element("mails").Elements("mail"))
                {
                    MailX mail = new MailX(m.Attribute("name").Value);
                    mail.ids = m.Attribute("id").Value;
                    mail.AddText(m.Value);
                    Ev_Mail.Add(mail);
                }
                foreach (XElement w in ev.Element("wanteds").Elements("wanted"))
                {
                    Ev_Wanted.Add(new E_Wanted(w.Attribute("id").Value, int.Parse(w.Value)));
                }
                foreach (XElement even in xDoc.Root.Element("ev").Elements("event"))
                {
                    TypeInEventX t_in    = TypeInEventX.None;
                    object       obj_inn = null;
                    switch (even.Element("in").Attribute("type").Value)
                    {
                    case "E_Scan":
                    {
                        t_in    = TypeInEventX.E_Scan;
                        obj_inn = FindEnemyId(even.Element("in").Element("enemy").Value);
                        break;
                    }

                    case "E_Crack":
                    {
                        t_in    = TypeInEventX.E_Crack;
                        obj_inn = FindEnemyId(even.Element("in").Element("enemy").Value);
                        break;
                    }

                    case "Time":
                    {
                        t_in    = TypeInEventX.Time;
                        obj_inn = int.Parse(even.Element("in").Element("time").Value);
                        break;
                    }

                    case "File":
                    {
                        t_in    = TypeInEventX.File;
                        obj_inn = FindFileId(even.Element("in").Element("file").Value);
                        break;
                    }

                    case "Wanted":
                    {
                        t_in    = TypeInEventX.Wanted;
                        obj_inn = int.Parse(even.Element("in").Element("wanted").Value);
                        break;
                    }

                    case "Connected":
                    {
                        t_in    = TypeInEventX.Connected;
                        obj_inn = FindEnemyId(even.Element("in").Element("enemy").Value);
                        break;
                    }

                    case "Service_off":
                    {
                        t_in    = TypeInEventX.Service_off;
                        obj_inn = FindServiceId(even.Element("in").Element("service").Value);
                        break;
                    }

                    default: t_in = TypeInEventX.None;
                        break;
                    }
                    object        obj_out = null;
                    TypeOutEventX t_out   = TypeOutEventX.None;
                    obj_out = FindEventOut(even.Element("out").Attribute("id").Value, out t_out);
                    X_Event.Add(game.AddEvent(t_in, t_out, obj_inn, obj_out));
                }
            }
        }
Exemplo n.º 12
0
    static void GenerateFileFrom(List <SceneElement> sceneAssets)
    {
        using (var fileWithWriter = FileX.OpenFileFlushedAndReadyToWrite(GENERATED_FILE_NAME))
        {
            StreamWriter writer = fileWithWriter.StreamWriter;

            writer.Write(
                @"// THIS CODE IS GENERATED
// DO NOT MODIFY IT

using UnityEditor;
using UnityEditor.SceneManagement;

public static class SceneShortcuts
{

");
            sceneAssets.Sort((a, b) => a.Path.CompareTo(b.Path));

            int    prio       = 0;
            string lastFolder = "";
            foreach (SceneElement scene in sceneAssets)
            {
                if (ShouldSceneBeExcluded(scene.Path))
                {
                    continue;
                }


                string sceneName      = Path.GetFileNameWithoutExtension(scene.Path);
                string scenePathNoExt = PathX.RemoveExtension(scene.Path);
                string folder         = scenePathNoExt.RemoveFirst(sceneName);
                string methodName     = scenePathNoExt.Replace(' ', '_').Replace('/', '_').Replace('(', '_').Replace(')', '_');

                if (lastFolder != folder)
                {
                    prio += 1000;
                }

                string menuItemName;
                if (FLATTEN)
                {
                    menuItemName = sceneName;
                }
                else
                {
                    menuItemName = scenePathNoExt;
                    foreach (string searchFolder in SCENE_SEARCH_FOLDERS)
                    {
                        if (scenePathNoExt.StartsWith(searchFolder))
                        {
                            menuItemName = menuItemName.Remove(0, searchFolder.Length + 1);
                        }
                    }

                    foreach (var word in MENU_ITEM_STRIPPED_WORDS)
                    {
                        menuItemName = menuItemName.RemoveFirst(word);
                    }
                }

                writer.WriteLine($@"    [MenuItem(""Scene Shortcuts/{menuItemName}"", priority = {prio++})]");
                writer.WriteLine($@"    public static void {methodName}() => LoadScene(""{scene.Path}"");");
                writer.WriteLine();

                lastFolder = folder;
            }
            writer.Write(
                @"
    private static void LoadScene(string scenePath)
    {
        if (EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo())
        {
            EditorSceneManager.OpenScene(scenePath);
        }
    }
}
");
            fileWithWriter.Dispose();
        }
    }
Exemplo n.º 13
0
        /**
         * Test scenario implementation.
         * @param testId        Test id.
         * @param threadId      Thread id.
         * @return              True is test successful, otherwise false.
         */
        static bool runTest(int testId, int threadId)
        {
            bool   testResult = true;
            String testDesc = "", resultDesc = "";

            int[,] a =
            {
                { 0, 0, 0, 8, 0, 0, 0, 0, 0 },
                { 4, 0, 0, 0, 1, 5, 0, 3, 0 },
                { 0, 2, 9, 0, 4, 0, 5, 1, 8 },
                { 0, 4, 0, 0, 0, 0, 1, 2, 0 },
                { 0, 0, 0, 6, 0, 2, 0, 0, 0 },
                { 0, 3, 2, 0, 0, 0, 0, 9, 0 },
                { 6, 9, 3, 0, 5, 0, 8, 7, 0 },
                { 0, 5, 0, 4, 8, 0, 0, 0, 1 },
                { 0, 0, 0, 0, 0, 3, 0, 0, 0 }
            };
            switch (testId)
            {
            case 0:
                testDesc = "SudokuSolver.setCell(int, int, int)";
                {
                    SudokuSolver s = new SudokuSolver();
                    s.setCell(0, 0, 0);
                    s.setCell(1, 0, 4);
                    s.setCell(2, 0, 0);
                    s.setCell(3, 0, 0);
                    s.setCell(4, 0, 0);
                    s.setCell(5, 0, 0);
                    s.setCell(6, 0, 6);
                    s.setCell(7, 0, 0);
                    s.setCell(8, 0, 0);
                    s.setCell(0, 1, 0);
                    s.setCell(1, 1, 0);
                    s.setCell(2, 1, 2);
                    s.setCell(3, 1, 4);
                    s.setCell(4, 1, 0);
                    s.setCell(5, 1, 3);
                    s.setCell(6, 1, 9);
                    s.setCell(7, 1, 5);
                    s.setCell(8, 1, 0);
                    s.setCell(0, 2, 0);
                    s.setCell(1, 2, 0);
                    s.setCell(2, 2, 9);
                    s.setCell(3, 2, 0);
                    s.setCell(4, 2, 0);
                    s.setCell(5, 2, 2);
                    s.setCell(6, 2, 3);
                    s.setCell(7, 2, 0);
                    s.setCell(8, 2, 0);
                    s.setCell(0, 3, 8);
                    s.setCell(1, 3, 0);
                    s.setCell(2, 3, 0);
                    s.setCell(3, 3, 0);
                    s.setCell(4, 3, 6);
                    s.setCell(5, 3, 0);
                    s.setCell(6, 3, 0);
                    s.setCell(7, 3, 4);
                    s.setCell(8, 3, 0);
                    s.setCell(0, 4, 0);
                    s.setCell(1, 4, 1);
                    s.setCell(2, 4, 4);
                    s.setCell(3, 4, 0);
                    s.setCell(4, 4, 0);
                    s.setCell(5, 4, 0);
                    s.setCell(6, 4, 5);
                    s.setCell(7, 4, 8);
                    s.setCell(8, 4, 0);
                    s.setCell(0, 5, 0);
                    s.setCell(1, 5, 5);
                    s.setCell(2, 5, 0);
                    s.setCell(3, 5, 0);
                    s.setCell(4, 5, 2);
                    s.setCell(5, 5, 0);
                    s.setCell(6, 5, 0);
                    s.setCell(7, 5, 0);
                    s.setCell(8, 5, 3);
                    s.setCell(0, 6, 0);
                    s.setCell(1, 6, 0);
                    s.setCell(2, 6, 5);
                    s.setCell(3, 6, 1);
                    s.setCell(4, 6, 0);
                    s.setCell(5, 6, 0);
                    s.setCell(6, 6, 8);
                    s.setCell(7, 6, 0);
                    s.setCell(8, 6, 0);
                    s.setCell(0, 7, 0);
                    s.setCell(1, 7, 3);
                    s.setCell(2, 7, 1);
                    s.setCell(3, 7, 2);
                    s.setCell(4, 7, 0);
                    s.setCell(5, 7, 9);
                    s.setCell(6, 7, 7);
                    s.setCell(7, 7, 0);
                    s.setCell(8, 7, 0);
                    s.setCell(0, 8, 0);
                    s.setCell(1, 8, 0);
                    s.setCell(2, 8, 8);
                    s.setCell(3, 8, 0);
                    s.setCell(4, 8, 0);
                    s.setCell(5, 8, 0);
                    s.setCell(6, 8, 0);
                    s.setCell(7, 8, 1);
                    s.setCell(8, 8, 0);
                    int[,] b = s.getBoard();

                    if ((SudokuStore.boardsAreEqual(a, b) == true))
                    {
                        resultDesc = "Expecting equal - are equal.";
                    }
                    else
                    {
                        resultDesc = "Expecting equal - are not equal.";
                        testResult = false;
                        SudokuStore.consolePrintln(s.getMessages());
                    }
                }
                break;

            case 1:
                testDesc = "SudokuSolver.getCellDigit(int, int)";
                {
                    SudokuSolver s1 = new SudokuSolver(a);
                    SudokuSolver s2 = new SudokuSolver();
                    for (int i = 0; i < SudokuBoard.BOARD_SIZE; i++)
                    {
                        for (int j = 0; j < SudokuBoard.BOARD_SIZE; j++)
                        {
                            int d = s1.getCellDigit(i, j);
                            s2.setCell(i, j, d);
                        }
                    }
                    int[,] b = s2.getBoard();
                    if ((SudokuStore.boardsAreEqual(a, b) == true))
                    {
                        resultDesc = "Expecting equal - are equal.";
                    }
                    else
                    {
                        resultDesc = "Expecting equal - are not equal.";
                        testResult = false;
                    }
                }
                break;

            case 2:
                testDesc = "SudokuSolver.getBoardCopy()";
                {
                    SudokuSolver s = new SudokuSolver(a);
                    int[,] b = s.getBoard();
                    int[,] c = s.getBoardCopy();
                    if ((SudokuStore.boardsAreEqual(b, c) == true))
                    {
                        resultDesc = "Expecting equal - are equal.";
                    }
                    else
                    {
                        resultDesc = "Expecting equal - are not equal.";
                        testResult = false;
                    }
                }
                break;

            case 3:
                testDesc = "SudokuSolver.getSolutionBoardCells()";
                {
                    SudokuSolver s = new SudokuSolver(a);
                    s.solve();
                    int[,] b = s.getSolvedBoard();
                    int[,] c = SudokuStore.boardCopy(a);
                    BoardCell[] sol = s.getSolutionBoardCells();
                    foreach (BoardCell bc in sol)
                    {
                        c[bc.rowIndex, bc.colIndex] = bc.digit;
                    }

                    if ((SudokuStore.boardsAreEqual(b, c) == true))
                    {
                        resultDesc = "Expecting equal - are equal.";
                    }
                    else
                    {
                        resultDesc = "Expecting equal - are not equal.";
                        testResult = false;
                    }
                }
                break;

            case 4:
                testDesc = "SudokuSolver.getAllBoardCells()";
                {
                    SudokuSolver s = new SudokuSolver(a);
                    int[,] b = s.getBoardCopy();
                    int[,] c = new int[SudokuBoard.BOARD_SIZE, SudokuBoard.BOARD_SIZE];
                    BoardCell[] bc = s.getAllBoardCells();
                    foreach (BoardCell cell in bc)
                    {
                        c[cell.rowIndex, cell.colIndex] = cell.digit;
                    }
                    if ((SudokuStore.boardsAreEqual(b, c) == true))
                    {
                        resultDesc = "Expecting equal - are equal.";
                    }
                    else
                    {
                        resultDesc = "Expecting equal - are not equal.";
                        testResult = false;
                    }
                }
                break;

            case 5:
                testDesc = "SudokuSolver.getAllSolutionsList()";
                {
                    SudokuSolver s = new SudokuSolver(SudokuPuzzles.PUZZLE_NON_UNIQUE_SOLUTION);
                    s.findAllSolutions();
                    List <SudokuBoard> solList;
                    solList = s.getAllSolutionsList();
                    foreach (SudokuBoard sb in solList)
                    {
                        if (SudokuStore.checkSolvedBoard(sb.board) == false)
                        {
                            testResult = false;
                            break;
                        }
                    }
                    if (testResult == true)
                    {
                        resultDesc = "Expecting each solution valid - each is valid.";
                    }
                    else
                    {
                        resultDesc = "Expecting each solution valid - found not valid.";
                    }
                }
                break;

            case 6:
                testDesc = "SudokuGenerator -> generate -> save -> load -> compare";
                {
                    String          filePath = FileX.getTmpDir() + FileX.genRndFileName(20, "txt");
                    SudokuGenerator g        = new SudokuGenerator(SudokuGenerator.PARAM_GEN_RND_BOARD);
                    int[,] generated = g.generate();
                    g.saveBoard(filePath, "generated", "saved");
                    int[,] loaded = SudokuStore.loadBoard(filePath);
                    FileX.removeFile(filePath);
                    if (SudokuStore.boardsAreEqual(generated, loaded) == false)
                    {
                        testResult = false;
                    }
                    if (testResult == true)
                    {
                        resultDesc = "Expecting equal - are equal.";
                    }
                    else
                    {
                        resultDesc = "Expecting equal - are not equal.";
                    }
                }
                break;

            case 7:
                testDesc = "SudokuSolver -> solve -> save -> load -> compare";
                {
                    String       filePath = FileX.getTmpDir() + FileX.genRndFileName(20, "txt");
                    SudokuSolver s        = new SudokuSolver(SudokuStore.getPuzzleExample());
                    s.solve();
                    int[,] solved = s.getSolvedBoard();
                    s.saveSolvedBoard(filePath, "solved", "saved");
                    int[,] loaded = SudokuStore.loadBoard(filePath);
                    FileX.removeFile(filePath);
                    if (SudokuStore.boardsAreEqual(solved, loaded) == false)
                    {
                        testResult = false;
                    }
                    if (testResult == true)
                    {
                        resultDesc = "Expecting equal - are equal.";
                    }
                    else
                    {
                        resultDesc = "Expecting equal - are not equal.";
                    }
                }
                break;
            }
            if (testResult == true)
            {
                SudokuStore.consolePrintln("(Thread: " + threadId + ") " + "Test: " + testId + " " + testDesc + " " + resultDesc + " >>> ApiTests, result: OK");
            }
            else
            {
                SudokuStore.consolePrintln("(Thread: " + threadId + ") " + "Test: " + testId + " " + testDesc + " " + resultDesc + " >>> ApiTests, result: ERROR");
            }
            return(testResult);
        }
Exemplo n.º 14
0
 public void AddFile(FileX file)
 {
     ListFile.Add(file);
 }
Exemplo n.º 15
0
        public override ResponseData CheckedEvent(GameScript handle)
        {
            ResponseData result = new ResponseData("event");

            if (!isEvented)
            {
                try
                {
                    switch (this.TypeInEvent)
                    {
                    case TypeInEventX.E_Crack:
                    {
                        EnemyComp e = inEventData as EnemyComp;
                        IEnumerable <EnemyComp> query = from ec in handle.ListEnemy
                                                        where ec.Addr == e.Addr
                                                        where ec.IsAllHack == true && ec.IsOffFirewall == true
                                                        select ec;
                        if (query.Count() > 0)
                        {
                            result = EventedData(handle);
                        }
                        break;
                    }

                    case TypeInEventX.E_Scan:
                    {
                        EnemyComp e = inEventData as EnemyComp;
                        IEnumerable <EnemyComp> query = from ec in handle.ListEnemy
                                                        where ec.Addr == e.Addr
                                                        where ec.isScaning == true
                                                        select ec;
                        if (query.Count() > 0)
                        {
                            result = EventedData(handle);
                        }
                        break;
                    }

                    case TypeInEventX.File:
                    {
                        FileX file = inEventData as FileX;
                        IEnumerable <FileX> query = from f in handle.player.Computer.FileList
                                                    where f.Name == file.Name
                                                    select f;
                        if (query.Count() > 0)
                        {
                            result = EventedData(handle);
                        }
                        break;
                    }

                    case TypeInEventX.Time:
                    {
                        if (isOk)
                        {
                            result = EventedData(handle);
                        }
                        break;
                    }

                    case TypeInEventX.Wanted:
                    {
                        int wanted = int.Parse(inEventData.ToString());
                        if (handle.player.Wanted >= wanted)
                        {
                            result = EventedData(handle);
                        }
                        break;
                    }

                    case TypeInEventX.Connected:
                    {
                        EnemyComp eComp = inEventData as EnemyComp;
                        if (eComp.isScaning)
                        {
                            if (handle.player.isConnected)
                            {
                                if ((handle.player.ConnectedEnemy.IsOffFirewall) && (handle.player.ConnectedEnemy.IsAllHack))
                                {
                                    if (handle.player.ConnectedEnemy.Addr == eComp.Addr)
                                    {
                                        result = EventedData(handle);
                                    }
                                }
                            }
                        }
                        break;
                    }

                    case TypeInEventX.Service_off:
                    {
                        ServiceX serv    = inEventData as ServiceX;
                        var      servOff = from ec in handle.ListEnemy
                                           where ec.Addr == serv.Parrent.Addr
                                           select ec into enC
                                           from ser in enC.Services
                                           where ser.Port == serv.Port
                                           select ser;
                        if (servOff.Count() > 0)
                        {
                            ServiceX s = servOff.ElementAt <ServiceX>(0);
                            if (s.isRun == false)
                            {
                                result = EventedData(handle);
                            }
                        }


                        break;
                    }
                    }
                }
                catch (Exception ex) { LOG.Error("Error event to: " + ex.Message); }
            }

            return(result);
        }
Exemplo n.º 16
0
 public FileXTests()
 {
     file = new FileX();
 }