public static CommandLineArguments Init(string[] args) { CommandLineDictionary d = CommandLineDictionary.FromArguments(args); if (d == null || d.ContainsKey("?") || d.ContainsKey("help")) { return(null); } CommandLineArguments a = new CommandLineArguments(); a.ParseArguments(args); if (a.Interval == null) { return(null); } if (a.Pid == null && a.ProcessName == null) { return(null); } return(a); }
public void TestCommonUsageWithCustomKeyAndValueCharacters() { string[] args = new string[] { "-verbose", "-runid:10" }; CommandLineDictionary d = CommandLineDictionary.FromArguments(args, '-', ':'); Assert.True(d.ContainsKey("verbose")); Assert.True(d.ContainsKey("runid")); Assert.Equal <int>(10, Int32.Parse(d["runid"], CultureInfo.InvariantCulture)); Assert.Equal <string>("-verbose -runid:10", d.ToString()); // bug! Assert.Equal <int>(2, d.Count); }
public void TestCommonUsage() { string[] args = new string[] { "/verbose", "/runid=10" }; CommandLineDictionary d = CommandLineDictionary.FromArguments(args); Assert.True(d.ContainsKey("verbose")); Assert.True(d.ContainsKey("runid")); Assert.Equal <int>(10, Int32.Parse(d["runid"], CultureInfo.InvariantCulture)); Assert.Equal <string>("/verbose /runid=10", d.ToString()); Assert.Equal <int>(2, d.Count); }
private static bool ValidateOptions(CommandLineDictionary cmd) { bool isValid = true; if (!(cmd.ContainsKey("url") && cmd.ContainsKey("user") && cmd.ContainsKey("password") && cmd.ContainsKey("project") && cmd.Count == 4)) { isValid = false; } return(isValid); }
public static void Main(String[] args) { CommandLineDictionary dictionary = CommandLineParser.Parse(args, new String[] { "activeProfile", "serverKey" }); if (dictionary.ContainsKey("activeProfile") && dictionary.ContainsKey("serverKey")) { throw new ArgumentException("You cannot define 'activeProfile' and 'serverKey' at the same time"); } try { new CoreApplication(ServerConfiguration.ReadServerInstances(dictionary)).Run(); } catch (Exception ex) { MessageBox.Show(ex.Message); return; } }
//- ~ReadServerInstances -// internal static List <Instance> ReadServerInstances(CommandLineDictionary dictionary) { List <Instance> instances = new List <Instance>(); DevServerConfigurationSection cs = DevServerConfigurationFacade.GetWebDevServerConfiguration(); //+ List <String> types = new List <String>(); for (int i = 0; i < cs.RequestTracing.AllowedContentTypes.Count; i++) { types.Add(cs.RequestTracing.AllowedContentTypes[i].Value); } //+ default documents List <String> documents = new List <String>(new String[] { "default.aspx", "default.htm", "default.html" }); for (int i = 0; i < cs.WebServer.DefaultDocuments.Count; i++) { if (!documents.Contains(cs.WebServer.DefaultDocuments[i].Name)) { documents.Add(cs.WebServer.DefaultDocuments[i].Name); } } //+ content type mappings Dictionary <String, String> contentTypeMappings = new Dictionary <String, String>(); contentTypeMappings.Add(".bmp", "image/bmp"); contentTypeMappings.Add(".css", "text/css"); contentTypeMappings.Add(".gif", "image/gif"); contentTypeMappings.Add(".ico", "image/x-icon"); contentTypeMappings.Add(".htm", "text/html"); contentTypeMappings.Add(".html", "text/html"); contentTypeMappings.Add(".jpe", "image/jpeg"); contentTypeMappings.Add(".jpeg", "image/jpeg"); contentTypeMappings.Add(".jpg", "image/jpeg"); contentTypeMappings.Add(".js", "text/javascript"); for (int i = 0; i < cs.WebServer.ContentTypeMappings.Count; i++) { if (!contentTypeMappings.ContainsKey(cs.WebServer.ContentTypeMappings[i].Extension)) { contentTypeMappings.Add(cs.WebServer.ContentTypeMappings[i].Extension, cs.WebServer.ContentTypeMappings[i].Type); } else if (cs.WebServer.ContentTypeMappings[i].Override) { contentTypeMappings.Remove(cs.WebServer.ContentTypeMappings[i].Extension); contentTypeMappings.Add(cs.WebServer.ContentTypeMappings[i].Extension, cs.WebServer.ContentTypeMappings[i].Type); } } //+ check command line arguments Boolean usingProfile = false; Boolean usingSpecifiedServerKey = false; String activeProfile = String.Empty; String serverKey = String.Empty; if (dictionary.ContainsKey("activeProfile")) { activeProfile = dictionary["activeProfile"]; } else if (dictionary.ContainsKey("serverKey")) { serverKey = dictionary["serverKey"]; } else if (cs.StartupProfiles.Count > 0 && !String.IsNullOrEmpty(cs.StartupProfiles.ActiveProfile) && cs.StartupProfiles.ActiveProfile.ToLower(System.Globalization.CultureInfo.CurrentCulture) != "none") { activeProfile = cs.StartupProfiles.ActiveProfile; } List <ServerElement> servers = new List <ServerElement>(); if (!String.IsNullOrEmpty(activeProfile) && activeProfile != "none") { servers = PullServersFromActiveProfile(activeProfile, cs); } //+ if (servers.Count > 0) { usingProfile = true; } else { if (!String.IsNullOrEmpty(serverKey)) { servers.Add(FindServerConfiguration(serverKey, cs.Servers)); usingSpecifiedServerKey = true; } else { for (int i = 0; i < cs.Servers.Count; i++) { servers.Add(cs.Servers[i]); } } } //+ if (servers.Count > 0) { for (int i = 0; i < servers.Count; i++) { if (!servers[i].Disabled || usingProfile || usingSpecifiedServerKey) { instances.Add(new Instance { Name = servers[i].Name, Port = servers[i].Port, VirtualPath = servers[i].VirtualPath, PhysicalPath = servers[i].PhysicalPath, BoundIPAddress = servers[i].Binding.Address, EnableIPAddressBinding = !String.IsNullOrEmpty(servers[i].Binding.Address), HostConfiguration = new HostConfiguration { AllowedContentTypes = types, EnableFaviconTracing = servers[i].RequestTracing.EnableFaviconTracing, EnableTracing = servers[i].RequestTracing.Enable, EnableVerboseTypeTracing = servers[i].RequestTracing.EnableVerboseTypeTracing, DefaultDocuments = documents, ContentTypeMappings = contentTypeMappings } }); } } } return(instances); }