public Redis(Action <IConfig> configuration = null) { if (configuration != null) { configuration(config); } executable = new TemporaryFile(typeof(RessourceTarget).Assembly.GetManifestResourceStream(typeof(RessourceTarget), "redis-server.exe"), "exe"); process.StartInfo = new ProcessStartInfo(" \"" + executable.Info.FullName + " \"") { UseShellExecute = false, Arguments = string.Format("--port {0} --bind 127.0.0.1 --persistence-available no", config.port), WindowStyle = ProcessWindowStyle.Maximized, CreateNoWindow = true, LoadUserProfile = false, RedirectStandardError = true, RedirectStandardOutput = true, StandardOutputEncoding = Encoding.ASCII, }; process.ErrorDataReceived += (sender, eventargs) => config.logger.Invoke(eventargs.Data); process.OutputDataReceived += (sender, eventargs) => config.logger.Invoke(eventargs.Data); process.OutputDataReceived += DetectServerReady; void ProcessExitedHandler(object sender, EventArgs eventargs) => throw new InvalidOperationException("The Redis process terminated unexpectedly."); process.EnableRaisingEvents = true; // The Exited event is only raised if this flag is set to `true` :) process.Exited += ProcessExitedHandler; process.Start(); process.BeginOutputReadLine(); process.BeginErrorReadLine(); WaitForRedisOrThrow(); process.Exited -= ProcessExitedHandler; process.OutputDataReceived -= DetectServerReady; }
public Redis(Action <IConfig> configuration = null) { configuration?.Invoke(config); executable = new TemporaryFile( GetType().GetTypeInfo().Assembly.GetManifestResourceStream("RedisInside.Executables.redis-server.exe"), config.Location, "exe"); var processStartInfo = new ProcessStartInfo(" \"" + executable.Info.FullName + " \"") { UseShellExecute = false, Arguments = $"--port {config.SelectedPort} --{config.Persistence}", CreateNoWindow = true, LoadUserProfile = false, RedirectStandardError = true, RedirectStandardOutput = true, StandardOutputEncoding = Encoding.ASCII }; Kill(); process = Process.Start(processStartInfo); process.ErrorDataReceived += (sender, args) => Log(args.Data); process.OutputDataReceived += (sender, args) => Log(args.Data); process.BeginOutputReadLine(); if (process.HasExited) { throw new Exception("Failed to start service"); } if (config.CheckStatus) { var result = CheckStatus().Result; } }
public Redis(Action<IConfig> configuration = null) { if (configuration != null) configuration(config); executable = new TemporaryFile(typeof(RessourceTarget).Assembly.GetManifestResourceStream(typeof(RessourceTarget), "redis-server.exe"), "exe"); var processStartInfo = new ProcessStartInfo(" \"" + executable.Info.FullName + " \"") { UseShellExecute = false, Arguments = string.Format("--port {0} --bind 127.0.0.1 --persistence-available no", config.port), WindowStyle = ProcessWindowStyle.Maximized, CreateNoWindow = true, LoadUserProfile = false, RedirectStandardError = true, RedirectStandardOutput = true, StandardOutputEncoding = Encoding.ASCII, }; process = Process.Start(processStartInfo); process.ErrorDataReceived += (sender, eventargs) => config.logger.Invoke(eventargs.Data); process.OutputDataReceived += (sender, eventargs) => config.logger.Invoke(eventargs.Data); process.BeginOutputReadLine(); }
public Redis(Action <IConfig> configuration = null) { configuration?.Invoke(config); string arguments = $"--port {config.port} --bind 127.0.0.1"; if (config.useExternalBinary) { var finder = IsLinux() ? "which" : "where"; var sp = Process.Start(new ProcessStartInfo(finder) { UseShellExecute = false, Arguments = "redis-server", WindowStyle = ProcessWindowStyle.Maximized, CreateNoWindow = true, LoadUserProfile = false, RedirectStandardError = true, RedirectStandardOutput = true, StandardOutputEncoding = Encoding.ASCII, }); if (sp == null) { throw new Exception("Could not start 'which redis-server' properly."); } sp.Start(); var externalPath = sp.StandardOutput.ReadToEnd().Trim(); sp.WaitForExit(); if (string.IsNullOrEmpty(externalPath)) { throw new Exception("Could not locate redis-server binary."); } if (!File.Exists(externalPath)) { throw new Exception($"Found invalid redis-server path (file does not exists or unreadable): {externalPath}"); } executable = new TemporaryFile(File.OpenRead(externalPath)); } else { executable = new TemporaryFile(typeof(RessourceTarget).Assembly.GetManifestResourceStream(typeof(RessourceTarget), "redis-server.exe"), "exe"); arguments += " --persistence-available no"; } var processStartInfo = new ProcessStartInfo(" \"" + executable.Info.FullName + " \"") { UseShellExecute = false, Arguments = arguments, WindowStyle = ProcessWindowStyle.Maximized, CreateNoWindow = true, LoadUserProfile = false, RedirectStandardError = true, RedirectStandardOutput = true, StandardOutputEncoding = Encoding.ASCII, }; process = Process.Start(processStartInfo); process.ErrorDataReceived += (sender, eventargs) => config.logger.Invoke(eventargs.Data); process.OutputDataReceived += (sender, eventargs) => config.logger.Invoke(eventargs.Data); process.BeginOutputReadLine(); }