Ejemplo n.º 1
0
 internal string GetUserName()
 {
     if (this.Account == ServiceAccount.NetworkService)
     {
         return(@"NT AUTHORITY\NetworkService");
     }
     else if (this.Account == ServiceAccount.LocalSystem)
     {
         return("LocalSystem");
     }
     else if (this.Account == ServiceAccount.LocalService)
     {
         return(@"NT AUTHORITY\LocalService");
     }
     else
     {
         if (!UserName.IsNullOrWhiteSpace())
         {
             return(ChoEnvironment.ToDomainUserName(UserName));
         }
         else
         {
             ChoConsole.Write("Enter UserId: ");
             return(ChoEnvironment.ToDomainUserName(ChoConsole.ReadLine()));
         }
     }
 }
Ejemplo n.º 2
0
 internal string GetPassword()
 {
     if (this.Account == ServiceAccount.NetworkService)
     {
         return(String.Empty);
     }
     else if (this.Account == ServiceAccount.LocalSystem)
     {
         return(String.Empty);
     }
     else if (this.Account == ServiceAccount.LocalService)
     {
         return(String.Empty);
     }
     else
     {
         if (!UserName.IsNullOrWhiteSpace())
         {
             return(Password);
         }
         else
         {
             ChoConsole.Write("Enter Password: ");
             return(ChoConsole.ReadPassword());
         }
     }
 }
Ejemplo n.º 3
0
        public void Start(ChoConsoleProgressorStart consoleProgressorStart, ChoAsyncCallback callback, object state, int timeout)
        {
            ChoGuard.NotDisposed(this);

            int isStarted = Interlocked.CompareExchange(ref _isStarted, 1, 0);

            if (isStarted == 1)
            {
                return;
            }

            Interlocked.CompareExchange(ref _stopRequested, 0, 1);

            lock (ChoConsole.SyncRoot)
            {
                ChoConsole.Clear();
                ChoConsole.ClearKeys();

                IChoAsyncResult result = ChoConsole.OutputQueuedExecutionService.Enqueue(() =>
                {
                    _location          = WriteNSavePosition(_msg + " ");
                    _statusMsgLocation = new ChoPoint(_consolePercentageProgressorSettings.ProgressBarMarginX, _location.Y + 1);
                    WriteSpinner("/");
                });
                result.AsyncWaitHandle.WaitOne();
            }

            Action <ChoConsoleSpinProgressor> wrappedFunc = delegate
            {
                _threadToKill = Thread.CurrentThread;

                try
                {
                    while (true)
                    {
                        if (_stopRequested == 1)
                        {
                            break;
                        }

                        ChoConsole.WriteLine(GetNextSpinChar().ToString(), _location, _foregroundColor, _backgroundColor);
                        bool retValue = consoleProgressorStart(this, state);
                        if (!retValue)
                        {
                            break;
                        }
                    }
                }
                catch (ThreadAbortException)
                {
                    Thread.ResetAbort();
                }
            };

            _result = ChoAbortableQueuedExecutionService.Global.Enqueue <ChoConsoleSpinProgressor>(wrappedFunc, this);
        }
        private void SetStatusMsg(string statusMsg)
        {
            if (statusMsg != null && statusMsg.Length > _consolePercentageProgressorSettings.ProgressBarStatusMsgSize)
            {
                statusMsg = statusMsg.Substring(0, _consolePercentageProgressorSettings.ProgressBarStatusMsgSize);
            }

            ChoConsole.Write(statusMsg.PadRight(_consolePercentageProgressorSettings.ProgressBarStatusMsgSize), _statusMsgLocation, _consolePercentageProgressorSettings.ProgressBarStatusMsgForegroundColor,
                             _consolePercentageProgressorSettings.ProgressBarStatusMsgBackgroundColor);
        }
Ejemplo n.º 5
0
 public void Write(string msg)
 {
     if (HasPositionSpecified)
     {
         ChoConsole.Write(msg, _cursorLeft.Value, _cursorTop.Value, _foregroundColor, _backgroundColor);
     }
     else
     {
         ChoConsole.Write(msg, _foregroundColor, _backgroundColor);
     }
 }
        private bool SetPercentageComplete(int percentage)
        {
            if (percentage < MinPercentage)
            {
                throw new ChoConsoleException(String.Format("Percentage must be >= {0}", MinPercentage));
            }
            if (percentage > MaxPercentage)
            {
                throw new ChoConsoleException(String.Format("Percentage must be <= {0}", MaxPercentage));
            }

            ChoConsole.WriteLine(String.Format("[{0}%]", percentage).PadRight(_padLength + 3), _location, _foregroundColor, _backgroundColor);

            return(percentage < MaxPercentage);
        }
        private void PrintHeader()
        {
            string applicationName = ApplicationName;

            if (applicationName.IsNullOrWhiteSpace())
            {
                applicationName = ChoGlobalApplicationSettings.Me.ApplicationName;
            }

            string version = ChoAssembly.GetEntryAssembly().GetName().Version.ToString();

            ChoConsole.WriteLine("{0} [Version {1}]".FormatString(applicationName, version));

            if (!Copyright.IsNullOrWhiteSpace())
            {
                ChoConsole.WriteLine(Copyright);
            }

            ChoConsole.WriteLine();
        }
Ejemplo n.º 8
0
        public void StartFileCopy(string sourceDirectory = null, string destDirectory = null)
        {
            try
            {
                ChoAppSettings appSettings = new ChoAppSettings();
                if (!SettingsFilePath.IsNullOrWhiteSpace())
                {
                    if (!File.Exists(SettingsFilePath))
                    {
                        throw new ArgumentException("Can't find '{0}' settings file.".FormatString(SettingsFilePath));
                    }

                    appSettings.LoadXml(File.ReadAllText(SettingsFilePath));
                }

                ChoConsole.WriteLine();

                ChoRoboCopyManager _roboCopyManager = new ChoRoboCopyManager(SettingsFilePath);
                _roboCopyManager.Status += (sender, e) =>
                {
                    ChoTrace.Write(e.Message);
                    ChoConsole.Write(e.Message, ConsoleColor.Yellow);
                };
                _roboCopyManager.AppStatus += (sender, e) =>
                {
                    ChoTrace.Write(e.Message);
                    ChoConsole.Write(e.Message, ConsoleColor.Yellow);
                };

                _roboCopyManager.Process(appSettings.RoboCopyFilePath, appSettings.GetCmdLineParams(),
                                         appSettings, true);
            }
            catch (ThreadAbortException)
            {
                Console.WriteLine("RoboCopy operation cancelled by user.");
            }
            catch (Exception ex)
            {
                Console.WriteLine("RoboCopy operation failed." + Environment.NewLine + ChoApplicationException.ToString(ex));
            }
        }
        public void Start(ChoConsolePercentageProgressorStart consolePercentageProgressorStart, ChoAsyncCallback callback, object state, int timeout)
        {
            ChoGuard.NotDisposed(this);

            //if (_isStarted) return;
            int isStarted = Interlocked.CompareExchange(ref _isStarted, 1, 0);

            if (isStarted == 1)
            {
                return;
            }

            Interlocked.CompareExchange(ref _stopRequested, 0, 1);

            lock (ChoConsole.SyncRoot)
            {
                ChoConsole.Clear();
                ChoConsole.ClearKeys();

                IChoAsyncResult result = ChoConsole.OutputQueuedExecutionService.Enqueue(() =>
                {
                    _location          = WriteNSavePosition(_msg + " ");
                    _statusMsgLocation = new ChoPoint(_consolePercentageProgressorSettings.ProgressBarMarginX, _location.Y + 1);
                    WritePercentage("[0%]");
                });

                result.AsyncWaitHandle.WaitOne();

                SetPercentageComplete(MinPercentage);
            }

            Action <ChoConsolePercentageProgressor, int> wrappedFunc = delegate
            {
                _threadToKill = Thread.CurrentThread;

                try
                {
                    int percentage    = MinPercentage;
                    int retPercentage = MinPercentage;

                    while (retPercentage < MaxPercentage)
                    {
                        if (_stopRequested == 1)
                        {
                            break;
                        }

                        retPercentage = consolePercentageProgressorStart(this, percentage, state);

                        if (percentage >= retPercentage)
                        {
                            throw new ChoConsoleException("Returned percentage '{0}' value <= running percentage '{1}' value. It may leads to infinite loop.".FormatString(retPercentage, percentage));
                        }
                        else
                        {
                            percentage = retPercentage;
                        }

                        lock (ChoConsole.SyncRoot)
                        {
                            SetPercentageComplete(retPercentage);
                        }
                    }
                }
                catch (ThreadAbortException)
                {
                    Thread.ResetAbort();
                }
            };

            //try
            //{
            //    ChoAPM.InvokeMethod(wrappedFunc, new object[] { this, MinPercentage }, timeout);
            //}
            //catch (Exception ex)
            //{
            //    ErrorOccured(this, new ChoExceptionEventArgs(ex));
            //}

            _result = ChoAbortableQueuedExecutionService.Global.Enqueue <ChoConsolePercentageProgressor, int>(wrappedFunc, this, MinPercentage, callback, state, timeout);
        }
Ejemplo n.º 10
0
 public void Clear()
 {
     ChoConsole.Clear();
 }
Ejemplo n.º 11
0
 static ChoConsoleSpinProgressor()
 {
     ChoConsole.Initialize();
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Reads the next character from the standard input stream within the specified timeout period.
 /// </summary>
 /// <param name="timeoutInMilliSeconds">A System.TimeSpan that represents the number of milliseconds to wait, or a System.TimeSpan that represents -1 milliseconds to wait indefinitely.</param>
 /// <param name="defaultValue">A default value will be returned from this call when the timeout period elapsed while reading from console.</param>
 /// <returns>The next line of characters from the input stream, or null if no more lines</returns>
 public int Read(int timeoutInMilliSeconds, int?defaultValue)
 {
     return(ChoConsole.Read(timeoutInMilliSeconds, defaultValue));
 }
Ejemplo n.º 13
0
 /// <summary>
 /// Reads the next line of characters from the standard input stream within the specified timeout period.
 /// </summary>
 /// <param name="timeoutInMilliSeconds">A System.TimeSpan that represents the number of milliseconds to wait, or a System.TimeSpan that represents -1 milliseconds to wait indefinitely.</param>
 /// <param name="defaultValue">A default value will be returned from this call when the timeout period elapsed while reading from console.</param>
 /// <param name="errMsg">A error message used to throw ChoTimeoutException when timeout happens while reading line from console and default value is not specified.</param>
 /// <returns>The next line of characters from the input stream, or null if no more lines</returns>
 public string ReadLine(int timeoutInMilliSeconds, string defaultValue, string errMsg)
 {
     return(ChoConsole.ReadLine(timeoutInMilliSeconds, defaultValue, errMsg));
 }
        public void Start(ChoConsolePercentageProgressorStartEx consolePercentageProgressorStart, ChoAsyncCallback callback, object state, int timeout)
        {
            ChoGuard.NotDisposed(this);

            int isStarted = Interlocked.CompareExchange(ref _isStarted, 1, 0);

            if (isStarted == 1)
            {
                return;
            }

            Interlocked.CompareExchange(ref _stopRequested, 0, 1);

            lock (ChoConsole.SyncRoot)
            {
                ChoConsole.Clear();
                ChoConsole.ClearKeys();

                _consoleCoordinate = new ConsoleCoordinate((short)(Console.CursorLeft + _consolePercentageProgressorSettings.ProgressBarMarginX),
                                                           (short)(Console.CursorTop + _consolePercentageProgressorSettings.ProgressBarMarginY));

                ShowProgress(MinPercentage, _msg);
            }

            Action <ChoConsolePercentageProgressorEx, int> wrappedFunc = delegate
            {
                _threadToKill = Thread.CurrentThread;

                try
                {
                    int percentage    = MinPercentage;
                    int retPercentage = MinPercentage;
                    while (retPercentage < MaxPercentage)
                    {
                        if (_stopRequested == 1)
                        {
                            break;
                        }

                        Tuple <int, string> retValue = consolePercentageProgressorStart(this, percentage, state);
                        retPercentage = retValue.Item1;

                        if (percentage >= retPercentage)
                        {
                            throw new ChoConsoleException("Returned percentage '{0}' value <= running percentage '{1}' value. It may leads to infinite loop.".FormatString(retPercentage, percentage));
                        }
                        else
                        {
                            percentage = retPercentage;
                        }

                        ShowProgress(retPercentage, retValue.Item2);
                    }
                }
                catch (ThreadAbortException)
                {
                    Thread.ResetAbort();
                }
                finally
                {
                    Console.WriteLine();
                    Console.WriteLine();
                    Console.ResetColor();
                }
            };

            _result = ChoAbortableQueuedExecutionService.Global.Enqueue <ChoConsolePercentageProgressorEx, int>(wrappedFunc, this, MinPercentage, callback, state, timeout);
        }
Ejemplo n.º 15
0
 /// <summary>
 /// Writes the default string value, followed by the current line terminator, to the standard output stream.
 /// Reads the next line of characters from the standard input stream.
 /// </summary>
 /// <param name="msg">The string message to be written to the console.</param>
 /// <returns>The next line of characters from the input stream, or null if no more lines are available.</returns>
 public string PauseLine(string msg)
 {
     return(ChoConsole.PauseLine(msg));
 }
Ejemplo n.º 16
0
 /// <summary>
 /// Reads the next character from the standard input stream.
 /// </summary>
 public int Read()
 {
     return(ChoConsole.Read());
 }
Ejemplo n.º 17
0
 public string ReadPassword(int maxLength)
 {
     return(ChoConsole.ReadPassword(maxLength));
 }
Ejemplo n.º 18
0
 /// <summary>
 /// Reads the next character from the standard input stream within the specified timeout period.
 /// </summary>
 /// <param name="timeoutInMilliSeconds">A System.TimeSpan that represents the number of milliseconds to wait, or a System.TimeSpan that represents -1 milliseconds to wait indefinitely.</param>
 /// <param name="defaultValue">A default value will be returned from this call when the timeout period elapsed while reading from console.</param>
 /// <param name="errMsg">A error message used to throw ChoTimeoutException when timeout happens while reading line from console and default value is not specified.</param>
 /// <returns>
 ///     A System.ConsoleKeyInfo object that describes the System.ConsoleKey constant and Unicode character, if any, that correspond to the pressed console key.
 ///     The System.ConsoleKeyInfo object also describes, in a bitwise combination of System.ConsoleModifiers values, whether one or more SHIFT, ALT, or
 ///     CTRL modifier keys was pressed simultaneously with the console key.
 /// </returns>
 public ConsoleKeyInfo ReadKey(int timeoutInMilliSeconds)
 {
     return(ChoConsole.ReadKey(timeoutInMilliSeconds));
 }
Ejemplo n.º 19
0
 /// <summary>
 /// Reads the next character from the standard input stream within the specified timeout period.
 /// </summary>
 /// <param name="timeoutInMilliSeconds">A System.TimeSpan that represents the number of milliseconds to wait, or a System.TimeSpan that represents -1 milliseconds to wait indefinitely.</param>
 /// <param name="defaultValue">A default value will be returned from this call when the timeout period elapsed while reading from console.</param>
 /// <param name="errMsg">A error message used to throw ChoTimeoutException when timeout happens while reading line from console and default value is not specified.</param>
 /// <returns>
 ///     A System.ConsoleKeyInfo object that describes the System.ConsoleKey constant and Unicode character, if any, that correspond to the pressed console key.
 ///     The System.ConsoleKeyInfo object also describes, in a bitwise combination of System.ConsoleModifiers values, whether one or more SHIFT, ALT, or
 ///     CTRL modifier keys was pressed simultaneously with the console key.
 /// </returns>
 public ConsoleKeyInfo ReadKey(int timeoutInMilliSeconds, ConsoleKeyInfo?defaultValue, string errMsg)
 {
     return(ChoConsole.ReadKey(timeoutInMilliSeconds, defaultValue, errMsg));
 }
Ejemplo n.º 20
0
 /// <summary>
 /// Reads the next character from the standard input stream.
 /// </summary>
 /// <returns>
 ///     A System.ConsoleKeyInfo object that describes the System.ConsoleKey constant and Unicode character, if any, that correspond to the pressed console key.
 ///     The System.ConsoleKeyInfo object also describes, in a bitwise combination of System.ConsoleModifiers values, whether one or more SHIFT, ALT, or
 ///     CTRL modifier keys was pressed simultaneously with the console key.
 /// </returns>
 public ConsoleKeyInfo ReadKey()
 {
     return(ChoConsole.ReadKey());
 }
Ejemplo n.º 21
0
 static ChoConsoleSession()
 {
     ChoConsole.Initialize();
 }
Ejemplo n.º 22
0
 /// <summary>
 /// Reads the next character from the standard input stream within the specified timeout period.
 /// </summary>
 /// <param name="timeoutInMilliSeconds">A System.TimeSpan that represents the number of milliseconds to wait, or a System.TimeSpan that represents -1 milliseconds to wait indefinitely.</param>
 /// <param name="defaultValue">A default value will be returned from this call when the timeout period elapsed while reading from console.</param>
 /// <param name="errMsg">A error message used to throw ChoTimeoutException when timeout happens while reading line from console and default value is not specified.</param>
 /// <returns>The next line of characters from the input stream, or null if no more lines</returns>
 public int Read(int timeoutInMilliSeconds, int?defaultValue, string errMsg)
 {
     return(ChoConsole.Read(timeoutInMilliSeconds, defaultValue, errMsg));
 }
Ejemplo n.º 23
0
 /// <summary>
 /// Reads the next line of characters from the standard input stream within the specified timeout period.
 /// </summary>
 /// <param name="timeoutInMilliSeconds">A System.TimeSpan that represents the number of milliseconds to wait, or a System.TimeSpan that represents -1 milliseconds to wait indefinitely.</param>
 /// <param name="defaultValue">A default value will be returned from this call when the timeout period elapsed while reading from console.</param>
 /// <param name="errMsg">A error message used to throw ChoTimeoutException when timeout happens while reading line from console and default value is not specified.</param>
 /// <returns>The next line of characters from the input stream, or null if no more lines</returns>
 public string ReadLine(int timeoutInMilliSeconds)
 {
     return(ChoConsole.ReadLine(timeoutInMilliSeconds));
 }
Ejemplo n.º 24
0
 public string ReadPassword(char maskChar, int maxLength)
 {
     return(ChoConsole.ReadPassword(maskChar, maxLength));
 }
Ejemplo n.º 25
0
 /// <summary>
 /// Reads the next line of characters from the standard input stream.
 /// </summary>
 public string ReadLine()
 {
     return(ChoConsole.ReadLine());
 }
Ejemplo n.º 26
0
 public static ConsoleKeyInfo[] ClearKeys()
 {
     return(ChoConsole.ClearKeys());
 }
 static ChoConsolePercentageProgressorEx()
 {
     ChoConsole.Initialize();
 }
Ejemplo n.º 28
0
 public static ConsoleKeyInfo[] ClearKeys(bool intercept)
 {
     return(ChoConsole.ClearKeys(intercept));
 }
Ejemplo n.º 29
0
 public string ReadPassword()
 {
     return(ChoConsole.ReadPassword('*'));
 }
Ejemplo n.º 30
0
 /// <summary>
 /// Reads the next character from the standard input stream within the specified timeout period.
 /// </summary>
 /// <param name="timeoutInMilliSeconds">A System.TimeSpan that represents the number of milliseconds to wait, or a System.TimeSpan that represents -1 milliseconds to wait indefinitely.</param>
 /// <param name="defaultValue">A default value will be returned from this call when the timeout period elapsed while reading from console.</param>
 /// <param name="errMsg">A error message used to throw ChoTimeoutException when timeout happens while reading line from console and default value is not specified.</param>
 /// <returns>The next line of characters from the input stream, or null if no more lines</returns>
 public int Read(int timeoutInMilliSeconds)
 {
     return(ChoConsole.Read(timeoutInMilliSeconds));
 }