/// <summary> /// Creates a new provider used to strip source control bindings. /// </summary> /// <param name="context">An <see cref="ApplicationContext"/> object containing contextual information.</param> /// <returns>A new <see cref="StripSccBindingsProvider"/> object.</returns> public static StripSccBindingsProviderBase CreateProvider(ApplicationContext context) { StripSccBindingsProviderBase provider = null; StripSccBindingsSection section = (StripSccBindingsSection)ConfigurationManager.GetSection(StripSccBindingsSection.SectionName); if (section == null) { throw new Exception("Could not find the provider section configuration in the application configuration file."); } else { ProviderSettings settings = section.Providers[context.Provider]; if (settings == null) { throw new Exception(string.Format("Could not find the provider '{0}' specified in the application configuration file.", context.Provider)); } AssemblyQualifiedTypeNameConverter converter = new AssemblyQualifiedTypeNameConverter(); Type type = (Type)converter.ConvertFrom(settings.Type); if (type != null) { provider = (StripSccBindingsProviderBase)Activator.CreateInstance(type); provider.Context = context; // Initialize the provider based on the configuration file. provider.Initialize(settings.Name, settings.Parameters); } } return provider; }
/// <summary> /// Creates a new <see cref="ApplicationContext"/> based on the command line arguments provided. /// </summary> /// <param name="args">The command-line arguments to use to generate the context.</param> /// <returns>A new <see cref="ApplicationContext"/> object.</returns> public static ApplicationContext Create(string[] args) { if (args == null) { throw new ArgumentNullException("args"); } ApplicationContext retval = new ApplicationContext(); retval.Provider = args[0].ToLower(); // Check for any options that are being set. for (int index = 1; index < args.Length - 1; index++) { string[] tokens = args[index].Split(':'); switch (tokens[0].ToLower()) { case "-recursive": retval.EnableFolderRecursion = true; break; case "-filter": if (tokens.Length == 1 || string.IsNullOrEmpty(tokens[1])) { throw new Exception("The filter settings were not provided."); } retval.Filter = tokens[1]; break; } } // Parse the path out of the arguments. retval.Path = args[args.Length - 1]; return retval; }