/// <summary>
        /// Initializes the singleton instance of the command.
        /// </summary>
        /// <param name="package">Owner package, not null.</param>
        /// <param name="token"></param>
        public static async Task InitializeAsync(IGoogleCloudExtensionPackage package, CancellationToken token)
        {
            if (package == null)
            {
                throw new ArgumentNullException(nameof(package));
            }

            if (await package.GetServiceAsync(typeof(IMenuCommandService)) is OleMenuCommandService commandService)
            {
                await package.JoinableTaskFactory.SwitchToMainThreadAsync(token);

                var menuCommandID = new CommandID(CommandSet, CommandId);
                var menuItem      = new OleMenuCommand(OnDeployCommand, menuCommandID);
                menuItem.BeforeQueryStatus += OnBeforeQueryStatus;
                commandService.AddCommand(menuItem);
            }

            // <summary>
            // This function is the callback used to execute the command when the menu item is clicked.
            // See the constructor to see how the menu item is associated with this function using
            // OleMenuCommandService service and MenuCommand class.
            // </summary>
            // <param name="sender">Event sender.</param>
            // <param name="e">Event args.</param>
            async void OnDeployCommand(object sender, EventArgs e)
            {
                await GoogleCloudExtensionPackage.Instance.JoinableTaskFactory.SwitchToMainThreadAsync();

                IParsedDteProject project = SolutionHelper.CurrentSolution.StartupProject.ParsedProject;

                PublishDialogWindow.PromptUser(project);
            }

            void OnBeforeQueryStatus(object sender, EventArgs e)
            {
#pragma warning disable VSTHRD109 // Switch instead of assert in async methods
                ThreadHelper.ThrowIfNotOnUIThread();
#pragma warning restore VSTHRD109 // Switch instead of assert in async methods
                if (!(sender is OleMenuCommand menuCommand))
                {
                    return;
                }

                menuCommand.Visible = true;

                IParsedDteProject startupProject = SolutionHelper.CurrentSolution.StartupProject?.ParsedProject;
                if (startupProject == null)
                {
                    menuCommand.Enabled = false;
                    menuCommand.Text    = Resources.PublishDialogGenericMenuHeader;
                }
                else
                {
                    menuCommand.Enabled =
                        PublishDialogWindow.CanPublish(startupProject) && !ShellUtils.Default.IsBusy();
                    menuCommand.Text = string.Format(Resources.PublishDialogProjectMenuHeader, startupProject.Name);
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Initializes a new instance of <seealso cref="ErrorReportingDetailViewModel"/> class.
        /// </summary>
        public ErrorReportingDetailViewModel()
        {
            _package                = GoogleCloudExtensionPackage.Instance;
            IsVisibleUnbound        = true;
            OnGotoSourceCommand     = new ProtectedCommand <StackFrame>(frame => ErrorFrameToSourceLine(GroupItem, frame));
            OnBackToOverViewCommand = new ProtectedAsyncCommand(async() => await ShowErrorReportingToolWindow());
            OnAutoReloadCommand     = new ProtectedCommand(() => ErrorHandlerUtils.HandleExceptionsAsync(UpdateGroupAndEventAsync));
            _datasource             = new Lazy <IStackdriverErrorReportingDataSource>(CreateDataSource);

            CredentialsStore.Default.CurrentProjectIdChanged += OnCurrentProjectChanged;
        }
        /// <summary>
        /// Create a new instance of <seealso cref="ErrorReportingViewModel"/> class.
        /// </summary>
        public ErrorReportingViewModel()
        {
            IsVisibleUnbound      = true;
            _package              = GoogleCloudExtensionPackage.Instance;
            _dataSourceLazy       = new Lazy <IStackdriverErrorReportingDataSource>(CreateDataSource);
            _groupStatsCollection = new ObservableCollection <ErrorGroupItem>();
            GroupStatsView        = new ListCollectionView(_groupStatsCollection);
            SelectedTimeRangeItem = TimeRangeItemList.Last();
            OnGotoDetailCommand   = new ProtectedAsyncCommand <ErrorGroupItem>(NavigateToDetailWindowAsync);
            OnAutoReloadCommand   = new ProtectedCommand(Reload);

            CredentialsStore.Default.CurrentProjectIdChanged += (sender, e) => OnProjectIdChanged();
        }
Esempio n. 4
0
        /// <summary>
        /// Ensures that the opt-in dialog is shown to the user.
        /// </summary>
        public static void EnsureAnalyticsOptIn()
        {
            IGoogleCloudExtensionPackage package  = GoogleCloudExtensionPackage.Instance;
            AnalyticsOptions             settings = package.GeneralSettings;

            if (!settings.DialogShown)
            {
                Debug.WriteLine("Showing the opt-in dialog.");
                settings.OptIn       = package.UserPromptService.PromptUser(new AnalyticsOptInWindowContent());
                settings.DialogShown = true;
                settings.SaveSettingsToStorage();
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Initializes the singleton instance of the command.
        /// </summary>
        /// <param name="package">Owner package, not null.</param>
        /// <param name="token"></param>
        public static async Task InitializeAsync(IGoogleCloudExtensionPackage package, CancellationToken token)
        {
            package.ThrowIfNull(nameof(package));

            if (await package.GetServiceAsync(typeof(IMenuCommandService)) is IMenuCommandService commandService)
            {
                await package.JoinableTaskFactory.SwitchToMainThreadAsync(token);

                var menuCommandID = new CommandID(CommandSet, CommandId);
                var menuItem      = new OleMenuCommand(OnGenerateConfiguration, menuCommandID);
                menuItem.BeforeQueryStatus += OnBeforeQueryStatus;
                commandService.AddCommand(menuItem);
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Initializes the singleton instance of the command.
        /// </summary>
        /// <param name="package">Owner package, not null.</param>
        /// <param name="token">The token to cancel adding the command.</param>
        public static async Task InitializeAsync(IGoogleCloudExtensionPackage package, CancellationToken token)
        {
            package.ThrowIfNull(nameof(package));

            if (await package.GetServiceAsync(typeof(IMenuCommandService)) is IMenuCommandService commandService)
            {
                await package.JoinableTaskFactory.SwitchToMainThreadAsync(token);

                var menuItem = new OleMenuCommand(
                    (sender, e) => package.JoinableTaskFactory.Run(ToolWindowCommandUtils.AddToolWindowAsync <LogsViewerToolWindow>),
                    MenuCommandID);
                menuItem.BeforeQueryStatus += ToolWindowCommandUtils.EnableMenuItemOnValidProjectId;
                commandService.AddCommand(menuItem);
            }
        }
        public static void InitializeAssembly(TestContext context)
        {
            // This fixes some odd unit test errors loading Microsoft.VisualStudio.Utilities
            // see: https://ci.appveyor.com/project/GoogleCloudPlatform/google-cloud-visualstudio/build/2.0.0-dev.135/tests
            new Mock <ISettingsManager>().Setup(m => m.GetSubset(It.IsAny <string>()))
            .Returns(Mock.Of <ISettingsSubset>());

            EventsReporterWrapper.DisableReporting();
            s_packageToRestore = GoogleCloudExtensionPackage.Instance;
            GoogleCloudExtensionPackage.Instance = null;
            // Enable pack URIs.
            Assert.AreEqual(new Application {
                ShutdownMode = ShutdownMode.OnExplicitShutdown
            }, Application.Current);
        }
        /// <summary>
        /// Initializes the singleton instance of the command.
        /// </summary>
        /// <param name="package">Owner package, not null.</param>
        /// <param name="token">The cancellation token.</param>
        public static async Task InitializeAsync(IGoogleCloudExtensionPackage package, CancellationToken token)
        {
            if (package == null)
            {
                throw new ArgumentNullException(nameof(package));
            }

            if (await package.GetServiceAsync(typeof(IMenuCommandService)) is OleMenuCommandService commandService)
            {
                await package.JoinableTaskFactory.SwitchToMainThreadAsync(token);

                var menuCommandID = new CommandID(CommandSet, CommandId);
                var menuItem      = new MenuCommand(ShowToolWindow, menuCommandID);
                commandService.AddCommand(menuItem);
            }
        }
Esempio n. 9
0
        /// <summary>
        /// Initializes the singleton instance of the command.
        /// </summary>
        /// <param name="package">Owner package, not null.</param>
        /// <param name="token">The cancellation token.</param>
        public static async Task InitializeAsync(IGoogleCloudExtensionPackage package, CancellationToken token)
        {
            object menuCommandService = await package.GetServiceAsync(typeof(IMenuCommandService));

            await package.JoinableTaskFactory.SwitchToMainThreadAsync(token);

            if (menuCommandService is OleMenuCommandService commandService)
            {
                var menuCommandID = new CommandID(s_commandSet, CommandId);
                var menuItem      = new MenuCommand(ShowToolWindow, menuCommandID);
                commandService.AddCommand(menuItem);
            }

            // <summary>
            // Shows the tool window when the menu item is clicked.
            // </summary>
            // <param name="sender">The event sender.</param>
            // <param name="e">The event args.</param>
            void ShowToolWindow(object sender, EventArgs e)
            {
                EventsReporterWrapper.EnsureAnalyticsOptIn();

                ErrorHandlerUtils.HandleExceptionsAsync(ShowToolWindowAsync);
            }

            async Task ShowToolWindowAsync()
            {
                // Get the instance number 0 of this tool window. This window is single instance so this instance
                // is actually the only one.
                // The last flag is set to true so that if the tool window does not exists it will be created.
                var window = package.FindToolWindow <CloudExplorerToolWindow>(true);

                if (window?.Frame == null)
                {
                    throw new NotSupportedException("Cannot create tool window");
                }

                await package.JoinableTaskFactory.SwitchToMainThreadAsync();

                var windowFrame = (IVsWindowFrame)window.Frame;

                Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(windowFrame.Show());
            }
        }
        /// <summary>
        /// Initialization of the package; this method is called right after the package is sited, so this is the place
        /// where you can put all the initialization code that rely on services provided by VisualStudio.
        /// </summary>
        protected override void Initialize()
        {
            base.Initialize();

            // An remember the package.
            Instance = this;

            // Register the command handlers.
            CloudExplorerCommand.Initialize(this);
            ManageAccountsCommand.Initialize(this);
            PublishProjectMainMenuCommand.Initialize(this);
            PublishProjectContextMenuCommand.Initialize(this);
            LogsViewerToolWindowCommand.Initialize(this);
            GenerateConfigurationContextMenuCommand.Initialize(this);
            ErrorReportingToolWindowCommand.Initialize(this);

            // Activity log utils, to aid in debugging.
            ActivityLogUtils.Initialize(this);
            ActivityLogUtils.LogInfo("Starting Google Cloud Tools.");

            _dteInstance = (DTE)GetService(typeof(DTE));
            VsVersion    = _dteInstance.Version;
            VsEdition    = _dteInstance.Edition;

            // Update the installation status of the package.
            CheckInstallationStatus();

            // Ensure the commands UI state is updated when the GCP project changes.
            CredentialsStore.Default.Reset += (o, e) => ShellUtils.InvalidateCommandsState();
            CredentialsStore.Default.CurrentProjectIdChanged += (o, e) => ShellUtils.InvalidateCommandsState();

            // With this setting we allow more concurrent connections from each HttpClient instance created
            // in the process. This will allow all GCP API services to have more concurrent connections with
            // GCP servers. The first benefit of this is that we can upload more concurrent files to GCS.
            ServicePointManager.DefaultConnectionLimit = MaximumConcurrentConnections;

            ExportProvider mefExportProvider = GetService <SComponentModel, IComponentModel>().DefaultExportProvider;

            _shellUtilsLazy      = mefExportProvider.GetExport <IShellUtils>();
            _gcpOutputWindowLazy = mefExportProvider.GetExport <IGcpOutputWindow>();
            _processService      = mefExportProvider.GetExport <IProcessService>();
            _statusbarService    = mefExportProvider.GetExport <IStatusbarService>();
            _userPromptService   = mefExportProvider.GetExport <IUserPromptService>();
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="LogsViewerToolWindowCommand"/> class.
        /// Adds our command handlers for menu (commands must exist in the command table file)
        /// </summary>
        /// <param name="package">Owner package, not null.</param>
        private LogsViewerToolWindowCommand(IGoogleCloudExtensionPackage package)
        {
            if (package == null)
            {
                throw new ArgumentNullException(nameof(package));
            }

            _package = package;

            var commandService = ServiceProvider.GetService(typeof(IMenuCommandService)) as IMenuCommandService;

            if (commandService != null)
            {
                var menuItem = new OleMenuCommand(
                    (sender, e) => ToolWindowCommandUtils.AddToolWindow <LogsViewerToolWindow>(), MenuCommandID);
                menuItem.BeforeQueryStatus += ToolWindowCommandUtils.EnableMenuItemOnValidProjectId;
                commandService.AddCommand(menuItem);
            }
        }
Esempio n. 12
0
        /// <summary>
        /// Initializes the singleton instance of the command.
        /// </summary>
        /// <param name="package">Owner package, not null.</param>
        /// <param name="token">The token to cancel adding the command.</param>
        public static async Task InitializeAsync(IGoogleCloudExtensionPackage package, CancellationToken token)
        {
            package.ThrowIfNull(nameof(package));

            IMenuCommandService commandService =
                await package.GetServiceAsync <IMenuCommandService, IMenuCommandService>();

            await package.JoinableTaskFactory.SwitchToMainThreadAsync(token);

            var menuCommandID = new CommandID(CommandSet, CommandId);
            var menuItem      = new OleMenuCommand(
                async(sender, e) =>
            {
                await ToolWindowCommandUtils.ShowToolWindowAsync <ErrorReportingToolWindow>();
                EventsReporterWrapper.ReportEvent(ErrorsViewerOpenEvent.Create());
            },
                menuCommandID);

            menuItem.BeforeQueryStatus += ToolWindowCommandUtils.EnableMenuItemOnValidProjectId;
            commandService.AddCommand(menuItem);
        }
Esempio n. 13
0
        /// <summary>
        /// Initializes an instance of <seealso cref="LogsViewerViewModel"/> class.
        /// </summary>
        /// <param name="toolWindowIdNumber"></param>
        public LogsViewerViewModel(int toolWindowIdNumber)
        {
            IsVisibleUnbound    = true;
            _package            = GoogleCloudExtensionPackage.Instance;
            _toolWindowIdNumber = toolWindowIdNumber;
            RefreshCommand      = new ProtectedCommand(OnRefreshCommand);
            LogItemCollection   = new ListCollectionView(_logs);
            LogItemCollection.GroupDescriptions.Add(new PropertyGroupDescription(nameof(LogItem.Date)));
            CancelRequestCommand    = new ProtectedCommand(CancelRequest);
            SimpleTextSearchCommand = new ProtectedCommand(() =>
            {
                EventsReporterWrapper.ReportEvent(LogsViewerSimpleTextSearchEvent.Create());
                AsyncAction = new AsyncProperty(ReloadAsync());
            });
            FilterSwitchCommand         = new ProtectedCommand(SwapFilter);
            SubmitAdvancedFilterCommand = new ProtectedCommand(() =>
            {
                EventsReporterWrapper.ReportEvent(LogsViewerAdvancedFilterEvent.Create());
                AsyncAction = new AsyncProperty(ReloadAsync());
            });
            AdvancedFilterHelpCommand = new ProtectedCommand(ShowAdvancedFilterHelp);
            DateTimePickerModel       = new DateTimePickerViewModel(
                TimeZoneInfo.Local, DateTime.UtcNow, isDescendingOrder: true);
            DateTimePickerModel.DateTimeFilterChange += (sender, e) => AsyncAction = new AsyncProperty(ReloadAsync());
            ResourceTypeSelector = new ResourceTypeMenuViewModel(() => DataSource);
            ResourceTypeSelector.PropertyChanged += (sender, args) =>
            {
                if (args.PropertyName == null ||
                    args.PropertyName == nameof(ResourceTypeMenuViewModel.SelectedMenuItem))
                {
                    LogIdList   = null;
                    AsyncAction = new AsyncProperty(ReloadAsync());
                }
            };

            OnDetailTreeNodeFilterCommand = new ProtectedAsyncCommand <ObjectNodeTree>(FilterOnTreeNodeValueAsync);
            OnAutoReloadCommand           = new ProtectedCommand(AutoReload);
        }
 /// <summary>
 /// Initializes the singleton instance of the command.
 /// </summary>
 /// <param name="package">Owner package, not null.</param>
 public static void Initialize(IGoogleCloudExtensionPackage package)
 {
     Instance = new LogsViewerToolWindowCommand(package);
 }