/// <summary> /// Loads the information about an automation library. /// </summary> /// <param name="filePath">The fully qualified path to the automation library file to load information from.</param> /// <returns>Fully populated automation library information, or null if the library could not be loaded.</returns> public static VsAutomationLibrary GetLibraryInformation(string filePath) { _logger.DebugEnter(); if (string.IsNullOrEmpty(filePath)) { _logger.Information( "No file path was provided for the library, no library information will be loaded."); _logger.DebugExit(); return(null); } var result = new VsAutomationLibrary(); try { if (!File.Exists(filePath)) { _logger.Information( $"The library file '{filePath}' was not found, no library information will be loaded."); _logger.DebugExit(); return(null); } var assemblyDirectory = Path.GetDirectoryName(filePath); if (!Directory.Exists(assemblyDirectory)) { _logger.Information( $"The directory path could not be extracted from the library file path of '{filePath}', no library information will be loaded."); _logger.DebugExit(); return(null); } var libraryAssembly = Assembly.LoadFrom(filePath); result.LibraryActions = libraryAssembly.GetLibraryActions(); result.SupportLibraries = libraryAssembly.GetExternalDependentLibraries(assemblyDirectory); result.LibraryFilePath = filePath; } catch (Exception getLibraryInformationError) { _logger.Error( $"The following unhandled exception occurred while loading the library information for '{filePath}'", getLibraryInformationError); result = null; } _logger.DebugExit(); return(result); }
/// <summary> /// Static method that loads a automated library's information into a debug configuration. /// </summary> /// <param name="debugLibraryInfo">The automation library information that is to be loaded for debugging purposes.</param> /// <param name="targetDirectory">The target directory that the debug configuration will be created or updated in.</param> /// <returns>Boolean flag that determines if the package configuration file was created successfully or not.</returns> public static bool PackageDebugConfigurationFile(VsAutomationLibrary debugLibraryInfo, string targetDirectory) { _logger.DebugEnter(); if (debugLibraryInfo == null) { _logger.Information( "No library information was provided cannot load the library into the debug configuration."); _logger.DebugExit(); return(false); } if (string.IsNullOrEmpty(targetDirectory)) { _logger.Information("No target directory was provided. cannot load the package debug configuration"); _logger.DebugExit(); return(false); } if (!Directory.Exists(targetDirectory)) { _logger.Information( $"The target directory '{targetDirectory}' does not exist. cannot create package debug configuration"); _logger.DebugExit(); return(false); } var configPath = Path.Combine(targetDirectory, DEBUG_CONFIG_FILE_NAME); try { if (File.Exists(configPath)) { File.Delete(configPath); } } catch (Exception deleteConfigFileError) { _logger.Error( "The following exception occurred while trying to delete the existing code factory configuration file.", deleteConfigFileError); var deleteConfigErrorMessage = string.Format(ConfigurationMessages.FailedToDeleteConfigFile, DEBUG_CONFIG_FILE_NAME, deleteConfigFileError); Console.WriteLine(deleteConfigErrorMessage); _logger.DebugExit(); return(false); } bool result = false; try { var debugLibrary = new List <VsLibraryConfiguration> { new VsLibraryConfiguration { AssemblyFilePath = debugLibraryInfo.LibraryFilePath, IsStoredInGac = false } }; var debugConfig = new VsFactoryConfiguration { CodeFactoryActions = debugLibraryInfo.LibraryActions, CodeFactoryLibraries = debugLibrary, SupportLibraries = debugLibraryInfo.SupportLibraries, Id = Guid.NewGuid(), Name = "Debug" }; int commandsCount = 0; int supportLibraryCount = 0; int factoryLibrariesCount = 0; if (debugConfig.CodeFactoryActions != null) { commandsCount = debugConfig.CodeFactoryActions.Count(); } if (debugConfig.CodeFactoryLibraries != null) { factoryLibrariesCount = debugConfig.CodeFactoryLibraries.Count(); } if (debugConfig.SupportLibraries != null) { supportLibraryCount = debugConfig.SupportLibraries.Count(); } Console.WriteLine(string.Format(ConfigurationMessages.CreatingConfigurationFile, DEBUG_CONFIG_FILE_NAME)); XamlServices.Save(configPath, debugConfig); var successMessage = string.Format(ConfigurationMessages.ConfigurationFileCreatedSuccessfully, DEBUG_CONFIG_FILE_NAME, factoryLibrariesCount, supportLibraryCount, commandsCount).Replace("\\r", "\r").Replace("\\n", "\n"); Console.WriteLine(successMessage); result = true; } catch (Exception saveConfigurationError) { _logger.Error("The follow exception occurred while trying to save the configuration file.", saveConfigurationError); Console.WriteLine(string.Format(ConfigurationMessages.FailedToCreateConfigurationFile, DEBUG_CONFIG_FILE_NAME, saveConfigurationError)); result = false; } _logger.DebugExit(); return(result); }