Example #1
0
        private string LoadGameForRequest()
        {
            string folder   = null;
            string gameFile = Request["file"];
            string id       = Request["id"];

            if (string.IsNullOrEmpty(gameFile))
            {
                if (!string.IsNullOrEmpty(id))
                {
                    IFileManager fileManager = FileManagerLoader.GetFileManager();
                    if (fileManager != null)
                    {
                        gameFile = fileManager.GetFileForID(id);
                    }
                }
            }

            AzureFileManager.ApiGame apiGameData = null;

            var loadData = Session["LoadData"] as string;

            Session["LoadData"] = null;

            if (loadData != null)
            {
                apiGameData = AzureFileManager.GetGameData(id);
                if (apiGameData == null)
                {
                    throw new InvalidOperationException("No API data returned for game id " + id);
                }
            }

            return(LoadGame(gameFile, id, folder, loadData, apiGameData));
        }
Example #2
0
        private async Task <string> LoadGameForRequest()
        {
            string folder     = null;
            string gameFile   = Request["file"];
            string id         = Request["id"];
            bool?  isCompiled = null;

            if (string.IsNullOrEmpty(gameFile))
            {
                if (!string.IsNullOrEmpty(id))
                {
                    IFileManager fileManager = FileManagerLoader.GetFileManager();
                    if (fileManager != null)
                    {
                        var result = await fileManager.GetFileForID(id);

                        gameFile   = result.Filename;
                        isCompiled = result.IsCompiled;
                    }
                }
            }

            AzureFileManager.ApiGame apiGameData = null;

            var loadData = Session["LoadData"] as string;

            Session["LoadData"] = null;

            if (loadData != null)
            {
                apiGameData = await AzureFileManager.GetGameData(id);

                if (apiGameData == null)
                {
                    throw new InvalidOperationException("No API data returned for game id " + id);
                }
            }

            return(LoadGame(gameFile, isCompiled, id, folder, loadData, apiGameData));
        }
Example #3
0
        private string LoadGame(string gameFile, bool?isCompiled, string id, string folder, string loadData, AzureFileManager.ApiGame apiGameData)
        {
            if (string.IsNullOrEmpty(gameFile) && loadData == null)
            {
                return("No game specified");
            }

            string rootPath = folder ?? ConfigurationManager.AppSettings["GameFolder"];
            string libPath  = ConfigurationManager.AppSettings["LibraryFolder"];
            string filename;

            if (Config.ReadGameFileFromAzureBlob)
            {
                filename = gameFile;
            }
            else
            {
                filename = WebPlayer.Play.GetGameFilename(gameFile, rootPath);
                if (filename == null)
                {
                    return("Invalid filename");
                }
            }

            List <string> errors;

            try
            {
                m_player                      = new PlayerHandler(filename, m_buffer);
                m_player.LoadData             = loadData;
                m_player.ApiGameData          = apiGameData;
                m_player.GameId               = m_gameId;
                m_player.LibraryFolder        = libPath;
                Games[m_gameId]               = m_player;
                m_player.BeginWait           += m_player_BeginWait;
                m_player.BeginPause          += m_player_BeginPause;
                m_player.ShowMenuDelegate     = m_player_ShowMenu;
                m_player.ShowQuestionDelegate = m_player_ShowQuestion;
                m_player.AddResource         += AddResource;
                m_player.PlayAudio           += m_player_PlayAudio;
                m_player.StopAudio           += m_player_StopAudio;
                if (Config.ReadGameFileFromAzureBlob)
                {
                    m_player.ResourceUrlRoot = AzureFileManager.GetResourceUrlRoot(id);
                }

                if (m_player.Initialise(out errors, isCompiled))
                {
                    Resources.AddGame(m_player.Game);

                    // Successful game start
                    return(m_player.ClearBuffer());
                }
            }
            catch (Exception ex)
            {
                return("<b>Error loading game:</b><br/>" + ex.Message);
            }

            string output = string.Empty;

            if (errors != null)
            {
                foreach (string error in errors)
                {
                    output += error + "<br/>";
                }
            }

            return(output);
        }
Example #4
0
        private string LoadGame(string gameFile, bool? isCompiled, string id, string folder, string loadData, AzureFileManager.ApiGame apiGameData)
        {
            if (string.IsNullOrEmpty(gameFile) && loadData == null)
            {
                return "No game specified";
            }

            string rootPath = folder ?? ConfigurationManager.AppSettings["GameFolder"];
            string libPath = ConfigurationManager.AppSettings["LibraryFolder"];
            string filename;

            if (Config.ReadGameFileFromAzureBlob)
            {
                filename = gameFile;
            }
            else
            {
                filename = WebPlayer.Play.GetGameFilename(gameFile, rootPath);
                if (filename == null)
                {
                    return "Invalid filename";
                }
            }

            List<string> errors;

            try
            {
                m_player = new PlayerHandler(filename, m_buffer);
                m_player.LoadData = loadData;
                m_player.ApiGameData = apiGameData;
                m_player.GameId = m_gameId;
                m_player.LibraryFolder = libPath;
                Games[m_gameId] = m_player;
                m_player.BeginWait += m_player_BeginWait;
                m_player.BeginPause += m_player_BeginPause;
                m_player.ShowMenuDelegate = m_player_ShowMenu;
                m_player.ShowQuestionDelegate = m_player_ShowQuestion;
                m_player.AddResource += AddResource;
                m_player.PlayAudio += m_player_PlayAudio;
                m_player.StopAudio += m_player_StopAudio;
                if (Config.ReadGameFileFromAzureBlob)
                {
                    m_player.ResourceUrlRoot = AzureFileManager.GetResourceUrlRoot(id);
                }
                
                if (m_player.Initialise(out errors, isCompiled))
                {
                    Resources.AddGame(m_player.Game);

                    // Successful game start
                    return m_player.ClearBuffer();
                }
            }
            catch (Exception ex)
            {
                return "<b>Error loading game:</b><br/>" + ex.Message;
            }

            string output = string.Empty;

            if (errors != null)
            {
                foreach (string error in errors)
                {
                    output += error + "<br/>";
                }
            }

            return output;
        }