public boolean performOk()

in PluginsAndFeatures/azure-toolkit-for-eclipse/com.microsoft.azuretools.core/src/com/microsoft/azuretools/core/ui/WindowsAzurePreferencePage.java [167:253]


    public boolean performOk() {
        boolean isSet = true;
        try {
            if (new File(pluginInstLoc).exists()) {
                if (new File(dataFile).exists()) {
                    Document doc = ParserXMLUtility.parseXMLFile(dataFile);
                    String oldPrefVal = DataOperations.getProperty(dataFile, Messages.prefVal);
                    DataOperations.updatePropertyValue(doc, Messages.prefVal,
                            String.valueOf(btnPreference.getSelection()));

                    final String version = DataOperations.getProperty(dataFile, Messages.version);
                    final String newVersion = Activator.getDefault().getBundle().getVersion().toString();
                    if (version == null || version.isEmpty()) {
                        DataOperations.updatePropertyValue(doc, Messages.version, newVersion);
                    } else if (!newVersion.equalsIgnoreCase(version)) {
                        DataOperations.updatePropertyValue(doc, Messages.version, newVersion);
                        AppInsightsClient.createByType(AppInsightsClient.EventType.Plugin, "", AppInsightsConstants.Upgrade, null, true);
                        EventUtil.logEvent(EventType.info, SYSTEM, PLUGIN_UPGRADE, null, null);
                    }

                    String instID = DataOperations.getProperty(dataFile, Messages.instID);
                    if (instID == null || instID.isEmpty() || !InstallationIdUtils.isValidHashMac(instID)) {
                        DataOperations.updatePropertyValue(doc, Messages.instID, InstallationIdUtils.getHashMac());
                        AppInsightsClient.createByType(AppInsightsClient.EventType.Plugin, "", AppInsightsConstants.Install, null, true);
                        EventUtil.logEvent(EventType.info, SYSTEM, PLUGIN_INSTALL, null, null);
                    }
                    ParserXMLUtility.saveXMLFile(dataFile, doc);
                    // Its necessary to call application insights custom create
                    // event after saving data.xml
                    final boolean acceptTelemetry = btnPreference.getSelection();
                    if (StringUtils.isNullOrEmpty(oldPrefVal) || Boolean.valueOf(oldPrefVal) != acceptTelemetry) {
                        // Boolean.valueOf(oldPrefVal) != acceptTelemetry means
                        // user changes his mind.
                        // Either from Agree to Deny, or from Deny to Agree.
                        final String action = acceptTelemetry ? AppInsightsConstants.Allow : AppInsightsConstants.Deny;
                        AppInsightsClient.createByType(AppInsightsClient.EventType.Telemetry, "", action, null, true);
                        EventUtil.logEvent(EventType.info, SYSTEM, acceptTelemetry ? TELEMETRY_ALLOW : TELEMETRY_DENY,
                                null, null);
                    }
                } else {
                    FileUtil.copyResourceFile(Messages.dataFileEntry, dataFile);
                    setValues(dataFile);
                }
            } else {
                new File(pluginInstLoc).mkdir();
                FileUtil.copyResourceFile(Messages.dataFileEntry, dataFile);
                setValues(dataFile);
            }
        } catch (SAXParseException ex2) {
            isSet = false;
            FileUtils.deleteQuietly(new File(this.dataFile));
            Activator.getDefault().log(ex2.getMessage(), ex2);
        } catch (Exception ex) {
            isSet = false;
            Activator.getDefault().log(ex.getMessage(), ex);
        }

        // new logic of persist settings
        final AzureConfiguration config = Azure.az().config();
        config.setCloud(AzureEnvironmentUtils.azureEnvironmentToString(cbAzureEnv.getValue()));
        config.setTelemetryEnabled(btnPreference.getSelection());
        String userAgent = String.format(Activator.USER_AGENT, config.getVersion(),
                Azure.az().config().getMachineId());
        CommonSettings.setUserAgent(userAgent);

        // we need to get rid of AuthMethodManager, using az.azure_account
        if (AuthMethodManager.getInstance().isSignedIn()) {
            final AuthMethodManager authMethodManager = AuthMethodManager.getInstance();
            final String azureEnv = authMethodManager.getAuthMethodDetails().getAzureEnv();
            final AzureEnvironment currentEnv = AzureEnvironmentUtils.stringToAzureEnvironment(azureEnv);
            if (!Objects.equals(currentEnv, cbAzureEnv.getValue())) {
                EventUtil.executeWithLog(ACCOUNT, SIGNOUT, (operation) -> {
                    authMethodManager.signOut();
                });
            }
        }

        AzureConfigInitializer.saveAzConfig();
        if (isSet) {
            // forget temporary values once OK button has been pressed.
            Activator.setPrefState("");
            return super.performOk();
        } else {
            PluginUtil.displayErrorDialog(getShell(), Messages.err, Messages.prefSaveErMsg);
            return false;
        }
    }