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 { } } }
//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(); }
// ----- METHODS ----- /// <summary> /// Takes as input the name of the provider and a NameValueCollection of configuration settings. /// Used to set property values for the provider instance including implementation-specific values /// and options specified in the configuration file (Machine.config or Web.config). /// </summary> /// <param name="name">The name of the provider.</param> /// <param name="config">Collection of configuration settings.</param> public override void Initialize(string name, NameValueCollection config) { providerName = name; // Get the location of the configuration items used by the application. try { if (!string.IsNullOrWhiteSpace(config[CONFIG_ITEM_DIRECTORY_NAME])) { configurationItemDirectoryPath = config[CONFIG_ITEM_DIRECTORY_NAME]; // Get the configuration item with the setup information from a file. ConfigurationItem configItem = new ConfigurationItem(HostingEnvironment.MapPath(configurationItemDirectoryPath), SIMPLE_AD_ROLE_PROVIDER_CONFIGURATION_ITEM_NAME, true); StringReader reader = new StringReader(configItem.Value); // Get the name of the application using this role provider. applicationName = reader.ReadLine(); if (string.IsNullOrWhiteSpace(applicationName)) { throw new ProviderException("The application name was not supplied in the configuration file."); } // Get the name of the configuration item containing connection information for Active Directory. string activeDirectoryConfigurationItemName = reader.ReadLine(); if (!string.IsNullOrWhiteSpace(activeDirectoryConfigurationItemName)) { // Setup a connection to active directory for the role provider. ad = new AD(HostingEnvironment.MapPath(configurationItemDirectoryPath), activeDirectoryConfigurationItemName); if (ad == null) { throw new ProviderException("Couldn't connect to Active Directory with configuration provided."); } } else { throw new ProviderException("The Active Directory configuration item name was not supplied in the configuration file."); } // Set the maximum length of role names for this provider. maxRoleNameLength = AD.GROUP_NAME_MAX_CHARS; } else { throw new ProviderException("The configuration items folder specified for use by the role provider could not be found in the supplied configuration data."); } } catch (ArgumentOutOfRangeException) { throw new ProviderException("The configuration items folder specified for use by the role provider could not be found in the supplied configuration data."); } }
// ----- METHODS ----- /// <summary> /// Takes as input the name of the provider and a NameValueCollection of configuration settings. /// Used to set property values for the provider instance including implementation-specific values /// and options specified in the configuration file (Machine.config or Web.config). /// </summary> /// <param name="name">The name of the provider.</param> /// <param name="config">Collection of configuration settings.</param> public override void Initialize(string name, NameValueCollection config) { providerName = name; // Get the location of the configuration items used by the application. try { if (!String.IsNullOrWhiteSpace(config[CONFIG_ITEM_DIRECTORY_NAME])) { configurationItemDirectoryPath = config[CONFIG_ITEM_DIRECTORY_NAME]; // Get the configuration item with the setup information from a file. ConfigurationItem configItem = new ConfigurationItem(HostingEnvironment.MapPath(configurationItemDirectoryPath), AD_ROLE_PROVIDER_CONFIGURATION_ITEM_NAME, true); StringReader reader = new StringReader(configItem.Value); // Get the name of the application using this role provider. applicationName = reader.ReadLine(); if (string.IsNullOrWhiteSpace(applicationName)) { throw new ProviderException("The application name was not supplied in the configuration file."); } // Get the OU that is set aside for use by the role provider. providerOUDn = reader.ReadLine(); if (string.IsNullOrWhiteSpace(applicationName)) { throw new ProviderException("The OU was not supplied in the configuration file."); } // (Optional) Get the prefix to use when naming groups. - NOTE: Leave a blank line the in configuration file if not used. groupPrefix = reader.ReadLine(); // (Optional) Get the suffix to use when naming groups. - NOTE: Leave a blank line the in configuration file if not used. groupSuffix = reader.ReadLine(); // Get the name of the configuration item containing connection information for Active Directory. string activeDirectoryConfigurationItemName = reader.ReadLine(); if (!string.IsNullOrWhiteSpace(activeDirectoryConfigurationItemName)) { // Setup a connection to active directory for the role provider. ad = new AD(HostingEnvironment.MapPath(configurationItemDirectoryPath), activeDirectoryConfigurationItemName); if (ad == null) { throw new ProviderException("Couldn't connect to Active Directory with configuration provided."); } } else { throw new ProviderException("The Active Directory configuration item name was not supplied in the configuration file."); } // Calculate and set the maximum length of role names for this provider. maxRoleNameLength = CalculateMaxRoleNameLength(); } else { throw new ProviderException("The configuration items folder specified for use by the role provider could not be found in the supplied configuration data."); } } catch (ArgumentOutOfRangeException) { throw new ProviderException("The configuration items folder specified for use by the role provider could not be found in the supplied configuration data."); } }
//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(); }