public bool WaitForOtherInstance() { Timing t = Timing.Start(); while (t.Elapsed < TimeSpan.FromSeconds(20)) { try { string serverName = apiManagerService.GetCurrentInstanceServerName(); if (!ApiIpcClient.IsServerRegistered(serverName)) { Log.Debug("Other instance has closed"); return(true); } } catch (Exception e) { Log.Exception(e, "Failed to check if other instance is running"); } Thread.Sleep(100); } Log.Error("Failed to wait for other instance"); return(false); }
public bool TryActivateExistingInstance(string modelFilePath, string[] args) { try { string serverName = apiManagerService.GetCurrentInstanceServerName(modelFilePath); if (ApiIpcClient.IsServerRegistered(serverName)) { using (ApiIpcClient apiIpcClient = new ApiIpcClient(serverName)) { IDependinatorApi dependinatorApi = apiIpcClient.Service <IDependinatorApi>(); dependinatorApi.Activate(args); Log.Debug($"Call Activate on: {serverName}"); } return(true); } } catch (Exception e) { Log.Exception(e, "Failed to activate other instance"); } return(false); }
public void Test2() { TestApiService instanceService = new TestApiService(); string serverName = Guid.NewGuid().ToString(); using (ApiIpcServer apiIpcServer = new ApiIpcServer(serverName)) using (ApiIpcClient apiIpcClient = new ApiIpcClient(serverName)) { if (apiIpcServer.TryPublishService <ITestApiService>(instanceService)) { if (ApiIpcClient.IsServerRegistered(serverName)) { // Another instance for that working folder is already running, activate that. ITestApiService service = apiIpcClient.Service <ITestApiService>(); string doubleName = service.GetDoubleName("hej"); Assert.AreEqual("hejhej", doubleName); return; } } } Assert.Fail("Error"); }
public async Task OpenModelAsync(ModelPaths modelPaths) { string solutionFilePath = modelPaths.ModelPath; string serverName = ApiServerNames.ServerName <IVsExtensionApi>(solutionFilePath); Log.Debug($"Calling: {serverName}"); bool isStartedDependinator = false; Stopwatch t = Stopwatch.StartNew(); while (t.Elapsed < TimeSpan.FromSeconds(60)) { try { if (ApiIpcClient.IsServerRegistered(serverName)) { Log.Debug($"Server started after {t.Elapsed}: {serverName}"); if (!isStartedDependinator) { using (ApiIpcClient apiIpcClient = new ApiIpcClient(serverName)) { apiIpcClient.Service <IVsExtensionApi>().Activate(); } } return; } // IVsExtensionApi not yet registered, lets try to start Dependinator, or wait a little. if (!isStartedDependinator) { if (!await TryStartVisualStudioAsync(solutionFilePath)) { return; } isStartedDependinator = true; t.Restart(); await Task.Delay(1000); } else { await Task.Delay(500); } } catch (Exception e) { Log.Error($"Failed to check studio is running {e}"); } } Log.Error("Failed to wait for other Dependiator instance"); }
private async Task CallAsync <TRemoteService>(Action <TRemoteService> action) { string serverName = ApiServerNames.ServerName <TRemoteService>(solutionFilePath); Log.Debug($"Calling: {serverName}"); bool isStartedDependinator = false; Stopwatch t = Stopwatch.StartNew(); while (t.Elapsed < TimeSpan.FromSeconds(20)) { try { if (ApiIpcClient.IsServerRegistered(serverName)) { using (ApiIpcClient apiIpcClient = new ApiIpcClient(serverName)) { action(apiIpcClient.Service <TRemoteService>()); } return; } // DependinatorApi not yet registered, lets try to start Dependinator, or wait a little. if (!isStartedDependinator) { isStartedDependinator = true; StartDependinator(solutionFilePath); await Task.Delay(300); } else { await Task.Delay(100); } } catch (RemotingException e) { Log.Warn($"Call error, {e.Message}"); } catch (Exception e) { Log.Error($"Failed to check if Dependiator instance is running, {e}"); throw; } } Log.Error("Failed to wait for other Dependiator instance"); throw new Exception("Timeout while waiting for Dependiator to start."); }
private static bool TryOpenInVisualStudio(ModelPaths modelPaths, Source source) { string solutionPath = modelPaths.ModelPath; string serverName = ApiServerNames.ServerName <IVsExtensionApi>(solutionPath); if (!ApiIpcClient.IsServerRegistered(serverName)) { return(false); } using (ApiIpcClient apiIpcClient = new ApiIpcClient(serverName)) { apiIpcClient.Service <IVsExtensionApi>().ShowFile(source.Path, source.LineNumber); apiIpcClient.Service <IVsExtensionApi>().Activate(); } return(true); }
public async Task OpenFileAsync(ModelPaths modelPaths, string filePath, int lineNumber) { string solutionFilePath = modelPaths.ModelPath; string serverName = ApiServerNames.ServerName <IVsExtensionApi>(solutionFilePath); if (!ApiIpcClient.IsServerRegistered(serverName)) { await OpenModelAsync(modelPaths); } if (ApiIpcClient.IsServerRegistered(serverName)) { using (ApiIpcClient apiIpcClient = new ApiIpcClient(serverName)) { apiIpcClient.Service <IVsExtensionApi>().ShowFile(filePath, lineNumber); apiIpcClient.Service <IVsExtensionApi>().Activate(); } } }