private void DownloadCompilerAndLogIn() { try { Message = "Downloading DSL compiler..."; ChangeMessage(); Compiler.Stop(false); var result = ServerActions.DownloadZip("dsl-platform", "dsl-compiler.zip", Compiler.CompilerPath); if (result.Success) { var old = DslCompiler; DslCompiler = Path.Combine(Compiler.CompilerPath, "dsl-compiler.exe"); CheckCompiler(); oldDslCompiler = old; } else { Message = result.Error; } ChangeMessage(); } catch (Exception ex) { Message = ex.Message; ChangeMessage(); } }
private Either <string> DownloadLatestCompiler() { try { Message = "Downloading DSL compiler..."; ChangeMessage(); Compiler.Stop(false); var result = ServerActions.DownloadZip("dsl-platform", "dsl-compiler.zip", Compiler.CompilerPath); if (result.Success) { var newPath = Path.Combine(Compiler.CompilerPath, "dsl-compiler.exe"); var fi = new FileInfo(newPath); var asm = System.Reflection.AssemblyName.GetAssemblyName(newPath); CompilerInfo = "Compiler: " + asm.Version; oldDslCompiler = DslCompiler; Targets.CompilerPath = newPath; DslCompiler = newPath; ChangeProperty("CompilerInfo"); return(Either.Success(DslCompiler)); } return(Either <string> .Fail(result.Error)); } catch (Exception ex) { return(Either <string> .Fail(ex.Message)); } }
private void CompileDsl(bool confirmedPostgres, bool confirmedOracle) { TryAction( "Compiling DSL ...", () => ServerActions.Compile(DTE, Targets, PostgresDb, OracleDb, confirmedPostgres, confirmedOracle)) .ContinueWith(t => { if (t.Exception == null && !t.Result.Success && t.Result.Error.Contains("Objects in database will be removed")) { Message = "Confirm unsafe migration"; if (PostgresDb.CompileMigration && (CurrentStep & CompilationStep.ConfirmedPostgres) == 0) { CurrentStep = CompilationStep.PostgresConfirmation; DiffDatabase(ServerActions.PostgresDiff, PostgresDb, "Postgres"); } else { CurrentStep = CompilationStep.OracleConfirmation; DiffDatabase(ServerActions.OracleDiff, OracleDb, "Oracle"); } } else { CurrentStep = CompilationStep.Done; DbChanges = null; Message = t.Result.Error; ChangeMessage(); } }); }
public ToolPresenter() { PostgresDb = new DatabaseInfo("Postgres"); OracleDb = new DatabaseInfo("Oracle"); ExtractPostgresDsl = new RelayCommand( () => TryAction("Loading latest applied DSL ...", () => ServerActions.ExtractPostgresDsl(PostgresDb)).OnSuccess((path) => Process.Start(path)), () => PostgresDb.ConnectionStringDefined); ExtractOracleDsl = new RelayCommand( () => TryAction("Loading latest applied DSL ...", () => ServerActions.ExtractOracleDsl(OracleDb)).OnSuccess((path) => Process.Start(path)), () => OracleDb.ConnectionStringDefined); Compile = new RelayCommand(CompileAction, CanCompile); Parse = new RelayCommand( () => TryAction("Parsing DSL ...", () => ServerActions.Parse(DTE)).OnSuccess(m => { Message = m; ChangeMessage(); }), HasCompiler); PostgresDiff = new RelayCommand(() => CreateDiffAction(ServerActions.PostgresDiff, PostgresDb), () => PostgresDb.CanDiff); OracleDiff = new RelayCommand(() => CreateDiffAction(ServerActions.OracleDiff, OracleDb), () => OracleDb.CanDiff); DownloadLibrary = new RelayCommand(arg => DonwloadLibraryAction(arg as string), () => true); ChangeBuild = new RelayCommand(arg => ChangeBuildType(arg as string), () => true); ChangeTarget = new RelayCommand(arg => ChangePathAction(arg as string, i => i.TargetPath, (i, p) => i.Target = p), () => true); ChangeDependencies = new RelayCommand( arg => ChangePathAction( arg as string, i => i.DependenciesPath, (i, p) => i.Dependencies = p), () => true); ChangePostgresSqlScripts = new RelayCommand(() => ChangeSqlPath(PostgresDb)); ChangeOracleSqlScripts = new RelayCommand(() => ChangeSqlPath(OracleDb)); ConfigurePoco = new RelayCommand(() => OpenConfigurationAction(new ConfigurationPocoControl())); ConfigureClient = new RelayCommand(() => OpenConfigurationAction(new ConfigurationClientControl())); ConfigurePortable = new RelayCommand(() => OpenConfigurationAction(new ConfigurationPortableControl())); ConfigurePhp = new RelayCommand(() => OpenConfigurationAction(new ConfigurationPhpControl())); ConfigureTypescript = new RelayCommand(() => OpenConfigurationAction(new ConfigurationTypescriptControl())); ConfigureWpf = new RelayCommand(() => OpenConfigurationAction(new ConfigurationWpfControl())); ConfigurePostgres = new RelayCommand(() => OpenConfigurationAction(new ConfigurationPostgresControl())); ConfigureOracle = new RelayCommand(() => OpenConfigurationAction(new ConfigurationOracleControl())); BackToStatus = new RelayCommand(GoBackAction); ConfirmDiff = new RelayCommand(StepThroughCompilation, CanCompile); DownloadCompiler = new RelayCommand( () => TryAction("Downloading DSL compiler...", () => DownloadLatestCompiler())); ConfirmVisibility = Visibility.Collapsed; ResetConfiguration(); SyntaxParser.Parsed += SyntaxParser_Parsed; }
private void DonwloadLibraryAction(string arg) { var splt = arg.Split(':'); var lib = Targets.ChooseLibrary(splt[0]); if (!lib.Success) { Message = lib.Error; ChangeMessage(); return; } var info = lib.Value; if (string.IsNullOrWhiteSpace(info.Dependencies)) { Message = "Dependency folder not specified. Please specify " + info.Name + " dependency folder"; } else { if (!info.DependenciesExists) { Directory.CreateDirectory(info.DependenciesPath); } TryAction("Downloading library...", () => ServerActions.DownloadZip(splt[1], splt[splt.Length - 1], info.DependenciesPath)) .OnSuccess(ef => { Message = "Library downloaded"; if (!ef) { Message += ". Extra files found in library folder."; System.Diagnostics.Process.Start(info.DependenciesPath); } ChangeMessage(); }); } ChangeMessage(); }
public static string GenerateAssembly( string assemblyPath, string[] sources, IEnumerable <string> references, int retries = 3) { var folder = Path.GetDirectoryName(assemblyPath); if (!Directory.Exists(folder)) { Directory.CreateDirectory(folder); } var parameters = new CompilerParameters(); parameters.GenerateExecutable = false; foreach (var r in references) { parameters.ReferencedAssemblies.Add(r); } parameters.GenerateInMemory = false; parameters.OutputAssembly = assemblyPath; parameters.IncludeDebugInformation = false; if (sources.Length == 0) { AppDomain.CurrentDomain.DefineDynamicAssembly( new AssemblyName(Path.GetFileNameWithoutExtension(assemblyPath)), AssemblyBuilderAccess.RunAndSave); return(parameters.OutputAssembly); } using (var provider = new CSharpCodeProvider()) { CompilerResults result = null; do { try { result = provider.CompileAssemblyFromSource(parameters, sources); } catch { retries--; if (retries < 0) { throw; } ServerActions.DeleteFile(assemblyPath); } } while (result == null); if (result.Errors.HasErrors) { var errors = string.Join( Environment.NewLine, (from CompilerError err in result.Errors where !err.IsWarning select err.ErrorText).Take(5)); throw new ApplicationException(@"Error during compilation: " + errors); } return(parameters.OutputAssembly); } }