< Summary - SonghayCore

Line coverage
15%
Covered lines: 22
Uncovered lines: 124
Coverable lines: 146
Total lines: 270
Line coverage: 15%
Branch coverage
21%
Covered branches: 6
Total branches: 28
Branch coverage: 21.4%
Method coverage

Method coverage is only available for sponsors.

Upgrade to PRO version

Metrics

File(s)

/home/rasx/sourceRoot/SonghayCore/SonghayCore/ProgramUtility._.cs

#LineLine coverage
 1namespace Songhay;
 2
 3/// <summary>
 4/// Defines shared routines for Studio programs.
 5/// </summary>
 6public static partial class ProgramUtility
 7{
 8    /// <summary>
 9    /// Initializes the trace source.
 10    /// </summary>
 11    /// <param name="listener">The listener.</param>
 12    public static TraceSource? InitializeTraceSource(TraceListener? listener)
 213    {
 214        var traceSource = TraceSources
 215            .Instance
 216            .GetTraceSourceFromConfiguredName()
 217            .WithSourceLevels();
 18
 419        if (listener != null) traceSource?.Listeners.Add(listener);
 20
 221        return traceSource;
 222    }
 23
 24    /// <summary>
 25    /// Loads the configuration.
 26    /// </summary>
 27    /// <param name="basePath">The base path.</param>
 28    public static IConfigurationRoot LoadConfiguration(string? basePath) =>
 429        LoadConfiguration(basePath, builderModifier: null);
 30
 31    /// <summary>
 32    /// Loads the built configuration.
 33    /// </summary>
 34    /// <param name="basePath">The base path.</param>
 35    /// <param name="requiredJsonConfigurationFiles">specify any additional JSON configuration files before build</param
 36    /// <returns>Returns the built configuration.</returns>
 37    public static IConfigurationRoot
 38        LoadConfiguration(string? basePath, params string[] requiredJsonConfigurationFiles) =>
 039        LoadConfiguration(basePath, builderModifier: null, requiredJsonConfigurationFiles);
 40
 41    /// <summary>
 42    /// Loads the built configuration.
 43    /// </summary>
 44    /// <param name="basePath">The base path.</param>
 45    /// <param name="builderModifier">Allows modification of <see cref="ConfigurationBuilder"/> before build.</param>
 46    /// <param name="requiredJsonConfigurationFiles">specify any additional JSON configuration files before build</param
 47    /// <returns>Returns the built configuration.</returns>
 48    public static IConfigurationRoot LoadConfiguration(string? basePath,
 49        Func<IConfigurationBuilder, IConfigurationBuilder>? builderModifier,
 50        params string[] requiredJsonConfigurationFiles)
 451    {
 452        Console.WriteLine("Loading configuration...");
 53
 454        var builder = new ConfigurationBuilder()
 455                .AddEnvironmentVariables()
 456                .SetBasePath(basePath)
 457                .AddJsonFile("./appsettings.json", optional: false, reloadOnChange: false)
 458            ;
 59
 1260        foreach (var jsonFile in requiredJsonConfigurationFiles)
 061        {
 062            builder.AddJsonFile(jsonFile, optional: false, reloadOnChange: false);
 063        }
 64
 465        if (builderModifier != null) builder = builderModifier(builder);
 66
 467        Console.WriteLine("Building configuration...");
 68
 469        var configuration = builder.Build();
 70
 471        return configuration;
 472    }
 73
 74    /// <summary>
 75    /// Pauses the shell Program in <c>DEBUG</c> mode.
 76    /// </summary>
 77    public static void HandleDebug()
 078    {
 79#if DEBUG
 080        Console.WriteLine($"{Environment.NewLine}Press any key to continue...");
 081        Console.ReadKey(false);
 82#endif
 083    }
 84}

/home/rasx/sourceRoot/SonghayCore/SonghayCore/ProgramUtility.Console.cs

#LineLine coverage
 1namespace Songhay;
 2
 3public static partial class ProgramUtility
 4{
 5    /// <summary>
 6    /// Gets the console characters.
 7    /// </summary>
 8    /// <param name="input">The input.</param>
 9    /// <returns>Returns formatted input.</returns>
 10    public static string? GetConsoleCharacters(string? input)
 011    {
 012        if (string.IsNullOrWhiteSpace(input)) return null;
 13
 14        #region replace operations:
 15
 016        input = input.Replace("©", "(C)");
 017        input = input.Replace("®", "(R)");
 018        input = input.Replace("™", "TM");
 019        input = input.Replace("‘", "'");
 020        input = input.Replace("’", "'");
 021        input = input.Replace("“", "\"");
 022        input = input.Replace("”", "\"");
 023        input = input.Replace("…", "...");
 24
 25        //Characters 192–223:
 026        input = input.Replace("À", "A");
 027        input = input.Replace("Á", "A");
 028        input = input.Replace("Â", "A");
 029        input = input.Replace("Ã", "A");
 030        input = input.Replace("Ä", "A");
 031        input = input.Replace("Å", "A");
 032        input = input.Replace("Æ", "AE");
 033        input = input.Replace("Ç", "C");
 034        input = input.Replace("È", "E");
 035        input = input.Replace("É", "E");
 036        input = input.Replace("Ê", "E");
 037        input = input.Replace("Ë", "E");
 038        input = input.Replace("Ì", "I");
 039        input = input.Replace("Í", "I");
 040        input = input.Replace("Î", "I");
 041        input = input.Replace("Ï", "I");
 042        input = input.Replace("Ð", "D");
 043        input = input.Replace("Ñ", "N");
 044        input = input.Replace("Ò", "O");
 045        input = input.Replace("Ó", "O");
 046        input = input.Replace("Ô", "O");
 047        input = input.Replace("Õ", "O");
 048        input = input.Replace("Ö", "O");
 049        input = input.Replace("×", "x");
 050        input = input.Replace("Ø", "O");
 051        input = input.Replace("Ù", "U");
 052        input = input.Replace("Ú", "U");
 053        input = input.Replace("Û", "U");
 054        input = input.Replace("Ü", "U");
 055        input = input.Replace("Ý", "Y");
 56
 57        //Characters 224–255:
 058        input = input.Replace("à", "a");
 059        input = input.Replace("á", "a");
 060        input = input.Replace("â", "a");
 061        input = input.Replace("ã", "a");
 062        input = input.Replace("ä", "a");
 063        input = input.Replace("å", "a");
 064        input = input.Replace("æ", "ae");
 065        input = input.Replace("ç", "c");
 066        input = input.Replace("è", "e");
 067        input = input.Replace("é", "e");
 068        input = input.Replace("ê", "e");
 069        input = input.Replace("ë", "e");
 070        input = input.Replace("ì", "i");
 071        input = input.Replace("í", "i");
 072        input = input.Replace("î", "i");
 073        input = input.Replace("ï", "i");
 074        input = input.Replace("ñ", "n");
 075        input = input.Replace("ò", "o");
 076        input = input.Replace("ó", "o");
 077        input = input.Replace("ô", "o");
 078        input = input.Replace("õ", "o");
 079        input = input.Replace("ö", "o");
 080        input = input.Replace("÷", "/");
 081        input = input.Replace("ø", "o");
 082        input = input.Replace("ù", "u");
 083        input = input.Replace("ú", "u");
 084        input = input.Replace("û", "u");
 085        input = input.Replace("ü", "u");
 086        input = input.Replace("ý", "y");
 087        input = input.Replace("ÿ", "y");
 88
 89        #endregion
 90
 091        return input;
 092    }
 93}

/home/rasx/sourceRoot/SonghayCore/SonghayCore/ProgramUtility.Process.cs

#LineLine coverage
 1namespace Songhay;
 2
 3public static partial class ProgramUtility
 4{
 5    /// <summary>
 6    /// Starts the process.
 7    /// </summary>
 8    /// <param name="command">The command.</param>
 9    public static void StartProcess(string? command)
 010    {
 011        if (string.IsNullOrWhiteSpace(command)) return;
 12
 013        string file = Environment.ExpandEnvironmentVariables(command);
 14        string? args;
 15
 016        if (File.Exists(file) || Directory.Exists(file))
 017        {
 18            //The entire entry is a file or directory:
 019            Process.Start(file);
 020        }
 21        else
 022        {
 23            //Look for file and arg’s:
 024            MatchCollection matches = Regex.Matches(command, @"""[^""]+""|\s+.+");
 025            if (matches.Count > 0)
 026            {
 027                if (File.Exists(matches[0].Value))
 028                {
 29                    //First match is file:
 030                    file = matches[0].Value;
 031                    args = command.Replace(file, string.Empty).Trim();
 032                }
 33                else
 034                {
 35                    //Assume all matches are arg's:
 036                    string[] matchedArgs = new string[matches.Count];
 037                    for (int i = 0; i < matches.Count; i++)
 038                    {
 039                        matchedArgs[i] = matches[i].Value;
 040                    }
 41
 042                    args = string.Join(" ", matchedArgs);
 043                    file = command.Replace(args, string.Empty).Trim();
 044                }
 45
 046                file = Environment.ExpandEnvironmentVariables(file);
 047                args = Environment.ExpandEnvironmentVariables(args);
 048                Process.Start(file, args);
 049            }
 50            else
 051            {
 052                throw new System.ComponentModel.Win32Exception(-2147467259);
 53            }
 054        }
 055    }
 56
 57    /// <summary>
 58    /// Starts the process.
 59    /// </summary>
 60    /// <param name="argumentOfExe">The argument of executable.</param>
 61    /// <param name="pathToExe">The path to executable.</param>
 62    /// <param name="useExe">if set to <c>true</c> use path to executable.</param>
 63    public static void StartProcess(string argumentOfExe, string pathToExe, bool useExe)
 064    {
 065        if (useExe)
 066            Process.Start(pathToExe, argumentOfExe);
 67        else
 068            Process.Start(argumentOfExe);
 069    }
 70}

/home/rasx/sourceRoot/SonghayCore/SonghayCore/ProgramUtility.StackTrace.cs

#LineLine coverage
 1namespace Songhay;
 2
 3public static partial class ProgramUtility
 4{
 5    /// <summary>
 6    /// Gets the name of the current method.
 7    /// </summary>
 8    [MethodImpl(MethodImplOptions.NoInlining)]
 09    public static string? GetCurrentMethodName() => GetMethodName(2);
 10
 11    /// <summary>
 12    /// Gets the name of the current method.
 13    /// </summary>
 14    /// <param name="stackFrameIndex">Index of the stack frame.</param>
 15    [MethodImpl(MethodImplOptions.NoInlining)]
 16    public static string? GetMethodName(int stackFrameIndex)
 017    {
 018        var trace = new StackTrace();
 019        var frame = trace.GetFrame(stackFrameIndex);
 20
 021        return frame?.GetMethod()?.Name;
 022    }
 23}