private static Uri BuildAlarmUrl(ConfiguredProperties configuredProperties) { var uriBuilder = new UriBuilder { Scheme = "https", Host = configuredProperties.Host, Path = configuredProperties.Path, Port = configuredProperties.Port }; Uri uri; if (!TryUri(uriBuilder, out uri)) { IPAddress ipAddress; if (configuredProperties.Host != null && IPAddress.TryParse(configuredProperties.Host, out ipAddress)) { } else { string hostName = Dns.GetHostName(); IPAddress[] addresses = Dns.GetHostAddresses(hostName); ipAddress = addresses.First(x => x.AddressFamily == AddressFamily.InterNetwork); } uriBuilder.Host = ipAddress.ToString(); uri = uriBuilder.Uri; } return(uri); }
/// <summary> /// Control flow begins here. /// </summary> /// <param name="args">Command-line arguments. See <see cref="CommandLineInput.ShowUsage"/> /// for usage.</param>. /// <returns>0 on success, -1 on bad input, 1 on runtime error. See also <see cref="Result"/> /// enum.</returns> public static int Main(string[] args) { var input = new CommandLineInput(args); Feature?feature = input.Parse(); if (feature == null) { return(CommandLineInput.ShowUsage()); } // hijack Console.Out so it writes to a text file RedirectOutput(input.OutputFilename); // load configurable properties from a properties file ConfiguredProperties properties = ConfiguredProperties.Load(input.PropertiesFilename); // map the feature and configurable properties to a Program instance Program p = GetProgramInstance(feature.Value, properties); if (p == null) { return(Result.Invalid); } return(TryToExecute(p, DateTime.Now)); }
private static Program GetProgramInstance(Feature feature, ConfiguredProperties properties) { Type programType = typeof(Program); foreach (Type type in programType.Assembly.GetTypes()) { // if a concrete type, derived from Program if (type.IsAbstract == false && type.BaseType == programType) { // if the type's name matches a Feature value if (type.Name.Equals(feature.ToString())) { // if it can be constructed from a ConfiguredProperties instance ConstructorInfo constructor = type.GetConstructor(new[] { typeof(ConfiguredProperties) }); if (constructor != null) { // use that type object invoked = constructor.Invoke(new object[] { properties }); return((Program)invoked); } } } } Console.WriteLine("Feature '{0}' not recognized.", feature); return(null); }
public LookupDobCarriers(ConfiguredProperties properties) : base(properties) { _exampleCarrierId = properties.ExampleCarrierId; }
public LookupCarrier(ConfiguredProperties properties) : base(properties) { }
public LookupSignedCarriers(ConfiguredProperties properties) : base(properties) { }
public LookupDobEvents(ConfiguredProperties properties) : base(properties) { _exampleSinceDate = properties.DobCarrierExampleSinceDate; }
public Search(ConfiguredProperties properties) : base(properties) { }
protected Program(ConfiguredProperties properties) { _properties = properties; AlarmUrl = BuildAlarmUrl(_properties); }
public Login(ConfiguredProperties properties) : base(properties) { }
public Alarm(ConfiguredProperties properties) : base(properties) { }