/// <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, "/"); }
public static void RefreshAllBundles(IBundleContext context) { // parse each folders to register new bundles foreach (var folderPath in Directory.GetDirectories(Path.GetFullPath(string.Format("Bundles")))) { var bundleName = new DirectoryInfo(folderPath).Name; var bundleInfo = context.GetBundle(bundleName); if (bundleInfo == null) { string path = Path.GetFullPath(string.Format("Bundles\\{0}\\{0}.dll", bundleName)); // the assembly doesn't exist, try the bundle.config? Web.config? if (!File.Exists(path)) { System.Configuration.Configuration configuration = null; if (File.Exists(Path.GetFullPath(string.Format("Bundles\\{0}\\{0}.dll.config", bundleName)))) { configuration = ConfigurationManager.OpenExeConfiguration(path); } else if (File.Exists(Path.GetFullPath(string.Format("Bundles\\{0}\\web.config", bundleName)))) { VirtualDirectoryMapping vdm = new VirtualDirectoryMapping( Path.GetFullPath(string.Format("Bundles\\{0}", bundleName)), true); WebConfigurationFileMap wcfm = new WebConfigurationFileMap(); wcfm.VirtualDirectories.Add("/", vdm); // Get the Web application configuration object. configuration = WebConfigurationManager.OpenMappedWebConfiguration(wcfm, "/"); } else { throw new BundleNotFoundException(bundleName, new Version()); } // TODO : better error handling var section = (BundleConfigurationSection) configuration.GetSection("bundleConfiguration"); path = Path.GetFullPath(string.Format("Bundles\\{0}\\{1}", bundleName, section.BundlePath)); if (!File.Exists(path)) throw new BundleNotFoundException(bundleName, new Version()); } // create the bundle with all information needed var assembly = Assembly.ReflectionOnlyLoadFrom(path); var version = assembly.GetName().Version; bundleInfo = new BundleInfo { Path = path, Name = bundleName, Version = assembly.GetName().Version, State = BundleState.Installed }; // and then, register it context.RegisterBundle(bundleInfo); } } }
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, "/"); }
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); }
public override object Clone () { WebConfigurationFileMap map = new WebConfigurationFileMap (); map.MachineConfigFilename = MachineConfigFilename; map.virtualDirectories = new VirtualDirectoryMappingCollection (); foreach (VirtualDirectoryMapping vmap in virtualDirectories) { VirtualDirectoryMapping nvmap = new VirtualDirectoryMapping (vmap.PhysicalDirectory, vmap.IsAppRoot, vmap.ConfigFileBaseName); map.virtualDirectories.Add (vmap.VirtualDirectory, nvmap); } return map; }
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, "/"); }
public void Add(string virtualDirectory, VirtualDirectoryMapping mapping) { virtualDirectory = ValidateVirtualDirectoryParameter(virtualDirectory); if (mapping == null) { throw new ArgumentNullException("mapping"); } if (this.Get(virtualDirectory) != null) { throw ExceptionUtil.ParameterInvalid("virtualDirectory"); } mapping.SetVirtualDirectory(VirtualPath.CreateAbsoluteAllowNull(virtualDirectory)); base.BaseAdd(virtualDirectory, mapping); }
public void CopyTo(VirtualDirectoryMapping[] array, int index) { if (array == null) { throw new ArgumentNullException("array"); } int c = Count; if (array.Length < c + index) { throw new ArgumentOutOfRangeException("index"); } for (int i = 0, j = index; i < c; i++, j++) { array[j] = Get(i); } }
static void Main(string[] args) { if (string.IsNullOrEmpty(ConfigurationManager.AppSettings["WindowsLoginCredentials"])) { VirtualDirectoryMapping vdm = new VirtualDirectoryMapping(@"C:\LDS\Phoenix\PhoenixWeb", true); WebConfigurationFileMap wcfm = new WebConfigurationFileMap(); wcfm.VirtualDirectories.Add("/", vdm); // Get the Web application configuration object. Configuration config = WebConfigurationManager.OpenMappedWebConfiguration(wcfm, "/"); string s = config.AppSettings.Settings["WindowsLoginCredentials"].Value; } Console.Read(); }
private void GetPathConfigFilename(string siteID, VirtualPath path, out string directory, out string baseName) { directory = null; baseName = null; if (this.IsSiteMatch(siteID)) { VirtualDirectoryMapping pathMapping = this.GetPathMapping(path, false); if (pathMapping != null) { directory = this.GetPhysicalPathForPath(path.VirtualPathString, pathMapping); if (directory != null) { baseName = pathMapping.ConfigFileBaseName; } } } }
/// <summary> /// Get web configuration /// </summary> /// <param name="physicalPath"></param> /// <returns>configuration object</returns> public static Configuration GetConfig(string physicalPath) { Configuration configuration; if (string.IsNullOrWhiteSpace(physicalPath)) configuration = WebConfigurationManager.OpenWebConfiguration("~"); else { var configFile = new FileInfo(physicalPath); var vdm = new VirtualDirectoryMapping(configFile.DirectoryName, true, configFile.Name); var wcfm = new WebConfigurationFileMap(); wcfm.VirtualDirectories.Add("/", vdm); var websiteName = HostingEnvironment.SiteName; configuration = WebConfigurationManager.OpenMappedWebConfiguration(wcfm, "/", websiteName); } return configuration; }
public void Add(string virtualDirectory, VirtualDirectoryMapping mapping) { virtualDirectory = ValidateVirtualDirectoryParameter(virtualDirectory); if (mapping == null) { throw new ArgumentNullException("mapping"); } if (Get(virtualDirectory) != null) { throw ExceptionUtil.ParameterInvalid("virtualDirectory"); } mapping.SetVirtualDirectory(VirtualPath.CreateAbsoluteAllowNull(virtualDirectory)); BaseAdd(virtualDirectory, mapping); }
public void ShouldAddModifiedAt () { CreateSampleConfigFile (); new WebConfigUpdater("Web.config") .OverrideAppSettingsWithEnvironmentVars (); string directory = Path.GetDirectoryName(Path.GetFullPath("Web.config")); 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, "/"); CollectionAssert.Contains (webConfig.AppSettings.Settings.AllKeys, "AppSettingsAutoReconfiguration_ModifiedAt"); Console.WriteLine (webConfig.AppSettings.Settings ["AppSettingsAutoReconfiguration_ModifiedAt"].Value); }
public void CopyTo(VirtualDirectoryMapping[] array, int index) { if (array == null) { throw new ArgumentNullException("array"); } int count = this.Count; if (array.Length < (count + index)) { throw new ArgumentOutOfRangeException("index"); } int num2 = 0; for (int i = index; num2 < count; i++) { array[i] = this.Get(num2); num2++; } }
public string MapPathFromMapper(string virtualPath) { string path = NormalizeVirtualPath(virtualPath); for (int j = 0; j < map.VirtualDirectories.Count; j++) { VirtualDirectoryMapping mapping = map.VirtualDirectories.Get(j); if (path.StartsWith(mapping.VirtualDirectory)) { int i = mapping.VirtualDirectory.Length; if (path.Length == i) { return(mapping.PhysicalDirectory); } else if (path [i] == '/') { string pathPart = path.Substring(i + 1).Replace('/', Path.DirectorySeparatorChar); return(Path.Combine(mapping.PhysicalDirectory, pathPart)); } } } throw new HttpException("Invalid virtual directory: " + virtualPath); }
/// <summary> /// Get the appropriate tool configuration for this service reference. /// /// If a reference.config file is present, the configuration object returned /// will be the merged view of: /// /// Machine Config /// ReferenceConfig /// /// If not reference.config file is present, the configuration object returned /// will be a merged view of: /// /// Machine.config /// web.config in application's physical path... /// /// </summary> /// <param name="mapFile">SvcMapFile representing the service</param> /// <returns></returns> private System.Configuration.Configuration GetToolConfig(SvcMapFile mapFile, string mapFilePath) { string toolConfigFile = null; if (mapFile != null && mapFilePath != null) { foreach (ExtensionFile extensionFile in mapFile.Extensions) { if (String.Equals(extensionFile.Name, TOOL_CONFIG_ITEM_NAME, StringComparison.Ordinal)) { toolConfigFile = extensionFile.FileName; } } } System.Web.Configuration.WebConfigurationFileMap fileMap; fileMap = new System.Web.Configuration.WebConfigurationFileMap(); System.Web.Configuration.VirtualDirectoryMapping mapping; if (toolConfigFile != null) { // // If we've got a specific tool configuration to use, we better load that... // mapping = new System.Web.Configuration.VirtualDirectoryMapping(System.IO.Path.GetDirectoryName(mapFilePath), true, toolConfigFile); } else { // // Otherwise we fall back to the default web.config file... // mapping = new System.Web.Configuration.VirtualDirectoryMapping(HostingEnvironment.ApplicationPhysicalPath, true); } fileMap.VirtualDirectories.Add("/", mapping); return(System.Web.Configuration.WebConfigurationManager.OpenMappedWebConfiguration(fileMap, "/", System.Web.Hosting.HostingEnvironment.SiteName)); }
public void Add(string virtualDirectory, VirtualDirectoryMapping mapping) { mapping.SetVirtualDirectory(virtualDirectory); BaseAdd(virtualDirectory, mapping); }
public void CopyTo (VirtualDirectoryMapping[] array, int index) { ((ICollection)this).CopyTo (array, index); }
public void Add (string virtualDirectory, VirtualDirectoryMapping mapping) { mapping.SetVirtualDirectory (virtualDirectory); BaseAdd (virtualDirectory, mapping); }
/// <summary> /// Gets the configuration settings for the installing assembly /// </summary> /// <returns></returns> public static System.Configuration.Configuration GetInstallingConfiguration() { Assembly assembly = GetEntryInstallingAssembly(); if (IsWebApplication()) { string websiteRootDirectory = Path.GetDirectoryName(Path.GetDirectoryName(assembly.Location)); VirtualDirectoryMapping vdm = new VirtualDirectoryMapping(websiteRootDirectory, true); WebConfigurationFileMap wcfm = new WebConfigurationFileMap(); wcfm.VirtualDirectories.Add("/", vdm); return WebConfigurationManager.OpenMappedWebConfiguration(wcfm, "/"); } else { string configFilePath = Path.Combine( Path.GetDirectoryName(assembly.Location), Path.GetFileNameWithoutExtension(assembly.Location)); return ConfigurationManager.OpenExeConfiguration(configFilePath); } }
public void CopyTo(VirtualDirectoryMapping[] array, int index) { }
public void Add(string virtualDirectory, VirtualDirectoryMapping mapping) { }
private string GetPhysicalPathForPath(string path, VirtualDirectoryMapping mapping) { string physicalDirectory; int length = mapping.VirtualDirectory.Length; if (path.Length == length) { physicalDirectory = mapping.PhysicalDirectory; } else { string str2; if (path[length] == '/') { str2 = path.Substring(length + 1); } else { str2 = path.Substring(length); } str2 = str2.Replace('/', '\\'); physicalDirectory = Path.Combine(mapping.PhysicalDirectory, str2); } if (this._pathsAreLocal && System.Web.Util.FileUtil.IsSuspiciousPhysicalPath(physicalDirectory)) { throw new HttpException(System.Web.SR.GetString("Cannot_map_path", new object[] { path })); } return physicalDirectory; }
/// <summary> /// Function that builds the contents of the generated file based on the contents of the input file /// </summary> /// <param name="inputFileContent">Content of the input file</param> /// <returns>Generated file as a byte array</returns> protected override byte[] GenerateCode(string inputFileContent) { var references = GetVSProject().References; // Add reference to our buildprovider and virtualpathprovider /* var buildprovAssembly = typeof(CompiledVirtualPathProvider).Assembly; if (references.Find(buildprovAssembly.GetName().Name) == null) { references.Add(buildprovAssembly.Location); } */ // Get the root folder of the project var appRoot = Path.GetDirectoryName(GetProject().FullName); // Determine the project-relative path string projectRelativePath = InputFilePath.Substring(appRoot.Length); // Turn it into a virtual path by prepending ~ and fixing it up string virtualPath = VirtualPathUtility.ToAppRelative("~" + projectRelativePath); var vdm = new VirtualDirectoryMapping(appRoot, true); var wcfm = new WebConfigurationFileMap(); wcfm.VirtualDirectories.Add("/", vdm); var config = WebConfigurationManager.OpenMappedWebConfiguration(wcfm, projectRelativePath); var sectGroup = new RazorWebSectionGroup { Host = (HostSection) config.GetSection(HostSection.SectionName) ?? new HostSection {FactoryType = typeof (MvcWebRazorHostFactory).AssemblyQualifiedName}, Pages = (RazorPagesSection) config.GetSection(RazorPagesSection.SectionName) }; // Create the same type of Razor host that's used to process Razor files in App_Code var host = IsHelper ? new WebCodeRazorHost(virtualPath, InputFilePath) : WebRazorHostFactory.CreateHostFromConfig(sectGroup, virtualPath, InputFilePath); // Set the namespace to be the same as what's used by default for regular .cs files host.DefaultNamespace = FileNameSpace; host.NamespaceImports.Remove("WebMatrix.Data"); host.NamespaceImports.Remove("WebMatrix.WebData"); var systemWebPages = config.GetSection("system.web/pages") as PagesSection; if (systemWebPages != null) { foreach (NamespaceInfo ns in systemWebPages.Namespaces) { if (!host.NamespaceImports.Contains(ns.Namespace)) { host.NamespaceImports.Add(ns.Namespace); } } } var compilationSection = config.GetSection("system.web/compilation") as CompilationSection; if (compilationSection != null) { foreach (AssemblyInfo assembly in compilationSection.Assemblies) { if (assembly.Assembly != "*" && references.Find(assembly.Assembly) == null) { references.Add(assembly.Assembly); } } } // Create a Razor engine and pass it our host var engine = new RazorTemplateEngine(host); // Generate code GeneratorResults results; try { using (TextReader reader = new StringReader(inputFileContent)) { results = engine.GenerateCode(reader,null,null,InputFilePath); } } catch (Exception e) { GeneratorError(4, e.ToString(), 1, 1); return RazorError; } // Output errors foreach (RazorError error in results.ParserErrors) { GeneratorError(4, error.Message, (uint)error.Location.LineIndex + 1, (uint)error.Location.CharacterIndex + 1); } CodeDomProvider provider = GetCodeProvider(); try { if (CodeGeneratorProgress != null) { // Report that we are 1/2 done CodeGeneratorProgress.Progress(50, 100); } using (StringWriter writer = new StringWriter(new StringBuilder())) { CodeGeneratorOptions options = new CodeGeneratorOptions { BlankLinesBetweenMembers = false, BracingStyle = "C" }; // Add a GeneratedCode attribute to the generated class CodeCompileUnit generatedCode = results.GeneratedCode; var ns = generatedCode.Namespaces[0]; CodeTypeDeclaration generatedType = ns.Types[0]; generatedType.CustomAttributes.Add( new CodeAttributeDeclaration( new CodeTypeReference(typeof(GeneratedCodeAttribute)), new CodeAttributeArgument(new CodePrimitiveExpression("RazorViewCompiler")), new CodeAttributeArgument(new CodePrimitiveExpression("1.0")))); if(!IsHelper) { generatedType.CustomAttributes.Add( new CodeAttributeDeclaration( new CodeTypeReference(typeof(PageVirtualPathAttribute)), new CodeAttributeArgument(new CodePrimitiveExpression(virtualPath)))); } // Generate the code provider.GenerateCodeFromCompileUnit(generatedCode, writer, options); if (CodeGeneratorProgress != null) { //Report that we are done CodeGeneratorProgress.Progress(100, 100); } writer.Flush(); // Save as UTF8 Encoding enc = Encoding.UTF8; // Get the preamble (byte-order mark) for our encoding byte[] preamble = enc.GetPreamble(); int preambleLength = preamble.Length; // Convert the writer contents to a byte array byte[] body = enc.GetBytes(writer.ToString()); // Prepend the preamble to body (store result in resized preamble array) Array.Resize<byte>(ref preamble, preambleLength + body.Length); Array.Copy(body, 0, preamble, preambleLength, body.Length); // Return the combined byte array return preamble; } } catch (Exception e) { GeneratorError(4, e.ToString(), 1, 1); return RazorError; } }
private void btnChange_Click(object sender, EventArgs e) { if (!String.IsNullOrEmpty(txtPathFolder.Text)) { foreach (var item in paths) { var configurationFileInfo = new FileInfo(String.Format(@"{0}{1}", txtPathFolder.Text, item)); configurationFileInfo.IsReadOnly = false; var vdm = new VirtualDirectoryMapping(configurationFileInfo.DirectoryName, true, configurationFileInfo.Name); var wcfm = new WebConfigurationFileMap(); wcfm.VirtualDirectories.Add("/", vdm); Configuration config = WebConfigurationManager.OpenMappedWebConfiguration(wcfm, "/"); var connectionStringsSection = (ConnectionStringsSection)config.GetSection("connectionStrings"); if (rbnBandes.Checked) { if (connectionStringsSection.ConnectionStrings["Infosis.Audit"] != null) connectionStringsSection.ConnectionStrings["Infosis.Audit"].ConnectionString = @"Data Source=SRV19\desenv;Initial Catalog=BancoDeAuditoriaParaTodosOsBancosNetDoSrv06;User ID=pdCase;Password=Banco2014!;MultipleActiveResultSets=True"; if (connectionStringsSection.ConnectionStrings["Infosis.Auditable"] != null) connectionStringsSection.ConnectionStrings["Infosis.Auditable"].ConnectionString = @"Data Source=SRV19\desenv;Initial Catalog=CloneProducaoSisbandesNet;User ID=pdCase;Password=Banco2014!;MultipleActiveResultSets=True"; if (connectionStringsSection.ConnectionStrings["Infosis.Dashboard"] != null) connectionStringsSection.ConnectionStrings["Infosis.Dashboard"].ConnectionString = @"Data Source=SRV19\desenv;Initial Catalog=CloneProducaoSisbandesNet;User ID=pdCase;Password=Banco2014!;MultipleActiveResultSets=True"; if (connectionStringsSection.ConnectionStrings["Infosis.Safeguard"] != null) connectionStringsSection.ConnectionStrings["Infosis.Safeguard"].ConnectionString = @"Data Source=SRV19\desenv;Initial Catalog=CloneProducaoSisbandesNet;User ID=pdCase;Password=Banco2014!;MultipleActiveResultSets=True"; if (connectionStringsSection.ConnectionStrings["SisbandesNet"] != null) connectionStringsSection.ConnectionStrings["SisbandesNet"].ConnectionString = @"Data Source=SRV19\desenv;Initial Catalog=CloneProducaoSisbandesNet;User ID=pdCase;Password=Banco2014!;MultipleActiveResultSets=True"; if (connectionStringsSection.ConnectionStrings["SisbandesNetReports"] != null) connectionStringsSection.ConnectionStrings["SisbandesNetReports"].ConnectionString = @"Data Source=SRV19\desenv;Initial Catalog=CloneProducaoSisbandesNet;User ID=pdCase;Password=Banco2014!;MultipleActiveResultSets=True"; if (connectionStringsSection.ConnectionStrings["Infosis.ServiceBroker"] != null) connectionStringsSection.ConnectionStrings["Infosis.ServiceBroker"].ConnectionString = @"Data Source=SRV19\desenv;Initial Catalog=CloneProducaoSisbandesNet;User ID=pdCase;Password=Banco2014!;MultipleActiveResultSets=True"; if (connectionStringsSection.ConnectionStrings["Infosis.ServiceBrokerReports"] != null) connectionStringsSection.ConnectionStrings["Infosis.ServiceBrokerReports"].ConnectionString = @"Data Source=SRV19\desenv;Initial Catalog=CloneProducaoSisbandesNet;User ID=pdCase;Password=Banco2014!;MultipleActiveResultSets=True"; if (connectionStringsSection.ConnectionStrings["DbSisbandes"] != null) connectionStringsSection.ConnectionStrings["DbSisbandes"].ConnectionString = @"Data Source=SRV19\desenv;Initial Catalog=CloneProducaoDbSisbandes;User ID=pdCase;Password=Banco2014!;MultipleActiveResultSets=True"; } else { if (connectionStringsSection.ConnectionStrings["Infosis.Audit"] != null) connectionStringsSection.ConnectionStrings["Infosis.Audit"].ConnectionString = @"Data Source=bandes-bdw\bandes_dsv;Initial Catalog=BancoDeAuditoriaParaTodosOsBancosNet;User ID=pdCase;Password=Banco2014!;MultipleActiveResultSets=True"; if (connectionStringsSection.ConnectionStrings["Infosis.Auditable"] != null) connectionStringsSection.ConnectionStrings["Infosis.Auditable"].ConnectionString = @"Data Source=bandes-bdw\bandes_dsv;Initial Catalog=SisbandesNet;User ID=pdCase;Password=Banco2014!;MultipleActiveResultSets=True"; if (connectionStringsSection.ConnectionStrings["Infosis.Dashboard"] != null) connectionStringsSection.ConnectionStrings["Infosis.Dashboard"].ConnectionString = @"Data Source=bandes-bdw\bandes_dsv;Initial Catalog=SisbandesNet;User ID=pdCase;Password=Banco2014!;MultipleActiveResultSets=True"; if (connectionStringsSection.ConnectionStrings["Infosis.Safeguard"] != null) connectionStringsSection.ConnectionStrings["Infosis.Safeguard"].ConnectionString = @"Data Source=bandes-bdw\bandes_dsv;Initial Catalog=SisbandesNet;User ID=pdCase;Password=Banco2014!;MultipleActiveResultSets=True"; if (connectionStringsSection.ConnectionStrings["SisbandesNet"] != null) connectionStringsSection.ConnectionStrings["SisbandesNet"].ConnectionString = @"Data Source=bandes-bdw\bandes_dsv;Initial Catalog=SisbandesNet;User ID=pdCase;Password=Banco2014!;MultipleActiveResultSets=True"; if (connectionStringsSection.ConnectionStrings["SisbandesNetReports"] != null) connectionStringsSection.ConnectionStrings["SisbandesNetReports"].ConnectionString = @"Data Source=bandes-bdw\bandes_dsv;Initial Catalog=SisbandesNet;User ID=pdCase;Password=Banco2014!;MultipleActiveResultSets=True"; if (connectionStringsSection.ConnectionStrings["Infosis.ServiceBroker"] != null) connectionStringsSection.ConnectionStrings["Infosis.ServiceBroker"].ConnectionString = @"Data Source=bandes-bdw\bandes_dsv;Initial Catalog=SisbandesNet;User ID=pdCase;Password=Banco2014!;MultipleActiveResultSets=True"; if (connectionStringsSection.ConnectionStrings["Infosis.ServiceBrokerReports"] != null) connectionStringsSection.ConnectionStrings["Infosis.ServiceBrokerReports"].ConnectionString = @"Data Source=bandes-bdw\bandes_dsv;Initial Catalog=SisbandesNet;User ID=pdCase;Password=Banco2014!;MultipleActiveResultSets=True"; if (connectionStringsSection.ConnectionStrings["DbSisbandes"] != null) connectionStringsSection.ConnectionStrings["DbSisbandes"].ConnectionString = @"Data Source=bandes-bdw\bandes_dsv;Initial Catalog=DbSisbandes;User ID=pdCase;Password=Banco2014!;MultipleActiveResultSets=True"; } config.Save(); ConfigurationManager.RefreshSection("connectionStrings"); configurationFileInfo.IsReadOnly = true; } MessageBox.Show("Alteração realizada com sucesso!"); } else { MessageBox.Show("Selecione o caminho do branch!"); } }
// Given a path and a VirtualDirectoryMapping, return the corresponding // physical path. string GetPhysicalPathForPath(string path, VirtualDirectoryMapping mapping) { string physicalPath; int l = mapping.VirtualDirectory.Length; if (path.Length == l) { physicalPath = mapping.PhysicalDirectory; } else { string childPart; if (path[l] == '/') { childPart = path.Substring(l+1); } else { childPart = path.Substring(l); } childPart = childPart.Replace('/', '\\'); physicalPath = Path.Combine(mapping.PhysicalDirectory, childPart); } // Throw if the resulting physical path is not canonical, to prevent potential // security issues (VSWhidbey 418125) if (_pathsAreLocal && FileUtil.IsSuspiciousPhysicalPath(physicalPath)) { throw new HttpException(SR.GetString(SR.Cannot_map_path, path)); } return physicalPath; }
RazorEngineHost CreateRazorHost (string fileName) { string virtualPath = "~/Views/Default.cshtml"; if (project != null) virtualPath = project.LocalToVirtualPath (fileName); WebPageRazorHost host = null; // Try to create host using web.config file var webConfigMap = new WebConfigurationFileMap (); var vdm = new VirtualDirectoryMapping (project.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; }
RazorEngineHost CreateRazorHost (string fileName) { if (project != null) { var projectFile = project.GetProjectFile (fileName); if (projectFile != null && projectFile.Generator == "RazorTemplatePreprocessor") { return new MonoDevelop.AspNet.Razor.Generator.PreprocessedRazorHost (fileName) { DesignTimeMode = true, EnableLinePragmas = false, }; } } 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 static WebPageRazorHost GetRazorWebPageRazorHost(string virtualPath, string physicalPath) { WebPageRazorHost webPageRazorHost = null; try { string physicalDirectory = physicalPath.Substring(0, physicalPath.Length - virtualPath.Length); string text = virtualPath.Replace('\\', '/'); if (!text.StartsWith("/", StringComparison.Ordinal)) { text = "/" + text; } int num = text.LastIndexOf('/'); text = text.Substring(0, (num == 0) ? 1 : num); WebConfigurationFileMap arg_62_0 = new WebConfigurationFileMap(); VirtualDirectoryMapping mapping = new VirtualDirectoryMapping(physicalDirectory, true); arg_62_0.VirtualDirectories.Add("/", mapping); Configuration configuration = WebConfigurationManager.OpenMappedWebConfiguration(arg_62_0, text); if (configuration != null) { RazorWebSectionGroup razorWebSectionGroup = (RazorWebSectionGroup)configuration.GetSectionGroup(RazorWebSectionGroup.GroupName); if (razorWebSectionGroup != null) { webPageRazorHost = WebRazorHostFactory.CreateHostFromConfig(razorWebSectionGroup, virtualPath, physicalPath); } } } catch (Exception) { } if (webPageRazorHost == null) { webPageRazorHost = WebRazorHostFactory.CreateDefaultHost(virtualPath, physicalPath); } return webPageRazorHost; }
/// <summary> /// Get the appropriate tool configuration for this service reference. /// /// If a reference.config file is present, the configuration object returned /// will be the merged view of: /// /// Machine Config /// ReferenceConfig /// /// If not reference.config file is present, the configuration object returned /// will be a merged view of: /// /// Machine.config /// web.config in application's physical path... /// /// </summary> /// <param name="mapFile">SvcMapFile representing the service</param> /// <returns></returns> private System.Configuration.Configuration GetToolConfig(SvcMapFile mapFile, string mapFilePath) { string toolConfigFile = null; if (mapFile != null && mapFilePath != null) { foreach (ExtensionFile extensionFile in mapFile.Extensions) { if (String.Equals(extensionFile.Name, TOOL_CONFIG_ITEM_NAME, StringComparison.Ordinal)) { toolConfigFile = extensionFile.FileName; } } } System.Web.Configuration.WebConfigurationFileMap fileMap; fileMap = new System.Web.Configuration.WebConfigurationFileMap(); System.Web.Configuration.VirtualDirectoryMapping mapping; if (toolConfigFile != null) { // // If we've got a specific tool configuration to use, we better load that... // mapping = new System.Web.Configuration.VirtualDirectoryMapping(System.IO.Path.GetDirectoryName(mapFilePath), true, toolConfigFile); } else { // // Otherwise we fall back to the default web.config file... // mapping = new System.Web.Configuration.VirtualDirectoryMapping(HostingEnvironment.ApplicationPhysicalPath, true); } fileMap.VirtualDirectories.Add("/", mapping); return System.Web.Configuration.WebConfigurationManager.OpenMappedWebConfiguration(fileMap, "/", System.Web.Hosting.HostingEnvironment.SiteName); }
public static Configuration OpenWebConfigFile(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, "/"); }
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; }
internal UserMapPath(ConfigurationFileMap fileMap, bool pathsAreLocal) { _pathsAreLocal = pathsAreLocal; if (!String.IsNullOrEmpty(fileMap.MachineConfigFilename)) { if (_pathsAreLocal) { _machineConfigFilename = Path.GetFullPath(fileMap.MachineConfigFilename); } else { _machineConfigFilename = fileMap.MachineConfigFilename; } } if (string.IsNullOrEmpty(_machineConfigFilename)) { // Defaults for machine.config and root web.config if not supplied by user _machineConfigFilename = HttpConfigurationSystem.MachineConfigurationFilePath; _rootWebConfigFilename = HttpConfigurationSystem.RootWebConfigurationFilePath; } else { _rootWebConfigFilename = Path.Combine(Path.GetDirectoryName(_machineConfigFilename), "web.config"); } _webFileMap = fileMap as WebConfigurationFileMap; if (_webFileMap != null) { // Use the site if supplied, otherwise use the default. if (!String.IsNullOrEmpty(_webFileMap.Site)) { _siteName = _webFileMap.Site; _siteID = _webFileMap.Site; } else { _siteName = WebConfigurationHost.DefaultSiteName; _siteID = WebConfigurationHost.DefaultSiteID; } if (_pathsAreLocal) { // validate mappings foreach (string virtualDirectory in _webFileMap.VirtualDirectories) { VirtualDirectoryMapping mapping = _webFileMap.VirtualDirectories[virtualDirectory]; mapping.Validate(); } } // Get the root web.config path VirtualDirectoryMapping rootWebMapping = _webFileMap.VirtualDirectories[null]; if (rootWebMapping != null) { _rootWebConfigFilename = Path.Combine(rootWebMapping.PhysicalDirectory, rootWebMapping.ConfigFileBaseName); _webFileMap.VirtualDirectories.Remove(null); } } }