Beispiel #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()));
            }
        }
Beispiel #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);
        }
Beispiel #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);
        }