Exemplo n.º 1
0
        private static Either <T> CompileDsl <T>(string args, Func <ChunkedMemoryStream, T> extract)
        {
            var process =
                new System.Diagnostics.Process
            {
                StartInfo = new ProcessStartInfo(DslCompiler, args)
                {
                    CreateNoWindow         = true,
                    WindowStyle            = ProcessWindowStyle.Hidden,
                    RedirectStandardOutput = true,
                    UseShellExecute        = false,
                    WorkingDirectory       = LibraryInfo.BasePath
                }
            };

            process.Start();
            var cms = new ChunkedMemoryStream();

            process.StandardOutput.BaseStream.CopyTo(cms);
            process.WaitForExit();
            cms.Position = 0;
            if (process.ExitCode == 0)
            {
                return(Either.Success(extract(cms)));
            }
            else
            {
                return(Either <T> .Fail(new StreamReader(cms).ReadToEnd()));
            }
        }
Exemplo n.º 2
0
        private static Stream Serialize <T>(T value)
        {
            var ser = new DataContractSerializer(typeof(T));
            var ms  = new ChunkedMemoryStream();

            ser.WriteObject(ms, value);
            ms.Position = 0;
            return(ms);
        }
Exemplo n.º 3
0
        private static string ProcessMigrationStream(
            bool force,
            ChunkedMemoryStream stream,
            DatabaseInfo dbInfo,
            Action <ChunkedMemoryStream, bool, DatabaseInfo> applyMigration)
        {
            var customPath = dbInfo.SqlScriptsPathExists;
            var sqlPath    = customPath
                                ? Path.Combine(LibraryInfo.BasePath, dbInfo.SqlScriptsPath)
                                : Compiler.TempPath;
            var name = dbInfo.Name + "-Migration-" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".sql";

            if (dbInfo.ApplyMigration && applyMigration != null)
            {
                try
                {
                    applyMigration(stream, force, dbInfo);
                    if (customPath)
                    {
                        SaveStreamToFile(sqlPath, "Applied-" + name, stream);
                    }
                }
                catch
                {
                    if (customPath)
                    {
                        SaveStreamToFile(sqlPath, "Failed-" + name, stream);
                    }
                    throw;
                }
            }
            else
            {
                SaveStreamToFile(sqlPath, name, stream);
                System.Diagnostics.Process.Start(sqlPath);
            }
            return(Compiler.TempPath);
        }