// ---------- PROPERTIES ---------- // ---------- CONSTRUCTORS ---------- /// <summary> /// Connects the client to SharePoint using the configuration in the specified configuration item. /// </summary> /// <param name="configurationItemDirectoryPath">The physical path to the directory where configuration item files can be found.</param> /// <param name="configurationItemName">The name of the configuration item containing the SharePoint client configuration.</param> public SharePointClient(string configurationItemDirectoryPath, string configurationItemName) { if (!string.IsNullOrWhiteSpace(configurationItemDirectoryPath) && !string.IsNullOrWhiteSpace(configurationItemName)) { // Get the configuration item with the connection data from a file. ConfigurationItem configItem = new ConfigurationItem(configurationItemDirectoryPath, configurationItemName, true); // Read the credentials from the configuration item. if (!string.IsNullOrWhiteSpace(configItem.Value)) { StringReader reader = new StringReader(configItem.Value); userName = reader.ReadLine(); password = reader.ReadLine(); domain = reader.ReadLine(); contextUrl = reader.ReadLine(); } // Initialize the client context. clientContext = new ClientContext(contextUrl) { // Add the credentials to the SharePoint context. Credentials = new NetworkCredential(userName, password, domain) }; } else { throw new ArgumentException("Unable to establish connection to SharePoint."); } }
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 { } } }
// ---------- PROPERTIES ---------- // ---------- CONSTRUCTORS ---------- /// <summary> /// Creates a utility object that can be used to perform operations against a MongoDB server. /// Note: /// Uses the authentication and database information from the supplied configuration item. /// </summary> /// <param name="configurationFolderPath">The path to the folder containing the encrypted configuration file containing information required to establish the connection to the server.</param> /// <param name="configurationItemName">The name of configuration item containing the information required to connect to the server. (Typically it's filename without the extension.)</param> public MongoDBUtility(string configurationFolderPath, string configurationItemName) { if (!string.IsNullOrWhiteSpace(configurationFolderPath) && !string.IsNullOrWhiteSpace(configurationItemName)) { ConfigurationItem configItem = new ConfigurationItem(configurationFolderPath, configurationItemName, true); try { // Read the connection string from the configuration file. url = MongoUrl.Create(configItem.Value); client = new MongoClient(url); server = client.GetServer(); database = server.GetDatabase(url.DatabaseName); } catch { throw new FormatException("Could not load configuration data from file. File is not of the correct format."); } } else { if (string.IsNullOrWhiteSpace(configurationFolderPath)) { throw new ArgumentNullException("configurationFolderPath", "A path to a configuration items folder must be supplied."); } else { throw new ArgumentNullException("configurationItemName", "The name of the configuration item to load must be supplied."); } } }
//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(); }
/// <summary> /// Creates a utility object that can be used to perform operations against a Couchbase server. /// Note: /// Uses the authentication and bucket information from the supplied configuration item. /// </summary> /// <param name="configurationFolderPath">The path to the folder containing the encrypted configuration file containing information required to establish the connection to the server.</param> /// <param name="configurationItemName">The name of configuration item containing the information required to connect to the server. (Typically it's filename without the extension.)</param> public CouchbaseUtility(string configurationFolderPath, string configurationItemName) { if (!string.IsNullOrWhiteSpace(configurationFolderPath) && !string.IsNullOrWhiteSpace(configurationItemName)) { ConfigurationItem configItem = new ConfigurationItem(configurationFolderPath, configurationItemName, true); try { // Read the values required from the configuration file. StringReader reader = new StringReader(configItem.Value); string urlsLine = reader.ReadLine(); string[] urls = new string[] { }; if (!string.IsNullOrWhiteSpace(urlsLine)) { urls = urlsLine.Split(','); } string bucket = reader.ReadLine(); string bucketPassword = reader.ReadLine(); if (urls.Length > 0 && !string.IsNullOrWhiteSpace(bucket) && !string.IsNullOrWhiteSpace(bucketPassword)) { // Configure the client. CouchbaseClientConfiguration config = new CouchbaseClientConfiguration(); foreach (string url in urls) { config.Urls.Add(new Uri(url)); } config.Bucket = bucket; config.BucketPassword = bucketPassword; // Create a connection with the Couchbase bucket. client = new CouchbaseClient(config); } else { throw new FormatException("Could not load configuration data from file. File is not of the correct format."); } } catch { throw new FormatException("Could not load configuration data from file. File is not of the correct format."); } } else { if (string.IsNullOrWhiteSpace(configurationFolderPath)) { throw new ArgumentNullException("configurationFolderPath", "A path to a configuration items folder must be supplied."); } else { throw new ArgumentNullException("configurationItemName", "The name of the configuration item to load must be supplied."); } } }
private void closeToolStripMenuItem_Click(object sender, EventArgs e) { nameLabel.Text = ""; valueTextBox.Text = ""; configItem = null; openFileLabel.Visible = true; openFileButton.Visible = true; saveToolStripMenuItem.Enabled = false; saveAsToolStripMenuItem.Enabled = false; closeToolStripMenuItem.Enabled = false; }
private void newToolStripMenuItem_Click(object sender, EventArgs e) { SaveFileDialog saveDialog = new SaveFileDialog(); saveDialog.DefaultExt = ".config"; saveDialog.Filter = "Config files (*.config)|*.config|All files (*.*)|*.*"; saveDialog.Title = "Create New Configuration File"; if (saveDialog.ShowDialog() == DialogResult.OK) { // Get the configuration item from the file specified by the user. FileInfo fileInfo = new FileInfo(saveDialog.FileName); configItem = new ConfigurationItem(fileInfo.DirectoryName, fileInfo.Name.Replace(".config", ""), true); // Load the data from the file. nameLabel.Text = configItem.Name; valueTextBox.Text = configItem.Value; openFileLabel.Visible = false; openFileButton.Visible = false; saveToolStripMenuItem.Enabled = true; saveAsToolStripMenuItem.Enabled = true; closeToolStripMenuItem.Enabled = true; } }
// ----- 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."); } }
private void saveAsToolStripMenuItem_Click(object sender, EventArgs e) { SaveFileDialog saveDialog = new SaveFileDialog(); saveDialog.DefaultExt = ".config"; saveDialog.Filter = "Config files (*.config)|*.config|All files (*.*)|*.*"; saveDialog.Title = "Save Configuration File As"; if (saveDialog.ShowDialog() == DialogResult.OK) { // Get the configuration item from the file specified by the user. FileInfo fileInfo = new FileInfo(saveDialog.FileName); ConfigurationItem newConfigItem = new ConfigurationItem(fileInfo.DirectoryName, fileInfo.Name.Replace(".config", ""), true); // Save the data shown in the interface to the file. newConfigItem.Value = valueTextBox.Text; // Set the new file as active in the interface. configItem = newConfigItem; // Load the data from the file. nameLabel.Text = configItem.Name; valueTextBox.Text = configItem.Value; } }
//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(); }
// ----- 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. configItem = new ConfigurationItem(HostingEnvironment.MapPath(configurationItemDirectoryPath), SIMPLE_MAPPING_ROLE_PROVIDER_CONFIGURATION_ITEM_NAME, true); // Read the roles from the configuration item. roles = ReadRoles(new StringReader(configItem.Value)); if (roles == null) { throw new ProviderException("Couldn't read roles from configuration item."); } } 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), 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."); } }
// ----- CONSTRUCTORS ----- /// <summary> /// Binds to Active Directory using the configuration in the specified configuration item. /// </summary> /// <param name="configurationItemDirectoryPath">The physical path to the directory where configuration item files can be found.</param> /// <param name="configurationItemName">The name of the configuration item containing the Active Directory configuration.</param> public ActiveDirectory(string configurationItemDirectoryPath, string configurationItemName) { if (!string.IsNullOrWhiteSpace(configurationItemDirectoryPath) && !string.IsNullOrWhiteSpace(configurationItemName)) { // Get the configuration item with the connection data from a file. ConfigurationItem configItem = new ConfigurationItem(configurationItemDirectoryPath, configurationItemName, true); // Get the connection data from the configuration item. StringReader reader = new StringReader(configItem.Value); string domainAndSiteLine = reader.ReadLine(); // Get the domain name and site name (if specified). string[] domainAndSiteLineSections = new string[] {}; if (!string.IsNullOrWhiteSpace(domainAndSiteLine)) { domainAndSiteLineSections = domainAndSiteLine.Split(':'); } string domainName = domainAndSiteLineSections[0]; string siteName = DEFAULT_FIRST_SITE_NAME; if (domainAndSiteLineSections.Length > 1) { siteName = domainAndSiteLineSections[1]; } string userName = reader.ReadLine(); SecureString password = new SecureString(); int intRead = reader.Read(); while (intRead >= 0) { char c = Convert.ToChar(intRead); if (c != '\n') { password.AppendChar(c); } else { break; } intRead = reader.Read(); } if (!string.IsNullOrWhiteSpace(domainName) && !string.IsNullOrWhiteSpace(userName) && password.Length > 0) { try { // Get a list of domain controllers from a specific site, if one was supplied. List<string> domainControllers = new List<string>(); if (!string.IsNullOrWhiteSpace(siteName)) { domainControllers = GetSiteDomainControllers(domainName, siteName); } if (domainControllers.Count == 0) { // Create the connection to the domain controller serving the current computer. ldap = new Galactic_LDAP(new List<string> { domainName }, Galactic_LDAP.LDAP_SSL_PORT, AuthType.Negotiate, userName, password, domainName); } else { // Create the connection to the domain controllers serving the specified site. ldap = new Galactic_LDAP(domainControllers, Galactic_LDAP.LDAP_SSL_PORT, AuthType.Negotiate, userName, password, domainName); } // Set the default search base and scope. ldap.SetSearchBaseAndScope(DistinguishedName); } catch { throw new ArgumentException("Unable to establish connection to Active Directory."); } } else { if (string.IsNullOrWhiteSpace(domainName)) { throw new ArgumentException("Domain name not provided in configuration item."); } else if (string.IsNullOrWhiteSpace(userName)) { throw new ArgumentException("User name not provided in configuration item."); } else { throw new ArgumentException("Password not provided in configuration item."); } } } else { throw new ArgumentException("Unable to establish connection to Active Directory."); } }
/// <summary> /// Creates the utility class that allows for loading iCalendar files. /// </summary> /// <param name="configurationItemDirectoryPath">The physical path to the directory where configuration item files can be found.</param> /// <param name="configurationItemName">The name of the configuration item containing the iCalendar configuration.</param> /// <exception cref="System.ArgumentNullException">Thrown if one of the parameters provided is empty, null, or whitespace.</exception> /// <exception cref="System.ArgumentException">Thrown if there was an error reading the configuration data.</exception> /// <remarks>Configuration data has the following format: Name|URI|username|password /// Username and password can be empty if they are not required. /// The configuration file should list one calendar per line.</remarks> public iCalendarUtility(string configurationItemDirectoryPath, string configurationItemName) { if (!string.IsNullOrWhiteSpace(configurationItemDirectoryPath) && !string.IsNullOrWhiteSpace(configurationItemName)) { // Get the configuration item with the configuration data from a file. ConfigurationItem configItem = new ConfigurationItem(configurationItemDirectoryPath, configurationItemName, true); try { // Get the configuration data from the configuration item. StringReader reader = new StringReader(configItem.Value); // NOTE: See remarks in method documentation above for configuration file format. // Load all of the calendars specified in the configuration file. string configLine = reader.ReadLine(); while (!string.IsNullOrWhiteSpace(configLine)) { // Split the line into its entries. string[] configLineEntries = configLine.Split('|'); // Get the calendar's name. string name = configLineEntries[0]; // Get the calendar's URI. Uri uri = new Uri(configLineEntries[1]); // Get the username and password to use with the calendar. string username = configLineEntries[2]; string password = configLineEntries[3]; // Add the calendar to the list of calendars. calendars.Add(name, uri); // If credentials were supplied, add them to the credentials dictionary. if (!string.IsNullOrWhiteSpace(username) && !string.IsNullOrWhiteSpace(password)) { credentials.Add(name, new KeyValuePair<string, string>(username, password)); } // Read the next configuration line. configLine = reader.ReadLine(); } } catch { throw new ArgumentException("Unable to read calendar configuration data from configuration item."); } } else { if (string.IsNullOrWhiteSpace(configurationItemDirectoryPath)) { throw new ArgumentNullException("configurationItemDirectoryPath"); } if (string.IsNullOrWhiteSpace(configurationItemName)) { throw new ArgumentNullException("configurationItemName"); } } }