예제 #1
0
        public DosToolsApplication()
        {
            try
            {
                _commandLineParser = new CommandLineParser();

                if (_commandLineParser.IsOptionSet("?", "h", "help"))
                {
                    Help();
                }

                _silent = _commandLineParser.IsOptionSet("silent");
            }
            catch
            {
                Help();
            }
        }
        public DosToolsApplication()
        {
            try
            {
                _commandLineParser = new CommandLineParser();

                if (_commandLineParser.IsOptionSet("?", "h", "help"))
                {
                    Help();
                }

                _silent = _commandLineParser.IsOptionSet("silent");
            }
            catch
            {
                Help();
            }
        }
예제 #3
0
        static void Main(String[] args)
        {
            try
            {
                CommandLineParser commandLineParser = new CommandLineParser();

                if (commandLineParser.IsOptionSet("?", "h", "help"))
                {
                    Console.WriteLine("Prints date and/or time in specified format | https://github.com/vurdalakov/dostools");
                    Console.WriteLine("Examples:");
                    Console.WriteLine("\tdatetime /format:\"dd.MM.yyyy HH.mm.ss.ffff\"");
                    Console.WriteLine("\tdatetime /adddays:-1 /format:yyyy-MM-dd");
                    Console.WriteLine("\tdatetime /newline");
                    Environment.Exit(1);
                }

                DateTime dateTime = DateTime.Now;

                Int32 addDays = commandLineParser.GetOptionInt("adddays", 0);
                if (addDays != 0)
                {
                    dateTime = dateTime.AddDays(addDays);
                }

                String format = commandLineParser.GetOptionString("format", "yyyy-MM-dd HH-mm-ss");

                String text = String.Format("{0:" + format + "}", dateTime);

                Console.Write(text);

                if (commandLineParser.IsOptionSet("newline"))
                {
                    Console.WriteLine();
                }

                Environment.Exit(0);
            }
            catch (Exception ex)
            {
                Console.WriteLine("ERROR: " + ex.Message);

                Environment.Exit(2);
            }
        }
예제 #4
0
        public DosToolsApplication(String[] args)
        {
            try
            {
                _commandLineParser = new CommandLineParser(args);

                _silent = _commandLineParser.IsOptionSet("silent");
            }
            catch
            {
                Help();
            }
        }
예제 #5
0
        static void Main(string[] args)
        {
            try
            {
                DateTime startTime = DateTime.Now;

                CommandLineParser commandLineParser = new CommandLineParser();

                if (commandLineParser.IsOptionSet("?", "h", "help"))
                {
                    Help();
                }

                if (commandLineParser.FileNames.Length != 1)
                {
                    Help();
                }

                String delay = commandLineParser.FileNames[0].ToLower();

                Char suffix = delay[delay.Length - 1];
                if (Char.IsDigit(suffix))
                {
                    suffix = 's';
                }
                else
                {
                    delay = delay.Substring(0, delay.Length - 1);
                }

                Double number;
                if (!Double.TryParse(delay, out number))
                {
                    Help();
                }

                switch (suffix)
                {
                case 's':
                    break;

                case 'm':
                    number *= 60;
                    break;

                case 'h':
                    number *= 3660;
                    break;

                case 'd':
                    number *= 86400;
                    break;

                default:
                    Help();
                    break;
                }

                number *= 1000;

                TimeSpan timeout = new TimeSpan();
                timeout = new TimeSpan(0, 0, 0, 0, (int)Math.Round(number));

                Thread.Sleep(timeout);

                if (commandLineParser.IsOptionSet("showdelay"))
                {
                    TimeSpan realTimeout = DateTime.Now - startTime;
                    Console.WriteLine("{0:N0} {1:00}:{2:00}:{3:00}.{4:000}", Math.Floor(realTimeout.TotalDays), realTimeout.Hours, realTimeout.Minutes, realTimeout.Seconds, realTimeout.Milliseconds);
                }

                Environment.Exit(0);
            }
            catch (Exception ex)
            {
                Console.WriteLine("ERROR: " + ex.Message);

                Environment.Exit(2);
            }
        }