internal Application(ConfigurationElement element, ApplicationCollection parent) : base(element, "application", null, parent, null, null) { Parent = parent; // IMPORTANT: avoid duplicate application tag. ForceCreateEntity(); if (string.IsNullOrWhiteSpace(Path)) { // IMPORTANT: fix path attribute after initialization. Path = "/"; } _collection = new VirtualDirectoryCollection(this); if (element == null) { return; } foreach (ConfigurationElement node in (ConfigurationElementCollection)element) { _collection.InternalAdd(new VirtualDirectory(node, _collection)); } Location = this.Site.Name + this.Path; foreach (ApplicationPool pool in Server.ApplicationPools) { if (pool.Name == ApplicationPoolName) { pool.ApplicationCount++; } } }
public bool AddBinding(string domainName) { var siteName = System.Configuration.ConfigurationManager.AppSettings["webSiteName"]; using (ServerManager serverManager = new ServerManager()) { Microsoft.Web.Administration.Configuration config = serverManager.GetApplicationHostConfiguration(); Microsoft.Web.Administration.ConfigurationSection sitesSection = config.GetSection("system.applicationHost/sites"); Microsoft.Web.Administration.ConfigurationElementCollection sitesCollection = sitesSection.GetCollection(); Microsoft.Web.Administration.ConfigurationElement siteElement = FindElement(sitesCollection, "site", "name", siteName); if (siteElement == null) { throw new InvalidOperationException("Element not found!"); } Microsoft.Web.Administration.ConfigurationElementCollection bindingsCollection = siteElement.GetCollection("bindings"); Microsoft.Web.Administration.ConfigurationElement bindingElement = bindingsCollection.CreateElement("binding"); bindingElement["protocol"] = @"http"; bindingElement["bindingInformation"] = @"*:80:" + domainName; bindingsCollection.Add(bindingElement); Microsoft.Web.Administration.ConfigurationElement bindingElement1 = bindingsCollection.CreateElement("binding"); bindingElement1["protocol"] = @"http"; bindingElement1["bindingInformation"] = @"*:80:www." + domainName; bindingsCollection.Add(bindingElement1); serverManager.CommitChanges(); } return(true); }
public static void Uninstall(UdpInstallerOptions options) { if (options.ListenerAdapterChecked) { WebAdmin.ServerManager sm = new WebAdmin.ServerManager(); WebAdmin.Configuration wasConfiguration = sm.GetApplicationHostConfiguration(); WebAdmin.ConfigurationSection section = wasConfiguration.GetSection(ListenerAdapterPath); WebAdmin.ConfigurationElementCollection listenerAdaptersCollection = section.GetCollection(); for (int i = 0; i < listenerAdaptersCollection.Count; i++) { WebAdmin.ConfigurationElement element = listenerAdaptersCollection[i]; if (string.Compare((string)element.GetAttribute("name").Value, UdpConstants.Scheme, StringComparison.OrdinalIgnoreCase) == 0) { listenerAdaptersCollection.RemoveAt(i); } } sm.CommitChanges(); wasConfiguration = null; sm = null; } if (options.ProtocolHandlerChecked) { Configuration rootWebConfig = GetRootWebConfiguration(); ProtocolsSection section = (ProtocolsSection)rootWebConfig.GetSection(ProtocolsPath); section.Protocols.Remove(UdpConstants.Scheme); rootWebConfig.Save(); } }
/// <summary> /// 添加IIS mime类型 /// </summary> /// <param name="mimeDic"></param> /// <returns></returns> private static bool AddMIMEType(Microsoft.Web.Administration.Configuration confg, Dictionary <string, string> mimeDic) { try { Microsoft.Web.Administration.ConfigurationSection section; section = confg.GetSection("system.webServer/staticContent"); //取得MimeMap所有节点(路径为:%windir%\Windows\System32\inetsrv\config\applicationHost.config) Microsoft.Web.Administration.ConfigurationElement filesElement = section.GetCollection(); Microsoft.Web.Administration.ConfigurationElementCollection filesCollection = filesElement.GetCollection(); foreach (var key in mimeDic.Keys) { Microsoft.Web.Administration.ConfigurationElement newElement = filesCollection.CreateElement(); //新建MimeMap节点 newElement.Attributes["fileExtension"].Value = key; newElement.Attributes["mimeType"].Value = mimeDic[key]; if (!filesCollection.Contains(newElement)) { filesCollection.Add(newElement); } } server.CommitChanges();//更改 return(true); } catch (Exception) { return(false); } }
public static void Install(UdpInstallerOptions options) { if (options.ListenerAdapterChecked) { WebAdmin.ServerManager sm = new WebAdmin.ServerManager(); WebAdmin.Configuration wasConfiguration = sm.GetApplicationHostConfiguration(); WebAdmin.ConfigurationSection section = wasConfiguration.GetSection(ListenerAdapterPath); WebAdmin.ConfigurationElementCollection listenerAdaptersCollection = section.GetCollection(); WebAdmin.ConfigurationElement element = listenerAdaptersCollection.CreateElement(); element.GetAttribute("name").Value = UdpConstants.Scheme; element.GetAttribute("identity").Value = WindowsIdentity.GetCurrent().User.Value; listenerAdaptersCollection.Add(element); sm.CommitChanges(); wasConfiguration = null; sm = null; } if (options.ProtocolHandlerChecked) { Configuration rootWebConfig = GetRootWebConfiguration(); ProtocolsSection section = (ProtocolsSection)rootWebConfig.GetSection(ProtocolsPath); ProtocolElement element = new ProtocolElement(UdpConstants.Scheme); element.ProcessHandlerType = typeof(UdpProcessProtocolHandler).AssemblyQualifiedName; element.AppDomainHandlerType = typeof(UdpAppDomainProtocolHandler).AssemblyQualifiedName; element.Validate = false; section.Protocols.Add(element); rootWebConfig.Save(); } }
internal ConfigurationLockCollection(ConfigurationElement element, ConfigurationLockType lockType) { _names = new ArrayList(); _element = element; _lockType = lockType; }
internal override void AddChild(ConfigurationElement child) { if (Schema?.CollectionSchema == null) { base.AddChild(child); } else if (Schema.CollectionSchema.ContainsAddElement(child.ElementTagName)) { Root.AddChild(child); } else if (child.ElementTagName == Schema.CollectionSchema.ClearElementName) { // TODO: test this Root.AddChild(child); } else if (child.ElementTagName == Schema.CollectionSchema.RemoveElementName) { // TODO: test this Root.AddChild(child); } else { base.AddChild(child); } }
/// <summary> /// Constructs instances when the external queries. /// </summary> /// <param name="name"></param> /// <param name="schema"></param> /// <param name="element"></param> internal ConfigurationAttribute(string name, ConfigurationAttributeSchema schema, ConfigurationElement element) { _element = element; Name = name; Schema = schema; IsProtected = schema?.IsEncrypted ?? false; var clear = this.Decrypt(this.ExtractDefaultValue()); IsInheritedFromDefaultValue = true; SetValue(clear); }
internal override void AddChild(ConfigurationElement child) { var application = child as VirtualDirectory; if (application != null) { _collection.Add(application); } else { base.AddChild(child); } }
/// <summary> /// Constructs instances from config file. /// </summary> /// <param name="name"></param> /// <param name="schema"></param> /// <param name="value"></param> /// <param name="element"></param> internal ConfigurationAttribute(string name, ConfigurationAttributeSchema schema, string value, ConfigurationElement element) { _element = element; Name = name; Schema = schema; IsProtected = schema?.IsEncrypted ?? false; var clear = Decrypt(value).ToString(); var raw = Schema == null ? clear : Schema.Parse(clear); var result = TypeMatch(raw); IsInheritedFromDefaultValue = (Schema == null || !Schema.IsRequired) && result.Equals(ExtractDefaultValue()); SetValue(raw); _element.InnerEntity.SetAttributeValue(Name, value); }
internal Site(ConfigurationElement element, SiteCollection parent) : base(element, "site", null, parent, null, null) { ApplicationDefaults = ChildElements["applicationDefaults"] == null ? new ApplicationDefaults(parent.ChildElements["applicationDefaults"], this) : new ApplicationDefaults(ChildElements["applicationDefaults"], this); Parent = parent; if (element == null) { return; } foreach (ConfigurationElement node in (ConfigurationElementCollection)element) { var app = new Application(node, Applications); Applications.InternalAdd(app); } }
private static void EnsureDefaultDocument(ServerManager iis) { IIS.Configuration applicationHostConfiguration = iis.GetApplicationHostConfiguration(); IIS.ConfigurationSection defaultDocumentSection = applicationHostConfiguration.GetSection("system.webServer/defaultDocument"); IIS.ConfigurationElementCollection filesCollection = defaultDocumentSection.GetCollection("files"); if (filesCollection.Any(ConfigurationElementContainsHostingStart)) { return; } IIS.ConfigurationElement addElement = filesCollection.CreateElement("add"); addElement["value"] = HostingStartHtml; filesCollection.Add(addElement); iis.CommitChanges(); }
private static void ConfigureCertificateRules(ConfigurationElement element) { var rulesCollection = element.GetCollection("rules"); var issuerRule = rulesCollection.CreateElement("add"); issuerRule["certificateField"] = @"Issuer"; issuerRule["certificateSubField"] = @"CN"; issuerRule["matchCriteria"] = @"CARoot"; issuerRule["compareCaseSensitive"] = true; var subjectRule = rulesCollection.CreateElement("add"); subjectRule["certificateField"] = @"Subject"; subjectRule["certificateSubField"] = @"CN"; subjectRule["matchCriteria"] = @"ClientCert"; subjectRule["compareCaseSensitive"] = true; rulesCollection.Add(issuerRule); rulesCollection.Add(subjectRule); }
public bool DeleteBinding(string domainName) { var siteName = System.Configuration.ConfigurationManager.AppSettings["webSiteName"]; using (ServerManager serverManager = new ServerManager()) { Microsoft.Web.Administration.Configuration config = serverManager.GetApplicationHostConfiguration(); Microsoft.Web.Administration.ConfigurationSection sitesSection = config.GetSection("system.applicationHost/sites"); Microsoft.Web.Administration.ConfigurationElementCollection sitesCollection = sitesSection.GetCollection(); Microsoft.Web.Administration.ConfigurationElement siteElement = FindElement(sitesCollection, "site", "name", siteName); if (siteElement == null) { throw new InvalidOperationException("Element not found!"); } Microsoft.Web.Administration.ConfigurationElementCollection bindingsCollection = siteElement.GetCollection("bindings"); var binding = FindElement(bindingsCollection, "binding", "bindingInformation", "*:80:" + domainName); if (binding == null) { throw new InvalidOperationException("Binding not found!"); } bindingsCollection.Remove(binding); var binding1 = FindElement(bindingsCollection, "binding", "bindingInformation", "*:80:www." + domainName); if (binding1 == null) { throw new InvalidOperationException("Binding not found!"); } bindingsCollection.Remove(binding1); serverManager.CommitChanges(); } return(true); }
internal ApplicationPool(ConfigurationElement element, ApplicationPoolCollection parent) : base(element, "add", null, parent, null, null) { Parent = parent; }
internal virtual void AddChild(ConfigurationElement child) { ChildElements.Add(child); }
internal Schedule(ConfigurationElement parent) : this(null, parent) { }
internal Schedule(ConfigurationElement element, ConfigurationElement parent) : base(element, "add", null, parent, null, null) { }
private void FillConfigurationElementWithData(ConfigurationElement item2Fill, HttpHeader header) { // item2Fill.SetAttributeValue(NameAttribute, header.Key); item2Fill.SetAttributeValue(ValueAttribute, header.Value); }
private bool GetSwitchBoardValue(ConfigurationElement switchboardElement) { return (0 == String.Compare((string)switchboardElement.GetAttributeValue("value"), "Enabled", StringComparison.OrdinalIgnoreCase)); }
public override void Install(IDictionary stateSaver) { base.Install(stateSaver); string targetDir = Context.Parameters[Argument.TargetDir].TrimEnd('\\'); string configFile = Path.Combine(targetDir, Assembly.GetExecutingAssembly().Location + ".config"); System.Configuration.ConfigurationFileMap fileMap = new ConfigurationFileMap(configFile); System.Configuration.Configuration config = System.Configuration.ConfigurationManager.OpenMappedMachineConfiguration(fileMap); AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(delegate(object sender, ResolveEventArgs args) { return(Assembly.LoadFile(Path.Combine(targetDir, args.Name + ".dll"))); }); UhuruSection section = (UhuruSection)config.GetSection("uhuru"); if (!string.IsNullOrEmpty(Context.Parameters[Argument.Capacity])) { section.Service.Capacity = int.Parse(Context.Parameters[Argument.Capacity], CultureInfo.InvariantCulture); } if (!string.IsNullOrEmpty(Context.Parameters[Argument.BaseDir])) { section.Service.BaseDir = Context.Parameters[Argument.BaseDir]; if (!Directory.Exists(section.Service.BaseDir)) { Directory.CreateDirectory(section.Service.BaseDir); } } if (!string.IsNullOrEmpty(Context.Parameters[Argument.Index])) { section.Service.Index = int.Parse(Context.Parameters[Argument.Index], CultureInfo.InvariantCulture); } if (!string.IsNullOrEmpty(Context.Parameters[Argument.StatusPort])) { int port = Convert.ToInt32(Context.Parameters[Argument.StatusPort], CultureInfo.InvariantCulture); section.Service.StatusPort = port; if (port != 0) { FirewallTools.OpenPort(port, "FileService Status"); } } if (!string.IsNullOrEmpty(Context.Parameters[Argument.LocalDb])) { section.Service.LocalDB = Context.Parameters[Argument.LocalDb]; } if (!string.IsNullOrEmpty(Context.Parameters[Argument.LocalRoute])) { section.Service.LocalRoute = Context.Parameters[Argument.LocalRoute]; } else { string ip = string.Empty; foreach (IPAddress address in Dns.GetHostEntry(Dns.GetHostName()).AddressList) { if (address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) { ip = address.ToString(); break; } } section.Service.LocalRoute = ip; } if (!string.IsNullOrEmpty(Context.Parameters[Argument.Mbus])) { section.Service.MBus = Context.Parameters[Argument.Mbus]; } if (!string.IsNullOrEmpty(Context.Parameters[Argument.MigrationNfs])) { section.Service.MigrationNFS = Context.Parameters[Argument.MigrationNfs]; } if (!string.IsNullOrEmpty(Context.Parameters[Argument.NodeId])) { section.Service.NodeId = Context.Parameters[Argument.NodeId]; } if (!string.IsNullOrEmpty(Context.Parameters[Argument.ZInterval])) { section.Service.ZInterval = int.Parse(Context.Parameters[Argument.ZInterval], CultureInfo.InvariantCulture); } if (!string.IsNullOrEmpty(Context.Parameters[Argument.Plan])) { section.Service.Plan = Context.Parameters[Argument.Plan]; } if (!string.IsNullOrEmpty(Context.Parameters[Argument.UseVhd])) { section.Service.Uhurufs.UseVHD = bool.Parse(Context.Parameters[Argument.UseVhd]); } if (!string.IsNullOrEmpty(Context.Parameters[Argument.MaxStorageSize])) { section.Service.Uhurufs.MaxStorageSize = long.Parse(Context.Parameters[Argument.MaxStorageSize], CultureInfo.InvariantCulture); } if (!string.IsNullOrEmpty(Context.Parameters[Argument.VhdFixedSize])) { section.Service.Uhurufs.VHDFixedSize = bool.Parse(Context.Parameters[Argument.VhdFixedSize]); } section.DEA = null; config.Save(); int lowPort = 5000; int highPort = 6000; using (ServerManager serverManager = new ServerManager()) { Microsoft.Web.Administration.Configuration iisConfig = serverManager.GetApplicationHostConfiguration(); Microsoft.Web.Administration.ConfigurationSection firewallSupportSection = iisConfig.GetSection("system.ftpServer/firewallSupport"); firewallSupportSection["lowDataChannelPort"] = lowPort; firewallSupportSection["highDataChannelPort"] = highPort; Microsoft.Web.Administration.ConfigurationSection sitesSection = iisConfig.GetSection("system.applicationHost/sites"); Microsoft.Web.Administration.ConfigurationElement siteDefaultsElement = sitesSection.GetChildElement("siteDefaults"); Microsoft.Web.Administration.ConfigurationElement ftpServerElement = siteDefaultsElement.GetChildElement("ftpServer"); Microsoft.Web.Administration.ConfigurationElement firewallSupportElement = ftpServerElement.GetChildElement("firewallSupport"); firewallSupportElement["externalIp4Address"] = @"0.0.0.0"; serverManager.CommitChanges(); } FirewallTools.OpenPortRange(lowPort, highPort, "UhuruFS Ports"); }
internal VirtualDirectory(ConfigurationElement element, VirtualDirectoryCollection parent) : base(element, "virtualDirectory", null, parent, null, null) { Parent = parent; }
internal static IDictionary<string, List<string>> GetProtocolBindingTable(ConfigurationElement site) { IDictionary<string, List<string>> bindingList = new Dictionary<string, List<string>>(); foreach (ConfigurationElement binding in site.GetCollection(MetabaseSettingsIis7Constants.BindingsElementName)) { string protocol = ((string)binding[MetabaseSettingsIis7Constants.ProtocolAttributeName]).ToLowerInvariant(); string bindingInformation = (string)binding[MetabaseSettingsIis7Constants.BindingInfoAttributeName]; if (!bindingList.ContainsKey(protocol)) { bindingList.Add(protocol, new List<string>()); } bindingList[protocol].Add(bindingInformation); } return bindingList; }
public void RunDeploy(String[] args) { if (args.Length < 3) { Console.Error.WriteLine("rdfWebDeploy: Error: 3 Arguments are required in order to use the -deploy mode, type rdfWebDeploy -help to see usage summary"); return; } if (args.Length > 3) { if (!this.SetOptions(args.Skip(3).ToArray())) { Console.Error.WriteLine("rdfWebDeploy: Deployment aborted since one/more options were not valid"); return; } } if (this._noLocalIIS) { Console.WriteLine("rdfWebDeploy: No Local IIS Server available so switching to -xmldeploy mode"); XmlDeploy xdeploy = new XmlDeploy(); xdeploy.RunXmlDeploy(args); return; } //Define the Server Manager object Admin.ServerManager manager = null; try { //Connect to the Server Manager if (!this._noIntegratedRegistration) { manager = new Admin.ServerManager(); } //Open the Configuration File System.Configuration.Configuration config = WebConfigurationManager.OpenWebConfiguration(args[1], this._site); Console.Out.WriteLine("rdfWebDeploy: Opened the Web.config file for the specified Web Application"); //Detect Folders String appFolder = Path.GetDirectoryName(config.FilePath); String binFolder = Path.Combine(appFolder, "bin\\"); String appDataFolder = Path.Combine(appFolder, "App_Data\\"); if (!Directory.Exists(binFolder)) { Directory.CreateDirectory(binFolder); Console.WriteLine("rdfWebDeploy: Created a bin\\ directory for the web application"); } if (!Directory.Exists(appDataFolder)) { Directory.CreateDirectory(appDataFolder); Console.WriteLine("rdfWebDeploy: Created an App_Data\\ directory for the web application"); } //Deploy dotNetRDF and required DLLs to the bin directory of the application String sourceFolder = RdfWebDeployHelper.ExecutablePath; IEnumerable <String> dlls = RdfWebDeployHelper.RequiredDLLs; if (this._sql) { dlls = dlls.Concat(RdfWebDeployHelper.RequiredSqlDLLs); } if (this._virtuoso) { dlls = dlls.Concat(RdfWebDeployHelper.RequiredVirtuosoDLLs); } if (this._fulltext) { dlls = dlls.Concat(RdfWebDeployHelper.RequiredFullTextDLLs); } foreach (String dll in dlls) { if (File.Exists(Path.Combine(sourceFolder, dll))) { File.Copy(Path.Combine(sourceFolder, dll), Path.Combine(binFolder, dll), true); Console.WriteLine("rdfWebDeploy: Deployed " + dll + " to the web applications bin directory"); } else { Console.Error.WriteLine("rdfWebDeploy: Error: Required DLL " + dll + " which needs deploying to the web applications bin directory could not be found"); return; } } //Deploy the configuration file to the App_Data directory if (File.Exists(args[2])) { File.Copy(args[2], Path.Combine(appDataFolder, args[2]), true); Console.WriteLine("rdfWebDeploy: Deployed the configuration file to the web applications App_Data directory"); } else if (!File.Exists(Path.Combine(appDataFolder, args[2]))) { Console.Error.WriteLine("rdfWebDeploy: Error: Unable to continue deployment as the configuration file " + args[2] + " could not be found either locally for deployment to the App_Data folder or already present in the App_Data folder"); return; } //Set the AppSetting for the configuration file config.AppSettings.Settings.Remove("dotNetRDFConfig"); config.AppSettings.Settings.Add("dotNetRDFConfig", "~/App_Data/" + Path.GetFileName(args[2])); Console.WriteLine("rdfWebDeploy: Set the \"dotNetRDFConfig\" appSetting to \"~/App_Data/" + Path.GetFileName(args[2]) + "\""); //Now load the Configuration Graph from the App_Data folder Graph g = new Graph(); FileLoader.Load(g, Path.Combine(appDataFolder, args[2])); Console.WriteLine("rdfWebDeploy: Successfully deployed required DLLs and appSettings"); Console.WriteLine(); //Get the sections of the Configuration File we want to edit HttpHandlersSection handlersSection = config.GetSection("system.web/httpHandlers") as HttpHandlersSection; if (handlersSection == null) { Console.Error.WriteLine("rdfWebDeploy: Error: Unable to access the Handlers section of the web applications Web.Config file"); return; } //Detect Handlers from the Configution Graph and deploy IUriNode rdfType = g.CreateUriNode(new Uri(RdfSpecsHelper.RdfType)); IUriNode dnrType = g.CreateUriNode(new Uri(ConfigurationLoader.PropertyType)); IUriNode httpHandler = g.CreateUriNode(new Uri(ConfigurationLoader.ClassHttpHandler)); //Deploy for IIS Classic Mode if (!this._noClassicRegistration) { Console.WriteLine("rdfWebDeploy: Attempting deployment for IIS Classic Mode"); foreach (INode n in g.GetTriplesWithPredicateObject(rdfType, httpHandler).Select(t => t.Subject)) { if (n.NodeType == NodeType.Uri) { String handlerPath = ((IUriNode)n).Uri.AbsolutePath; INode type = g.GetTriplesWithSubjectPredicate(n, dnrType).Select(t => t.Object).FirstOrDefault(); if (type == null) { Console.Error.WriteLine("rdfWebDeploy: Error: Cannot deploy the Handler <" + n.ToString() + "> as there is no dnr:type property specified"); continue; } if (type.NodeType == NodeType.Literal) { String handlerType = ((ILiteralNode)type).Value; //First remove any existing registration handlersSection.Handlers.Remove("*", handlerPath); //Then add the new registration handlersSection.Handlers.Add(new HttpHandlerAction(handlerPath, handlerType, "*")); Console.WriteLine("rdfWebDeploy: Deployed the Handler <" + n.ToString() + "> to the web applications Web.Config file"); } else { Console.Error.WriteLine("rdfWebDeploy: Error: Cannot deploy the Handler <" + n.ToString() + "> as the value given for the dnr:type property is not a Literal"); continue; } } else { Console.Error.WriteLine("rdfWebDeploy: Error: Cannot deploy a Handler which is not specified as a URI Node"); } } //Deploy Negotiate by File Extension if appropriate if (this._negotiate) { HttpModulesSection modulesSection = config.GetSection("system.web/httpModules") as HttpModulesSection; if (modulesSection == null) { Console.Error.WriteLine("rdfWebDeploy: Error: Unable to access the Modules section of the web applications Web.Config file"); return; } modulesSection.Modules.Remove("NegotiateByExtension"); modulesSection.Modules.Add(new HttpModuleAction("NegotiateByExtension", "VDS.RDF.Web.NegotiateByFileExtension")); Console.WriteLine("rdfWebDeploy: Deployed the Negotiate by File Extension Module"); } Console.WriteLine("rdfWebDeploy: Successfully deployed for IIS Classic Mode"); } //Save the completed Configuration File config.Save(ConfigurationSaveMode.Minimal); Console.WriteLine(); //Deploy for IIS Integrated Mode if (!this._noIntegratedRegistration) { Console.WriteLine("rdfWebDeploy: Attempting deployment for IIS Integrated Mode"); Admin.Configuration adminConfig = manager.GetWebConfiguration(this._site, args[1]); Admin.ConfigurationSection newHandlersSection = adminConfig.GetSection("system.webServer/handlers"); Admin.ConfigurationElementCollection newHandlers = newHandlersSection.GetCollection(); foreach (INode n in g.GetTriplesWithPredicateObject(rdfType, httpHandler).Select(t => t.Subject)) { if (n.NodeType == NodeType.Uri) { String handlerPath = ((IUriNode)n).Uri.AbsolutePath; INode type = g.GetTriplesWithSubjectPredicate(n, dnrType).Select(t => t.Object).FirstOrDefault(); if (type == null) { Console.Error.WriteLine("rdfWebDeploy: Error: Cannot deploy the Handler <" + n.ToString() + "> as there is no dnr:type property specified"); continue; } if (type.NodeType == NodeType.Literal) { String handlerType = ((ILiteralNode)type).Value; //First remove any existing registration foreach (Admin.ConfigurationElement oldReg in newHandlers.Where(el => el.GetAttributeValue("name").Equals(handlerPath)).ToList()) { newHandlers.Remove(oldReg); } //Then add the new registration Admin.ConfigurationElement reg = newHandlers.CreateElement("add"); reg["name"] = handlerPath; reg["path"] = handlerPath; reg["verb"] = "*"; reg["type"] = handlerType; newHandlers.AddAt(0, reg); Console.WriteLine("rdfWebDeploy: Deployed the Handler <" + n.ToString() + "> to the web applications Web.Config file"); } else { Console.Error.WriteLine("rdfWebDeploy: Error: Cannot deploy the Handler <" + n.ToString() + "> as the value given for the dnr:type property is not a Literal"); continue; } } else { Console.Error.WriteLine("rdfWebDeploy: Error: Cannot deploy a Handler which is not specified as a URI Node"); } //Deploy Negotiate by File Extension if appropriate if (this._negotiate) { Admin.ConfigurationSection newModulesSection = adminConfig.GetSection("system.webServer/modules"); if (newModulesSection == null) { Console.Error.WriteLine("rdfWebDeploy: Error: Unable to access the Modules section of the web applications Web.Config file"); return; } //First remove the Old Module Admin.ConfigurationElementCollection newModules = newModulesSection.GetCollection(); foreach (Admin.ConfigurationElement oldReg in newModules.Where(el => el.GetAttribute("name").Equals("NegotiateByExtension")).ToList()) { newModules.Remove(oldReg); } //Then add the new Module Admin.ConfigurationElement reg = newModules.CreateElement("add"); reg["name"] = "NegotiateByExtension"; reg["type"] = "VDS.RDF.Web.NegotiateByFileExtension"; newModules.AddAt(0, reg); Console.WriteLine("rdfWebDeploy: Deployed the Negotiate by File Extension Module"); } } manager.CommitChanges(); Console.WriteLine("rdfWebDeploy: Successfully deployed for IIS Integrated Mode"); } } catch (ConfigurationException configEx) { Console.Error.WriteLine("rdfWebDeploy: Configuration Error: " + configEx.Message); } catch (Exception ex) { Console.Error.WriteLine("rdfWebDeploy: Error: " + ex.Message); Console.Error.WriteLine(ex.StackTrace); } finally { if (manager != null) { manager.Dispose(); } } }
private static bool ConfigurationElementContainsHostingStart(ConfigurationElement configurationElement) { object valueAttribute = configurationElement["value"]; return valueAttribute != null && String.Equals(HostingStartHtml, valueAttribute.ToString(), StringComparison.OrdinalIgnoreCase); }
private void ConvertHeliconZooEngineToElement(HeliconZooEngine item, ConfigurationElement engine) { engine.SetAttributeValue("name", item.name); engine.SetAttributeValue("displayName", item.displayName); engine.SetAttributeValue("arguments", item.arguments); engine.SetAttributeValue("fullPath", item.fullPath); engine.SetAttributeValue("arguments", item.arguments); engine.SetAttributeValue("transport", item.transport); engine.SetAttributeValue("protocol", item.protocol); engine.SetAttributeValue("host", item.host); engine.SetAttributeValue("portLower", item.portLower); engine.SetAttributeValue("portUpper", item.portUpper); engine.SetAttributeValue("maxInstances", item.maxInstances); engine.SetAttributeValue("minInstances", item.minInstances); engine.SetAttributeValue("timeLimit", item.timeLimit); engine.SetAttributeValue("gracefulShutdownTimeout", item.gracefulShutdownTimeout); engine.SetAttributeValue("memoryLimit", item.memoryLimit); ConfigurationElementCollection envColl = engine.GetChildElement("environmentVariables").GetCollection(); foreach(HeliconZooEnv env in item.environmentVariables) { ConfigurationElement envElement = envColl.CreateElement(); envElement.SetAttributeValue("name", env.Name); envElement.SetAttributeValue("value", env.Value); envColl.Add(envElement); } }
private HttpHeader GetCustomHttpHeader(ConfigurationElement element) { if (element == null) return null; // return new HttpHeader { Key = Convert.ToString(element.GetAttributeValue(NameAttribute)), Value = Convert.ToString(element.GetAttributeValue(ValueAttribute)) }; }
private HeliconZooEnv ConvertElementToHeliconZooEnv(ConfigurationElement item) { HeliconZooEnv result = new HeliconZooEnv(); result.Name = (string)item.GetAttributeValue("name"); result.Value = (string)item.GetAttributeValue("value"); return result; }
internal ConfigurationElement(ConfigurationElement element, string name, ConfigurationElementSchema schema, ConfigurationElement parent, XElement entity, FileContext core, string fileName = null, bool isSection = false, string location = null) { Methods = new ConfigurationMethodCollection(); FileContext = parent?.FileContext ?? element?.FileContext ?? core; if (isSection) { Section = (ConfigurationSection)this; Section.Location = location; } else { Section = parent?.Section; } InnerEntity = entity ?? element?.InnerEntity; _overriddenFileName = fileName; if (element == null) { ElementTagName = name ?? throw new ArgumentException("empty name"); _attributes = new ConfigurationAttributeCollection(this); ChildElements = new ConfigurationChildElementCollection(this); Collections = new List <ConfigurationElementCollection>(); _rawAttributes = new Dictionary <string, string>(); ParentElement = parent; if (parent == null) { Schema = schema ?? throw new ArgumentException(); IsLocallyStored = true; } else { IsLocallyStored = !parent.Section.IsLocked; var collection = parent.Schema.CollectionSchema; if (collection == null) { Schema = parent.Schema.ChildElementSchemas[name]; } else { Schema = parent.Schema.CollectionSchema.GetElementSchema(name) ?? parent.Schema.ChildElementSchemas[name]; } if (Schema == null) { throw new ArgumentException("empty schema"); } } ParseAttributes(_overriddenFileName ?? FileContext.FileName); } else { IsLocallyStored = element.IsLocallyStored; ElementTagName = element.ElementTagName; _attributes = element.Attributes; ChildElements = element.ChildElements; Collections = element.Collections; _rawAttributes = element.RawAttributes; Schema = element.Schema; ParentElement = parent ?? element.ParentElement; if (schema != null) { // TODO: here we ignore second schema //throw new ArgumentException(); } } }
private bool FillConfigurationElementWithData(ConfigurationElement item2Fill, HttpError error, WebVirtualDirectory virtualDir) { // code Int64 statusCode = 0; if (!Int64.TryParse(error.ErrorCode, out statusCode) || statusCode < 400 || statusCode > 999) return false; // sub-code Int32 subStatusCode = -1; if (!Int32.TryParse(error.ErrorSubcode, out subStatusCode)) return false; // if (subStatusCode == 0) subStatusCode = -1; // correct error content string errorContent = error.ErrorContent; if (error.HandlerType.Equals("File")) { if(error.ErrorContent.Length > virtualDir.ContentPath.Length) errorContent = errorContent.Substring(virtualDir.ContentPath.Length); errorContent = FileUtils.CorrectRelativePath(errorContent); } item2Fill.SetAttributeValue(StatusCodeAttribute, statusCode); item2Fill.SetAttributeValue(SubStatusCodeAttribute, subStatusCode); item2Fill.SetAttributeValue(PathAttribute, errorContent); // item2Fill.SetAttributeValue(ResponseModeAttribute, error.HandlerType); // We are succeeded return true; }
internal ApplicationPoolDefaults(ConfigurationElement element, ConfigurationElement parent) : base(element, "applicationPoolDefaults", null, parent, null, null) { }
internal void SetSiteDefaults(ConfigurationElement defaults) { _defaults = defaults; }
internal SiteLogFile(ConfigurationElement element, ConfigurationElement parent) : base(element, "logFile", null, parent, null, null) { var server = (parent as Site)?.Server; _logFile = server?.SiteDefaults.LogFile; }
private static bool ConfigurationElementContainsHostingStart(IIS.ConfigurationElement configurationElement) { object valueAttribute = configurationElement["value"]; return(valueAttribute != null && String.Equals(HostingStartHtml, valueAttribute.ToString(), StringComparison.OrdinalIgnoreCase)); }
internal ConfigurationElement(ConfigurationElement element, string name, ConfigurationElementSchema schema, ConfigurationElement parent, XElement entity, FileContext core) { Methods = new ConfigurationMethodCollection(); this.FileContext = parent?.FileContext ?? element?.FileContext ?? core; Section = parent?.Section; this.InnerEntity = entity ?? element?.InnerEntity; if (element == null) { if (name == null) { throw new ArgumentException("empty name"); } ElementTagName = name; Attributes = new ConfigurationAttributeCollection(this); ChildElements = new ConfigurationChildElementCollection(this); Collections = new List<ConfigurationElementCollection>(); RawAttributes = new Dictionary<string, string>(); ParentElement = parent; if (parent == null) { if (schema == null) { throw new ArgumentException(); } Schema = schema; IsLocallyStored = true; } else { IsLocallyStored = !parent.Section.IsLocked; var collection = parent.Schema.CollectionSchema; if (collection == null) { Schema = parent.Schema.ChildElementSchemas[name]; } else { Schema = parent.Schema.CollectionSchema.GetElementSchema(name) ?? parent.Schema.ChildElementSchemas[name]; } if (Schema == null) { throw new ArgumentException("empty schema"); } } ParseAttributes(); } else { IsLocallyStored = element.IsLocallyStored; ElementTagName = element.ElementTagName; Attributes = element.Attributes; ChildElements = element.ChildElements; Collections = element.Collections; RawAttributes = element.RawAttributes; Schema = element.Schema; ParentElement = parent ?? element.ParentElement; if (schema != null) { // TODO: here we ignore second schema //throw new ArgumentException(); } } }
private void SetSwitchBoardValue(ConfigurationElement switchboardElement, bool enabled) { switchboardElement.SetAttributeValue("value", enabled ? "Enabled" : "Disabled"); }
private static ConfigurationElement CreateInboundGwRemoteUserRule(ConfigModel model, ConfigurationElement ruleElement) { ruleElement["name"] = model.RuleName; ruleElement["patternSyntax"] = "ECMAScript"; ruleElement["stopProcessing"] = true; var matchElement = ruleElement.GetChildElement("match"); matchElement["url"] = "(.*)"; var conditionsElement = ruleElement.GetChildElement("conditions"); var conditionsCollection = conditionsElement.GetCollection(); //Get the origin requested : var inputElement = conditionsCollection.CreateElement("add"); inputElement["input"] = "{" + ServerVariable.SERVER_VARIABLE_HTTP_HOST + "}"; inputElement["pattern"] = model.Pattern; conditionsCollection.Add(inputElement); string arrServer = Environment.ExpandEnvironmentVariables(@"%APPSETTING_WEBSITE_SITE_NAME%"); // set the server variable var variablesCollection = ruleElement.GetChildElement("serverVariables").GetCollection(); AddServerVariable(variablesCollection, ServerVariable.SERVER_VARIABLE_HTTP_X_UNPROXIED_URL, arrServer + "{R:1}"); AddServerVariable(variablesCollection, ServerVariable.SERVER_VARIABLE_HTTP_X_ORIGINAL_ACCEPT_ENCODING, "{" + ServerVariable.SERVER_VARIABLE_ACCEPT_ENCODING + "}"); AddServerVariable(variablesCollection, ServerVariable.SERVER_VARIABLE_HTTP_X_ORIGINAL_HOST, "{" + ServerVariable.SERVER_VARIABLE_HTTP_HOST + "}"); AddServerVariable(variablesCollection, ServerVariable.SERVER_VARIABLE_ACCEPT_ENCODING, ""); AddServerVariable(variablesCollection, ServerVariable.SERVER_VARIABLE_HTTP_REFERER, model.UrlRewrite + "/{R:1}"); var actionElement = ruleElement.GetChildElement("action"); actionElement["type"] = "Rewrite"; actionElement["url"] = model.UrlRewrite+"/{R:1}"; return ruleElement; }
private HeliconZooEngine ConvertElementToHeliconZooEngine(ConfigurationElement item) { HeliconZooEngine result = new HeliconZooEngine(); result.name = (string)item.GetAttributeValue("name"); result.displayName = (string)item.GetAttributeValue("displayName"); result.arguments = (string)item.GetAttributeValue("arguments"); result.fullPath = (string)item.GetAttributeValue("fullPath"); result.arguments = (string)item.GetAttributeValue("arguments"); result.transport = (string)item.GetAttributeValue("transport"); result.protocol = (string)item.GetAttributeValue("protocol"); result.host = (string)item.GetAttributeValue("host"); result.portLower = (long) item.GetAttributeValue("portLower"); result.portUpper = (long) item.GetAttributeValue("portUpper"); result.maxInstances = (long) item.GetAttributeValue("maxInstances"); result.minInstances = (long) item.GetAttributeValue("minInstances"); result.timeLimit = (long) item.GetAttributeValue("timeLimit"); result.gracefulShutdownTimeout = (long) item.GetAttributeValue("gracefulShutdownTimeout"); result.memoryLimit = (long) item.GetAttributeValue("memoryLimit"); List<HeliconZooEnv> envList = new List<HeliconZooEnv>(); ConfigurationElementCollection envColl = item.GetChildElement("environmentVariables").GetCollection(); foreach (ConfigurationElement el in envColl) { envList.Add(ConvertElementToHeliconZooEnv(el)); } result.environmentVariables = envList.ToArray(); // TODO: fix this result.isUserEngine = false; // TODO: disabled return result; }
private MimeMap GetMimeMap(ConfigurationElement element) { // skip inherited mime mappings if (element == null || !element.IsLocallyStored) return null; // return new MimeMap { Extension = Convert.ToString(element.GetAttributeValue(FileExtensionAttribute)), MimeType = Convert.ToString(element.GetAttributeValue(MimeTypeAttribute)) }; }
private HttpError GetHttpError(ConfigurationElement element, WebVirtualDirectory virtualDir) { if (element == null || virtualDir == null) return null; // skip inherited http errors if (!element.IsLocallyStored) return null; // var error = new HttpError { ErrorCode = Convert.ToString(element.GetAttributeValue(StatusCodeAttribute)), ErrorSubcode = Convert.ToString(element.GetAttributeValue(SubStatusCodeAttribute)), ErrorContent = Convert.ToString(element.GetAttributeValue(PathAttribute)), HandlerType = Enum.GetName(typeof(HttpErrorResponseMode), element.GetAttributeValue(ResponseModeAttribute)) }; // Make error path relative to the virtual directory's root folder if (error.HandlerType.Equals("File") // 0 is supposed to be File && error.ErrorContent.Length > virtualDir.ContentPath.Length) { error.ErrorContent = error.ErrorContent.Substring(virtualDir.ContentPath.Length); } // return error; }
private void FillConfigurationElementWithData(ConfigurationElement item2Fill, MimeMap mapping) { if (mapping == null || item2Fill == null || String.IsNullOrEmpty(mapping.MimeType) || String.IsNullOrEmpty(mapping.Extension)) { return; } // item2Fill.SetAttributeValue(MimeTypeAttribute, mapping.MimeType); item2Fill.SetAttributeValue(FileExtensionAttribute, mapping.Extension); }
public Counters(ConfigurationElement serverConfig) { _serverConfig = serverConfig; }
internal SiteLogFile(ConfigurationElement parent) : this(null, parent) { }