private void CreateAndAddOperation(Type operationType, BindableTreeNode batchNode, int operationIndex) { Batch batch = (Batch)batchNode.DataSource; IOperation operation = (IOperation)Activator.CreateInstance(operationType, new object[] { batch }); AddOperation(operation, batchNode, operationIndex); }
private void CreateAndAddDataSource(Type dataSourceType, BindableTreeNode connectionNode, int dataSourceIndex) { IConnection connection = (IConnection)connectionNode.DataSource; IDataSource dataSource = (IDataSource)Activator.CreateInstance(dataSourceType, new object[] { connection }); AddDataSource(dataSource, connectionNode, dataSourceIndex); }
public static BindableTreeNode GetContextMenuTreeviewNode(BindableTreeView treeView, object sender) { BindableTreeNode node = default(BindableTreeNode); if (sender is ContextMenuStrip) { ContextMenuStrip contextMenuStrip = (ContextMenuStrip)sender; TreeViewHitTestInfo testInfo = treeView.HitTest(treeView.PointToClient(new Point(contextMenuStrip.Left, contextMenuStrip.Top))); if (testInfo.Node != default(TreeNode)) { node = (BindableTreeNode)testInfo.Node; } } else if (sender is ToolStripMenuItem) { ToolStripMenuItem menuItem = (ToolStripMenuItem)sender; node = GetContextMenuTreeviewNode(treeView, menuItem.Owner); } else if (sender is ToolStripDropDownMenu) { ToolStripDropDownMenu menu = (ToolStripDropDownMenu)sender; node = GetContextMenuTreeviewNode(treeView, menu.OwnerItem); } return(node); }
private void DuplicateDataSource(BindableTreeNode dataSourceNode) { IDataSource dataSource = (IDataSource)dataSourceNode.DataSource; IDataSource dataSourceClone = dataSource.Clone(true); AddDataSource(dataSourceClone, (BindableTreeNode)dataSourceNode.Parent, dataSourceNode.Index + 1); dataSourceTreeView.SelectedNode = dataSourceTreeView.Find(dataSourceClone.ID); }
private void DuplicateOperation(BindableTreeNode operationNode) { IOperation operation = (IOperation)operationNode.DataSource; IOperation operationClone = operation.Clone(true); AddOperation(operationClone, (BindableTreeNode)operationNode.Parent, operationNode.Index + 1); batchTreeView.SelectedNode = batchTreeView.Find(operationClone.ID); }
private void OperationContextMenuStrip_Opening(object sender, System.ComponentModel.CancelEventArgs e) { try { BindableTreeNode operationNode = ClientUtility.GetContextMenuTreeviewNode(batchTreeView, sender); executeOperationToolStripMenuItem.Enabled = operationNode.DataSource is IExecutable; if (operationNode.DataSource is IOperation operation) { executeOperationToolStripMenuItem.Enabled = operationNode.DataSource is IExecutable && operation.Enabled; enableOperationToolStripMenuItem.Visible = !operation.Enabled; disableOperationToolStripMenuItem.Visible = operation.Enabled; } int menuItemCount = operationContextMenuStrip.Items.IndexOf(customEndToolStripSeparator) - operationContextMenuStrip.Items.IndexOf(customStartToolStripSeparator) - 1; // hide any custom menu items for (int menuItemsRemoved = 0; menuItemsRemoved < menuItemCount; menuItemsRemoved++) { operationContextMenuStrip.Items.RemoveAt(operationContextMenuStrip.Items.IndexOf(customStartToolStripSeparator) + 1); } if (operationNode.DataSource is ICustomMenuItemProvider) { customEndToolStripSeparator.Visible = true; List <CustomMenuItem> menuItems = ((ICustomMenuItemProvider)operationNode.DataSource).GetCustomMenuItems(); foreach (CustomMenuItem menuItem in menuItems) { ToolStripMenuItem customToolStripMenuItem = new ToolStripMenuItem() { Text = menuItem.Text, ToolTipText = menuItem.ToolTip, Image = menuItem.Icon, ImageScaling = ToolStripItemImageScaling.None, Size = new Size(182, 38), Tag = menuItem, Enabled = menuItem.Enabled }; customToolStripMenuItem.Click += CustomToolStripMenuItem_Click; operationContextMenuStrip.Items.Insert(operationContextMenuStrip.Items.IndexOf(customEndToolStripSeparator), customToolStripMenuItem); } } else { customEndToolStripSeparator.Visible = false; } } catch (Exception ex) { ApplicationState.Default.RaiseNotification(new NotificationEventArgs(NotificationType.Error, ex.Message, ex)); } }
private void DuplicateConnection(BindableTreeNode connectionNode) { IConnection connection = (IConnection)connectionNode.DataSource; IConnection connectionClone = connection.Clone(); AddConnection(connectionClone, connectionNode.Index + 1); if (connectionNode.IsExpanded) { dataSourceTreeView.SelectedNode.Expand(); } }
private void RemoveOperationToolStripMenuItem_Click(object sender, EventArgs e) { try { BindableTreeNode operationNode = ClientUtility.GetContextMenuTreeviewNode(batchTreeView, sender); RemoveOperation((BindableTreeNode)operationNode.Parent, operationNode.Index, true); } catch (Exception ex) { ApplicationState.Default.RaiseNotification(new NotificationEventArgs(NotificationType.Error, ex.Message, ex)); } }
private void DuplicateBatchToolStripMenuItem_Click(object sender, EventArgs e) { try { BindableTreeNode batchNode = ClientUtility.GetContextMenuTreeviewNode(batchTreeView, sender); DuplicateBatch(batchNode); } catch (Exception ex) { ApplicationState.Default.RaiseNotification(new NotificationEventArgs(NotificationType.Error, ex.Message, ex)); } }
private void DuplicateBatch(BindableTreeNode batchNode) { Batch batch = (Batch)batchNode.DataSource; Batch batchClone = batch.Clone(); AddBatch(batchClone, batchNode.Index + 1); if (batchNode.IsExpanded) { batchTreeView.SelectedNode.Expand(); } }
private void OpenDataSourceInBrowserToolStripMenuItem_Click(object sender, EventArgs e) { try { BindableTreeNode dataSourceNode = ClientUtility.GetContextMenuTreeviewNode(dataSourceTreeView, sender); IUrlAddressable dataSource = (IUrlAddressable)dataSourceNode.DataSource; System.Diagnostics.Process.Start(dataSource.Url.ToString()); } catch (Exception ex) { ApplicationState.Default.RaiseNotification(new NotificationEventArgs(NotificationType.Error, ex.Message, ex)); } }
private void GetRecordCountToolStripMenuItem_Click(object sender, EventArgs e) { try { BindableTreeNode stepNode = ClientUtility.GetContextMenuTreeviewNode(dataSourceTreeView, sender); IDataSource dataSource = (IDataSource)stepNode.DataSource; GetRecordCountAsync(dataSource); } catch (Exception ex) { ApplicationState.Default.RaiseNotification(new NotificationEventArgs(NotificationType.Error, ex.Message, ex)); } }
private void AddDataSource(IDataSource dataSource, BindableTreeNode connectionNode, int dataSourceIndex) { IConnection connection = (IConnection)connectionNode.DataSource; connection.DataSources.Insert(dataSourceIndex, dataSource); if (!connectionNode.IsExpanded) { connectionNode.Expand(); } dataSourceTreeView.SelectedNode = dataSourceTreeView.Find(dataSource.ID); }
private void DisableOperationToolStripMenuItem_Click(object sender, EventArgs e) { try { BindableTreeNode operationNode = ClientUtility.GetContextMenuTreeviewNode(batchTreeView, sender); IOperation operation = (IOperation)operationNode.DataSource; operation.Enabled = false; } catch (Exception ex) { ApplicationState.Default.RaiseNotification(new NotificationEventArgs(NotificationType.Error, ex.Message, ex)); } }
private void AddOperationToolStripMenuItem_Click(object sender, EventArgs e) { try { BindableTreeNode batchNode = ClientUtility.GetContextMenuTreeviewNode(batchTreeView, sender); Type operationType = (Type)((ToolStripMenuItem)sender).Tag; CreateAndAddOperation(operationType, batchNode, ((Batch)batchNode.DataSource).Operations.Count); } catch (Exception ex) { ApplicationState.Default.RaiseNotification(new NotificationEventArgs(NotificationType.Error, ex.Message, ex)); } }
private void AddOperation(IOperation operation, BindableTreeNode batchNode, int operationIndex) { Batch batch = (Batch)batchNode.DataSource; batch.Operations.Insert(operationIndex, operation); if (!batchNode.IsExpanded) { batchNode.Expand(); } batchTreeView.SelectedNode = batchTreeView.Find(operation.ID); //OnItemChanged(new ItemEventArgs(batch)); }
private void RemoveDataSource(BindableTreeNode connectionNode, int dataSourceIndex, bool displayDialog) { IConnection connection = (IConnection)connectionNode.DataSource; IDataSource dataSource = connection.DataSources[dataSourceIndex]; DialogResult result = DialogResult.Yes; if (displayDialog) { result = MessageBox.Show(string.Format("Are you sure you want to remove {0}?", dataSource.Name), "Remove Data Source Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question); } if (result == DialogResult.Yes) { connection.DataSources.RemoveAt(dataSourceIndex); ApplicationState.Default.SelectedItem = default(object); } }
private void DataSourceContextMenuStrip_Opening(object sender, System.ComponentModel.CancelEventArgs e) { try { BindableTreeNode dataSourceNode = ClientUtility.GetContextMenuTreeviewNode(dataSourceTreeView, sender); object dataSource = dataSourceNode.DataSource; viewDataSourceSampleDataToolStripMenuItem.Visible = dataSource is ISampleDataProvider; getRecordCountToolStripMenuItem.Visible = dataSource is IRecordCountProvider; openDataSourceInBrowserToolStripMenuItem.Visible = dataSource is IUrlAddressable; duplicateToolStripSeparator.Visible = dataSource is IRecordCountProvider || dataSource is IUrlAddressable; } catch (Exception ex) { ApplicationState.Default.RaiseNotification(new NotificationEventArgs(NotificationType.Error, ex.Message, ex)); } }
private void RemoveOperation(BindableTreeNode batchNode, int operationIndex, bool displayDialog) { Batch batch = (Batch)batchNode.DataSource; IOperation operation = batch.Operations[operationIndex]; DialogResult result = DialogResult.Yes; if (displayDialog) { result = MessageBox.Show(string.Format(Properties.Resources.MainFormOperationRemovePrompt, operation.Name), Properties.Resources.MainFormOperationRemoveTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Question); } if (result == DialogResult.Yes) { batch.Operations.RemoveAt(operationIndex); //OnItemChanged(new ItemEventArgs(batch)); ApplicationState.Default.SelectedItem = null; } }
private void ConnectionContextMenuStrip_Opening(object sender, System.ComponentModel.CancelEventArgs e) { try { BindableTreeNode connectionNode = ClientUtility.GetContextMenuTreeviewNode(dataSourceTreeView, sender); Type connectionType = connectionNode.DataSource.GetType(); ConnectionAttribute connectionAttribute = (ConnectionAttribute)Attribute.GetCustomAttribute(connectionType, typeof(ConnectionAttribute)); IConnection connection = (IConnection)connectionNode.DataSource; testConnectionToolStripMenuItem.Visible = connection is IAvailableProvider; openConnectionInBrowserToolStripMenuItem.Visible = connection is IUrlAddressable; openConnectionInBrowserToolStripMenuItem.Enabled = connection is IUrlAddressable && ((IUrlAddressable)connection).Url != default(Uri); testOpenToolStripSeparator.Visible = connection is IAvailableProvider || connection is IUrlAddressable; ConnectionCache cache = new ConnectionCache((IConnection)connectionNode.DataSource); clearCacheToolStripMenuItem.Enabled = cache.Count > 0; addDataSourceToolStripMenuItem.DropDownItems.Clear(); List <Type> dataSourceTypes = CoreUtility.GetInterfaceImplementorsWithAttribute(typeof(IDataSource), typeof(DataSourceAttribute)); foreach (Type dataSourceType in dataSourceTypes) { DataSourceAttribute dataSourceAttribute = (DataSourceAttribute)Attribute.GetCustomAttribute(dataSourceType, typeof(DataSourceAttribute)); if (connectionType == dataSourceAttribute.ConnectionType || connectionType.IsSubclassOf(dataSourceAttribute.ConnectionType)) { ToolStripMenuItem dataSourceToolStripMenuItem = new ToolStripMenuItem() { ImageScaling = ToolStripItemImageScaling.None, Tag = dataSourceType }; dataSourceToolStripMenuItem.Click += AddDataSourceToolStripMenuItem_Click; dataSourceToolStripMenuItem.Text = dataSourceAttribute.DisplayName; dataSourceToolStripMenuItem.ToolTipText = dataSourceAttribute.Description; dataSourceToolStripMenuItem.Image = dataSourceAttribute.GetIcon(dataSourceType.Assembly); addDataSourceToolStripMenuItem.DropDownItems.Add(dataSourceToolStripMenuItem); } } addDataSourceToolStripMenuItem.Enabled = addDataSourceToolStripMenuItem.DropDownItems.Count > 0; } catch (Exception ex) { ApplicationState.Default.RaiseNotification(new NotificationEventArgs(NotificationType.Error, ex.Message, ex)); } }
private void BatchContextMenuStrip_Opening(object sender, System.ComponentModel.CancelEventArgs e) { try { addOperationToolStripMenuItem.DropDownItems.Clear(); BindableTreeNode batchNode = ClientUtility.GetContextMenuTreeviewNode(batchTreeView, sender); Type batchType = batchNode.DataSource.GetType(); List <Type> operationTypes = CoreUtility.GetInterfaceImplementorsWithAttribute(typeof(IOperation), typeof(OperationAttribute)); foreach (Type operationType in operationTypes) { OperationAttribute operationAttribute = (OperationAttribute)Attribute.GetCustomAttribute(operationType, typeof(OperationAttribute)); ToolStripMenuItem addOperationToolStripMenuItem = new ToolStripMenuItem() { ImageScaling = ToolStripItemImageScaling.None, Tag = operationType }; addOperationToolStripMenuItem.Click += AddOperationToolStripMenuItem_Click; addOperationToolStripMenuItem.Text = operationAttribute.DisplayName; addOperationToolStripMenuItem.ToolTipText = operationAttribute.Description; addOperationToolStripMenuItem.Image = operationAttribute.GetIcon(operationType.Assembly); this.addOperationToolStripMenuItem.DropDownItems.Add(addOperationToolStripMenuItem); } // sort by name ArrayList menuItems = new ArrayList(this.addOperationToolStripMenuItem.DropDownItems); menuItems.Sort(new ToolStripItemComparer()); addOperationToolStripMenuItem.DropDownItems.Clear(); foreach (ToolStripItem menuItem in menuItems) { addOperationToolStripMenuItem.DropDownItems.Add(menuItem); } addOperationToolStripMenuItem.Enabled = addOperationToolStripMenuItem.DropDownItems.Count > 0; } catch (Exception ex) { ApplicationState.Default.RaiseNotification(new NotificationEventArgs(NotificationType.Error, ex.Message, ex)); } }
private void BatchTreeView_DragDrop(object sender, DragEventArgs e) { try { if (!e.Data.GetDataPresent(DataFormats.FileDrop)) { BindableTreeNode draggedNode = (BindableTreeNode)e.Data.GetData(typeof(BindableTreeNode)); BindableTreeNode droppedNode = (BindableTreeNode)batchTreeView.HitTest(batchTreeView.PointToClient(new Point(e.X, e.Y)))?.Node; if (draggedNode.DataSource is Batch && droppedNode.DataSource is Batch && draggedNode.ID != droppedNode.ID) { // rearrange batches bool expanded = droppedNode.IsExpanded; int droppedIndex = droppedNode.Index; RemoveBatch(draggedNode.Index, false); AddBatch((Batch)draggedNode.DataSource, droppedIndex); if (expanded) { batchTreeView.SelectedNode.Expand(); // todo - this flashes a bit } } else if (draggedNode.DataSource is IOperation && droppedNode.DataSource is IOperation && draggedNode.ID != droppedNode.ID) { // rearrange operations int droppedIndex = droppedNode.Index; RemoveOperation((BindableTreeNode)draggedNode.Parent, draggedNode.Index, false); AddOperation((IOperation)draggedNode.DataSource, (BindableTreeNode)droppedNode.Parent, droppedIndex); } } } catch (Exception ex) { ApplicationState.Default.RaiseNotification(new NotificationEventArgs(NotificationType.Error, ex.Message, ex)); } }
/// <summary> /// Performs drag and drop operations to re-arrange or duplicate connections or data sources. /// </summary> private void DataSourceTreeView_DragDrop(object sender, DragEventArgs e) { try { if (!e.Data.GetDataPresent(DataFormats.FileDrop)) { BindableTreeNode draggedNode = (BindableTreeNode)e.Data.GetData(typeof(BindableTreeNode)); BindableTreeNode droppedNode = (BindableTreeNode)dataSourceTreeView.HitTest(dataSourceTreeView.PointToClient(new Point(e.X, e.Y)))?.Node; if (draggedNode.DataSource is IConnection && droppedNode.DataSource is IConnection && draggedNode.ID != droppedNode.ID) { // rearrange connections bool expanded = droppedNode.IsExpanded; int droppedIndex = droppedNode.Index; RemoveConnection(draggedNode.Index, false); AddConnection((IConnection)draggedNode.DataSource, droppedIndex); if (expanded) { dataSourceTreeView.SelectedNode.Expand(); } } else if (draggedNode.DataSource is IDataSource && droppedNode.DataSource is IDataSource && draggedNode.Parent == droppedNode.Parent && draggedNode.ID != droppedNode.ID) { // rearrange data sources int droppedIndex = droppedNode.Index; RemoveDataSource((BindableTreeNode)draggedNode.Parent, draggedNode.Index, false); AddDataSource((IDataSource)draggedNode.DataSource, (BindableTreeNode)droppedNode.Parent, droppedIndex); } } } catch (Exception ex) { ApplicationState.Default.RaiseNotification(new NotificationEventArgs(NotificationType.Error, ex.Message, ex)); } }