Ejemplo n.º 1
0
        public static SqlConnection Parse(string s)
        {
            string[] split = s.Split('¬');

            if (split.Length != 4)
            {
                return(null);
            }

            string id               = split[0];
            string name             = split[1];
            string connectionString = split[2];
            string providerName     = split[3];

            SqlConnectionManager sqlConnectionManager =
                SqlConnectionManager.GetInstance();

            SqlDataProvider provider =
                sqlConnectionManager.GetProviderByInvariantName(providerName);

            if (provider == null)
            {
                return(null);
            }

            return(new SqlConnection(
                       id, name, connectionString, provider));
        }
Ejemplo n.º 2
0
        public SqlMetalForm(SqlConnection selectedConnection)
        {
            InitializeComponent();

            _applicationManager =
                QuickSharp.Core.ApplicationManager.GetInstance();

            _persistenceManager = _applicationManager.
                                  GetPersistenceManager(Constants.PLUGIN_NAME);

            _sqlConnectionManager =
                SqlConnectionManager.GetInstance();

            _provider         = selectedConnection.Provider;
            _connectionString = selectedConnection.ConnectionString;

            _useCompactEdition = _sqlConnectionManager.
                                 ConnectionIsSqlServerCe(selectedConnection);

            _output = _applicationManager.GetDockedForm(
                QuickSharp.Output.Constants.DOCKED_FORM_KEY)
                      as OutputForm;

            /*
             * Get the tool path.
             */

            _sqlMetalPath = _persistenceManager.ReadString(
                Constants.KEY_SQL_METAL_PATH,
                Constants.SQL_METAL_DEFAULT_PATH);

            /*
             * Populate the filename with the database name.
             */

            _filenameTextBox.Text = GetOutputFilename();

            /*
             * Update the UI
             */

            Text = Resources.SqlMetalFormTitle;
            _filenameLabel.Text     = Resources.SqlMetalFormFilename;
            _includeGroupBox.Text   = Resources.SqlMetalFormIncludeGroup;
            _viewsCheckBox.Text     = Resources.SqlMetalFormViews;
            _functionsCheckBox.Text = Resources.SqlMetalFormFunctions;
            _sprocsCheckBox.Text    = Resources.SqlMetalFormSprocs;
            _okButton.Text          = Resources.SqlMetalFormOk;
            _cancelButton.Text      = Resources.SqlMetalFormCancel;

            CheckToolAvailable();

            /*
             * Allow client applications to modify form.
             */

            SqlMetalFormProxy.GetInstance().
            UpdateFormControls(Controls);
        }
Ejemplo n.º 3
0
        public static SqlConnectionManager GetInstance()
        {
            if (_singleton == null)
            {
                _singleton = new SqlConnectionManager();
            }

            return(_singleton);
        }
Ejemplo n.º 4
0
        public SqlConnectionForm(
            Dictionary <String, SqlConnection> sqlConnections,
            string id)
        {
            InitializeComponent();

            _sqlConnectionManager = SqlConnectionManager.GetInstance();
            _sqlConnections       = sqlConnections;
            _connectionId         = id;

            foreach (SqlDataProvider provider in
                     _sqlConnectionManager.SqlDataProviders.Values)
            {
                _providerComboBox.Items.Add(provider);
            }

            if (_providerComboBox.Items.Count > 0)
            {
                _providerComboBox.SelectedIndex = 0;
            }

            if (_connectionId != null)
            {
                if (!_sqlConnections.ContainsKey(id))
                {
                    throw new Exception("Invalid connection ID");
                }

                SqlConnection connection = _sqlConnections[id];
                _nameTextBox.Text             = connection.Name;
                _connectionStringTextBox.Text =
                    connection.ConnectionStringForEditing;

                SelectedProviderByInvariantName(
                    connection.Provider.InvariantName);
            }

            // Allow client applications to modify the form.
            SqlConnectionFormProxy.GetInstance().
            UpdateFormControls(Controls);
        }
        public SqlConnectionsOptionsPage()
        {
            _sqlConnectionManager = SqlConnectionManager.GetInstance();
            _sqlConnections       = new Dictionary <String, SqlConnection>();

            /*
             * Make a local copy of the connections to allow cancel.
             */

            foreach (string id in _sqlConnectionManager.SqlConnections.Keys)
            {
                _sqlConnections[id] =
                    _sqlConnectionManager.SqlConnections[id];
            }

            _selectedConnection = _sqlConnectionManager.SelectedConnectionId;

            Name      = Constants.UI_OPTIONS_PAGE_CONNECTIONS;
            PageText  = Resources.OptionsPageTextConnections;
            GroupText = Resources.OptionsGroupText;

            _listView                = new ListView();
            _nameColumnHeader        = new ColumnHeader();
            listViewContextMenuStrip = new ContextMenuStrip();
            UI_CONTEXT_MENU_NEW      = new ToolStripMenuItem();
            UI_CONTEXT_MENU_EDIT     = new ToolStripMenuItem();
            UI_CONTEXT_MENU_CLONE    = new ToolStripMenuItem();
            UI_CONTEXT_MENU_DELETE   = new ToolStripMenuItem();

            Controls.Add(this._listView);

            #region Form Layout

            _listView.Columns.AddRange(new ColumnHeader[] {
                _nameColumnHeader
            });
            _listView.ContextMenuStrip = listViewContextMenuStrip;
            _listView.Font             = new Font("Tahoma", 8.25F, FontStyle.Regular, GraphicsUnit.Point, ((byte)(0)));
            _listView.FullRowSelect    = true;
            _listView.HeaderStyle      = ColumnHeaderStyle.Nonclickable;
            _listView.Location         = new Point(0, 0);
            _listView.MultiSelect      = false;
            _listView.Name             = m_listView;
            _listView.Size             = new Size(430, 250);
            _listView.TabIndex         = 0;
            _listView.UseCompatibleStateImageBehavior = false;
            _listView.View = View.Details;

            _nameColumnHeader.Text  = Resources.ListColumnName;
            _nameColumnHeader.Name  = m_nameColumnHeader;
            _nameColumnHeader.Width = 405;

            listViewContextMenuStrip.Items.AddRange(new ToolStripItem[] {
                UI_CONTEXT_MENU_NEW,
                UI_CONTEXT_MENU_EDIT,
                UI_CONTEXT_MENU_CLONE,
                UI_CONTEXT_MENU_DELETE
            });
            listViewContextMenuStrip.Name = m_listViewContextMenuStrip;
            listViewContextMenuStrip.Size = new Size(153, 92);

            UI_CONTEXT_MENU_NEW.Name = Constants.UI_CONTEXT_MENU_NEW;
            UI_CONTEXT_MENU_NEW.Text = Resources.ContextMenuNew;

            UI_CONTEXT_MENU_EDIT.Name = Constants.UI_CONTEXT_MENU_EDIT;
            UI_CONTEXT_MENU_EDIT.Text = Resources.ContextMenuEdit;

            UI_CONTEXT_MENU_CLONE.Name = Constants.UI_CONTEXT_MENU_CLONE;
            UI_CONTEXT_MENU_CLONE.Text = Resources.ContextMenuClone;

            UI_CONTEXT_MENU_DELETE.Name = Constants.UI_CONTEXT_MENU_DELETE;
            UI_CONTEXT_MENU_DELETE.Text = Resources.ContextMenuDelete;

            #endregion

            listViewContextMenuStrip.Opening +=
                new CancelEventHandler(ListViewContextMenuStrip_Opening);

            UI_CONTEXT_MENU_NEW.Click +=
                new EventHandler(UI_CONTEXT_MENU_NEW_Click);
            UI_CONTEXT_MENU_EDIT.Click +=
                new EventHandler(UI_CONTEXT_MENU_EDIT_Click);
            UI_CONTEXT_MENU_CLONE.Click +=
                new EventHandler(UI_CONTEXT_MENU_CLONE_Click);
            UI_CONTEXT_MENU_DELETE.Click +=
                new EventHandler(UI_CONTEXT_MENU_DELETE_Click);
            _listView.DoubleClick +=
                new EventHandler(ListView_DoubleClick);

            UpdateListView();
        }
Ejemplo n.º 6
0
        private void ActivatePlugin()
        {
            ModuleProxy.GetInstance().Module = this;

            _applicationManager   = ApplicationManager.GetInstance();
            _pluginManager        = PluginManager.GetInstance();
            _sqlConnectionManager = SqlConnectionManager.GetInstance();
            _sqlConnectionManager.Load();

            /*
             * Enable SqlMetal/DMBL extract features if client flag set.
             */

            bool enableSqlMetal =
                _applicationManager.ClientProfile.HaveFlag(
                    ClientFlags.SqlManagerEnableDbmlExtract);

            _output = _applicationManager.GetDockedForm(
                QuickSharp.Output.Constants.DOCKED_FORM_KEY) as
                      OutputForm;

            _toolsMenuRunQuery = MenuTools.CreateMenuItem(
                Constants.UI_TOOLS_MENU_RUN_QUERY,
                Resources.MainToolsMenuRunQuery,
                Resources.RunQuery,
                Keys.F5, null, UI_TOOLBAR_RUN_SQL_QUERY_Click,
                true);

            ToolStripMenuItem toolsMenu = _mainForm.GetMenuItemByName(
                QuickSharp.Core.Constants.UI_TOOLS_MENU);

            int index = toolsMenu.DropDownItems.IndexOfKey(
                QuickSharp.Core.Constants.UI_TOOLS_MENU_OPTIONS);

            /*
             * If menu not found insert at the top.
             */

            if (index == -1)
            {
                index = 0;
            }

            toolsMenu.DropDownItems.Insert(index, _toolsMenuRunQuery);

            /*
             * Create toolbar buttons.
             */

            _toolbarSqlConnection = MenuTools.CreateToolbarButton(
                Constants.UI_TOOLBAR_SQL_CONNECTION,
                Resources.ToolbarSqlConnection,
                Resources.SqlConnection,
                UI_TOOLBAR_SQL_CONNECTION_Click,
                true);

            _toolbarSqlConnection.ToolTipText =
                Resources.ToolbarActivateConnection;

            _toolbarSqlConnectionSelect =
                MenuTools.CreateToolbarDropDownButton(
                    Constants.UI_TOOLBAR_SQL_CONNECTION_SELECT, null);

            _toolbarSqlConnectionSelect.DropDownOpening +=
                new EventHandler(
                    ToolbarSqlConnectionSelect_DropDownOpening);

            _toolbarSqlRunQuery = MenuTools.CreateToolbarButton(
                Constants.UI_TOOLBAR_SQL_RUN_QUERY,
                Resources.ToolbarSqlRunQuery,
                Resources.RunQuery,
                UI_TOOLBAR_RUN_SQL_QUERY_Click);

            _toolbarSqlExtractDbml = MenuTools.CreateToolbarButton(
                Constants.UI_TOOLBAR_SQL_EXTRACT_DBML,
                Resources.ToolbarSqlExtractDbml,
                Resources.ExtractDbml,
                UI_TOOLBAR_SQL_EXTRACT_DBML_Click);

            _mainForm.MainToolbar.Items.Add(_toolbarSqlConnection);
            _mainForm.MainToolbar.Items.Add(_toolbarSqlConnectionSelect);
            _mainForm.MainToolbar.Items.Add(_toolbarSqlRunQuery);

            if (enableSqlMetal)
            {
                _mainForm.MainToolbar.Items.Add(_toolbarSqlExtractDbml);
            }

            _mainForm.FormClosing +=
                new FormClosingEventHandler(MainForm_FormClosing);

            _mainForm.ClientWindow.ActiveDocumentChanged +=
                new EventHandler(ClientWindow_ActiveDocumentChanged);

            _applicationManager.RegisterOptionsPageFactory(
                delegate { return(new SqlConnectionsOptionsPage()); });

            if (enableSqlMetal)
            {
                _applicationManager.RegisterOptionsPageFactory(
                    delegate { return(new SqlMetalOptionsPage()); });
            }

            _applicationManager.FileSystemChange +=
                new MessageHandler(UpdateUI);

            /*
             * We don't have any build tools but we want SQL files
             * recognised as source files. Register with the
             * non-tool source files list in the application store.
             */

            ApplicationStorage appStore = ApplicationStorage.GetInstance();

            /*
             * We have no dependency on the BuildTools plugin so we
             * can't assume the non-tool source list has been created.
             * Use the Get method to create the list if it doesn't exist.
             */

            List <String> nonToolSourceTypes = appStore.Get(
                Constants.APP_STORE_KEY_NON_TOOL_SOURCE_TYPES,
                typeof(List <String>)) as List <String>;

            if (nonToolSourceTypes != null)
            {
                nonToolSourceTypes.Add(Constants.DOCUMENT_TYPE_SQL);
            }

            UpdateUI();
        }