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");
        }
Beispiel #2
0
        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();
                }
            }
        }
 public string GetCurrentInstanceServerName() =>
 ApiServerNames.ServerName <IDependinatorApi>(modelMetadataService.ModelFilePath);
 public string GetCurrentInstanceServerName(string modelFilePath) =>
 ApiServerNames.ServerName <IDependinatorApi>(modelFilePath);
Beispiel #7
0
 private static string GetServerName(string solutionFilePath) =>
 ApiServerNames.ServerName <IVsExtensionApi>(solutionFilePath);