string ServiceHostUriFor(ProcessSettings serviceHostProcessSettings) { lock (this) { var uriFile = UriFileFor(serviceHostProcessSettings.Executable); EnsureServiceHostProcessIsUp(uriFile, serviceHostProcessSettings); return FirstLineOf(uriFile); } }
void EnsureServiceHostProcessIsUp(IFile uriFile, ProcessSettings serviceHostProcessSettings) { if (!uriFile.TryToDelete()) { Logger.Log("server is already running"); return; } StartServiceHost(serviceHostProcessSettings); WaitFor(uriFile, TimeSpan.FromMilliseconds(200)); }
IObservableX<IObservableServiceClient> CreateClientFor(ProcessSettings serviceHostProcessSettings) { return ObservableX.CreateWithDisposable<IObservableServiceClient>(observer => { try { var serviceHostUri = ServiceHostUriFor(serviceHostProcessSettings); observer.CompleteWith(new ObservableServiceClient(serviceHostUri)); } catch (Exception e) { Logger.LogError(e); observer.OnError(e); } return Disposable.Empty; }); }
public IObservableX<IObservableServiceClient> ClientFor(ProcessSettings serviceHostProcessSettings) { return CreateClientFor(serviceHostProcessSettings).RetryEvery(TimeSpan.FromMilliseconds(500), 3); }
void StartServiceHost(ProcessSettings serviceHostProcessSettings) { Logger.Log("Starting {0}".Fmt(serviceHostProcessSettings.Executable)); using (Shell.StartManagedProcess(serviceHostProcessSettings)) { // this doesn't kill the actual process but // just releases any resources attached to // the object } }