Ejemplo n.º 1
0
        public static string GetClientIfFound()
        {
            if (!string.IsNullOrWhiteSpace(_gitPath))
            {
                return(_gitPath);
            }

            _gitPath = Shell.GetExecutableInPath("git");

            if (string.IsNullOrWhiteSpace(_gitPath))
            {
                _gitPath = $@"{Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles)}\git\bin\git.exe";
            }

            if (!File.Exists(_gitPath))
            {
                _gitPath = $@"{Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86)}\git\bin\git.exe";
            }

            if (!File.Exists(_gitPath))
            {
                GenLog.Error("git.exe not found in any standard location");
                _gitPath = null;
            }

            return(_gitPath);
        }
Ejemplo n.º 2
0
 public void Run()
 {
     try
     {
         DoWork();
         InteractionHandler.ExitWithSuccess("All done");
     }
     catch (Exception e)
     {
         GenLog.Error(e.StackTrace);
         InteractionHandler.ExitWithError(e.Message);
     }
 }
Ejemplo n.º 3
0
        public static async Task OnExceptionAsync(
            [InstantHandle] Func <Task> action, string introMessage, CancellationToken cancellationToken, int numRetries = 3, int delay = 3000)

        {
            if (numRetries < 0)
            {
                numRetries = 0;
            }

            while (numRetries-- > 0 && !cancellationToken.IsCancellationRequested)
            {
                try
                {
                    if (!introMessage.IsEmpty())
                    {
                        GenLog.Info(introMessage);
                    }
                    await action();

                    return;
                }
                catch (FatalException e)
                {
                    GenLog.Error($"Aborting due to fatal exception: {e?.InnerException?.Message}");
                    throw;
                }
                catch (Exception e)
                {
                    if (cancellationToken.IsCancellationRequested)
                    {
                        GenLog.Warning("Cancelling retry-able operation");
                        throw;
                    }

                    GenLog.Warning("Caught exception during retry-able operation:");
                    GenLog.Warning(e.Message);
                    if (numRetries == 0)
                    {
                        GenLog.Error("No more retries left");
                        throw;
                    }
                    GenLog.Info($"Retries remaining: {numRetries}");
                    await Task.Delay(delay, cancellationToken);

                    delay *= 2;
                }
            }
        }
Ejemplo n.º 4
0
        protected static XDocument GetParsedXml(string file)
        {
            XDocument xelement;

            try
            {
                xelement = XDocument.Parse(File.ReadAllText(file));
            }
            catch (XmlException e)
            {
                GenLog.Error($"XML Exception while loading {file}: {e.Message}");
                throw;
            }

            return(xelement);
        }
Ejemplo n.º 5
0
        public string GetTextInput(string prompt)
        {
            if (Options.Passive)
            {
                throw new ConfigurationException($"Cannot request info without defaults in passive mode: '{prompt}'");
            }

            while (true)
            {
                var result = GetTextInput(prompt, null);
                if (!string.IsNullOrWhiteSpace(result))
                {
                    return(result);
                }

                GenLog.Error("Value cannot be empty");
            }
        }
 public override void ExitWithError(string message)
 {
     GenLog.Error(message);
     Pause();
     Environment.Exit(1);
 }