Example #1
0
        void Provider_SelectionChanged(Object sender, NodesChangedEventArgs args)
        {
            try
            {
                var t    = args.GetType();
                var pi   = t.GetProperty("ChangedNodes");
                var coll = (ICollection)pi.GetValue(args, null);

                foreach (INavigationContext n in coll)
                {
                    if ((n != null) && (n.Parent == null))
                    {
                        log.Info("New Server Connected " + n.Name + " -  " + n.Connection.ServerName);

                        // this could mean that new server was added
                        var res = " server " + n.Name + n.Connection.ServerName;

                        if (OnNewServerConnected != null)
                        {
                            OnNewServerConnected((SqlConnectionInfo)n.Connection);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error("Error processing OnSelectionChanged event: " + ex.Message, ex);
            }
        }
        // ReSharper disable once UnusedMember.Local
        // ReSharper disable once UnusedParameter.Local
        private void Provider_SelectionChanged(object sender, NodesChangedEventArgs args)
        {
            if (args.ChangedNodes.Count <= 0)
            {
                return;
            }
            var node = args.ChangedNodes[0];

            if (node == null)
            {
                return;
            }
            Debug.WriteLine(node.UrnPath);
            Debug.WriteLine(node.Name);
            Debug.WriteLine(node.Context);
            if (_serverMenu == null && _urnPath == node.UrnPath)
            {
                _serverMenu = (HierarchyObject)node.GetService(typeof(IMenuHandler));
                //var separator = new ToolStripSeparatorMenuItem();
                //_serverMenu.AddChild(string.Empty, separator);
                var item = new DatabaseMenuItem(_package);
                _serverMenu.AddChild(string.Empty, item);
            }

            if (_tableMenu == null && _tableUrnPath == node.UrnPath)
            {
                _tableMenu = (HierarchyObject)node.GetService(typeof(IMenuHandler));
                //var separator = new ToolStripSeparatorMenuItem();
                //_serverMenu.AddChild(string.Empty, separator);
                var item = new TableMenuItem(_package);
                _tableMenu.AddChild(string.Empty, item);
            }
        }
Example #3
0
        private void Provider_SelectionChanged(object sender, NodesChangedEventArgs args)
        {
            INavigationContextProvider provider = (INavigationContextProvider)sender;
            INodeInformation           node     = (args.ChangedNodes.Count > 0 ? args.ChangedNodes[0] : null);

            if (_tableMenu == null &&
                _tableRegex.IsMatch(node.Context))
            {
                _tableMenu = (HierarchyObject)node.GetService(typeof(IMenuHandler));

                MenuItem item = new MenuItem();
                _tableMenu.AddChild(string.Empty, item);
            }
        }
Example #4
0
        private void Provider_SelectionChanged(object sender, NodesChangedEventArgs args)
        {
            INavigationContextProvider provider = (INavigationContextProvider)sender;
            INodeInformation node = (args.ChangedNodes.Count > 0 ? args.ChangedNodes[0] : null);

            if (_tableMenu == null &&
                _tableRegex.IsMatch(node.Context))
            {
                _tableMenu = (HierarchyObject)node.GetService(typeof(IMenuHandler));

                MenuItem item = new MenuItem();
                _tableMenu.AddChild(string.Empty, item);
            }
        }
Example #5
0
        void provider_SelectionChanged(object sender, NodesChangedEventArgs args)
        {
            //_outputWindowPane.OutputString("SelectionChanged \n");
            //var res = "";
            //foreach (var n in args.ChangedNodes)
            //{
            //    if (n.Parent == null)
            //        res += " server " + n.Name + n.Connection.ServerName;
            //    else
            //        res += n.Name;
            //}

            //_outputWindowPane.OutputString(res);
        }
Example #6
0
        /// <summary>
        /// when the object explorer is loaded and change
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        void ObjectExplorerContext_CurrentContextChanged(object sender, NodesChangedEventArgs args)
        {
            debug_message("ObjectExplorerContext_CurrentContextChanged::");
            try
            {
                if (_trv == null)
                {
                    _trv = GetObjectExplorerTreeView();
                }

                if (_trv != null && !_trv.InvokeRequired)
                {
                    if (_objectExplorerExtender == null)
                    {
                        logger.LogStart("ObjectExplorerExtender");
                        _objectExplorerExtender = new ObjectExplorerExtender();
                        logger.LogEnd("ObjectExplrerExtender");
                        if (_trv != null)
                        {
                            logger.LogStart("ImageList");
                            if (!_trv.ImageList.Images.ContainsKey("FolderSelected"))
                            {
                                _trv.ImageList.Images.Add("FolderSelected", Resources.folder);
                                _trv.ImageList.Images.Add("Table", Resources.tab_ico);
                                _trv.ImageList.Images.Add("FolderDown", Resources.folder_closed);
                                _trv.ImageList.Images.Add("FolderEdit", Resources.folder);
                                _trv.ImageList.Images.Add("FunctionFun", Resources.fun_ico);

                                _trv.BeforeExpand += new TreeViewCancelEventHandler(_trv_BeforeExpand);
                                _trv.AfterExpand  += new TreeViewEventHandler(_trv_AfterExpand);
                                //TODO: _trv.NodeMouseClick += new TreeNodeMouseClickEventHandler(_trv_NodeMouseClick);
                            }
                            logger.LogEnd("ImageList");
                        }
                    }
                }
                else if (_trv != null)
                {
                    logger.LogStart(" Inovke Required sender is " + (sender == null ? "null" : "not null"), "args is " +
                                    (args == null ? "null" : "not null"));
                    //IntPtr ptr = _trv.Handle;
                    _trv.BeginInvoke(new NodesChangedEventHandler(ObjectExplorerContext_CurrentContextChanged), new object[] { sender, args });
                    logger.LogEnd("Invoke Required ");
                }
            }
            catch (Exception ObjectExplorerContextException)
            {
                debug_message(String.Format("ObjectExplorerContext_CurrentContextChanged::ERROR:{0}", ObjectExplorerContextException.Message));
            }
        }
Example #7
0
        /// <summary>
        /// Handles the NodesRefreshed event of the IObjectExplorerEventProvider object.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="args">The <see cref="Microsoft.SqlServer.Management.UI.VSIntegration.ObjectExplorer.NodesChangedEventArgs"/> instance containing the event data.</param>
        private void Provider_NodesRefreshed(object sender, NodesChangedEventArgs args)
        {
            Control objectExplorer = (sender as Control);

            if (objectExplorer.InvokeRequired)
            {
                objectExplorer.Invoke(new NodesChangedEventHandler(Provider_NodesRefreshed), new object[] { sender, args });

                return;
            }

            if (objectExplorerExtender == null)
            {
                objectExplorerExtender = new ObjectExplorerExtender(this.windowManager);
            }
        }
Example #8
0
        private void Provider_SelectionChanged(object sender, NodesChangedEventArgs args)
        {
            Connect.ViewsSelected = false;
            INodeInformation node = Connect.ObjectExplorerSelectedNode;

            if (node != null)
            {
                System.Diagnostics.Debug.WriteLine(node.UrnPath);
                System.Diagnostics.Debug.WriteLine(node.Name);
                System.Diagnostics.Debug.WriteLine(node.Context);
                // Mobile Device connections not supported
                if (node.Connection.ServerName.StartsWith("Mobile Device\\", StringComparison.Ordinal))
                {
                    // short circuit
                    node = null;
                }
            }

            if (node != null && _serverMenu == null &&
                urnPath == node.UrnPath)
            {
                _serverMenu = (HierarchyObject)node.GetService(typeof(IMenuHandler));

                _serverMenu.AddChild(string.Empty, new ToolStripSeparatorMenuItem());
                DatabaseMenuItem item = new DatabaseMenuItem();
                _serverMenu.AddChild(string.Empty, item);
                ServerMenuItem serveritem = new ServerMenuItem();
                _serverMenu.AddChild(string.Empty, serveritem);
            }

            if (node != null && _tableMenu == null &&
                tableUrnPath == node.UrnPath)
            {
                _tableMenu = (HierarchyObject)node.GetService(typeof(IMenuHandler));

                _tableMenu.AddChild(string.Empty, new ToolStripSeparatorMenuItem());
                EditTableMenuItem itemE = new EditTableMenuItem();
                _tableMenu.AddChild(string.Empty, itemE);

                _tableMenu.AddChild(string.Empty, new ToolStripSeparatorMenuItem());
                ScriptTableMenuItem item = new ScriptTableMenuItem();
                _tableMenu.AddChild(string.Empty, item);

                _tableMenu.AddChild(string.Empty, new ToolStripSeparatorMenuItem());
                ImportTableMenuItem item2 = new ImportTableMenuItem();
                _tableMenu.AddChild(string.Empty, item2);

                _tableMenu.AddChild(string.Empty, new ToolStripSeparatorMenuItem());
                RenameTableMenuItem item3 = new RenameTableMenuItem();
                _tableMenu.AddChild(string.Empty, item3);
            }

            if (node != null && _indexMenu == null && indexUrnPath == node.UrnPath)
            {
                _indexMenu = (HierarchyObject)node.GetService(typeof(IMenuHandler));

                _indexMenu.AddChild(string.Empty, new ToolStripSeparatorMenuItem());
                ScriptIndexMenuItem itemI = new ScriptIndexMenuItem();
                _indexMenu.AddChild(string.Empty, itemI);
            }

            if (node != null && _viewMenu == null &&
                viewUrnPath == node.UrnPath)
            {
                _viewMenu = (HierarchyObject)node.GetService(typeof(IMenuHandler));

                _viewMenu.AddChild(string.Empty, new ToolStripSeparatorMenuItem());
                EditTableMenuItem itemV = new EditTableMenuItem();
                _viewMenu.AddChild(string.Empty, itemV);
            }

            // Set this each time
            if (node != null && viewUrnPath == node.UrnPath)
            {
                Connect.ViewsSelected = true;
            }
        }
Example #9
0
        private void Provider_SelectionChanged(object sender, NodesChangedEventArgs args)
        {
            Connect.ViewsSelected = false;
            INodeInformation node = Connect.ObjectExplorerSelectedNode;
            if (node != null)
            {
                System.Diagnostics.Debug.WriteLine(node.UrnPath);
                System.Diagnostics.Debug.WriteLine(node.Name);
                System.Diagnostics.Debug.WriteLine(node.Context);
                // Mobile Device connections not supported
                if (node.Connection.ServerName.StartsWith("Mobile Device\\", StringComparison.Ordinal))
                {
                    // short circuit
                    node = null;
                }
            }

            if (node != null && _serverMenu == null &&
                urnPath == node.UrnPath)
            {
                _serverMenu = (HierarchyObject)node.GetService(typeof(IMenuHandler));
                
                _serverMenu.AddChild(string.Empty, new ToolStripSeparatorMenuItem());
                DatabaseMenuItem item = new DatabaseMenuItem();
                _serverMenu.AddChild(string.Empty, item);
                ServerMenuItem serveritem = new ServerMenuItem();
                _serverMenu.AddChild(string.Empty, serveritem);
            }

            if (node != null && _tableMenu == null &&
                tableUrnPath == node.UrnPath)
            {
                _tableMenu = (HierarchyObject)node.GetService(typeof(IMenuHandler));

                _tableMenu.AddChild(string.Empty, new ToolStripSeparatorMenuItem());
                EditTableMenuItem itemE = new EditTableMenuItem();
                _tableMenu.AddChild(string.Empty, itemE);

                _tableMenu.AddChild(string.Empty, new ToolStripSeparatorMenuItem());
                ScriptTableMenuItem item = new ScriptTableMenuItem();
                _tableMenu.AddChild(string.Empty, item);

                _tableMenu.AddChild(string.Empty, new ToolStripSeparatorMenuItem());
                ImportTableMenuItem item2 = new ImportTableMenuItem();
                _tableMenu.AddChild(string.Empty, item2);

                _tableMenu.AddChild(string.Empty, new ToolStripSeparatorMenuItem());
                RenameTableMenuItem item3 = new RenameTableMenuItem();
                _tableMenu.AddChild(string.Empty, item3);
            }

            if (node != null && _indexMenu == null && indexUrnPath == node.UrnPath)
            {
                _indexMenu = (HierarchyObject)node.GetService(typeof(IMenuHandler));

                _indexMenu.AddChild(string.Empty, new ToolStripSeparatorMenuItem());
                ScriptIndexMenuItem itemI = new ScriptIndexMenuItem();
                _indexMenu.AddChild(string.Empty, itemI);
            }

            if (node != null && _viewMenu == null &&
                    viewUrnPath == node.UrnPath)
            {
                _viewMenu = (HierarchyObject)node.GetService(typeof(IMenuHandler));

                _viewMenu.AddChild(string.Empty, new ToolStripSeparatorMenuItem());
                EditTableMenuItem itemV = new EditTableMenuItem();
                _viewMenu.AddChild(string.Empty, itemV);
            }

            // Set this each time
            if (node != null && viewUrnPath == node.UrnPath)
            {
                Connect.ViewsSelected = true;
            }
            
        }
Example #10
0
 private void Provider_SelectionChanged(object sender, NodesChangedEventArgs args)
 {
     throw new NotImplementedException();
 }
Example #11
0
        private void Provider_SelectionChanged(object sender, NodesChangedEventArgs args)
        {
            Regex tableRegex = new Regex(@"^Server\[@Name='(?<Server>[^\]]*)'\]/Database\[@Name='(?<Database>[^']*)'\]/(?<ObjectType>(UserDefinedFunction|StoredProcedure|View))\[@Name='(?<Object>[^']*)' and @Schema='(?<Schema>[^']*)'\]$");

            var ob = args.ChangedNodes[0];

            Match match = tableRegex.Match(ob.Context);
              //  MessageBox.Show(ob.Context);

            if (match != null)
            {

                if (match.Groups["Server"].Success && match.Groups["Object"].Success && match.Groups["Schema"].Success && match.Groups["Database"].Success && match.Groups["ObjectType"].Success)
                {

                string server = match.Groups["Server"].Value;
                string obname = match.Groups["Object"].Value;
                string schema = match.Groups["Schema"].Value;
                string database = match.Groups["Database"].Value;
                string objectType = match.Groups["ObjectType"].Value;
                string connectionString = ob.Parent.Connection.ConnectionString + ";Database=" + database;

                try
                {
                    string sql = "SELECT  OBJECT_DEFINITION(OBJECT_ID('{0}.{1}'))";

                    SqlCommand command = new SqlCommand(string.Format(sql, schema, obname));
                    command.CommandType = CommandType.Text;
                    command.Connection = new SqlConnection(connectionString);
                    command.Connection.Open();

                    var defn = command.ExecuteScalar();

                    command.Connection.Close();

                    string path = string.Format("C:\\Scripts\\{0}-{1}", server, database);

                    if (!Directory.Exists(path))
                        Directory.CreateDirectory(path);

                    path = path + string.Format("\\{0}", objectType);
                    if (!Directory.Exists(path))
                        Directory.CreateDirectory(path);
                    File.WriteAllText(string.Format("{0}\\{1}.{2}.sql", path,  schema, obname), defn.ToString());
                } // try
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                } // catch

                } // if

            } // if
        }
 /// <summary>
 /// Handles the <see cref="FileSystemTreeViewBase.NodeAdded"/> and
 /// <see cref="FileSystemTreeViewBase.NodeRemoved"/> events of the sources tree view.
 /// </summary>
 /// <remarks>
 /// This raised the <see cref="PropertyChanged"/> event on the <see cref="Sources"/> property.
 /// </remarks>
 /// <param name="sender">The object that raised the event.</param>
 /// <param name="e">A <see cref="NodesChangedEventArgs"/> describing the event arguments.</param>
 private void ftvSource_NodesChanged(object sender, NodesChangedEventArgs e)
 {
     PropertyChanged(this, new PropertyChangedEventArgs(ObjectHelper.GetPropertyName(() => Sources)));
 }