public void Refresh()
        {
            const string queryTemplate =
                @"SELECT Entity.FullName, Entity.Namespace, Entity.BaseType, (Entity.Type ISA 'System.Indication') AS IsIndication,
	Entity.Properties.Name, Entity.Properties.Type, Entity.Properties.IsNavigable, Entity.Properties.IsInherited, Entity.Properties.IsKey,
	Entity.Verbs.EntityName, Entity.Verbs.Name, Entity.IsAbstract{0}
FROM Metadata.Entity";
            const string crudFragment =
                ", Entity.CanCreate, Entity.CanDelete, Entity.CanInvoke, Entity.CanRead, Entity.CanUpdate";

            string query = string.Format(queryTemplate, SupportsAccessControl() ? crudFragment : string.Empty);

            entities = info.Query <Entity>(query).ToDictionary(entity => entity.FullName);

            foreach (var entity in entities.Values)
            {
                Entity baseEntity;
                if (entity.BaseType != null && entities.TryGetValue(entity.BaseType, out baseEntity))
                {
                    entity.BaseEntity = baseEntity;
                }
            }

            EntitiesRefreshed?.Invoke(this, new EventArgs());
        }
        public void Refresh()
        {
            const string query =
                @"SELECT Entity.FullName, Entity.Namespace, Entity.BaseType, (Entity.Type ISA 'System.Indication') AS IsIndication,
	Entity.Properties.Name, Entity.Properties.Type, Entity.Properties.IsNavigable, Entity.Properties.IsInherited, Entity.Properties.IsKey,
	Entity.Verbs.EntityName, Entity.Verbs.Name, Entity.IsAbstract, Entity.CanCreate, Entity.CanDelete, Entity.CanInvoke, Entity.CanRead, Entity.CanUpdate
FROM Metadata.Entity";

            entities = info.Query <Entity>(query).ToDictionary(entity => entity.FullName);

            foreach (var entity in entities.Values)
            {
                Entity baseEntity;
                if (entity.BaseType != null && entities.TryGetValue(entity.BaseType, out baseEntity))
                {
                    entity.BaseEntity = baseEntity;
                }
            }
        }
Esempio n. 3
0
        public void AddServer(IMetadataProvider provider, ConnectionInfo connection)
        {
            //Check if the current connection can create subscription
            DataTable dt = null;

            try
            {
                dt = connection.Query("SELECT CanCreate FROM Metadata.Entity WHERE FullName='System.Subscription'");
            }
            catch (ApplicationException e)
            {
                log.Info("Exception checking if we can create subscriptions.", e);
            }

            if (dt != null && (dt.Rows.Count == 1 && dt.Columns.Count == 1))
            {
                connection.CanCreateSubscription = Convert.ToBoolean(dt.Rows[0][0]);
            }

            var tableContextMenu = new ContextMenu();

            tableContextMenu.MenuItems.Add("Generate Select Statement", (s, e) => GenerateSelectStatement(_contextMenuNode.Tag as Entity, false));
            tableContextMenu.MenuItems.Add("Generate Select Statement (with Inherited Properties)", (s, e) => GenerateSelectStatement(_contextMenuNode.Tag as Entity, true));

            if (connection.CanCreateSubscription)
            {
                tableContextMenu.MenuItems.Add("Subscribe", StartSubscription);
            }

            _tableContextMenuItems.Add(connection.Title, tableContextMenu);

            var serverContextMenu = new ContextMenu();

            serverContextMenu.MenuItems.Add("Refresh", (s, e) => RefreshServer(_contextMenuNode));

            if (connection.CanCreateSubscription)
            {
                serverContextMenu.MenuItems.Add("Activity Monitor", (s, e) => OpenActivityMonitor(_contextMenuNode));
            }

            serverContextMenu.MenuItems.Add("Generate C# Code...", (s, e) => GenerateCSharpCode(_contextMenuNode));
            serverContextMenu.MenuItems.Add("Close", (s, e) => CloseServer(_contextMenuNode));

            _serverContextMenuItems.Add(connection.Title, serverContextMenu);


            TreeNode node = CreateDatabaseNode(provider, connection);

            TreeNode[] existingNodes = _treeData.Nodes.Find(node.Name, false);
            if (existingNodes.Length == 0)
            {
                // Node doesn't already exist.  Add it
                _treeData.Nodes.Add(node);
                _treeData.SelectedNode = node;
                RefreshServer(node);
            }
            else
            {
                // Node exists.  Just focus on it.
                _treeData.SelectedNode = existingNodes[0];
                UpdateDrawnNodesSelection();
            }

            connection.ConnectionClosed += (o, e) =>
            {
                _tableContextMenuItems.Remove(connection.Title);
                tableContextMenu.Dispose();
                tableContextMenu = null;

                _serverContextMenuItems.Remove(connection.Title);
                serverContextMenu.Dispose();
                serverContextMenu = null;
            };
        }
Esempio n. 4
0
        public void AddServer(IMetadataProvider provider, ConnectionInfo connection)
        {
            //Check if the current connection can create subscription
            DataTable dt = null;

            try
            {
                dt = connection.Query("SELECT CanCreate FROM Metadata.Entity WHERE FullName='System.Subscription'");
            }
            catch (ApplicationException e)
            {
                log.Info("Exception checking if we can create subscriptions.", e);
            }

            if (dt != null && (dt.Rows.Count == 1 && dt.Columns.Count == 1))
            {
                connection.CanCreateSubscription = Convert.ToBoolean(dt.Rows[0][0]);
            }

            var tableContextMenuWithoutCrud = new ContextMenu();
            var tableContextMenuWithCrud    = new ContextMenu();

            var commonTableContextMenus = new[] { tableContextMenuWithCrud, tableContextMenuWithoutCrud };

            foreach (var tableContextMenu in commonTableContextMenus)
            {
                tableContextMenu.MenuItems.Add("Generate Select Statement", (s, e) => GenerateSelectStatement(_contextMenuNode.Tag as Entity, false));
                tableContextMenu.MenuItems.Add("Generate Select Statement (with Inherited Properties)", (s, e) => GenerateSelectStatement(_contextMenuNode.Tag as Entity, true));

                if (connection.CanCreateSubscription)
                {
                    tableContextMenu.MenuItems.Add("Subscribe", StartSubscription);
                }
            }

            tableContextMenuWithCrud.MenuItems.Add("-");
            // note: the names are crucial for disabling/enabling the menu based on operations allowed
            tableContextMenuWithCrud.MenuItems.Add("Create", (s, e) => Crud(_contextMenuNode.Tag as Entity, CrudOperation.Create)).Name = "create";
            tableContextMenuWithCrud.MenuItems.Add("Update", (s, e) => Crud(_contextMenuNode.Tag as Entity, CrudOperation.Update)).Name = "update";
            tableContextMenuWithCrud.MenuItems.Add("Delete", (s, e) => Crud(_contextMenuNode.Tag as Entity, CrudOperation.Delete)).Name = "delete";


            _tableContextMenuItems.Add(connection.Title, tableContextMenuWithoutCrud);
            _tableCrudContextMenuItems.Add(connection.Title, tableContextMenuWithCrud);

            var serverContextMenu = new ContextMenuStrip();

            serverContextMenu.Items.Add("Refresh", Properties.Resources.Refresh_16x, (s, e) => RefreshServer(_contextMenuNode));

            if (connection.CanCreateSubscription)
            {
                serverContextMenu.Items.Add("Activity Monitor", null, (s, e) => OpenActivityMonitor(_contextMenuNode));
            }

            serverContextMenu.Items.Add("Generate C# Code...", null, (s, e) => GenerateCSharpCode(_contextMenuNode));
            var closeMenuItem = new ToolStripMenuItem("Disconnect", Properties.Resources.Disconnect_16x,
                                                      (s, e) => CloseServer(_contextMenuNode));

            serverContextMenu.Items.Add(closeMenuItem);

            _serverContextMenuItems.Add(connection.Title, serverContextMenu);


            TreeNode node = CreateDatabaseNode(provider, connection);

            TreeNode[] existingNodes = _treeData.Nodes.Find(node.Name, false);
            if (existingNodes.Length == 0)
            {
                // Node doesn't already exist.  Add it
                _treeData.Nodes.Add(node);
                _treeData.SelectedNode = node;
                RefreshServer(node);
            }
            else
            {
                // Node exists.  Just focus on it.
                _treeData.SelectedNode = existingNodes[0];
                UpdateDrawnNodesSelection();
            }
        }