예제 #1
0
        public static void Execute(IServiceProvider serviceProvider, TaskEnum task, string version = "")
        {
            var dte     = serviceProvider.GetService(typeof(DTE)) as DTE;
            var options = OptionsHelper.GetOptions(dte);

            Execute(dte, options.DbType, options.Connection, task, version);
        }
예제 #2
0
        public static List <string> GetMigrations(DTE dte)
        {
            var migrations = new List <string>();

            var options = OptionsHelper.GetOptions(dte);

            var project = GetSelectedProject(dte);

            if (project == null)
            {
                return(migrations);
            }

            BuildProject(dte, project);

            var assembly = GetProjectAssemblyPath(project);
            var migrate  = GetMigratePath(project);

            var process = new Process
            {
                StartInfo = new ProcessStartInfo
                {
                    FileName               = "cmd.exe",
                    Arguments              = $@"/k """"{migrate}"" -c=""{options.Connection}"" -db={options.DbType} --task:listmigrations -target=""{assembly}""",
                    UseShellExecute        = false,
                    RedirectStandardOutput = true,
                    RedirectStandardError  = true,
                    CreateNoWindow         = true
                }
            };

            process.Start();

            while (!process.StandardOutput.EndOfStream)
            {
                var line = process.StandardOutput.ReadLine();

                if (string.IsNullOrEmpty(line))
                {
                    break;
                }

                var match = Regex.Match(line, @"\[\+\] (\d*):");
                if (match.Success)
                {
                    migrations.Add(match.Groups[1].Value);
                }
            }

            return(migrations);
        }