Ejemplo n.º 1
0
        public static bool Execute(ICmdProcessCaller processCaller, string command, Action <StreamReader> resultAction = null)
        {
            Stopwatch sw      = Stopwatch.StartNew();
            var       process = processCaller.Call(command);

            if (process is null || process.StartInfo?.FileName != FileName)
            {
                return(false);
            }
            Console.WriteLine($"{nameof(DotnetCmdProcessHelper)} executes 'dotnet {command}'");
            using (var sr = process.StandardOutput)
            {
                if (resultAction is null)
                {
                    Console.WriteLine(sr.ReadToEnd());
                }
                else
                {
                    resultAction.Invoke(sr);
                }
            }
            sw.Stop();
            Console.WriteLine($"{nameof(DotnetCmdProcessHelper)} runs {sw.ElapsedMilliseconds}ms");
            process.Dispose();
            return(true);
        }
Ejemplo n.º 2
0
        public static bool ExistTemplate(ICmdProcessCaller processCaller, string keyword, string type = DotnetTemplateType)
        {
            bool result = false;

            Execute(processCaller, $"new --list --type {type}", (sr) =>
            {
                while (!sr.EndOfStream)
                {
                    string str = sr.ReadLine();
                    if (!string.IsNullOrEmpty(str) && str.Contains(keyword))
                    {
                        result = true;
                        break;
                    }
                }
            });
            return(result);
        }
Ejemplo n.º 3
0
        public static bool InstallTemplate(ICmdProcessCaller processCaller, NugetPackageInfo packageInfo)
        {
            string command = "new -i " + packageInfo.Id + (string.IsNullOrEmpty(packageInfo.Version) ? null : ("::" + packageInfo.Version));
            bool   instOK  = true;
            bool   exeOK   = Execute(processCaller, command, (sr) =>
            {
                while (!sr.EndOfStream)
                {
                    string str = sr.ReadLine();
                    if (!string.IsNullOrEmpty(str) && str.Contains(": error "))
                    {
                        Console.WriteLine($"{nameof(InstallTemplate)} Error: {str}");
                        instOK = false;
                        break;
                    }
                }
            });

            return(instOK && exeOK);
        }
Ejemplo n.º 4
0
 public static bool ShowTemplateList(ICmdProcessCaller processCaller, string type = DotnetTemplateType) => Execute(processCaller, $"new --list --type {type}");
Ejemplo n.º 5
0
 public static bool ApplyTemplateUpdates(ICmdProcessCaller processCaller) => Execute(processCaller, "new --update-apply");
Ejemplo n.º 6
0
 public static bool CheckTemplateUpdates(ICmdProcessCaller processCaller) => Execute(processCaller, "new --update-check");
Ejemplo n.º 7
0
 public static bool UninstallTemplate(ICmdProcessCaller processCaller, NugetPackageInfo packageInfo) => Execute(processCaller, "new -u " + packageInfo.Id);
Ejemplo n.º 8
0
 public SpiderXNewCmdProcessWrapper(string projectName, string projectNamespace, IConfiguration config, ICmdProcessCaller caller = null)
 {
     if (config is null)
     {
         throw new ArgumentNullException();
     }
     if (string.IsNullOrEmpty(projectName))
     {
         throw new ArgumentNullException();
     }
     Caller           = caller ?? new DotnetCmdProcessCaller();
     ProjectName      = projectName;
     ProjectNamespace = projectNamespace;
     NugetPackageInfo = new NugetPackageInfo(config.GetSection("NugetPackageId").Value);
     CmdKey           = config.GetSection(nameof(CmdKey)).Value;
 }