void Application_Start(object sender, EventArgs e) { // Code that runs on application startup AreaRegistration.RegisterAllAreas(); GlobalConfiguration.Configure(WebApiConfig.Register); RouteConfig.RegisterRoutes(RouteTable.Routes); // Setup an AD client. ad = new ActiveDirectory(HostingEnvironment.MapPath(CONFIG_ITEM_DIRECTORY), ACTIVE_DIRECTORY_CONFIGURATION_ITEM_NAME); // Get our SQL connection string. ConfigurationItem sqlConfig = new ConfigurationItem(HostingEnvironment.MapPath(CONFIG_ITEM_DIRECTORY), DB_CONFIGURATION_ITEM_NAME, true); connectionString = sqlConfig.Value; // Setup the application config gwentAppConfig = new ConfigurationItem(HostingEnvironment.MapPath(CONFIG_ITEM_DIRECTORY), GWENTAPP_CONFIGURATION_ITEM_NAME, false); //Initial configuration check/read in //If the file exists, then read it in. If not, then the controller checks will have to do. if (System.IO.File.Exists(gwentAppConfig.FilePath)) { //Read the data here string gwentAppOptions = gwentAppConfig.Value; try { gAppOptions = JsonConvert.DeserializeObject<AppOptions>(gwentAppOptions); } catch { } } }
/// <summary> /// This function will read the existing app options from the configuration file text and return them in the AppOptions class object /// </summary> /// <param name="fileContents"></param> /// <returns></returns> public static AppOptions ReadAppOptions(string fileContents) { AppOptions currentOptions = new AppOptions(); try { string gwentAppOptions = fileContents; currentOptions = JsonConvert.DeserializeObject<AppOptions>(gwentAppOptions); } catch { currentOptions = new AppOptions(); //currentOptions.adminOptions = new Dictionary<string, string>(); } return currentOptions; }
/// <summary> /// This will write the app options to disk. Either a default set or a passed set based upon the last boolean argument /// </summary> /// <param name="filePath"></param> /// <param name="options"></param> /// <param name="isDefaults"></param> /// <returns></returns> public static bool WriteOptions(string filePath, AppOptions options, bool isDefaults) { //DB Maxes for sanity check: weather 12, n-units 14, n-heroes 4, f-units 32, f-heroes 4 //Define check var bool writeSuccess = false; //Define write object AppOptions optionsToWrite = new AppOptions(); if (isDefaults) { //Define object then fill it AppOptions defaultOptions = new AppOptions(); //Final count of cards dealt to player from initialized deck defaultOptions.StartingDeckSize = 10; //Max size of initialized deck defaultOptions.MaxDeckSize = 28; //Max number of weather cards to be dealt defaultOptions.MaxWeatherCards = 4; //Max number of neutral unit cards to be dealt defaultOptions.MaxNeutralUnits = 3; //Max number of neutral hero cards to be dealt defaultOptions.MaxNeutralHeroes = 3; //Max number of neutral special cards to be dealt defaultOptions.MaxNeutralSpecials = 3; //Max number of faction hero cards to be dealt defaultOptions.MaxFactionHeroes = 3; //Max number of faction unit cards to be dealt defaultOptions.MaxFactionUnits = 12; //Min number of faction units to be included in deck. defaultOptions.MinFactionUnits = 2; //Define SQL query constants. These work off of existing views in the database. //Get all weather cards defaultOptions.SelectAllWeatherCards = "select * from AllWeather"; //Get all neutral unit cards defaultOptions.SelectAllNeutralUnits = "select * from AllNeutralUnits"; //Get all neutral hero cards defaultOptions.SelectAllNeutralHeroes = "select * from AllNeutralHeros"; //Get all neutral special cards defaultOptions.SelectAllNeutralSpecials = "select * from AllNeutralSpecials"; //Get all selected faction hero cards. defaultOptions.SelectAllNRHeroes = "select * from AllNRHeroes"; defaultOptions.SelectAllNEHeroes = "select * from AllNEHeroes"; defaultOptions.SelectAllSTHeroes = "select * from AllSTHeroes"; defaultOptions.SelectAllMSHeroes = "select * from AllMSHeroes"; //Get all selected faction unit cards. defaultOptions.SelectAllNRUnits = "select * from AllNRUnits"; defaultOptions.SelectAllNEUnits = "select * from AllNEUnits"; defaultOptions.SelectAllSTUnits = "select * from AllSTUnits"; defaultOptions.SelectAllMSUnits = "select * from AllMSUnits"; //Define SQL query constants defaultOptions.SelectAllFactions = "select * from dbo.factions"; defaultOptions.SelectAllLeaders = "select * from dbo.leaders"; defaultOptions.SelectAllPlayerCards = "select * from dbo.cards"; //Define modal search values defaultOptions.CloseIdentifier = "Close"; defaultOptions.SiegeIdentifier = "Siege"; defaultOptions.RangedIdentifier = "Ranged"; defaultOptions.WeatherIdentifier = "Weather"; defaultOptions.NeutralIdentifier = "Neutral"; //Set optionsToWrite optionsToWrite = defaultOptions; } else { //Set optionsToWrite optionsToWrite = options; //DB Maxes for sanity check: weather 12, n-units 14, n-heroes 4, f-units 32, f-heroes 4 if (optionsToWrite.MaxWeatherCards > 12) { optionsToWrite.MaxWeatherCards = 12; } if (optionsToWrite.MaxNeutralUnits > 14) { optionsToWrite.MaxNeutralUnits = 14; } if (optionsToWrite.MaxNeutralHeroes > 4) { optionsToWrite.MaxNeutralHeroes = 4; } if (optionsToWrite.MaxFactionUnits > 32) { optionsToWrite.MaxFactionUnits = 32; } if (optionsToWrite.MaxFactionHeroes > 4) { optionsToWrite.MaxFactionHeroes = 4; } } try { //Init json string json = JsonConvert.SerializeObject(optionsToWrite); //Write out to file System.IO.File.WriteAllText(filePath, json); //Set success flag writeSuccess = true; } catch { //Set fail flag to be caught by parent. writeSuccess = false; } return writeSuccess; }
public ActionResult UpdateAppOptions(AppOptions appOptions) { //Write the new options bool writeSuccess = WriteOptions(Global.gwentAppConfig.FilePath, appOptions, false); //Immediately force a read to get instant update, otherwise you're using cached Global.gAppOptions = ReadAppOptions(Global.gwentAppConfig.Value); return Redirect("~/Setup/"); }
//Maybe don't create lists for each faction. Dynamically build the player deck using in mem queries from the gAllCards. Don't work twice void Application_Start(object sender, EventArgs e) { // Code that runs on application startup AreaRegistration.RegisterAllAreas(); GlobalConfiguration.Configure(WebApiConfig.Register); RouteConfig.RegisterRoutes(RouteTable.Routes); // Setup an AD client. ad = new ActiveDirectory(HostingEnvironment.MapPath(CONFIG_ITEM_DIRECTORY), ACTIVE_DIRECTORY_CONFIGURATION_ITEM_NAME); // Get our SQL connection string. ConfigurationItem sqlConfig = new ConfigurationItem(HostingEnvironment.MapPath(CONFIG_ITEM_DIRECTORY), DB_CONFIGURATION_ITEM_NAME, true); connectionString = sqlConfig.Value; // Setup the application config gwentAppConfig = new ConfigurationItem(HostingEnvironment.MapPath(CONFIG_ITEM_DIRECTORY), GWENTAPP_CONFIGURATION_ITEM_NAME, false); if (System.IO.File.Exists(gwentAppConfig.FilePath)) { if (gwentAppConfig.Value.Length > 1) { try { //Read the options gAppOptions = (AdminPageController.ReadAppOptions(gwentAppConfig.Value)); //Check for valid data if (gAppOptions.MaxDeckSize < 1) { //If unable to, recreate as defaults bool writesuccess = AdminPageController.WriteOptions(gwentAppConfig.FilePath, new AppOptions(), true); gAppOptions = (AdminPageController.ReadAppOptions(gwentAppConfig.Value)); } } catch { } } else { //If unable to, recreate as defaults bool writesuccess = AdminPageController.WriteOptions(gwentAppConfig.FilePath, new AppOptions(), true); gAppOptions = (AdminPageController.ReadAppOptions(gwentAppConfig.Value)); } } else { //If unable to, recreate as defaults bool writesuccess = AdminPageController.WriteOptions(gwentAppConfig.FilePath, new AppOptions(), true); gAppOptions = (AdminPageController.ReadAppOptions(gwentAppConfig.Value)); } //Map path to pictures pictureMapPath = HostingEnvironment.MapPath(PICTURE_DIRECTORY); //Fill the lists of cards, leaders and factions here DatabaseRead(); }
//Maybe don't create lists for each faction. Dynamically build the player deck using in mem queries from the gAllCards. Don't work twice void Application_Start(object sender, EventArgs e) { // Code that runs on application startup AreaRegistration.RegisterAllAreas(); GlobalConfiguration.Configure(WebApiConfig.Register); RouteConfig.RegisterRoutes(RouteTable.Routes); try { // Setup an AD client. ad = new ActiveDirectory(HostingEnvironment.MapPath(CONFIG_ITEM_DIRECTORY), ACTIVE_DIRECTORY_CONFIGURATION_ITEM_NAME); } catch (System.ArgumentNullException ex) { //If the file doesn't exist, or if it's 0 bytes. Note that as of this writing, a 0-byte file will be created if it does not already exist. //System.IO.FileNotFoundException might be a better fit... Console.WriteLine("The file {0}{1}, does not exist, please create it in Astrolabe from the template template.{1}, exception is: {2}", CONFIG_ITEM_DIRECTORY, ACTIVE_DIRECTORY_CONFIGURATION_ITEM_NAME, ex.Source); } catch (System.ArgumentException ex) { //Hits here if the info in ACTIVE_DIRECTORY_CONFIGURATION_ITEM_NAME was not valid. Console.WriteLine("There was a problem with your AD config file {0}{1}, please create it in Astrolabe from the template template.{1}, exception is: {2}", CONFIG_ITEM_DIRECTORY, ACTIVE_DIRECTORY_CONFIGURATION_ITEM_NAME, ex.Source); } // Get our SQL connection string. ConfigurationItem sqlConfig = new ConfigurationItem(HostingEnvironment.MapPath(CONFIG_ITEM_DIRECTORY), DB_CONFIGURATION_ITEM_NAME, true); connectionString = sqlConfig.Value; // Setup the application config gwentAppConfig = new ConfigurationItem(HostingEnvironment.MapPath(CONFIG_ITEM_DIRECTORY), GWENTAPP_CONFIGURATION_ITEM_NAME, false); if (System.IO.File.Exists(gwentAppConfig.FilePath)) { if (gwentAppConfig.Value.Length > 1) { try { //Read the options gAppOptions = (AdminPageController.ReadAppOptions(gwentAppConfig.Value)); //Check for valid data if (gAppOptions.MaxDeckSize < 1) { //If unable to, recreate as defaults bool writesuccess = AdminPageController.WriteOptions(gwentAppConfig.FilePath, new AppOptions(), true); gAppOptions = (AdminPageController.ReadAppOptions(gwentAppConfig.Value)); } } catch { } } else { //If unable to, recreate as defaults bool writesuccess = AdminPageController.WriteOptions(gwentAppConfig.FilePath, new AppOptions(), true); gAppOptions = (AdminPageController.ReadAppOptions(gwentAppConfig.Value)); } } else { //If unable to, recreate as defaults bool writesuccess = AdminPageController.WriteOptions(gwentAppConfig.FilePath, new AppOptions(), true); gAppOptions = (AdminPageController.ReadAppOptions(gwentAppConfig.Value)); } //Map path to pictures pictureMapPath = HostingEnvironment.MapPath(PICTURE_DIRECTORY); //Fill the lists of cards, leaders and factions here DatabaseRead(); }