Пример #1
0
        static void AddAliasInteractiveConsole(MultiDomainManagementService service, string primaryDomain)
        {
            Console.WriteLine();
            Console.WriteLine("No batch file option (-f). Entering interactive mode.");
            Console.WriteLine("Press CTRL+C to quit.");
            Console.WriteLine();
            while (true)  //continue until CTRL+C
            {
                bool   confirm = false;
                string user = null, alias = null;
                while (string.IsNullOrEmpty(user))
                {
                    Console.Write("User to alias [user@domain]: ");
                    user = Console.ReadLine();
                }
                while (string.IsNullOrEmpty(alias))
                {
                    Console.Write(String.Format("Alias for {0}: ", user));
                    alias = Console.ReadLine();
                }

                Console.Write(string.Format("Please confirm: Add alias {0} to {1} (y/n)? ", alias, user));
                confirm = Console.ReadLine().StartsWith("y", StringComparison.InvariantCultureIgnoreCase);
                if (!confirm)
                {
                    Console.WriteLine("Cancelled. Alias not created.");
                }
                else
                {
                    try
                    {
                        Console.WriteLine(AddAlias(service, primaryDomain, user, alias));
                    }
                    catch (InvalidCredentialsException)
                    {
                        Console.WriteLine();
                        Console.WriteLine("Invalid Credentials.");
                        Console.WriteLine();
                        //collect new credentials
                        var options = new GoogleAppsAddDomainAliasProgramOptions()
                        {
                            Domain = primaryDomain
                        };
                        CollectOptionsInteractiveConsole(options);
                        service.setUserCredentials(options.Username, options.Password);
                    }
                }
                Console.WriteLine();
            }
        }
Пример #2
0
        static void Main(string[] args)
        {
            //parse options
            var options = GoogleAppsAddDomainAliasProgramOptions.Parse(args);

            if (options.Help)
            {
                options.PrintHelp(Console.Out); return;
            }
            if (options.Incomplete)
            {
                CollectOptionsInteractiveConsole(options);
            }
            if (!options.Username.Contains("@"))
            {
                Console.WriteLine("Whoops. Your username must be an email address.");
                options.Username = null;
                CollectOptionsInteractiveConsole(options);
            }
            //create service object
            var service = new MultiDomainManagementService(options.Domain, null);

            service.setUserCredentials(options.Username, options.Password);

            try
            {
                //add aliases
                if (string.IsNullOrEmpty(options.File))
                {
                    AddAliasInteractiveConsole(service, options.Domain);
                }
                else
                {
                    AddAliasBatch(Console.Out, service, options.Domain, options.File);
                }
            }
            catch (InvalidCredentialsException)
            {
                Console.WriteLine();
                Console.WriteLine("Invalid Credentials.");
            }
            catch (CaptchaRequiredException)
            {
                Console.WriteLine();
                Console.WriteLine("Your account has been locked by Google.");
                Console.WriteLine("Use your browser to unlock your account.");
                Console.WriteLine("https://www.google.com/accounts/UnlockCaptcha");
            }
        }
Пример #3
0
        public static GoogleAppsAddDomainAliasProgramOptions Parse(string[] args)
        {
            var programOptions = new GoogleAppsAddDomainAliasProgramOptions();

            programOptions.Options = new OptionSet()
            {
                { "d|domain=", "Primary Google Apps {DOMAIN}", x => programOptions.Domain = x },
                { "u|username="******"{USERNAME}", x => programOptions.Username = x },
                { "p|password="******"{PASSWORD}", x => programOptions.Password = x },
                { "f|file=", "Tab-delimited {FILE} of user and alias", x => programOptions.File = x },
                { "?|help", "Show this message and exit.", x => programOptions.Help = (x != null) }
            };

            programOptions.Options.Parse(args);

            return(programOptions);
        }
Пример #4
0
        static void CollectOptionsInteractiveConsole(GoogleAppsAddDomainAliasProgramOptions options)
        {
            while (string.IsNullOrEmpty(options.Domain))
            {
                Console.Write("Primary Google Apps Domain: ");
                options.Domain = Console.ReadLine();
            }

            while (string.IsNullOrEmpty(options.Username))
            {
                Console.Write("Admin username: "******"Password: "******"\b \b");
                        }
                    }
                    else
                    {
                        stringBuilder.Append(keyInfo.KeyChar);
                        Console.Write("*");
                    }
                }
                Console.WriteLine();
                options.Password = stringBuilder.ToString();
            }
        }
        static void CollectOptionsInteractiveConsole( GoogleAppsAddDomainAliasProgramOptions options )
        {
            while( string.IsNullOrEmpty( options.Domain ) )
            {
                Console.Write( "Primary Google Apps Domain: " );
                options.Domain = Console.ReadLine();
            }

            while( string.IsNullOrEmpty( options.Username ) )
            {
                Console.Write( "Admin username: "******"Password: "******"\b \b" );
                        }
                    }
                    else
                    {
                        stringBuilder.Append( keyInfo.KeyChar );
                        Console.Write( "*" );
                    }
                }
                Console.WriteLine();
                options.Password = stringBuilder.ToString();
            }
        }
        static void AddAliasInteractiveConsole( MultiDomainManagementService service, string primaryDomain )
        {
            Console.WriteLine();
            Console.WriteLine( "No batch file option (-f). Entering interactive mode." );
            Console.WriteLine( "Press CTRL+C to quit." );
            Console.WriteLine();
            while( true ) //continue until CTRL+C
            {
                bool confirm = false;
                string user=null, alias=null;
                while( string.IsNullOrEmpty( user ) )
                {
                    Console.Write( "User to alias [user@domain]: " );
                    user = Console.ReadLine();
                }
                while( string.IsNullOrEmpty( alias ) )
                {
                    Console.Write( String.Format( "Alias for {0}: ", user ) );
                    alias = Console.ReadLine();
                }

                Console.Write( string.Format("Please confirm: Add alias {0} to {1} (y/n)? ", alias, user) );
                confirm = Console.ReadLine().StartsWith( "y", StringComparison.InvariantCultureIgnoreCase );
                if( !confirm )
                {
                    Console.WriteLine( "Cancelled. Alias not created.");
                }
                else
                {
                    try
                    {
                        Console.WriteLine( AddAlias( service, primaryDomain, user, alias ) );
                    }
                    catch( InvalidCredentialsException )
                    {
                        Console.WriteLine();
                        Console.WriteLine( "Invalid Credentials." );
                        Console.WriteLine();
                        //collect new credentials
                        var options = new GoogleAppsAddDomainAliasProgramOptions() { Domain = primaryDomain };
                        CollectOptionsInteractiveConsole( options );
                        service.setUserCredentials( options.Username, options.Password );
                    }
                }
                Console.WriteLine();
            }
        }
        public static GoogleAppsAddDomainAliasProgramOptions Parse( string[] args )
        {
            var programOptions = new GoogleAppsAddDomainAliasProgramOptions();

            programOptions.Options = new OptionSet()
            {
                { "d|domain=", "Primary Google Apps {DOMAIN}", x => programOptions.Domain = x },
                { "u|username="******"{USERNAME}", x => programOptions.Username = x },
                { "p|password="******"{PASSWORD}", x => programOptions.Password = x },
                { "f|file=", "Tab-delimited {FILE} of user and alias", x => programOptions.File = x },
                { "?|help", "Show this message and exit.", x => programOptions.Help = (x != null) }
            };

            programOptions.Options.Parse( args );

            return programOptions;
        }