//Saves any changes to the Pages Table
    protected void saveButton_Click(object sender, EventArgs e)
    {
        PagesTable pagesTable = new PagesTable(new DatabaseConnection());

        pageTable.saveContentChanges();
        pages.Pages = pageTable.getContent();

        //Foreach tableRow do the applicable database command (update/insert/delete) to mirror what the user has done in the table.
        int deleted = 0;

        foreach (ObjectTableRow objRow in pageTable.ObjectRows)
        {
            CustomPage page = (CustomPage)objRow.Obj;

            if (page.MarkedForDeletion == true) //delete page from database AND file structure
            {
                pagesTable.deleteCustomPage(page.PageID);
                File.Delete(Server.MapPath("~/") + page.PageURL);
                pages.Pages.Remove(page.SortIndex);
                deleted++;
            }
            else
            {
                page.SortIndex -= deleted;
                pagesTable.updateCustomPage(page); //update page
            }
        }

        //Remove Content
        Session.Remove("savedContent");
        Session["message"] = new Message("Pages Saved!", System.Drawing.Color.Green);

        //Reload page to clear any nonsense before loading
        Response.Redirect("CustomPageTool");
    }
Esempio n. 2
0
    //Loads all the NavBar content for each game the user is playing in.
    protected void loadPlayerGames()
    {
        Panel playerGames = new Panel();

        playerGames.ID       = "playerGames";
        playerGames.CssClass = "outerDropdownContainer";

        //Foreach Game database says User is playing in, create a corresponding Game Dropdown and associated panel.  These are both 'pretend' games
        //to display what it should look like if you actually are playing in two games.
        foreach (Game game in playerGamesList)
        {
            GameLink gameLink = new GameLink(playerGamesLink, playerCarrot);
            gameLink.ID           = Server.HtmlDecode(game.GameName + "PlayerLink");
            gameLink.Text         = game.GameName;
            gameLink.Text        += "<i class=\"fa fa-caret-down\"></i>";
            gameLink.GameCarrotID = game.GameName + "PlayerCarrot";
            gameLink.CssClass     = "dropdown-btn";
            playerGames.Controls.Add(gameLink);

            Panel gamePanel = new Panel();
            gamePanel.ID       = Server.HtmlDecode(game.GameName + "PlayerPanel");
            gamePanel.CssClass = "innerDropdownContainer";
            {
                GamePageButton gameInfo = new GamePageButton(gameLink, "Player/GameInformation", game);
                gameInfo.Text   = "Game Information";
                gameInfo.Click += new EventHandler(gamePageButtonClicked);
                gamePanel.Controls.Add(gameInfo);

                GamePageButton charList = new GamePageButton(gameLink, "Player/GameParty", game);
                charList.Text   = "Game Party";
                charList.Click += new EventHandler(gamePageButtonClicked);
                gamePanel.Controls.Add(charList);

                //Add Custom Pages
                PagesTable     pagesTable = new PagesTable(new DatabaseConnection());
                CustomPageList pages      = pagesTable.getGamePages(game.GameID);

                for (int i = 0; i < pages.Pages.Count; i++)
                {
                    CustomPage     page       = pages.Pages[i];
                    GamePageButton publicPage = new GamePageButton(gameLink, page.PageURL, game, true);
                    publicPage.Text   = page.PageName;
                    publicPage.Click += new EventHandler(gamePageButtonClicked);
                    gamePanel.Controls.Add(publicPage);
                }
            }
            playerGames.Controls.Add(gamePanel);
        }

        //Give a nice label if user has no games, so they are not sad :(
        if (playerGamesList.Count == 0)
        {
            Label noGamesLabel = new Label();
            noGamesLabel.Text     = "You have no games.";
            noGamesLabel.CssClass = "innerDropdownNoGames";
            playerGames.Controls.Add(noGamesLabel);
            playerGamesDropdown.Controls.Add(noGamesLabel);
        }

        else
        {
            playerGamesDropdown.Controls.Add(playerGames);
        }
    }
Esempio n. 3
0
 public void ReleaseResources()
 {
     PagesTable.DeallocateAllPages();
 }
Esempio n. 4
0
        public void DoNextInstruction()
        {
            if (IsFinished)
            {
                return;
            }

            string command = m_realMachine.ReadMem(PagesTable.GetPhysicalAddress(PC)).GetString().TrimStart();

            PC++;

            if (command.StartsWith(Commands.ADD.ToString()))
            {
                DoAdd();
                return;
            }
            if (command.StartsWith(Commands.SUB.ToString()))
            {
                DoSub();
                return;
            }
            if (command.StartsWith(Commands.CMP.ToString()))
            {
                DoCmp();
                return;
            }
            if (command.StartsWith(Commands.MUL.ToString()))
            {
                DoMul();
                return;
            }
            if (command.StartsWith(Commands.DIV.ToString()))
            {
                DoDiv();
                return;
            }
            if (command.StartsWith(Commands.WR.ToString()))
            {
                DoWR(command);
                return;
            }
            if (command.StartsWith(Commands.RD.ToString()))
            {
                DoRd(command);
                return;
            }
            if (command.StartsWith(Commands.LD.ToString()))
            {
                DoLD(command);
                return;
            }
            if (command.StartsWith(Commands.PT.ToString()))
            {
                DoPT(command);
                return;
            }
            if (command.StartsWith(Commands.JP.ToString()))
            {
                DoJp(command);
                return;
            }
            if (command.StartsWith(Commands.JE.ToString()))
            {
                DoJe(command);
                return;
            }
            if (command.StartsWith(Commands.JL.ToString()))
            {
                DoJL(command);
                return;
            }
            if (command.StartsWith(Commands.JG.ToString()))
            {
                DoJG(command);
                return;
            }
            if (command.StartsWith(Commands.FORK.ToString()))
            {
                DoFork();
                return;
            }
            // flush stack - removes one element from stack
            if (command.StartsWith(Commands.FLUS.ToString()))
            {
                DoFlus();
                return;
            }
            if (command.StartsWith(Commands.COPY.ToString()))
            {
                DoCopy();
                return;
            }
            if (command.StartsWith(Commands.STOP.ToString()))
            {
                DoStop();
                return;
            }
            //print symbol
            if (command.StartsWith(Commands.PRTS.ToString()))
            {
                DoPRTS();
                return;
            }
            //print number
            if (command.StartsWith(Commands.PRTN.ToString()))
            {
                DoPRTN();
                return;
            }
            //prints until & symbol is found - print buffer
            if (command.StartsWith(Commands.PF.ToString()))
            {
                DoPF(command);
                return;
            }
            //stack data address
            if (command.StartsWith(Commands.DA.ToString()))
            {
                DoDA(command);
                return;
            }
            //STACK DATA
            if (command.StartsWith(Commands.SD.ToString()))
            {
                DoSD(command);
                return;
            }
            //PUSH
            if (command.StartsWith(Commands.PS.ToString()))
            {
                DoPs(command);
                return;
            }
            if (String.IsNullOrWhiteSpace(command))
            {
                throw new ProgramContractException("Command instruction is blank line");
            }
            throw new ProgramContractException("Cound not find instruction: " + command);
        }
Esempio n. 5
0
 private void WriteMem(int virtualAddress, Word word)
 {
     m_realMachine.WriteMem(PagesTable.GetPhysicalAddress(virtualAddress), word);
 }
Esempio n. 6
0
 private Word ReadMem(int virtualAddress)
 {
     return(m_realMachine.ReadMem(PagesTable.GetPhysicalAddress(virtualAddress)));
 }
Esempio n. 7
0
        //Loads program (file) to memory and checks if program is good
        public void LoadProgramToMemmory(string programFilePath)
        {
            StreamReader file = new StreamReader(@programFilePath);

            try
            {
                //first line must be $AMJ
                var line = file.ReadLine();
                checkLine(line);
                if (!line.ToUpper().Equals(Settings.Default.ProgramCodeStartSymbol))
                {
                    throw new ProgramContractException("Program must start with $AMJ sign");
                }

                line = file.ReadLine();
                checkLine(line);
                Name = line;

                int  programPointer         = 0;
                var  maxProgramPointerValue = Settings.Default.ProgramSegmentPagesCount * Settings.Default.PageSize - 1;
                bool stopReadingProgramCode = false;
                do
                {
                    line = file.ReadLine();
                    checkLine(line);

                    if (programPointer > maxProgramPointerValue)
                    {
                        throw new ProgramContractException("Program's code is too long!");
                    }
                    if (!line.ToUpper().Equals(Settings.Default.ProgramDataStartSymbol))
                    {
                        var physicalAddress = PagesTable.GetPhysicalAddress(programPointer);
                        m_realMachine.WriteMem(physicalAddress, new Word(line));
                    }
                    else
                    {
                        stopReadingProgramCode = true;
                    }
                    programPointer++;
                } while (!stopReadingProgramCode);

                var dataPointer         = maxProgramPointerValue + 1;
                var maxDataPointerValue = dataPointer + Settings.Default.DataSegmentPagesCount * Settings.Default.PageSize;
                var stopReadingDataCode = false;
                do
                {
                    line = file.ReadLine();
                    checkLine(line);
                    if (dataPointer > maxDataPointerValue)
                    {
                        throw new ProgramContractException("Data code is too long!");
                    }
                    if (!line.ToUpper().Equals(Settings.Default.ProgramEndSymbol))
                    {
                        m_realMachine.WriteMem(PagesTable.GetPhysicalAddress(dataPointer), new Word(line));
                    }
                    else
                    {
                        stopReadingDataCode = true;
                    }
                    dataPointer++;
                } while (!stopReadingDataCode);
            }
            catch (Exception e)
            {
                PagesTable.DeallocateAllPages();
                throw;
            }
            finally
            {
                file.Close();
            }
        }
    //Loads the custom pages from the database
    private void loadPages()
    {
        PagesTable pagesTable = new PagesTable(new DatabaseConnection());

        pages = pagesTable.getGamePages(game.GameID);
    }
    //Uploads PDF files and makes new custom pages
    protected void uploadButton_Click(object sender, EventArgs e)
    {
        try
        {
            if (this.PageUploader.HasFile)
            {
                if (pageNameTextBox.Text != "")
                {
                    if (PageUploader.PostedFile.ContentType == "application/pdf")
                    {
                        if (PageUploader.PostedFile.ContentLength < 26214400)
                        {
                            string filename  = Path.GetFileName(PageUploader.FileName);
                            string folderUrl = Server.MapPath("~/Resources\\") + game.GameID;
                            string url       = folderUrl + "\\" + filename;

                            if (!Directory.Exists(folderUrl))
                            {
                                Directory.CreateDirectory(folderUrl);
                            }

                            //If a file already exists, delete it and overwrite
                            if (File.Exists(url))
                            {
                                File.Delete(url);
                                PageUploader.SaveAs(url);
                                Session["message"] = new Message("File already exists, overwrote with provided file.", System.Drawing.Color.Green);
                            }
                            //Else make the new file, and add it to the database and pages list
                            else
                            {
                                //Upload new file
                                PageUploader.SaveAs(url);

                                //Make CustomPage at end of existing pages
                                CustomPage page = new CustomPage();
                                page.PageName  = pageNameTextBox.Text;
                                page.GameID    = game.GameID;
                                page.PageURL   = "Resources/" + game.GameID + "/" + PageUploader.FileName;
                                page.SortIndex = pages.Pages.Count;

                                PagesTable pagesTable = new PagesTable(new DatabaseConnection());
                                int        pageID     = pagesTable.insertCustomPage(page);
                                if (pageID > 0)
                                {
                                    page.PageID = pageID;
                                }

                                //Save Content and add to table
                                pageTable.saveContentChanges();
                                pages.Pages = pageTable.getContent();

                                pages.Pages.Add(page.SortIndex, page);

                                Session["message"] = new Message("Upload successful!", System.Drawing.Color.Green);
                            }
                        }
                        else
                        {
                            Session["message"] = new Message("Upload failed: The file has to be less than 25 mb!", System.Drawing.Color.Red);
                        }
                    }
                    else
                    {
                        Session["message"] = new Message("Upload failed: Only PDF files are accepted!", System.Drawing.Color.Red);
                    }
                }
                else
                {
                    Session["message"] = new Message("Upload failed: A Page Name must be provided!", System.Drawing.Color.Red);
                }
            }
            else
            {
                Session["message"] = new Message("Upload failed: You must select a file to upload!", System.Drawing.Color.Red);
            }
        }
        catch (Exception)
        {
            Session["message"] = new Message("Upload failed: Unable to upload this file.", System.Drawing.Color.Red);
        }

        this.Page.Session["savedContent"] = pages;

        //Reload page to clear any nonsense before loading
        this.Page.Response.Redirect("CustomPageTool");
    }