Example #1
0
        /// <summary>
        /// Installs friendly information for any currently known drivers.
        /// Note: Windows installs a separate driver for each USB port you plug a device into for some bizzare reason,
        /// and this will only install info for currently known drivers.
        /// </summary>
        static void Main(string[] args)
        {
            WindowsIdentity  identity  = WindowsIdentity.GetCurrent();
            WindowsPrincipal principal = new WindowsPrincipal(identity);

            if (!principal.IsInRole(WindowsBuiltInRole.Administrator))
            {
                throw new ZeitgeberException("Installing device information requires administrator privileges");
            }

            Console.WriteLine("Installing device information for all currently known devices...");

            Zeitgeber zeitgeber = new Zeitgeber();

            zeitgeber.InstallDriverInfo();

            Console.WriteLine("Done.");
        }
Example #2
0
        static void Main(string[] argv)
        {
            try
            {
                args = new Args();
                opts = new OptionSet()
                {
                    { "h|help", v => args.showhelp = (v != null) },
                    { "v|verbose", v => args.verbose = (v != null) },
                };

                List <string> subargs = opts.Parse(argv);

                if (args.showhelp) // --help
                {
                    ShowHelp();
                    return;
                }

                // Un-named parameters
                if (subargs.Count < 1)
                {
                    Console.WriteLine("No action specified");
                    Console.WriteLine("");
                    ShowHelp();
                    return;
                }
                string action_str = subargs[0];
                try
                {
                    args.action = (CommandLineAction)Enum.Parse(typeof(CommandLineAction), action_str, true);
                }
                catch (System.ArgumentException e)
                {
                    throw new ZeitgeberException(String.Format("Invalid action '{0}'", action_str), e);
                }



                zeitgeber = new Zeitgeber();
                zeitgeber.Connect();

                if (args.verbose)
                {
                    Console.WriteLine(String.Format("Connected to '{0}'", zeitgeber.DeviceDescription));
                }

                switch (args.action)
                {
                case CommandLineAction.Ping:
                    PingDevice();
                    break;

                case CommandLineAction.Reset:
                    ResetDevice();
                    break;

                case CommandLineAction.Query:
                    QueryDevice();
                    break;

                case CommandLineAction.SyncTime:
                    SyncTime();
                    break;

                case CommandLineAction.Screenshot:
                    string filename = (subargs.Count >= 2) ? subargs[1] : "screenshot.png";
                    Screenshot(filename);
                    break;

                case CommandLineAction.Calendar:
                    CalendarSubCommand(subargs.Skip(1).ToArray());
                    break;

                default:
                    throw new NotImplementedException("The action is not yet implemented");
                }
            }
            catch (Exception e)
            {
                //Console.Error.WriteLine();
#if DEBUG
                Console.Error.WriteLine(e);
#else
                Console.Error.WriteLine("Error: " + e.Message);
#endif
                //Console.Error.WriteLine();
            }
            finally
            {
                Console.WriteLine("Done.");
#if DEBUG
                // Pause the console so we can see the output
                Console.WriteLine("Press any key to continue...");
                Console.ReadKey();
#endif
            }
        }