Exemplo n.º 1
0
        private void OnStartInstanceCommand()
        {
            try
            {
                if (!UserPromptUtils.YesNoPrompt(
                        String.Format(Resources.CloudExplorerGceStartInstanceConfirmationPrompt, Instance.Name),
                        String.Format(Resources.CloudExplorerGceStartInstanceConfirmationPromptCaption, Instance.Name)))
                {
                    Debug.WriteLine($"The user cancelled starting instance {Instance.Name}.");
                    return;
                }

                var operation = _owner.DataSource.StartInstance(Instance);
                UpdateInstanceState(operation);
            }
            catch (DataSourceException ex)
            {
                GcpOutputWindow.Activate();
                GcpOutputWindow.OutputLine(String.Format(Resources.CloudExplorerGceFailedToStartInstanceMessage, Instance.Name, ex.Message));
            }
            catch (OAuthException ex)
            {
                ShowOAuthErrorDialog(ex);
            }
        }
        /// <summary>
        /// Return a list of projects. Returns empty list if no item is found.
        /// </summary>
        private async Task <IList <Project> > GetProjectsAsync()
        {
            ResourceManagerDataSource resourceManager = DataSourceFactories.CreateResourceManagerDataSource();

            if (resourceManager == null)
            {
                return(new List <Project>());
            }

            IsReady = false;
            try
            {
                var projects = await resourceManager.GetSortedActiveProjectsAsync();

                if (!projects.Any())
                {
                    UserPromptUtils.OkPrompt(
                        message: Resources.CsrNoProjectMessage,
                        title: Resources.CsrConnectSectionTitle);
                }
                return(projects);
            }
            finally
            {
                IsReady = true;
            }
        }
Exemplo n.º 3
0
        private bool Validate()
        {
            if (String.IsNullOrEmpty(UserName))
            {
                UserPromptUtils.ErrorPrompt(
                    Resources.AddWindowsCredentialValidationEmptyUser,
                    Resources.AddWindowsCredentialValidationErrorTtitle);
                return(false);
            }

            var invalidChars = UserName.Intersect(UserNameInvalidChars).ToArray();

            if (invalidChars.Length > 0)
            {
                UserPromptUtils.ErrorPrompt(
                    String.Format(Resources.AddWindowsCredentialValidationInvalidChars, new string(invalidChars)),
                    Resources.AddWindowsCredentialValidationErrorTtitle);
                return(false);
            }

            if (ManualPassword && String.IsNullOrEmpty(Password))
            {
                UserPromptUtils.ErrorPrompt(
                    Resources.AddWindowsCredentialValidationEmptyPassword,
                    Resources.AddWindowsCredentialValidationErrorTtitle);
                return(false);
            }

            // Valid entry.
            return(true);
        }
        /// <summary>
        /// This method will enable the list of services given.
        /// </summary>
        /// <param name="serviceNames">The list of services to enable.</param>
        /// <returns>A task that will be completed once the operation finishes.</returns>
        public async Task EnableServicesAsync(IEnumerable <string> serviceNames)
        {
            ServiceManagementDataSource dataSource = _dataSource.Value;

            if (dataSource == null)
            {
                return;
            }

            try
            {
                await ProgressDialogWindow.PromptUser(
                    dataSource.EnableAllServicesAsync(serviceNames),
                    new ProgressDialogWindow.Options
                {
                    Title         = Resources.ApiManagerEnableServicesTitle,
                    Message       = Resources.ApiManagerEnableServicesProgressMessage,
                    IsCancellable = false
                });
            }
            catch (DataSourceException ex)
            {
                UserPromptUtils.ErrorPrompt(
                    message: Resources.ApiManagerEnableServicesErrorMessage,
                    title: Resources.UiErrorCaption,
                    errorDetails: ex.Message);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Prompts the user about deleting the subscription, then calls the datasource to delete it.
        /// </summary>
        internal async void OnDeleteSubscriptionCommand()
        {
            IsLoading = true;
            try
            {
                bool doDelete = UserPromptUtils.ActionPrompt(
                    string.Format(Resources.PubSubDeleteSubscriptionWindowMessage, _subscriptionItem.Name),
                    Resources.PubSubDeleteSubscriptionWindowHeader,
                    actionCaption: Resources.UiDeleteButtonCaption);
                if (doDelete)
                {
                    try
                    {
                        await DataSource.DeleteSubscriptionAsync(_subscriptionItem.FullName);

                        EventsReporterWrapper.ReportEvent(PubSubSubscriptionDeletedEvent.Create(CommandStatus.Success));
                    }
                    catch (DataSourceException e)
                    {
                        Debug.Write(e.Message, "Delete Subscription");
                        EventsReporterWrapper.ReportEvent(PubSubSubscriptionDeletedEvent.Create(CommandStatus.Failure));
                        UserPromptUtils.ErrorPrompt(
                            Resources.PubSubDeleteSubscriptionErrorMessage,
                            Resources.PubSubDeleteSubscriptionErrorHeader,
                            e.Message);
                    }
                    await _owner.Refresh();
                }
            }
            finally
            {
                IsLoading = false;
            }
        }
Exemplo n.º 6
0
        private void UploadFiles(IEnumerable <string> files)
        {
            try
            {
                CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
                var uploadOperationsQueue = _fileOperationsEngine.StartUploadOperations(
                    files,
                    bucket: Bucket.Name,
                    bucketPath: _currentState.CurrentPath,
                    cancellationToken: cancellationTokenSource.Token);

                GcsFileProgressDialogWindow.PromptUser(
                    caption: Resources.GcsFileBrowserUploadingProgressCaption,
                    message: Resources.GcsFileBrowserUploadingProgressMessage,
                    progressMessage: Resources.GcsFileBrowserUploadingOverallProgressMessage,
                    operations: uploadOperationsQueue.Operations,
                    cancellationTokenSource: cancellationTokenSource);

                EventsReporterWrapper.ReportEvent(GcsFileBrowserStartUploadEvent.Create(CommandStatus.Success));
            }
            catch (IOException ex)
            {
                UserPromptUtils.ErrorPrompt(
                    message: Resources.GcsFileProgressDialogFailedToEnumerateFiles,
                    title: Resources.UiErrorCaption,
                    errorDetails: ex.Message);

                EventsReporterWrapper.ReportEvent(GcsFileBrowserStartUploadEvent.Create(CommandStatus.Failure));
            }

            UpdateCurrentState();
        }
Exemplo n.º 7
0
 /// <summary>
 /// Prompts the user about deleting the subscription, then calls the datasource to delete it.
 /// </summary>
 private async void OnDeleteSubscriptionCommand()
 {
     IsLoading = true;
     try
     {
         try
         {
             bool doDelete = UserPromptUtils.ActionPrompt(
                 string.Format(Resources.PubSubDeleteSubscriptionWindowMessage, _subscriptionItem.Name),
                 Resources.PubSubDeleteSubscriptionWindowHeader,
                 actionCaption: Resources.UiDeleteButtonCaption);
             if (doDelete)
             {
                 await DataSource.DeleteSubscriptionAsync(_subscriptionItem.FullName);
             }
         }
         catch (DataSourceException e)
         {
             Debug.Write(e.Message, "Delete Subscription");
             UserPromptUtils.ErrorPrompt(
                 Resources.PubSubDeleteSubscriptionErrorMessage,
                 Resources.PubSubDeleteSubscriptionErrorHeader);
         }
         await _owner.Refresh();
     }
     finally
     {
         IsLoading = false;
     }
 }
Exemplo n.º 8
0
 private static void ShowOAuthErrorDialog(OAuthException ex)
 {
     Debug.WriteLine($"Failed to fetch oauth credentials: {ex.Message}");
     UserPromptUtils.OkPrompt(
         String.Format(Resources.CloudExplorerGceFailedToGetOauthCredentialsMessage, CredentialsStore.Default.CurrentAccount.AccountName),
         Resources.CloudExplorerGceFailedToGetOauthCredentialsCaption);
 }
Exemplo n.º 9
0
        private void OnStartInstanceCommand()
        {
            try
            {
                if (!UserPromptUtils.ActionPrompt(
                        String.Format(Resources.CloudExplorerGceStartInstanceConfirmationPrompt, Instance.Name),
                        String.Format(Resources.CloudExplorerGceStartInstanceConfirmationPromptCaption, Instance.Name),
                        actionCaption: Resources.UiStartButtonCaption))
                {
                    Debug.WriteLine($"The user cancelled starting instance {Instance.Name}.");
                    return;
                }

                var operation = _owner.DataSource.StartInstance(Instance);
                UpdateInstanceState(operation);

                EventsReporterWrapper.ReportEvent(StartGceInstanceEvent.Create(CommandStatus.Success));
            }
            catch (DataSourceException ex)
            {
                GcpOutputWindow.Activate();
                GcpOutputWindow.OutputLine(String.Format(Resources.CloudExplorerGceFailedToStartInstanceMessage, Instance.Name, ex.Message));

                EventsReporterWrapper.ReportEvent(StartGceInstanceEvent.Create(CommandStatus.Failure));
            }
        }
        /// <summary>
        /// Prompts the user for a new subscription, and creates it.
        /// </summary>
        internal async void OnNewSubscriptionCommand()
        {
            IsLoading = true;
            try
            {
                Subscription subscription = NewSubscriptionUserPrompt(Item.FullName);
                if (subscription != null)
                {
                    try
                    {
                        await DataSource.NewSubscriptionAsync(subscription);

                        EventsReporterWrapper.ReportEvent(PubSubSubscriptionCreatedEvent.Create(CommandStatus.Success));
                        await Refresh();
                    }
                    catch (DataSourceException e)
                    {
                        Debug.Write(e.Message, "New Subscription");
                        EventsReporterWrapper.ReportEvent(PubSubSubscriptionCreatedEvent.Create(CommandStatus.Failure));

                        Owner.Refresh();
                        UserPromptUtils.ErrorPrompt(
                            Resources.PubSubNewSubscriptionErrorMessage,
                            Resources.PubSubNewSubscriptionErrorHeader,
                            e.Message);
                    }
                }
            }
            finally
            {
                IsLoading = false;
            }
        }
Exemplo n.º 11
0
 /// <summary>
 /// Prompts the user for a new subscription, and creates it.
 /// </summary>
 private async void OnNewSubscriptionCommand()
 {
     IsLoading = true;
     try
     {
         try
         {
             Subscription subscription = NewSubscriptionWindow.PromptUser(TopicItem.FullName);
             if (subscription != null)
             {
                 await DataSource.NewSubscriptionAsync(subscription);
             }
         }
         catch (DataSourceException e)
         {
             Debug.Write(e.Message, "New Subscription");
             UserPromptUtils.ErrorPrompt(
                 Resources.PubSubNewSubscriptionErrorMessage, Resources.PubSubNewSubscriptionErrorHeader);
         }
         await Refresh();
     }
     finally
     {
         IsLoading = false;
     }
 }
Exemplo n.º 12
0
        private bool GetAllProcessesList()
        {
            var dte       = Shell.Package.GetGlobalService(typeof(DTE)) as DTE;
            var debugger  = dte.Debugger as Debugger2;
            var transport = debugger.Transports.Item("Default");

            // Show engine types
            EngineTypes = new List <string>();
            EngineTypes.Add(Resources.AttachDebuggerAutomaticallyDetectEngineTypeItemName);
            foreach (var engineType in transport.Engines)
            {
                var engine = engineType as Engine;
                if (engine == null)
                {
                    Debug.WriteLine("engine is null, might be a code bug.");
                    continue;
                }
                EngineTypes.Add(engine.Name);
            }
            SelectedEngine = s_detectEngineTypeItemName;

            Processes processes = debugger.GetProcesses(transport, Context.PublicIp);

            _allProcesses = new List <ProcessItem>();
            foreach (var process in processes)      // Linq does not work on COM list
            {
                var pro2 = process as Process2;
                _allProcesses.Add(new ProcessItem(pro2));
            }

            if (_allProcesses.Count == 0)
            {
                UserPromptUtils.ErrorPrompt(
                    message: Resources.AttachDebuggerListProcessEmptyResultErrorMessage,
                    title: Resources.UiDefaultPromptTitle);
                return(false);
            }

            if (!String.IsNullOrWhiteSpace(AttachDebuggerSettings.Current.DefaultDebuggeeProcessName))
            {
                var matching = _allProcesses
                               .Where(x => x.Name.ToLowerInvariant() == AttachDebuggerSettings.Current.DefaultDebuggeeProcessName.ToLowerInvariant());
                if (!matching.Any())
                {
                    ResetDefaultSelection();
                }
                else if (matching.Count() == 1)
                {
                    Processes       = matching;
                    SelectedProcess = matching.First();
                    SelectedEngine  = AttachDebuggerSettings.Current.DefaultDebuggerEngineType;
                    return(true);
                }
            }

            Processes       = _allProcesses;
            SelectedProcess = Processes.FirstOrDefault();
            return(true);
        }
Exemplo n.º 13
0
        /// <summary>
        /// This method will check that all given services are enabled and if not will prompt the user to enable the
        /// necessary services.
        /// </summary>
        /// <param name="serviceNames">The services to check.</param>
        /// <param name="prompt">The prompt to use in the prompt dialog to ask the user for permission to enable the services.</param>
        /// <returns>A task that will be true if all services where enabled, false if the user cancelled or if the operation failed.</returns>
        public async Task <bool> EnsureAllServicesEnabledAsync(
            IEnumerable <string> serviceNames,
            string prompt)
        {
            ServiceManagementDataSource dataSource = _dataSource.Value;

            if (dataSource == null)
            {
                return(false);
            }

            try
            {
                // Check all services in parallel.
                IList <string> servicesToEnable = (await dataSource.CheckServicesStatusAsync(serviceNames))
                                                  .Where(x => !x.Enabled)
                                                  .Select(x => x.Name)
                                                  .ToList();
                if (servicesToEnable.Count == 0)
                {
                    Debug.WriteLine("All the services are already enabled.");
                    return(true);
                }

                // Need to enable the services, prompt the user.
                Debug.WriteLine($"Need to enable the services: {string.Join(",", servicesToEnable)}.");
                if (!UserPromptUtils.ActionPrompt(
                        prompt: prompt,
                        title: Resources.ApiManagerEnableServicesTitle,
                        actionCaption: Resources.UiEnableButtonCaption))
                {
                    return(false);
                }

                // Enable all services in parallel.
                await ProgressDialogWindow.PromptUser(
                    dataSource.EnableAllServicesAsync(servicesToEnable),
                    new ProgressDialogWindow.Options
                {
                    Title         = Resources.ApiManagerEnableServicesTitle,
                    Message       = Resources.ApiManagerEnableServicesProgressMessage,
                    IsCancellable = false
                });

                return(true);
            }
            catch (DataSourceException ex)
            {
                UserPromptUtils.ErrorPrompt(
                    message: Resources.ApiManagerEnableServicesErrorMessage,
                    title: Resources.UiErrorCaption,
                    errorDetails: ex.Message);
                return(false);
            }
        }
Exemplo n.º 14
0
        private bool ValidateInput()
        {
            int replicas = 0;

            if (!int.TryParse(Replicas, out replicas))
            {
                UserPromptUtils.ErrorPrompt(Resources.GkePublishInvalidReplicasMessage, Resources.UiInvalidValueTitle);
                return(false);
            }

            return(true);
        }
Exemplo n.º 15
0
 private void OnCopyCommand()
 {
     try
     {
         Clipboard.SetText(Password);
     }
     catch
     {
         Debug.WriteLine("Failed to copy the string to the clipboard.");
         UserPromptUtils.ErrorPrompt(Resources.ShowPasswordCopyFailedMessage, Resources.ShowPasswordCopyFailedTitle);
     }
 }
Exemplo n.º 16
0
        /// <summary>
        /// Ensures that the opt-in dialog is shown to the user.
        /// </summary>
        public static void EnsureAnalyticsOptIn()
        {
            var settings = GoogleCloudExtensionPackage.Instance.AnalyticsSettings;

            if (!settings.DialogShown)
            {
                Debug.WriteLine("Showing the opt-in dialog.");
                settings.OptIn       = UserPromptUtils.YesNoPrompt(Resources.AnalyticsPromptMessage, Resources.AnalyticsPromptTitle);
                settings.DialogShown = true;
                settings.SaveSettingsToStorage();
            }
        }
Exemplo n.º 17
0
        private async void OnRenameFolderCommand()
        {
            var newLeafName = NamePromptWindow.PromptUser(new NamePromptWindow.Options
            {
                InitialName = SelectedItem.LeafName,
                Title       = Resources.GcsFileBrowserRenameFolderTitle
            });

            if (newLeafName == null)
            {
                return;
            }

            try
            {
                IsLoading = true;

                CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
                var renameDirectoryOperations = await _fileOperationsEngine.StartDirectoryRenameOperationsAsync(
                    bucket : Bucket.Name,
                    parentName : CurrentState.CurrentPath,
                    oldLeafName : SelectedItem.LeafName,
                    newLeafName : newLeafName,
                    cancellationToken : cancellationTokenSource.Token);

                GcsFileProgressDialogWindow.PromptUser(
                    caption: Resources.GcsFileBrowserRenamingFilesCaption,
                    message: Resources.GcsFileBrowserRenamingFilesMessage,
                    progressMessage: Resources.GcsFileBrowserRenamingFilesProgressMessage,
                    operations: renameDirectoryOperations.Operations,
                    cancellationTokenSource: cancellationTokenSource);

                EventsReporterWrapper.ReportEvent(GcsFileBrowserStartRenameDirectoryEvent.Create(CommandStatus.Success));
            }
            catch (DataSourceException ex)
            {
                UserPromptUtils.ErrorPrompt(
                    message: string.Format(Resources.GcsFileBrowserRenameFailedMessage, SelectedItem.LeafName),
                    title: Resources.UiErrorCaption,
                    errorDetails: ex.Message);

                EventsReporterWrapper.ReportEvent(GcsFileBrowserStartRenameDirectoryEvent.Create(CommandStatus.Failure));
            }
            finally
            {
                IsLoading = false;
            }

            UpdateCurrentState();
        }
        private void OnDeleteCredentialsCommand()
        {
            if (!UserPromptUtils.ActionPrompt(
                    String.Format(Resources.ManageWindowsCredentialsDeleteCredentialsPromptMessage, SelectedCredentials.User),
                    Resources.ManageWindowsCredentialsDeleteCredentialsPromptTitle,
                    message: Resources.UiOperationCannotBeUndone,
                    actionCaption: Resources.UiDeleteButtonCaption))
            {
                return;
            }

            WindowsCredentialsStore.Default.DeleteCredentialsForInstance(_instance, SelectedCredentials);
            CredentialsList = WindowsCredentialsStore.Default.GetCredentialsForInstance(_instance);
        }
Exemplo n.º 19
0
 private static void OpenCurrentVersionProjectPrompt(string assemblyName, string assemblyVersion)
 {
     if (UserPromptUtils.ActionPrompt(
             prompt: String.Format(Resources.LogsViewerPleaseOpenProjectPrompt, assemblyName, assemblyVersion),
             title: Resources.uiDefaultPromptTitle,
             message: Resources.LogsViewerAskToOpenProjectMessage))
     {
         ShellUtils.OpenProject();
     }
     else
     {
         throw new FileNotFoundException(null);
     }
 }
Exemplo n.º 20
0
        private async void OnRenameFileCommand()
        {
            var choosenName = NamePromptWindow.PromptUser(new NamePromptWindow.Options
            {
                InitialName = SelectedItem.LeafName,
                Title       = Resources.GcsFileBrowserRenameFileTitle
            });

            if (choosenName == null)
            {
                return;
            }

            try
            {
                IsLoading = true;

                var newName = GcsPathUtils.Combine(CurrentState.CurrentPath, choosenName);
                Debug.WriteLine($"Renaming {SelectedItem.BlobName} to {newName}");
                await ProgressDialogWindow.PromptUser(
                    _dataSource.MoveFileAsync(
                        bucket: Bucket.Name,
                        sourceName: SelectedItem.BlobName,
                        destName: newName),
                    new ProgressDialogWindow.Options
                {
                    Message       = Resources.GcsFileBrowserRenamingProgressMessage,
                    Title         = Resources.UiDefaultPromptTitle,
                    IsCancellable = false
                });

                EventsReporterWrapper.ReportEvent(GcsFileBrowserRenameFileEvent.Create(CommandStatus.Success));
            }
            catch (DataSourceException ex)
            {
                UserPromptUtils.ErrorPrompt(
                    message: string.Format(Resources.GcsFileBrowserRenameFailedMessage, SelectedItem.LeafName),
                    title: Resources.UiErrorCaption,
                    errorDetails: ex.Message);

                EventsReporterWrapper.ReportEvent(GcsFileBrowserRenameFileEvent.Create(CommandStatus.Failure));
            }
            finally
            {
                IsLoading = false;
            }

            UpdateCurrentState();
        }
Exemplo n.º 21
0
        private async void OnDownloadCommand()
        {
            FBD dialog = new FBD();

            dialog.Description         = Resources.GcsFileBrowserFolderSelectionMessage;
            dialog.ShowNewFolderButton = true;

            var result = dialog.ShowDialog();

            if (result == System.Windows.Forms.DialogResult.Cancel)
            {
                return;
            }
            var downloadRoot = dialog.SelectedPath;

            try
            {
                IsLoading = true;

                CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
                var downloadOperationsQueue = await _fileOperationsEngine.StartDownloadOperationsAsync(
                    SelectedItems.Select(x => new GcsUtils.GcsItemRef(x.Bucket, x.BlobName)),
                    downloadRoot,
                    cancellationTokenSource.Token);

                GcsFileProgressDialogWindow.PromptUser(
                    caption: Resources.GcsFileBrowserDownloadingProgressCaption,
                    message: Resources.GcsFileBrowserDownloadingProgressMessage,
                    progressMessage: Resources.GcsFileBrowserDownloadingOverallProgressMessage,
                    operations: downloadOperationsQueue.Operations,
                    cancellationTokenSource: cancellationTokenSource);

                EventsReporterWrapper.ReportEvent(GcsFileBrowserStartDownloadEvent.Create(CommandStatus.Success));
            }
            catch (IOException ex)
            {
                UserPromptUtils.ErrorPrompt(
                    message: Resources.GcsFileBrowserFailedToCreateDirMessage,
                    title: Resources.UiErrorCaption,
                    errorDetails: ex.Message);

                EventsReporterWrapper.ReportEvent(GcsFileBrowserStartDownloadEvent.Create(CommandStatus.Failure));
                return;
            }
            finally
            {
                IsLoading = false;
            }
        }
        /// <summary>
        /// Starts the attaching remote debugger wizard.
        /// </summary>
        /// <param name="gceInstance">A GCE windows VM <seealso cref="Instance"/> object.</param>
        public static void PromptUser(Instance gceInstance)
        {
            if (String.IsNullOrWhiteSpace(gceInstance.GetPublicIpAddress()))
            {
                UserPromptUtils.OkPrompt(
                    message: StringResources.AttachDebuggerAddPublicIpAddressMessage,
                    title: StringResources.UiDefaultPromptTitle);
                return;
            }

            var dialog = new AttachDebuggerWindow(gceInstance);

            EventsReporterWrapper.ReportEvent(RemoteDebuggerWindowOpenEvent.Create());
            dialog.ShowModal();
        }
Exemplo n.º 23
0
 private async Task <IEnumerable <string> > ListAllLocationsAsync()
 {
     try
     {
         IEnumerable <string> result = (await _dataSource.GetFlexLocationsAsync()).OrderBy(x => x);
         SelectedLocation = DefaultRegionName;
         return(result);
     }
     catch (DataSourceException ex)
     {
         UserPromptUtils.ExceptionPrompt(ex);
         _owner.Close();
         return(Enumerable.Empty <string>());
     }
 }
        /// <summary>
        /// Repeatedly make list log entries request till it gets desired number of logs or it reaches end.
        /// _nextPageToken is used to control if it is getting first page or continuous page.
        ///
        /// On complex filters, scanning through logs take time. The server returns empty results
        ///   with a next page token. Continue to send request till some logs are found.
        /// </summary>
        /// <param name="cancellationToken">A cancellation token. The caller can monitor the cancellation event.</param>
        /// <param name="autoReload">Indicate if the request comes from autoReload event.</param>
        private async Task LoadLogsAsync(CancellationToken cancellationToken, bool autoReload = false)
        {
            if (_logs.Count >= MaxLogEntriesCount)
            {
                UserPromptUtils.ErrorPrompt(
                    message: Resources.LogViewerResultSetTooLargeMessage,
                    title: Resources.UiDefaultPromptTitle);
                _cancellationTokenSource?.Cancel();
                return;
            }

            try
            {
                var startTimestamp = DateTime.Now;

                var order = DateTimePickerModel.IsDescendingOrder ? "timestamp desc" : "timestamp asc";
                int count = 0;
                while (count < DefaultPageSize && !cancellationToken.IsCancellationRequested)
                {
                    Debug.WriteLine($"LoadLogs, count={count}, firstPage={_nextPageToken == null}");

                    // Here, it does not do pageSize: _defaultPageSize - count,
                    // Because this is requried to use same page size for getting next page.
                    var results = await _dataSource.Value.ListLogEntriesAsync(_filter, order,
                                                                              pageSize : DefaultPageSize, nextPageToken : _nextPageToken, cancelToken : cancellationToken);

                    _nextPageToken = results.NextPageToken;
                    if (results?.LogEntries != null)
                    {
                        count += results.LogEntries.Count;
                        AddLogs(results.LogEntries, autoReload);
                    }

                    if (String.IsNullOrWhiteSpace(_nextPageToken))
                    {
                        _nextPageToken = null;
                        break;
                    }
                }

                EventsReporterWrapper.ReportEvent(LogsViewerLogsLoadedEvent.Create(CommandStatus.Success, DateTime.Now - startTimestamp));
            }
            catch (Exception ex) when(!ErrorHandlerUtils.IsCriticalException(ex))
            {
                EventsReporterWrapper.ReportEvent(LogsViewerLogsLoadedEvent.Create(CommandStatus.Failure));
                throw;
            }
        }
        /// <summary>
        /// Validates the input. Prompts the user on validation errors.
        /// </summary>
        /// <returns>Returns true if validation succeded, false if the user had to be prompted</returns>
        private bool ValidateInput()
        {
            var results = PubSubNameValidationRule.Validate(TopicName, Resources.NewTopicWindowNameFieldName);
            var details = String.Join("\n", results.Select(result => result.Message));

            if (!String.IsNullOrEmpty(details))
            {
                string message = String.Format(Resources.PubSubNewTopicNameInvalidMessage, TopicName);
                UserPromptUtils.ErrorPrompt(message, Resources.PubSubNewTopicNameInvalidTitle, details);
                return(false);
            }
            else
            {
                return(true);
            }
        }
Exemplo n.º 26
0
        private void OnDeleteAccountCommand()
        {
            Debug.WriteLine($"Attempting to delete account: {CurrentAccountName}");
            if (!UserPromptUtils.ActionPrompt(
                    String.Format(Resources.ManageAccountsDeleteAccountPromptMessage, CurrentAccountName),
                    Resources.ManageAccountsDeleteAccountPromptTitle,
                    actionCaption: Resources.UiDeleteButtonCaption))
            {
                Debug.WriteLine($"The user cancelled the deletion of the account.");
                return;
            }

            AccountsManager.DeleteAccount(CurrentUserAccount.UserAccount);
            // Refreshing everything.
            UserAccountsList = LoadUserCredentialsViewModel();
        }
Exemplo n.º 27
0
        private bool Validate()
        {
            if (String.IsNullOrEmpty(Name))
            {
                UserPromptUtils.ErrorPrompt(Resources.NamePromptEmptyNameMessage, Resources.UiErrorCaption);
                return(false);
            }

            if (Name.Contains('/'))
            {
                UserPromptUtils.ErrorPrompt(Resources.NamePromptInvalidCharsMessage, Resources.UiErrorCaption);
                return(false);
            }

            return(true);
        }
Exemplo n.º 28
0
        private async Task <WindowsInstanceCredentials> CreateOrResetCredentials(string user)
        {
            try
            {
                Debug.WriteLine("The user requested the password to be generated.");
                if (!UserPromptUtils.ActionPrompt(
                        prompt: String.Format(Resources.ResetPasswordConfirmationPromptMessage, user, _instance.Name),
                        title: Resources.ResetPasswordConfirmationPromptTitle,
                        message: Resources.UiOperationCannotBeUndone,
                        actionCaption: Resources.UiResetButtonCaption,
                        isWarning: true))
                {
                    Debug.WriteLine("The user cancelled resetting the password.");
                    return(null);
                }

                Debug.WriteLine($"Resetting the password for the user {user}");

                // Check that gcloud is in the right state to invoke the reset credentials method.
                if (!await VerifyGCloudDependencies())
                {
                    Debug.WriteLine("Missing gcloud dependencies for resetting password.");
                    return(null);
                }

                var context = new GCloudContext
                {
                    CredentialsPath = CredentialsStore.Default.CurrentAccountPath,
                    ProjectId       = CredentialsStore.Default.CurrentProjectId,
                    AppName         = GoogleCloudExtensionPackage.ApplicationName,
                    AppVersion      = GoogleCloudExtensionPackage.ApplicationVersion,
                };
                return(await GCloudWrapper.ResetWindowsCredentialsAsync(
                           instanceName : _instance.Name,
                           zoneName : _instance.GetZoneName(),
                           userName : user,
                           context : context));
            }
            catch (GCloudException ex)
            {
                UserPromptUtils.ErrorPrompt(
                    message: String.Format(Resources.ResetPasswordFailedPromptMessage, _instance.Name),
                    title: Resources.ResetPasswordConfirmationPromptTitle,
                    errorDetails: ex.Message);
                return(null);
            }
        }
        /// <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>
        private void OnGenerateConfiguration(object sender, EventArgs e)
        {
            ErrorHandlerUtils.HandleExceptions(() =>
            {
                var selectedProject = SolutionHelper.CurrentSolution.SelectedProject;
                Debug.WriteLine($"Generating configuration for project: {selectedProject.FullPath}");
                var configurationStatus = AppEngineFlexDeployment.CheckProjectConfiguration(selectedProject);

                // If the app.yaml already exists allow the user to skip its generation to preserve the existing file.
                if (!configurationStatus.HasAppYaml ||
                    UserPromptUtils.ActionPrompt(
                        prompt: Resources.GenerateConfigurationAppYamlOverwriteMessage,
                        title: Resources.GenerateConfigurationOverwritePromptTitle,
                        actionCaption: Resources.UiOverwriteButtonCaption,
                        cancelCaption: Resources.UiSkipFileButtonCaption))
                {
                    Debug.WriteLine($"Generating app.yaml for {selectedProject.FullPath}");
                    if (!AppEngineFlexDeployment.GenerateAppYaml(selectedProject))
                    {
                        UserPromptUtils.ErrorPrompt(
                            String.Format(Resources.GenerateConfigurationFileGenerationErrorMessage, AppEngineFlexDeployment.AppYamlName),
                            Resources.GenerateConfigurationFileGeneratinErrorTitle);
                        return;
                    }
                    GcpOutputWindow.OutputLine(Resources.GenerateConfigurationAppYamlGeneratedMessage);
                }

                // If the Dockerfile already exists allow the user to skip its generation to preserve the existing file.
                if (!configurationStatus.HasDockerfile ||
                    UserPromptUtils.ActionPrompt(
                        prompt: Resources.GenerateConfigurationDockerfileOverwriteMessage,
                        title: Resources.GenerateConfigurationOverwritePromptTitle,
                        actionCaption: Resources.UiOverwriteButtonCaption,
                        cancelCaption: Resources.UiSkipFileButtonCaption))
                {
                    Debug.WriteLine($"Generating Dockerfile for {selectedProject.FullPath}");
                    if (!AppEngineFlexDeployment.GenerateDockerfile(selectedProject))
                    {
                        UserPromptUtils.ErrorPrompt(
                            String.Format(Resources.GenerateConfigurationFileGenerationErrorMessage, AppEngineFlexDeployment.DockerfileName),
                            Resources.GenerateConfigurationFileGeneratinErrorTitle);
                        return;
                    }
                    GcpOutputWindow.OutputLine(Resources.GenerateConfigurationDockerfileGeneratedMessage);
                }
            });
        }
Exemplo n.º 30
0
        private bool ValidateInput()
        {
            if (String.IsNullOrEmpty(Version))
            {
                UserPromptUtils.ErrorPrompt(Resources.FlexPublishEmptyVersionMessage, Resources.UiInvalidValueTitle);
                return(false);
            }
            if (!GcpPublishStepsUtils.IsValidName(Version))
            {
                UserPromptUtils.ErrorPrompt(
                    String.Format(Resources.FlexPublishInvalidVersionMessage, Version),
                    Resources.UiInvalidValueTitle);
                return(false);
            }

            return(true);
        }