/// <summary>
 /// Runs custom wizard logic at the beginning of a template wizard run.
 /// </summary>
 /// <param name="automationObject">The automation object being used by the template wizard.</param>
 /// <param name="replacementsDictionary">The list of standard parameters to be replaced.</param>
 /// <param name="runKind">A <see cref="T:Microsoft.VisualStudio.TemplateWizard.WizardRunKind" /> indicating the type of wizard run.</param>
 /// <param name="customParams">The custom parameters with which to perform parameter replacement in the project.</param>
 public void RunStarted(Object automationObject, Dictionary <string, string> replacementsDictionary, WizardRunKind runKind, Object[] customParams)
 {
     try
     {
         dte = automationObject as DTE;
         Array   activeProjects = (Array)dte.ActiveSolutionProjects;
         Project activeProj     = (Project)activeProjects.GetValue(0);
         _projectPath          = System.IO.Path.GetDirectoryName(activeProj.FullName);
         _projectNamespace     = activeProj.Properties.Item("DefaultNamespace").Value.ToString();
         _NetFxVersion         = replacementsDictionary["$targetframeworkversion$"];
         _itemTemplateTempPath = customParams[0].ToString().Substring(0, customParams[0].ToString().LastIndexOf("\\"));
         ItemTemplatesWebWizard form = new ItemTemplatesWebWizard(_language, dte, _projectType);
         form.StartPosition = FormStartPosition.CenterScreen;
         DialogResult result = form.ShowDialog();
         if (result == DialogResult.OK)
         {
             GetFormValues(form);
             string providerConnectionString = ItemTemplateUtilities.GetProviderConnectionString(_selectedModel, dte, false);
             if (!string.IsNullOrEmpty(providerConnectionString))
             {
                 _connectionString = providerConnectionString;
                 _connectionName   = ItemTemplateUtilities.GetConnectionStringName(_selectedModel, dte, false);
                 _connection       = new MySqlConnection(_connectionString);
             }
         }
     }
     catch (WizardCancelledException wce)
     {
         throw wce;
     }
     catch (Exception e)
     {
         SendToGeneralOutputWindow(string.Format("An error occurred: {0}\n\n {1}", e.Message, e.StackTrace));
     }
 }
Exemplo n.º 2
0
        internal void FillTables(string modelName, DTE dte, bool checkForAppConfig)
        {
            string edmxFileName             = string.Format("{0}.edmx", modelName);
            string providerConnectionString = ItemTemplateUtilities.GetProviderConnectionString(edmxFileName, dte, checkForAppConfig);

            if (string.IsNullOrEmpty(providerConnectionString))
            {
                return;
            }

            this.ConnectionString = providerConnectionString;
            this.ConnectionName   = ItemTemplateUtilities.GetConnectionStringName(edmxFileName, dte, checkForAppConfig);
            LockUI();

            try
            {
                DoWorkEventHandler doWorker = (worker, doWorkerArgs) =>
                {
                    Application.DoEvents();
                    var cnn = new MySqlConnection(providerConnectionString);
                    cnn.Open();
                    var dtTables = cnn.GetSchema("Tables", new string[] { null, cnn.Database });
                    cnn.Close();
                    _tables = new BindingList <DbTables>();

                    this.Invoke((Action)(() =>
                    {
                        ComboEntities.Items.Clear();

                        for (int i = 0; i < dtTables.Rows.Count; i++)
                        {
                            _tables.Add(new DbTables(false, dtTables.Rows[i][2].ToString()));
                        }

                        _sourceTables.DataSource = _tables;

                        foreach (string table in _tables.Select(t => t.Name))
                        {
                            ComboEntities.Items.Add(table);
                        }

                        SetEntitiesAutoCompleteCollection();
                    }));
                };

                if (Worker != null)
                {
                    Worker.DoWork             -= doWorker;
                    Worker.RunWorkerCompleted -= _worker_RunWorkerCompleted;
                    Worker.Dispose();
                }

                Worker = new BackgroundWorker();
                Worker.WorkerSupportsCancellation = true;
                Worker.DoWork             += doWorker;
                Worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(_worker_RunWorkerCompleted);
                Worker.RunWorkerAsync();
            }
            finally
            {
                UnlockUI();
            }
        }