Ejemplo n.º 1
0
        protected void bgWorkerPopulateTree_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs args)
        {
            try
            {
                _stopwatch.Stop();

                if (args.Cancelled)
                {
                    return;
                }

                if (args.Error != null)
                {
                    // show error dialog
                    ModelBuilderWizardForm.ShowDatabaseConnectionErrorDialog(args.Error);

                    Visited = false;
                    Wizard.OnPrevious();
                }
                else
                {
                    using (new VsUtils.HourglassHelper())
                    {
                        // No errors, populate nodes in TreeView - create the nodes accordingly
                        var result       = (ICollection <EntityStoreSchemaFilterEntry>[])args.Result;
                        var tableEntries = result[0];
                        var viewEntries  = result[1];
                        var sprocEntries = result[2];

                        CreateTreeForNewModel(tableEntries, viewEntries, sprocEntries);

                        // if there are Sproc entries then enable the Create Function Imports box and by default set to checked
                        if (sprocEntries != null && sprocEntries.Count > 0)
                        {
                            chkCreateFunctionImports.Enabled = true;
                            chkCreateFunctionImports.Checked = true;
                        }

                        // Hide status message
                        databaseObjectTreeView.HideStatus();

                        // Set focus to TreeView
                        databaseObjectTreeView.TreeViewControl.SelectedNode = databaseObjectTreeView.TreeViewControl.Nodes[0];
                        databaseObjectTreeView.Focus();

                        _initializedDataConnection      = Wizard.ModelBuilderSettings.DesignTimeConnectionString;
                        _initializedUsingLegacyProvider = Wizard.ModelBuilderSettings.UseLegacyProvider;
                        _initializedGenerationOption    = Wizard.ModelBuilderSettings.GenerationOption;
                        modelNamespaceTextBox.Enabled   = Wizard.ModelBuilderSettings.GenerationOption != ModelGenerationOption.CodeFirstFromDatabase;
                    }
                }

                // Enable wizard navigation
                Wizard.OnValidationStateChanged(this);
            }
            catch (Exception e)
            {
                databaseObjectTreeView.ShowStatus(
                    String.Format(
                        CultureInfo.CurrentCulture,
                        ModelWizard.Properties.Resources.SelectTablesPage_ErrorRetrievingTablesText, e.Message));
                Wizard.EnableButton(ButtonType.Cancel, true);
            }
        }
Ejemplo n.º 2
0
        internal override bool OnWizardFinish()
        {
            using (new VsUtils.HourglassHelper())
            {
                UpdateSettingsFromGui();
            }

            //
            // validate app config connection name
            //
            if (checkBoxSaveInAppConfig.Checked)
            {
                var id = textBoxAppConfigConnectionName.Text;
                if (!EscherAttributeContentValidator.IsValidCsdlEntityContainerName(id) ||
                    !_identifierUtil.IsValidIdentifier(id))
                {
                    VsUtils.ShowErrorDialog(
                        string.Format(CultureInfo.CurrentCulture, Resources.ConnectionStringNonValidIdentifier, id));
                    textBoxAppConfigConnectionName.Focus();
                    _isFocusSet = true;
                    return(false);
                }

                // only check that the connection string name is new if started in
                // 'PerformAllFunctionality' mode
                if (ModelBuilderWizardForm.WizardMode.PerformAllFunctionality == Wizard.Mode)
                {
                    string connectionString;
                    if (ConnectionManager.GetExistingConnectionStrings(_configFileUtils).TryGetValue(id, out connectionString) &&
                        !string.Equals(textBoxConnectionString.Text, connectionString, StringComparison.Ordinal))
                    {
                        VsUtils.ShowErrorDialog(
                            string.Format(CultureInfo.CurrentCulture, Resources.ConnectionStringDuplicateIdentifer, id));
                        textBoxAppConfigConnectionName.Focus();
                        _isFocusSet = true;
                        return(false);
                    }
                }
            }

            // the Model Namespace and the Entity Container name must differ
            if (ModelBuilderWizardForm.ModelNamespaceAndEntityContainerNameSame(Wizard.ModelBuilderSettings))
            {
                var s = Resources.NamespaceAndEntityContainerSame;
                VsUtils.ShowErrorDialog(
                    String.Format(CultureInfo.CurrentCulture, s, Wizard.ModelBuilderSettings.AppConfigConnectionPropertyName));
                textBoxAppConfigConnectionName.Focus();
                _isFocusSet = true;
                return(false);
            }

            try
            {
                // this might cause dataConnection to include some sensitive data into connectionString
                // the Open function also can cause DDEX to put up a prompt for the username/password for an existing connection
                // that does not have any saved password information.
                _dataConnection.Open();

                if (!IsDataValid)
                {
                    sensitiveInfoTextBox.Enabled        = true;
                    allowSensitiveInfoButton.Checked    = false;
                    allowSensitiveInfoButton.Enabled    = true;
                    disallowSensitiveInfoButton.Checked = false;
                    disallowSensitiveInfoButton.Enabled = true;

                    var result = VsUtils.ShowMessageBox(
                        PackageManager.Package,
                        Resources.SensitiveDataInfoText,
                        OLEMSGBUTTON.OLEMSGBUTTON_YESNOCANCEL,
                        OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_THIRD,
                        OLEMSGICON.OLEMSGICON_QUERY);

                    switch (result)
                    {
                    case DialogResult.Yes:
                        allowSensitiveInfoButton.Checked = true;
                        break;

                    case DialogResult.No:
                        disallowSensitiveInfoButton.Checked = true;
                        break;

                    default:
                        Wizard.OnValidationStateChanged(this);
                        return(false);
                    }
                }
            }
            catch (DataConnectionOpenCanceledException)
            {
                return(false);
            }
            catch (Exception e)
            {
                // show error dialog
                ModelBuilderWizardForm.ShowDatabaseConnectionErrorDialog(e);

                return(false);
            }
            finally
            {
                if (_dataConnection.State != DataConnectionState.Closed)
                {
                    _dataConnection.Close();
                }
            }

            return(true);
        }
Ejemplo n.º 3
0
        protected void bgWorkerPopulateTree_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs args)
        {
            try
            {
                _stopwatch.Stop();

                if (args.Cancelled)
                {
                    return;
                }

                if (args.Error != null)
                {
                    // show error dialog
                    var errMsg = ModelBuilderWizardForm.ShowDatabaseConnectionErrorDialog(args.Error);

                    Visited = false;

                    // if database config could be at fault revert to database config page
                    // otherwise just show the error message in the wizard and enable the cancel button
                    if (ModelBuilderWizardForm.WizardMode.PerformDatabaseConfigAndSelectTables == Wizard.Mode)
                    {
                        Wizard.OnPrevious();
                    }
                    else
                    {
                        ShowStatus(errMsg);
                        Wizard.EnableButton(ButtonType.Cancel, true);
                    }
                }
                else
                {
                    // No errors, populate nodes in TreeViews
                    var result       = (ICollection <EntityStoreSchemaFilterEntry>[])args.Result;
                    var tableEntries = result[0];
                    var viewEntries  = result[1];
                    var sprocEntries = result[2];

                    // First find all tables, views and storedProc's which exist in the current model (before update from DB)
                    // (value is not used - but list is in sorted order to ensure they show up correctly on the wizard)
                    SortedDictionary <DatabaseObject, int> existingTables;
                    SortedDictionary <DatabaseObject, int> existingViews;
                    SortedDictionary <DatabaseObject, int> existingStoredProcs;
                    GetExistingTablesViewsAndSprocs(
                        Wizard.ModelBuilderSettings.Artifact,
                        out existingTables, out existingViews, out existingStoredProcs);

                    // now create the tree nodes
                    string storageEntityContainerName = null;
                    if (null != Wizard.ModelBuilderSettings.Artifact &&
                        null != Wizard.ModelBuilderSettings.Artifact.StorageModel() &&
                        null != Wizard.ModelBuilderSettings.Artifact.StorageModel().FirstEntityContainer &&
                        null != Wizard.ModelBuilderSettings.Artifact.StorageModel().FirstEntityContainer.LocalName &&
                        null != Wizard.ModelBuilderSettings.Artifact.StorageModel().FirstEntityContainer.LocalName.Value)
                    {
                        storageEntityContainerName =
                            Wizard.ModelBuilderSettings.Artifact.StorageModel().FirstEntityContainer.LocalName.Value;
                    }
                    CreateAddRefreshAndDeleteTreeNodes(
                        tableEntries,
                        viewEntries,
                        sprocEntries,
                        existingTables,
                        existingViews,
                        existingStoredProcs,
                        storageEntityContainerName);

                    // Hide status message
                    HideStatus();

                    // Enable tab pages and make Description fields visible
                    AddUpdateDeleteTabControl.Enabled = true;
                    DescriptionTextBox.Visible        = true;

                    // Set focus to TreeView
                    var currentTreeView = CurrentTreeView;
                    if (null != currentTreeView)
                    {
                        currentTreeView.FocusAndSetFirstNodeSelected();
                    }

                    TreeViewsInitialized       = true;
                    _initializedDataConnection = Wizard.ModelBuilderSettings.DesignTimeConnectionString;
                }

                // Enable wizard navigation
                Wizard.OnValidationStateChanged(this);
            }
            catch (Exception e)
            {
                ShowStatus(
                    String.Format(
                        CultureInfo.CurrentCulture,
                        Resources.SelectTablesPage_ErrorRetrievingTablesText,
                        e.Message));
                Wizard.EnableButton(ButtonType.Cancel, true);
            }
        }