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 virtual ICloudRunner GetCloudRunner()
        {
            if (_cloudRunner == null)
            {
                _cloudRunner = new CloudRunner(
                    GetSdkConfigFactory(),
                    new CredentialManager(new CredentialConfig.Factory(GetJsonUtil()),
                                          new VsiAccountOptionLoader(GetVsiService().Options)),
                    new CloudConnection(GetFileSystem(), new CloudConnection.ChannelFactory()),
                    new GgpSDKUtil());
            }

            return(_cloudRunner);
        }
Esempio n. 3
0
        public void SetUp()
        {
            sdkConfigFactory  = Substitute.For <SdkConfig.Factory>();
            credentialManager = Substitute.For <ICredentialManager>();
            cloudConnection   = Substitute.For <ICloudConnection>();
            funcToRun         = Substitute.For <GrpcProjectFunction>();
            // Since a channel doesn't initialize the connection until an API is called, and since
            // we don't call any APIs we can use a real channel object. Use an empty host - if
            // this behaviour changes in the future, the channel will fail to connect.
            var channel = new Channel("", ChannelCredentials.Insecure);

            cloudConnection.CreateChannel(Arg.Any <string>(), Arg.Any <string>()).Returns(channel);
            cloudRunner = new CloudRunner(sdkConfigFactory, credentialManager, cloudConnection,
                                          new GgpSDKUtil());
        }
        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);
        }
Esempio n. 5
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);
        }