private Configuration OpenWebConfiguration(string path, string appPhysPath, bool getWebConfigForSubDir) { // check if session expired if (String.IsNullOrEmpty(ApplicationPath) || String.IsNullOrEmpty((string)Session[APP_PHYSICAL_PATH])) { Server.Transfer("~/home2.aspx"); } if (String.IsNullOrEmpty(path)) { return(WebConfigurationManager.OpenWebConfiguration(null)); } string appVPath = (string)Session[APP_PATH]; if (!getWebConfigForSubDir) { appVPath = path; } WebConfigurationFileMap fileMap = new WebConfigurationFileMap(); fileMap.VirtualDirectories.Add(appVPath, new VirtualDirectoryMapping(appPhysPath, true)); return(WebConfigurationManager.OpenMappedWebConfiguration(fileMap, path)); }
/// <summary> /// 获取标准Web应用程序的配置信息,合并Web.config和global配置文件 /// </summary> /// <param name="machineConfigPath">global配置文件地址</param> /// <param name="ignoreFileNotExist">是否忽略不存在的文件</param> /// <param name="globalConfig">返回的全局配置</param> /// <param name="fileDependencies">缓存依赖文件</param> /// <returns>Web.config和global配置文件合并后的Configuration对象</returns> private static System.Configuration.Configuration GetStandardWebAndGlobalConfiguration(string machineConfigPath, bool ignoreFileNotExist, out System.Configuration.Configuration globalConfig, params string[] fileDependencies) { string cacheKey = ConfigurationBroker.CreateConfigurationCacheKey(machineConfigPath); System.Configuration.Configuration config; globalConfig = null; WebConfigurationFileMap fileMap = new WebConfigurationFileMap(); fileMap.MachineConfigFilename = machineConfigPath; VirtualDirectoryMapping vDirMap = new VirtualDirectoryMapping( HostingEnvironment.ApplicationPhysicalPath, true); fileMap.VirtualDirectories.Add("/", vDirMap); if (ConfigurationCache.Instance.TryGetValue(cacheKey, out config) == false) { config = WebConfigurationManager.OpenMappedWebConfiguration(fileMap, "/", HostingEnvironment.SiteName); Array.Resize <string>(ref fileDependencies, fileDependencies.Length + 1); fileDependencies[fileDependencies.Length - 1] = machineConfigPath; ConfigurationBroker.AddConfigurationToCache(cacheKey, config, ignoreFileNotExist, fileDependencies); } globalConfig = GetGlobalConfiguration(machineConfigPath, ignoreFileNotExist, () => WebConfigurationManager.OpenMappedMachineConfiguration(fileMap), fileDependencies); return(config); }
/// <summary> /// Disables database migration in codeRR.Server.Web project /// </summary> private static void DisableDatabaseMigrations() { var webConfigFilename = Path.Combine( Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"..\..\..\..\codeRR.Server.Web\")), "web.config"); Console.WriteLine($"Setting DisableMigrations=true in '{webConfigFilename}'"); // Prevent SchemaUpdateModule from running var configFile = new FileInfo(webConfigFilename); var vdm = new VirtualDirectoryMapping(configFile.DirectoryName, true, configFile.Name); var wcfm = new WebConfigurationFileMap(); wcfm.VirtualDirectories.Add("/", vdm); var configuration = WebConfigurationManager.OpenMappedWebConfiguration(wcfm, "/"); var appSettings = configuration.AppSettings.Settings; if (appSettings["DisableMigrations"] == null) { appSettings.Add("DisableMigrations", "true"); } else { appSettings["DisableMigrations"].Value = "true"; } configuration.Save(); }
private void cbxWebApp_SelectedIndexChanged(object sender, EventArgs e) { try { currWebApp = cbxWebApp.SelectedItem as WebAppInfo; wbEditor.Navigate(currWebApp.WebConfigPath); //convert physical path to virtual path //ref: http://stackoverflow.com/questions/2368748/how-to-openwebconfiguration-with-physical-path FileInfo fi = new FileInfo(currWebApp.WebConfigPath); VirtualDirectoryMapping vdm = new VirtualDirectoryMapping( fi.DirectoryName, true, fi.Name); WebConfigurationFileMap wcfm = new WebConfigurationFileMap(); wcfm.VirtualDirectories.Add("/", vdm); currConf = WebConfigurationManager.OpenMappedWebConfiguration(wcfm, "/"); chgEncryptButtonStatus(); } catch (Exception ex) { MessageBox.Show("Error: " + ex.Message); btnExecute.Enabled = false; } }
private Configuration CreateConfig(string configFullName, bool isShowError) { textBoxError.Text = ""; if (!IsValideConfigFile(configFullName) && true == isShowError) { textBoxError.Text = "配置文件非法,不能创建Configuration对象,无法进行操作。 "; return(null); } try { btnEncrypt.Enabled = true; btnDecrypt.Enabled = true; if (string.Equals(Path.GetFileName(configFullName), "web.config", StringComparison.OrdinalIgnoreCase)) { FileInfo configFile = new FileInfo(configFullName); VirtualDirectoryMapping vdm = new VirtualDirectoryMapping(configFile.DirectoryName, true, configFile.Name); WebConfigurationFileMap wcfm = new WebConfigurationFileMap(); wcfm.VirtualDirectories.Add("/", vdm); return(WebConfigurationManager.OpenMappedWebConfiguration(wcfm, "/")); } string exePath = configFullName.Remove(configFullName.LastIndexOf(".")); return(ConfigurationManager.OpenExeConfiguration(exePath)); } catch (Exception ex) { if (true == isShowError) { textBoxError.Text = "不能创建Configuration对象,无法进行操作。 " + ex.Message; } btnEncrypt.Enabled = false; btnDecrypt.Enabled = false; } return(null); }
void btnSaveConfig_Click(object sender, EventArgs e) { //ConfigurationFileMap configurationFile = new ConfigurationFileMap(); WebConfigurationFileMap fileMap = new WebConfigurationFileMap(); lblLastName.Text = AppDomain.CurrentDomain.BaseDirectory + "-----" + Environment.CurrentDirectory; VirtualDirectoryMapping vDirMap = new VirtualDirectoryMapping(AppDomain.CurrentDomain.BaseDirectory, true, "web.config"); fileMap.VirtualDirectories.Add("/", vDirMap); foreach (string key in fileMap.VirtualDirectories.AllKeys) { Response.Write(fileMap.VirtualDirectories[key].VirtualDirectory); Response.Write(fileMap.VirtualDirectories[key].PhysicalDirectory); } //string filename = AppDomain.CurrentDomain.BaseDirectory + "Web.config"; //fileName.TrimStart(new char[] { '~', '/' }); Configuration config = WebConfigurationManager.OpenMappedWebConfiguration(fileMap, "/"); //Configuration config = WebConfigurationManager.OpenMappedWebConfiguration( // webConigurationFile, HttpContext.Current.Request.ApplicationPath); config.AppSettings.Settings["test"].Value = "test3"; config.Save(); }
static private Configuration GetConfigurationHelper(VirtualPath vpath, string physicalPath) { // Set up the configuration file map string machineConfigPath = MachineConfigPath; WebConfigurationFileMap fileMap = new WebConfigurationFileMap(machineConfigPath); // Set up file maps for the current directory and parent directories up to application root VirtualPath currentVPath = vpath; while (currentVPath != null && currentVPath.IsWithinAppRoot) { string vpathString = currentVPath.VirtualPathStringNoTrailingSlash; if (physicalPath == null) { physicalPath = HostingEnvironment.MapPath(currentVPath); } fileMap.VirtualDirectories.Add(vpathString, new VirtualDirectoryMapping(physicalPath, IsAppRoot(currentVPath))); currentVPath = currentVPath.Parent; physicalPath = null; } Configuration config = WebConfigurationManager.OpenMappedWebConfiguration(fileMap, vpath.VirtualPathStringNoTrailingSlash, HostingEnvironment.SiteName); return(config); }
RazorEngineHost CreateRazorHost(string fileName) { var projectFile = project.GetProjectFile(fileName); if (projectFile != null && projectFile.Generator == "RazorTemplatePreprocessor") { var h = MonoDevelop.RazorGenerator.RazorTemplatePreprocessor.CreateHost(fileName); h.DesignTimeMode = true; return(h); } string virtualPath = "~/Views/Default.cshtml"; if (aspProject != null) { virtualPath = aspProject.LocalToVirtualPath(fileName); } WebPageRazorHost host = null; // Try to create host using web.config file var webConfigMap = new WebConfigurationFileMap(); if (aspProject != null) { var vdm = new VirtualDirectoryMapping(aspProject.BaseDirectory.Combine("Views"), true, "web.config"); webConfigMap.VirtualDirectories.Add("/", vdm); } Configuration configuration; try { configuration = WebConfigurationManager.OpenMappedWebConfiguration(webConfigMap, "/"); } catch { configuration = null; } if (configuration != null) { var rws = configuration.GetSectionGroup(RazorWebSectionGroup.GroupName) as RazorWebSectionGroup; if (rws != null) { host = WebRazorHostFactory.CreateHostFromConfig(rws, virtualPath, fileName); host.DesignTimeMode = true; } } if (host == null) { host = new MvcWebPageRazorHost(virtualPath, fileName) { DesignTimeMode = true }; // Add default namespaces from Razor section host.NamespaceImports.Add("System.Web.Mvc"); host.NamespaceImports.Add("System.Web.Mvc.Ajax"); host.NamespaceImports.Add("System.Web.Mvc.Html"); host.NamespaceImports.Add("System.Web.Routing"); } return(host); }
private Configuration GetWebConfiguration(string websiteDirectory) { string dummyVirtualPath = "/" + Guid.NewGuid(); WebConfigurationFileMap map = new WebConfigurationFileMap(); map.VirtualDirectories.Add(dummyVirtualPath, new VirtualDirectoryMapping(websiteDirectory, true)); return(WebConfigurationManager.OpenMappedWebConfiguration(map, dummyVirtualPath)); }
private static System.Configuration.Configuration InitializeWebConfiguration() { VirtualDirectoryMapping vdm = new VirtualDirectoryMapping(Paths.RhetosServerRootPath, true); WebConfigurationFileMap wcfm = new WebConfigurationFileMap(); wcfm.VirtualDirectories.Add("/", vdm); return(WebConfigurationManager.OpenMappedWebConfiguration(wcfm, "/")); }
private Configuration GetDBConfiguration() { VirtualDirectoryMapping vdm = new VirtualDirectoryMapping(RhetosPath, true); WebConfigurationFileMap wcfm = new WebConfigurationFileMap(); wcfm.VirtualDirectories.Add("/", vdm); return(WebConfigurationManager.OpenMappedWebConfiguration(wcfm, "/")); }
/// <summary> /// Open the web.config file /// </summary> /// <param name="configPath"></param> /// <returns></returns> public static Configuration OpenWebConfiguration(string configPath) { VirtualDirectoryMapping vdm = new VirtualDirectoryMapping(Path.GetDirectoryName(configPath), true); WebConfigurationFileMap wcfm = new WebConfigurationFileMap(); wcfm.VirtualDirectories.Add("/", vdm); return(WebConfigurationManager.OpenMappedWebConfiguration(wcfm, "/")); }
/// <summary> /// Gets the configuration for the specified feature file directory. /// </summary> /// <param name="path">The path of the directory which contains the feature file.</param> /// <returns>The <see cref="Configuration"/>.</returns> protected virtual PluginSection GetConfiguration(string path) { WebConfigurationFileMap fileMap = new WebConfigurationFileMap(); string rootPath = Path.GetFullPath(path); DirectoryInfo directory; try { directory = new DirectoryInfo(path); } catch (SecurityException) { return(null); } path = rootPath; while (directory != null) { try { if (directory.GetFiles(ConfigurationFileName).Length > 0) { rootPath = directory.FullName; } directory = directory.Parent; } catch (SecurityException) { directory = null; } } path = path.Remove(0, rootPath.Length); if ((path.Length == 0) || (path[0] != Path.DirectorySeparatorChar)) { path = Path.DirectorySeparatorChar + path; } fileMap.VirtualDirectories.Add("/", new VirtualDirectoryMapping(rootPath, true, ConfigurationFileName)); PluginSection result; (new SecurityPermission(SecurityPermissionFlag.UnmanagedCode)).Demand(); AppDomain.CurrentDomain.AssemblyResolve += ExecutingAssemblyResolver; try { result = (PluginSection)WebConfigurationManager.OpenMappedWebConfiguration(fileMap, path).GetSection(SectionName); } finally { AppDomain.CurrentDomain.AssemblyResolve -= ExecutingAssemblyResolver; } return(result); }
private static Configuration GetWebConfig() { var vdm = new VirtualDirectoryMapping(_settings.SourceDirectory, true); var wcfm = new WebConfigurationFileMap(); wcfm.VirtualDirectories.Add("/", vdm); return(WebConfigurationManager.OpenMappedWebConfiguration(wcfm, "/")); }
public static Configuration OpenConfigFile(string configPath) { var configFile = new FileInfo(configPath); var vdm = new VirtualDirectoryMapping(configFile.DirectoryName, true, configFile.Name); var wcfm = new WebConfigurationFileMap(); wcfm.VirtualDirectories.Add("/", vdm); return(WebConfigurationManager.OpenMappedWebConfiguration(wcfm, "/")); }
public TSection GetSection <TSection>(string sectionName) where TSection : class { var map = new WebConfigurationFileMap(); map.VirtualDirectories.Add("/", GetVDirMapping()); var configuration = WebConfigurationManager.OpenMappedWebConfiguration(map, "/"); return(configuration.GetSection(sectionName) as TSection); }
public static Configuration GetWebConfig(string wwwPath) { var webConfigFile = new FileInfo("Web.config"); var vdm = new VirtualDirectoryMapping(wwwPath, true, webConfigFile.Name); var wcfm = new WebConfigurationFileMap(); wcfm.VirtualDirectories.Add("/", vdm); var siteName = "Sandbox"; return(WebConfigurationManager.OpenMappedWebConfiguration(wcfm, "/", siteName)); }
private void EnsureInitialized() { if (_configuration != null) { return; } var webConfigurationFileMap = new WebConfigurationFileMap(); webConfigurationFileMap.VirtualDirectories.Add(VirtualDirectory, new VirtualDirectoryMapping(_path, true)); _configuration = WebConfigurationManager.OpenMappedWebConfiguration(webConfigurationFileMap, VirtualDirectory); }
/// <summary> /// Adds standard configuration from specified web application. /// This method is similar to <see cref="ConfigurationSourcesBuilderExtensions.AddConfigurationManagerConfiguration"/> but work on a different application context: /// It is needed for utility applications that reference the generated Rhetos applications and use it's runtime components. /// This method load's the Rhetos application's configuration, while <see cref="ConfigurationSourcesBuilderExtensions.AddConfigurationManagerConfiguration"/> loads the current utility application's configuration. /// When executed from the generated Rhetos application, it should yield same result as <see cref="ConfigurationSourcesBuilderExtensions.AddConfigurationManagerConfiguration"/>. /// </summary> public static IConfigurationBuilder AddWebConfiguration(this IConfigurationBuilder builder, string webRootPath) { webRootPath = Path.GetFullPath(webRootPath); VirtualDirectoryMapping vdm = new VirtualDirectoryMapping(webRootPath, true); WebConfigurationFileMap wcfm = new WebConfigurationFileMap(); wcfm.VirtualDirectories.Add("/", vdm); System.Configuration.Configuration configuration = WebConfigurationManager.OpenMappedWebConfiguration(wcfm, "/"); builder.Add(new ConfigurationFileSource(configuration)); return(builder); }
public override void Initialize(RazorHost razorHost, IDictionary <string, string> directives) { string projectPath = GetProjectRoot(razorHost.ProjectRelativePath, razorHost.FullPath).TrimEnd(Path.DirectorySeparatorChar); string currentPath = razorHost.FullPath; string directoryVirtualPath = null; var configFileMap = new WebConfigurationFileMap(); var virtualDirectories = configFileMap.VirtualDirectories; while (!currentPath.Equals(projectPath, StringComparison.OrdinalIgnoreCase)) { currentPath = Path.GetDirectoryName(currentPath); string relativePath = currentPath.Substring(projectPath.Length); bool isAppRoot = currentPath.Equals(projectPath, StringComparison.OrdinalIgnoreCase); string virtualPath = relativePath.Replace('\\', '/'); if (virtualPath.Length == 0) { virtualPath = "/"; } directoryVirtualPath = directoryVirtualPath ?? virtualPath; virtualDirectories.Add(virtualPath, new VirtualDirectoryMapping(currentPath, isAppRoot: isAppRoot)); } try { var config = WebConfigurationManager.OpenMappedWebConfiguration(configFileMap, directoryVirtualPath); RazorPagesSection section = config.GetSection(RazorPagesSection.SectionName) as RazorPagesSection; if (section != null) { string baseType = section.PageBaseType; if (!DefaultBaseType.Equals(baseType, StringComparison.OrdinalIgnoreCase)) { _transformers.Add(new SetBaseType(baseType)); } if (section != null) { foreach (NamespaceInfo n in section.Namespaces) { razorHost.NamespaceImports.Add(n.Namespace); } } } } catch (IndexOutOfRangeException) { // Bug in Mono framework. // Configure namespaces using the RazorGenerator directives file instead. } base.Initialize(razorHost, directives); }
public static System.Configuration.Configuration LoadWebConfigForUnitTests() { var unitTestAssembly = typeof(WebConfigLoaderForUnitTests).Assembly; var directoryName = Path.GetDirectoryName(unitTestAssembly.Location); var assemblyPath = directoryName.Replace(@"file:\", string.Empty); var webConfigFile = new FileInfo(Path.Combine(assemblyPath, unitTestAssembly.GetName().Name + ".dll.config")); var virtualDirectoryMapping = new VirtualDirectoryMapping(webConfigFile.DirectoryName, true, webConfigFile.Name); var webConfigurationFileMap = new WebConfigurationFileMap(); webConfigurationFileMap.VirtualDirectories.Add("/", virtualDirectoryMapping); return(WebConfigurationManager.OpenMappedWebConfiguration(webConfigurationFileMap, "/")); }
public virtual void SetUp() { var rootPathProvider = new InvoiceGenRootPathProvider(); var webConfigFile = new FileInfo(Path.Combine(rootPathProvider.GetRootPath(), "web.config")); var virtualDirectoryMapping = new VirtualDirectoryMapping(webConfigFile.DirectoryName, true, webConfigFile.Name); var webConfigurationFileMap = new WebConfigurationFileMap(); webConfigurationFileMap.VirtualDirectories.Add("/", virtualDirectoryMapping); var configuration = WebConfigurationManager.OpenMappedWebConfiguration(webConfigurationFileMap, "/"); _sut = CompositionRoot.Compose(configuration); }
/// <summary> /// Load web.config from a diferent context (like a script) /// </summary> /// <returns></returns> private static Configuration GetConfiguration() { var path = Path.GetFullPath( Path.Combine( Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "..\\Web.config")); var configFile = new FileInfo(path); var vdm = new VirtualDirectoryMapping(configFile.DirectoryName, true, configFile.Name); var wcfm = new WebConfigurationFileMap(); wcfm.VirtualDirectories.Add("/", vdm); return(WebConfigurationManager.OpenMappedWebConfiguration(wcfm, "/")); }
public void OverrideAppSettingsWithEnvironmentVars() { throw new NotImplementedException("Not implemented as WebConfigurationManager seems buggy in Mono 3.2.4"); string directory = Path.GetDirectoryName(Path.GetFullPath(configFile)); WebConfigurationFileMap wcfm = new WebConfigurationFileMap(); VirtualDirectoryMapping vdm = new VirtualDirectoryMapping(directory, true, "Web.config"); wcfm.VirtualDirectories.Add("/", vdm); //WebConfigurationManager seems bugging in Mono 3.2.4 Configuration webConfig = WebConfigurationManager.OpenMappedWebConfiguration(wcfm, "/"); }
/// <summary> /// 获取标准Web应用程序的配置信息,合并Web.config和 global配置文件 /// </summary> /// <param name="machineConfigPath">global配置文件地址</param> /// <returns>Web.config和global配置文件合并后的Configuration对象</returns> private static System.Configuration.Configuration GetStandardWebConfiguration(string machineConfigPath) { System.Configuration.Configuration config; WebConfigurationFileMap webFileMap = new WebConfigurationFileMap() { MachineConfigFilename = machineConfigPath }; VirtualDirectoryMapping vDirMap = new VirtualDirectoryMapping(HttpContext.Current.Request.PhysicalApplicationPath, true); webFileMap.VirtualDirectories.Add("/", vDirMap); config = WebConfigurationManager.OpenMappedWebConfiguration(webFileMap, "/", System.Web.Hosting.HostingEnvironment.SiteName); return(config); }
public static void setReserveTimeUnit(int hr) { Configuration c = null; if (HostingEnvironment.ApplicationVirtualPath == "/") { c = WebConfigurationManager.OpenWebConfiguration("~/web.config"); } WebConfigurationFileMap fileMap = CreateFileMap(HostingEnvironment.ApplicationVirtualPath); c = WebConfigurationManager.OpenMappedWebConfiguration(fileMap, HostingEnvironment.ApplicationVirtualPath); c.AppSettings.Settings["reserveTimeUnit"].Value = hr.ToString(); c.Save(); }
protected override void Execute(CodeActivityContext context) { Configuration config = null; if (IsWebsite.Get(context)) { var configFile = new FileInfo(ConfigFilename.Get(context)); var vdm = new VirtualDirectoryMapping(configFile.DirectoryName, true, configFile.Name); var wcfm = new WebConfigurationFileMap(); wcfm.VirtualDirectories.Add("/", vdm); config = WebConfigurationManager.OpenMappedWebConfiguration(wcfm, "/"); } else { config = ConfigurationManager.OpenMappedExeConfiguration(new ExeConfigurationFileMap { ExeConfigFilename = ConfigFilename.Get(context) }, ConfigurationUserLevel.None); } ConfigurationSection section = config.GetSection(Section.Get(context)); section.SectionInformation.ProtectSection("RSAProtectedConfigurationProvider"); config.Save(); var console = context.GetExtension <ActivityConsole>(); if (console == null) { console = new ActivityConsole(); } console.WriteLine(string.Format("Encrypted section '{0}' in '{1}'", Section.Get(context), ConfigFilename.Get(context))); console.WriteLine(""); string username = Username.Get(context); if (!string.IsNullOrEmpty(username)) { Helpers.CommandLine cmdExecutor = new CommandLine(); string output = string.Empty; int exitCode = cmdExecutor.Execute(string.Format("{0}\\{1}", Helpers.FrameworkHelper.GetDotNetInstallationFolder(), "aspnet_regiis"), string.Format("-pa \"NetFrameworkConfigurationKey\" \"{0}\"", username), out output); if (exitCode != 0 || !output.Contains("Succeeded!")) { throw new ArgumentException(string.Format("Failed to set Encryption key security privileges for user '{0}'\n{1}", username, output)); } console.WriteLine(string.Format("Successfully set read access to Encryption key for user '{0}'.", username)); } }
public override SyntaxTree GetSyntaxTree(string sourcePath, Stream sourceStream, CSharpParseOptions parseOptions) { try { var viewFullPath = sourcePath; var viewVirtualPath = GetRelativeUri(sourcePath, Compilation.CurrentDirectory.FullName); var viewConfig = WebConfigurationManager.OpenMappedWebConfiguration(_configMap, viewVirtualPath); var razorConfig = viewConfig.GetSectionGroup("system.web.webPages.razor") as RazorWebSectionGroup; var host = razorConfig == null ? WebRazorHostFactory.CreateDefaultHost(viewVirtualPath, viewFullPath) : WebRazorHostFactory.CreateHostFromConfig(razorConfig, viewVirtualPath, viewFullPath); using (var rdr = new StreamReader(sourceStream, Compilation.Encoding, detectEncodingFromByteOrderMarks: true)) using (var provider = CodeDomProvider.CreateProvider("csharp")) using (var generatedStream = new MemoryStream()) using (var generatedWriter = new StreamWriter(generatedStream, Compilation.Encoding)) { var engine = new RazorTemplateEngine(host); var razorOut = engine.GenerateCode(rdr, null, null, viewFullPath); // add the CompiledFromFileAttribute to the generated class razorOut.GeneratedCode .Namespaces.OfType <CodeNamespace>().FirstOrDefault()? .Types.OfType <CodeTypeDeclaration>().FirstOrDefault()? .CustomAttributes.Add( new CodeAttributeDeclaration( new CodeTypeReference(typeof(CompiledFromFileAttribute)), new CodeAttributeArgument(new CodePrimitiveExpression(viewFullPath)) )); var codeGenOptions = new CodeGeneratorOptions { VerbatimOrder = true, ElseOnClosing = false, BlankLinesBetweenMembers = false }; provider.GenerateCodeFromCompileUnit(razorOut.GeneratedCode, generatedWriter, codeGenOptions); // rewind generatedWriter.Flush(); generatedStream.Position = 0; return(base.GetSyntaxTree(sourcePath, generatedStream, parseOptions)); } } catch (Exception ex) { Compilation.Diagnostics.Add(Diagnostic.Create(Compilation.ViewGenerationFailed, Compilation.AsLocation(sourcePath), ex.ToString())); return(null); } }
public void SetCredentials() { var webConfigurationFileMap = new WebConfigurationFileMap(); webConfigurationFileMap.VirtualDirectories.Add(_path, new VirtualDirectoryMapping(_path, isAppRoot: true)); var webConfig = WebConfigurationManager.OpenMappedWebConfiguration(webConfigurationFileMap, string.Empty); var map = new ExeConfigurationFileMap { ExeConfigFilename = @_path }; var configfile = ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None); var test = WebConfigurationManager.AppSettings[""]; var a = webConfig.GetSection("appSettings"); //TODO: get this working so I dont have to hardcode the key and secret... //_secret = ConfigurationManager.AppSettings["KrakenSecret"]; }
private static void ReadConnectionString(MigrationToolSettings settings) { var vdm = new VirtualDirectoryMapping(_settings.SourceDirectory, true); var wcfm = new WebConfigurationFileMap(); wcfm.VirtualDirectories.Add("/", vdm); var config = WebConfigurationManager.OpenMappedWebConfiguration(wcfm, "/"); var connectionString = config.ConnectionStrings.ConnectionStrings["EPiServerDB"].ConnectionString; if (string.IsNullOrWhiteSpace(connectionString)) { throw new ConfigurationErrorsException("Cannot find EPiServer database connection"); } settings.ConnectionString = connectionString; }