Пример #1
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);
        }
Пример #2
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();
        }
Пример #3
0
        public void RecordWithDebugSessionId()
        {
            const string DebugSessionId1 = "abc123";
            const string DebugSessionId2 = "def456";

            metrics.NewDebugSessionId().Returns(DebugSessionId1);

            debugSessionMetrics.UseNewDebugSessionId();
            Assert.AreEqual(DebugSessionId1, debugSessionMetrics.DebugSessionId);
            debugSessionMetrics.RecordEvent(EventType, logEvent);
            logEvent.DebugSessionIdStr = DebugSessionId1;
            metrics.Received(1).RecordEvent(EventType, logEvent);

            metrics.ClearReceivedCalls();

            debugSessionMetrics.DebugSessionId = DebugSessionId2;
            debugSessionMetrics.RecordEvent(EventType, logEvent);
            logEvent.DebugSessionIdStr = DebugSessionId2;
            metrics.Received(1).RecordEvent(EventType, logEvent);
        }
Пример #4
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);
        }