// Constructor for tests.
 public GgpDebugQueryTarget(IFileSystem fileSystem, SdkConfig.Factory sdkConfigFactory,
                            IGameletClientFactory gameletClientFactory,
                            IApplicationClientFactory applicationClientFactory,
                            CancelableTask.Factory cancelableTaskFactory,
                            IDialogUtil dialogUtil, IRemoteDeploy remoteDeploy,
                            DebugSessionMetrics metrics,
                            ICredentialManager credentialManager,
                            ITestAccountClientFactory testAccountClientFactory,
                            IGameletSelectorFactory gameletSelectorFactory,
                            ICloudRunner cloudRunner, Versions.SdkVersion sdkVersion,
                            ChromeClientLaunchCommandFormatter launchCommandFormatter,
                            DebugEngine.DebugEngine.Params.Factory paramsFactory,
                            IYetiVSIService yetiVsiService, IGameLauncher gameLauncher)
 {
     _fileSystem               = fileSystem;
     _sdkConfigFactory         = sdkConfigFactory;
     _gameletClientFactory     = gameletClientFactory;
     _applicationClientFactory = applicationClientFactory;
     _cancelableTaskFactory    = cancelableTaskFactory;
     _dialogUtil               = dialogUtil;
     _remoteDeploy             = remoteDeploy;
     _metrics                  = metrics;
     _credentialManager        = credentialManager;
     _testAccountClientFactory = testAccountClientFactory;
     _cloudRunner              = cloudRunner;
     _yetiVsiService           = yetiVsiService;
     _gameletSelectorFactory   = gameletSelectorFactory;
     _sdkVersion               = sdkVersion;
     _launchCommandFormatter   = launchCommandFormatter;
     _paramsFactory            = paramsFactory;
     _gameLauncher             = gameLauncher;
 }
        public virtual GgpDebugQueryTarget Create()
        {
            // Factory creation for the YetiGameletDebugger entry point.
            var taskContext = _serviceManager.GetJoinableTaskContext();

            taskContext.ThrowIfNotOnMainThread();
            var fileSystem       = new FileSystem();
            var jsonUtil         = new JsonUtil();
            var sdkConfigFactory = new SdkConfig.Factory(jsonUtil);
            var yetiVsiService   =
                (YetiVSIService)_serviceManager.GetGlobalService(typeof(YetiVSIService));
            var options                 = yetiVsiService.Options;
            var accountOptionLoader     = new VsiAccountOptionLoader(options);
            var credentialConfigFactory = new CredentialConfig.Factory(jsonUtil);
            var credentialManager       =
                new CredentialManager(credentialConfigFactory, accountOptionLoader);
            var cloudConnection = new CloudConnection();
            // NOTE: this CloudRunner is re-used for all subsequent debug sessions.
            var cloudRunner = new CloudRunner(sdkConfigFactory, credentialManager, cloudConnection,
                                              new GgpSDKUtil());
            var applicationClientFactory = GetApplicationClientFactory();
            var gameletClientFactory     = GetGameletClientFactory();
            var testAccountClientFactory = GetTestAccountClientFactory();
            var managedProcessFactory    = new ManagedProcess.Factory();
            var remoteCommand            = GetRemoteCommand(managedProcessFactory);
            var remoteFile   = new RemoteFile(managedProcessFactory);
            var remoteDeploy = new RemoteDeploy(remoteCommand, remoteFile, managedProcessFactory,
                                                fileSystem);
            var metrics               = _serviceManager.GetGlobalService(typeof(SMetrics)) as IMetrics;
            var sdkVersion            = GetSdkVersion();
            var sshManager            = GetSshManager(managedProcessFactory, cloudRunner);
            var launchParamsConverter =
                new LaunchGameParamsConverter(sdkConfigFactory, new QueryParametersParser());
            var debugSessionMetrics = new DebugSessionMetrics(metrics);
            var actionRecorder      = new ActionRecorder(debugSessionMetrics);
            var gameLaunchManager   = new GameLaunchBeHelper(gameletClientFactory.Create(cloudRunner),
                                                             launchParamsConverter);
            var vsiLaunchFactory = new VsiGameLaunchFactory(
                gameletClientFactory.Create(cloudRunner), GetCancelableTaskFactory(),
                gameLaunchManager, actionRecorder, _dialogUtil);
            var gameLauncher = new GameLauncher(gameletClientFactory.Create(cloudRunner),
                                                yetiVsiService, launchParamsConverter,
                                                GetCancelableTaskFactory(), actionRecorder,
                                                _dialogUtil, vsiLaunchFactory);
            var gameletSelectorFactory = new GameletSelectorFactory(
                _dialogUtil, cloudRunner, GetGameletSelectorWindowFactory(),
                GetCancelableTaskFactory(), gameletClientFactory, sshManager, remoteCommand,
                gameLaunchManager, taskContext);
            var serializer             = new JsonUtil();
            var launchCommandFormatter = new ChromeClientLaunchCommandFormatter(serializer);
            var paramsFactory          = new DebugEngine.DebugEngine.Params.Factory(serializer);

            return(new GgpDebugQueryTarget(fileSystem, sdkConfigFactory, gameletClientFactory,
                                           applicationClientFactory, GetCancelableTaskFactory(),
                                           _dialogUtil, remoteDeploy, debugSessionMetrics,
                                           credentialManager, testAccountClientFactory,
                                           gameletSelectorFactory, cloudRunner, sdkVersion,
                                           launchCommandFormatter, paramsFactory, yetiVsiService,
                                           gameLauncher));
        }
        public DebugSessionMetrics GetDebugSessionMetrics()
        {
            if (_debugSessionMetrics == null)
            {
                _debugSessionMetrics = new DebugSessionMetrics(
                    CreateServiceManager().GetGlobalService(typeof(SMetrics)) as IMetrics);
            }

            return(_debugSessionMetrics);
        }
Example #4
0
        public void SetUp()
        {
            logEvent = new DeveloperLogEvent
            {
                StatusCode          = DeveloperEventStatus.Types.Code.Success,
                LatencyMilliseconds = ElapsedMilliseconds,
                LatencyType         = DeveloperLogEvent.Types.LatencyType.LatencyTool
            };

            metrics             = Substitute.For <IMetrics>();
            debugSessionMetrics = new DebugSessionMetrics(metrics);
        }
Example #5
0
        public int EnumPorts(out IEnumDebugPorts2 portsEnum)
        {
            var debugSessionMetrics = new DebugSessionMetrics(_metrics);

            debugSessionMetrics.UseNewDebugSessionId();
            var actionRecorder = new ActionRecorder(debugSessionMetrics);

            var action        = actionRecorder.CreateToolAction(ActionType.GameletsList);
            var gameletClient = _gameletClientFactory.Create(_cloudRunner.Intercept(action));
            var gameletsTask  = _cancelableTaskFactory.Create(
                "Querying instances...", () => gameletClient.ListGameletsAsync(onlyOwned: false));

            try
            {
                gameletsTask.RunAndRecord(action);
                List <Gamelet> gamelets = gameletsTask.Result;
                // show reserved instances first
                gamelets.Sort((g1, g2) =>
                {
                    if (g1.ReserverEmail != _developerAccount &&
                        g2.ReserverEmail != _developerAccount)
                    {
                        return(string.CompareOrdinal(g2.ReserverEmail, g1.ReserverEmail));
                    }

                    if (g1.ReserverEmail == _developerAccount &&
                        g2.ReserverEmail == _developerAccount)
                    {
                        return(string.CompareOrdinal(g2.DisplayName, g1.DisplayName));
                    }

                    return(g1.ReserverEmail == _developerAccount ? 1 : -1);
                });
                _ports = gamelets
                         .Select(gamelet => _debugPortFactory.Create(
                                     gamelet, this, debugSessionMetrics.DebugSessionId))
                         .ToList();
            }
            catch (CloudException e)
            {
                Trace.WriteLine(e.ToString());
                _dialogUtil.ShowError(e.Message);
                _ports.Clear();
            }

            portsEnum = new PortsEnum(_ports.ToArray());
            return(VSConstants.S_OK);
        }
Example #6
0
        public CoreAttachWindow(IServiceProvider serviceProvider)
        {
            var serviceManager = new ServiceManager();

            _taskContext = serviceManager.GetJoinableTaskContext();

            _dialogUtil = new DialogUtil();
            IExtensionOptions options =
                ((YetiVSIService)serviceManager.RequireGlobalService(typeof(YetiVSIService)))
                .Options;
            var managedProcessFactory = new ManagedProcess.Factory();
            var progressDialogFactory = new ProgressDialog.Factory();

            _cancelableTaskFactory =
                new CancelableTask.Factory(_taskContext, progressDialogFactory);
            _coreListRequest = new CoreListRequest.Factory().Create();
            var jsonUtil = new JsonUtil();
            var credentialConfigFactory = new CredentialConfig.Factory(jsonUtil);
            var accountOptionLoader     = new VsiAccountOptionLoader(options);
            var credentialManager       =
                new CredentialManager(credentialConfigFactory, accountOptionLoader);

            _developerAccount = credentialManager.LoadAccount();
            IRemoteCommand remoteCommand = new RemoteCommand(managedProcessFactory);

            _remoteFile = new RemoteFile(managedProcessFactory);
            var cloudConnection  = new CloudConnection();
            var sdkConfigFactory = new SdkConfig.Factory(jsonUtil);

            // NOTE: the lifetime of this CloudRunner is limited to the current CoreAttachWindow.
            _cloudRunner = new CloudRunner(sdkConfigFactory, credentialManager, cloudConnection,
                                           new GgpSDKUtil());
            _gameletClientFactory = new GameletClient.Factory();
            var sshKeyLoader        = new SshKeyLoader(managedProcessFactory);
            var sshKnownHostsWriter = new SshKnownHostsWriter();

            _sshManager = new SshManager(_gameletClientFactory, _cloudRunner, sshKeyLoader,
                                         sshKnownHostsWriter, remoteCommand);
            _debugSessionMetrics = new DebugSessionMetrics(
                serviceProvider.GetService(typeof(SMetrics)) as IMetrics);
            _debugSessionMetrics.UseNewDebugSessionId();
            _actionRecorder = new ActionRecorder(_debugSessionMetrics);

            InitializeComponent();
            _instanceSelectionWindowFactory = new ProjectInstanceSelection.Factory();
            _paramsFactory = new DebugEngine.DebugEngine.Params.Factory(jsonUtil);
            SelectInstanceOnInit();
        }
        public virtual List <IInterceptor> CreateApiAspects()
        {
            DebuggerOptions.DebuggerOptions debuggerOptions     = GetVsiService().DebuggerOptions;
            DebugSessionMetrics             debugSessionMetrics = GetDebugSessionMetrics();

            // Creates aspects for tracing, exception handling and metrics.
            // Additionally, it creates gRPC interceptors for use in the DebugTransport.
            var apiAspects = new List <IInterceptor>();

            // It is important that this aspect be added as the first aspect so that it is the
            // outer most decorator.
            if (debuggerOptions[DebuggerOption.EXCEPTION_LOGGING] == DebuggerOptionState.ENABLED)
            {
                apiAspects.Add(new LogExceptionAspect());
            }

            if (debuggerOptions[DebuggerOption.EXCEPTION_METRICS] == DebuggerOptionState.ENABLED)
            {
                apiAspects.Add(
                    new ExceptionRecorderAspect(new ExceptionRecorder(debugSessionMetrics)));
            }

            if (debuggerOptions[DebuggerOption.DEBUGGER_TRACING] == DebuggerOptionState.ENABLED)
            {
                SetupDebuggerTracing(apiAspects);
            }

            if (debuggerOptions[DebuggerOption.CALL_SEQUENCE_LOGGING] ==
                DebuggerOptionState.ENABLED)
            {
                SetupCallSequenceLogging(apiAspects);
            }

            if (debuggerOptions[DebuggerOption.PARAMETER_LOGGING] == DebuggerOptionState.ENABLED)
            {
                apiAspects.Add(new InvocationLoggerAspect(new InvocationLogUtil()));
            }

            if (debuggerOptions[DebuggerOption.STEP_TIME_METRICS] == DebuggerOptionState.ENABLED)
            {
                SetupStepTimeMetrics(apiAspects, debugSessionMetrics);
            }

            return(apiAspects);
        }
Example #8
0
 DebugPort(DebugProcess.Factory debugProcessFactory,
           ProcessListRequest.Factory processListRequestFactory,
           CancelableTask.Factory cancelableTaskFactory, IDialogUtil dialogUtil,
           ISshManager sshManager, IMetrics metrics, Gamelet gamelet,
           IDebugPortSupplier2 supplier, string debugSessionId, string developerAccount)
 {
     _debugProcessFactory       = debugProcessFactory;
     _processListRequestFactory = processListRequestFactory;
     _dialogUtil            = dialogUtil;
     _guid                  = Guid.NewGuid();
     _supplier              = supplier;
     _developerAccount      = developerAccount;
     _cancelableTaskFactory = cancelableTaskFactory;
     _sshManager            = sshManager;
     _debugSessionMetrics   = new DebugSessionMetrics(metrics);
     _debugSessionMetrics.DebugSessionId = debugSessionId;
     _actionRecorder = new ActionRecorder(_debugSessionMetrics);
     Gamelet         = gamelet;
 }
Example #9
0
        public int AddPort(IDebugPortRequest2 request, out IDebugPort2 port)
        {
            var debugSessionMetrics = new DebugSessionMetrics(_metrics);

            debugSessionMetrics.UseNewDebugSessionId();
            var actionRecorder = new ActionRecorder(debugSessionMetrics);

            port = null;

            if (request.GetPortName(out string gameletIdOrName) != VSConstants.S_OK)
            {
                return(VSConstants.E_FAIL);
            }

            var action        = actionRecorder.CreateToolAction(ActionType.GameletGet);
            var gameletClient = _gameletClientFactory.Create(_cloudRunner.Intercept(action));
            var gameletTask   = _cancelableTaskFactory.Create(
                "Querying instance...",
                async() => await gameletClient.LoadByNameOrIdAsync(gameletIdOrName));

            try
            {
                gameletTask.RunAndRecord(action);
            }
            catch (CloudException e)
            {
                Trace.WriteLine(e.ToString());
                _dialogUtil.ShowError(e.Message);
                return(VSConstants.S_OK);
            }

            var debugPort = _debugPortFactory.Create(gameletTask.Result, this,
                                                     debugSessionMetrics.DebugSessionId);

            _ports.Add(debugPort);
            port = debugPort;
            return(VSConstants.S_OK);
        }
        public void SetUp()
        {
            _gamelet1 = new Gamelet
            {
                Id     = "test_gamelet1",
                Name   = "test_gamelet_name1",
                IpAddr = "1.2.3.4",
                State  = GameletState.Reserved,
            };

            _gamelet2 = new Gamelet
            {
                Id     = "test_gamelet2",
                Name   = "test_gamelet_name2",
                IpAddr = "1.2.3.5",
                State  = GameletState.Reserved,
            };

            _metrics = Substitute.For <IMetrics>();
            _metrics.NewDebugSessionId().Returns(_testDebugSessionId);

            _dialogUtil = Substitute.For <IDialogUtil>();

            var sdkConfigFactory = Substitute.For <SdkConfig.Factory>();
            var sdkConfig        = new SdkConfig();

            sdkConfigFactory.LoadOrDefault().Returns(sdkConfig);

            var credentialManager = Substitute.For <YetiCommon.ICredentialManager>();

            credentialManager.LoadAccount().Returns(_testAccount);

            _instanceSelectionWindow = Substitute.For <IInstanceSelectionWindow>();
            var gameletSelectionWindowFactory = Substitute.For <InstanceSelectionWindow.Factory>();

            gameletSelectionWindowFactory.Create(Arg.Any <List <Gamelet> >())
            .Returns(_instanceSelectionWindow);

            var cloudRunner = new CloudRunner(sdkConfigFactory, credentialManager,
                                              new CloudConnection(), new GgpSDKUtil());

            CancelableTask.Factory cancelableTaskFactory =
                FakeCancelableTask.CreateFactory(new JoinableTaskContext(), false);

            _gameletClient = Substitute.For <IGameletClient>();
            var gameletClientFactory = Substitute.For <GameletClient.Factory>();

            gameletClientFactory.Create(Arg.Any <ICloudRunner>()).Returns(_gameletClient);

            _sshManager = Substitute.For <ISshManager>();

            _sshManager.EnableSshAsync(_gamelet1, Arg.Any <IAction>())
            .Returns(Task.FromResult(true));
            _sshManager.EnableSshAsync(_gamelet2, Arg.Any <IAction>())
            .Returns(Task.FromResult(true));

            _remoteCommand = Substitute.For <IRemoteCommand>();

            var debugSessionMetrics = new DebugSessionMetrics(_metrics);

            debugSessionMetrics.UseNewDebugSessionId();
            _actionRecorder = new ActionRecorder(debugSessionMetrics);

            _gameletSelector = new GameletSelectorLegacyFlow(_dialogUtil, cloudRunner,
                                                             gameletSelectionWindowFactory,
                                                             cancelableTaskFactory,
                                                             gameletClientFactory, _sshManager,
                                                             _remoteCommand, _actionRecorder);
        }
Example #11
0
        public void SetUp()
        {
            _targetPath = "/any/old/target/path";
            var fileSystem = new MockFileSystem();

            fileSystem.AddFile(_targetPath, new MockFileData(""));

            _outputDirectory = Path.GetTempPath();

            _project = Substitute.For <IAsyncProject>();
            _project.GetTargetPathAsync().Returns(_targetPath);
            _project.GetTargetDirectoryAsync().Returns(Path.GetDirectoryName(_targetPath));
            _project.GetTargetFileNameAsync().Returns(Path.GetFileName(_targetPath));
            _project.GetOutputDirectoryAsync().Returns(_outputDirectory);
            _project.GetAbsoluteRootPathAsync().Returns(_testProjectDir);
            _project.GetApplicationAsync().Returns(_testApplicationName);
            _project.GetQueryParamsAsync().Returns(_customQueryParams);

            var sdkConfigFactory = Substitute.For <SdkConfig.Factory>();
            var sdkConfig        = new SdkConfig();

            sdkConfig.OrganizationId = _testOrganizationId;
            sdkConfig.ProjectId      = _testProjectId;
            sdkConfigFactory.LoadOrDefault().Returns(sdkConfig);

            _gameletClient = Substitute.For <IGameletClient>();
            var gameletClientFactory = Substitute.For <GameletClient.Factory>();

            gameletClientFactory.Create(Arg.Any <ICloudRunner>()).Returns(_gameletClient);

            var remoteCommand = Substitute.For <IRemoteCommand>();

            _remoteDeploy = Substitute.For <IRemoteDeploy>();
            _dialogUtil   = Substitute.For <IDialogUtil>();

            var credentialManager = Substitute.For <YetiCommon.ICredentialManager>();

            credentialManager.LoadAccount().Returns(_testAccount);

            var cancelableTaskFactory =
                FakeCancelableTask.CreateFactory(new JoinableTaskContext(), false);

            _applicationClient = Substitute.For <IApplicationClient>();
            var application = new Application
            {
                Id = _testApplicationId, Name = _testApplicationName
            };

            _applicationClient.LoadByNameOrIdAsync(_testApplicationName)
            .Returns(Task.FromResult(application));
            var applicationClientFactory = Substitute.For <ApplicationClient.Factory>();

            applicationClientFactory.Create(Arg.Any <ICloudRunner>()).Returns(_applicationClient);

            _testAccountClientFactory = Substitute.For <TestAccountClient.Factory>();
            var testAccount = new TestAccount()
            {
                Name = $"organizations/{_testOrganizationId}" +
                       $"/projects/{_testProjectId}/testAccounts/{_testTestAccountId}"
            };
            var testAccountClient = Substitute.For <ITestAccountClient>();

            testAccountClient
            .LoadByIdOrGamerTagAsync(_testOrganizationId, _testProjectId, _testTestAccountId)
            .Returns(new List <TestAccount> {
                testAccount
            });
            _testAccountClientFactory.Create(Arg.Any <ICloudRunner>()).Returns(testAccountClient);

            Substitute.For <IExtensionOptions>();

            _yetiVsiService = Substitute.For <IYetiVSIService>();
            var options         = Substitute.For <IExtensionOptions>();
            var debuggerOptions = new YetiVSI.DebuggerOptions.DebuggerOptions();

            _yetiVsiService.DebuggerOptions.Returns(debuggerOptions);
            options.LaunchGameApiFlow.Returns(LaunchGameApiFlow.DISABLED);
            _yetiVsiService.Options.Returns(options);
            _metrics = Substitute.For <IMetrics>();
            _metrics.NewDebugSessionId().Returns(_testDebugSessionId);
            var debugMetrics = new DebugSessionMetrics(_metrics);
            var cloudRunner  = new CloudRunner(sdkConfigFactory, credentialManager,
                                               new CloudConnection(), new GgpSDKUtil());

            _gameletSelector        = Substitute.For <IGameletSelector>();
            _gameletSelectorFactory = Substitute.For <IGameletSelectorFactory>();
            _gameletSelectorFactory.Create(Arg.Any <bool>(), Arg.Any <ActionRecorder>())
            .Returns(_gameletSelector);
            var serializer = new JsonUtil();

            _launchCommandFormatter = new ChromeClientLaunchCommandFormatter(serializer);
            _paramsFactory          = new YetiVSI.DebugEngine.DebugEngine.Params.Factory(serializer);

            _gameLauncher = Substitute.For <IGameLauncher>();
            _gameLauncher.LaunchGameApiEnabled.Returns(false);
            _gameLaunch = Substitute.For <IVsiGameLaunch>();
            _gameLaunch.LaunchName.Returns("launch_name");
            _ggpDebugQueryTarget = new GgpDebugQueryTarget(fileSystem, sdkConfigFactory,
                                                           gameletClientFactory,
                                                           applicationClientFactory,
                                                           cancelableTaskFactory, _dialogUtil,
                                                           _remoteDeploy, debugMetrics,
                                                           credentialManager,
                                                           _testAccountClientFactory,
                                                           _gameletSelectorFactory, cloudRunner,
                                                           _sdkVersion, _launchCommandFormatter,
                                                           _paramsFactory, _yetiVsiService,
                                                           _gameLauncher);
        }