Example #1
0
        private static void Main(string[] args)
        {
            options = new ZmanimOptions();

            p = new OptionSet
                    {
                        {"d|date=", "Set date. <mm/dd/yyyy>", x => options.Date = DateTime.ParseExact(x, "MM/dd/yyyy", CultureInfo.InvariantCulture)},
                        {"lat|latitude=", "Set location's latitude", (double x) => options.Latitude = x},
                        {"lon|longitude=", "Set location's longitude", (double x) => options.Longitude = x},
                        {"e|elevation=", "Set location's elevation; Positive only", (double x) => options.Elevation = x},
                        {"tz|timezone=", "Set location's TimeZone", x => options.TimeZone = x},
                        {"tf|timeformat=", "Set the way the application formats a DateTime object.", x => options.DateTimeFormat = x},
                        {"h|?|help", "Shows this help message", v => ShowHelp()}
                    };

            List<string> extraArgs;
            try
            {
                extraArgs = p.Parse(args);
            }
            catch (OptionException)
            {
                ShowHelp();
                return;
            }

            var timeZone = new OlsonTimeZone(options.TimeZone);
            var location =
                new GeoLocation(string.Empty, options.Latitude, options.Longitude, options.Elevation, timeZone);
            var czc = new ComplexZmanimCalendar(new DateTime(options.Date.Year, options.Date.Month, options.Date.Day), location);

            var methods = GetDateTimeAndLongMethods();

            foreach (var first in
                extraArgs.Select(extraArg =>
                                 methods.Where(
                                     f => f.Name.Remove(0, 3).ToLowerInvariant() == extraArg.ToLowerInvariant()).First())
                )
            {
                object invoke = first.Invoke(czc, null);

                if (extraArgs.Count > 1)
                    Console.Write(first.Name.Remove(0, 3) + ": ");

                if (invoke.GetType() == typeof(DateTime))
                {
                    var time = (DateTime)invoke;
                    Console.Write(time.ToString(options.DateTimeFormat));
                }
                else if (invoke.GetType() == typeof(long))
                {
                    Console.WriteLine((long)invoke);
                }

                if (extraArgs.Count > 1)
                    Console.WriteLine();
            }
            //Console.Read();
        }
Example #2
0
        private static void Main(string[] args)
        {
            options = new ZmanimOptions();

            p = new OptionSet
            {
                { "d|date=", "Set date. <mm/dd/yyyy>", x => options.Date = DateTime.ParseExact(x, "MM/dd/yyyy", CultureInfo.InvariantCulture) },
                { "lat|latitude=", "Set location's latitude", (double x) => options.Latitude = x },
                { "lon|longitude=", "Set location's longitude", (double x) => options.Longitude = x },
                { "e|elevation=", "Set location's elevation; Positive only", (double x) => options.Elevation = x },
                { "tz|timezone=", "Set location's TimeZone", x => options.TimeZone = x },
                { "tf|timeformat=", "Set the way the application formats a DateTime object.", x => options.DateTimeFormat = x },
                { "h|?|help", "Shows this help message", v => ShowHelp() }
            };

            List <string> extraArgs;

            try
            {
                extraArgs = p.Parse(args);
            }
            catch (OptionException)
            {
                ShowHelp();
                return;
            }

            var timeZone = new OlsonTimeZone(options.TimeZone);
            var location =
                new GeoLocation(string.Empty, options.Latitude, options.Longitude, options.Elevation, timeZone);
            var czc = new ComplexZmanimCalendar(new DateTime(options.Date.Year, options.Date.Month, options.Date.Day), location);

            var methods = GetDateTimeAndLongMethods();

            foreach (var first in
                     extraArgs.Select(extraArg =>
                                      methods.Where(
                                          f => f.Name.Remove(0, 3).ToLowerInvariant() == extraArg.ToLowerInvariant()).First())
                     )
            {
                object invoke = first.Invoke(czc, null);

                if (extraArgs.Count > 1)
                {
                    Console.Write(first.Name.Remove(0, 3) + ": ");
                }

                if (invoke.GetType() == typeof(DateTime))
                {
                    var time = (DateTime)invoke;
                    Console.Write(time.ToString(options.DateTimeFormat));
                }
                else if (invoke.GetType() == typeof(long))
                {
                    Console.WriteLine((long)invoke);
                }

                if (extraArgs.Count > 1)
                {
                    Console.WriteLine();
                }
            }
            //Console.Read();
        }