Example #1
0
        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);
        }
Example #2
0
        /// <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));
        }
Example #3
0
        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);
        }
Example #4
0
 public LookupDobCarriers(ConfiguredProperties properties)
     : base(properties)
 {
     _exampleCarrierId = properties.ExampleCarrierId;
 }
Example #5
0
 public LookupCarrier(ConfiguredProperties properties) : base(properties)
 {
 }
Example #6
0
 public LookupSignedCarriers(ConfiguredProperties properties)
     : base(properties)
 {
 }
Example #7
0
 public LookupDobEvents(ConfiguredProperties properties)
     : base(properties)
 {
     _exampleSinceDate = properties.DobCarrierExampleSinceDate;
 }
Example #8
0
 public Search(ConfiguredProperties properties) : base(properties)
 {
 }
Example #9
0
 protected Program(ConfiguredProperties properties)
 {
     _properties = properties;
     AlarmUrl    = BuildAlarmUrl(_properties);
 }
Example #10
0
 public Login(ConfiguredProperties properties) : base(properties)
 {
 }
Example #11
0
 public Alarm(ConfiguredProperties properties) : base(properties)
 {
 }