Ejemplo n.º 1
0
        public static bool AskAndPerformAction( string questionText, string sureDoText, string sureDoNotText, Action action, LogBuffer logBuffer = null )
        {
            for( ;; )
            {
                Console.WriteLine( questionText + " (y/n)" );
                string answer = Console.ReadLine( );

                bool doAction = !string.IsNullOrEmpty( answer ) && answer.ToLower( ).StartsWith( "y" );
                if( ConsoleHelper.Confirm( doAction ? sureDoText : sureDoNotText ) )
                {
                    if( doAction )
                    {
                        try
                        {
                            action( );
                        }
                        catch( Exception ex )
                        {
                            if( logBuffer != null )
                            {
                                logBuffer.Add( ex.Message );
                            }
                        }
                    }
                    return doAction;
                }
            }
        }
Ejemplo n.º 2
0
        public static bool AskAndPerformAction(string questionText, string sureDoText, string sureDoNotText, Action action, LogBuffer logBuffer = null)
        {
            for ( ;;)
            {
                Console.WriteLine(questionText + " (y/n)");
                string answer = Console.ReadLine( );

                bool doAction = !string.IsNullOrEmpty(answer) && answer.ToLower( ).StartsWith("y");
                if (ConsoleHelper.Confirm(doAction ? sureDoText : sureDoNotText))
                {
                    if (doAction)
                    {
                        try
                        {
                            action( );
                        }
                        catch (Exception ex)
                        {
                            if (logBuffer != null)
                            {
                                logBuffer.Add(ex.Message);
                            }
                        }
                    }
                    return(doAction);
                }
            }
        }