private void actionsDataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e) { try { if (e.AddedItems.Count == 1) { OctopusLib.Action selectedAction = e.AddedItems[0] as OctopusLib.Action; if (selectedAction != null) { foreach (OctopusLib.Action action in m_actionVM.ActionCollection) { action.ActionCommands.ItemPropertyChanged += m_actionVM.PropertyChangedHandler; } m_actionVM.SelectedRow = selectedAction; actionsCommandsDataGrid.ItemsSource = selectedAction.ActionCommands; } } else { actionsCommandsDataGrid.ItemsSource = null; } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public void DeleteCommand(OctopusLib.Action selectedAction, object obj) { if (selectedAction != null) { var collection = ((IList)obj).Cast <OctopusLib.Command>(); List <OctopusLib.Command> selectedCommands = new List <OctopusLib.Command>(collection); if (selectedCommands.Count > 0) { MessageBoxResult result = MessageBox.Show("Are you sure you want to delete the selected items?", "Confirm", MessageBoxButton.YesNo, MessageBoxImage.Question); if (result == MessageBoxResult.Yes) { foreach (OctopusLib.Command command in selectedCommands) { this.SelectedRow.ActionCommands.Remove(command); } ReSequence(this.SelectedRow); IsModified = true; Message = "Action commands be deleted."; } else { return; } } } }
public void InsertAction() { OctopusLib.Action newAction = new OctopusLib.Action { Name = string.Format("New Action {0}", ActionCollection.Count() + 1), ActionCommands = new ObservableCollectionEx <OctopusLib.Command>(), }; this.SelectedRow = newAction; newAction.ActionCommands.ItemPropertyChanged += PropertyChangedHandler; this.ActionCollection.Add(newAction); IsModified = true; Message = "New action be added."; }
public void MoveUp(OctopusLib.Action selectedAction, object obj) { if (selectedAction != null) { var collection = ((IList)obj).Cast <OctopusLib.Command>(); OctopusLib.Command selectedCommand = new List <OctopusLib.Command>(collection)[0]; int targetIndex = selectedCommand.Sequence - 1; OctopusLib.Command targetCommand = selectedAction.ActionCommands.Where(o => o.Sequence == targetIndex).Single() as OctopusLib.Command; targetCommand.Sequence = targetIndex + 1; selectedCommand.Sequence = targetIndex; selectedAction.ActionCommands.Sort(o => o.Sequence); IsModified = true; } }
private void ReSequence(OctopusLib.Action selectedAction) { if (selectedAction != null) { int index = 0; foreach (OctopusLib.Command command in selectedAction.ActionCommands.OrderBy(o => o.Sequence)) { index++; if (command.Sequence == index) { continue; } else { command.Sequence = index; } } } }
public void InsertCommand(OctopusLib.Action selectedAction) { if (selectedAction != null) { CommandTypeSelection ctsWindow = new CommandTypeSelection() { Title = "Command Type Selection Dialog", ShowInTaskbar = false, // don't show the dialog on the taskbar Topmost = true, // ensure we're Always On Top ResizeMode = ResizeMode.NoResize, // remove excess caption bar buttons Owner = Application.Current.MainWindow, WindowStartupLocation = System.Windows.WindowStartupLocation.CenterOwner, }; ctsWindow.ShowDialog(); if (!string.IsNullOrEmpty(ctsWindow.CommandType)) { int sequence = selectedAction.ActionCommands.Count + 1; switch (ctsWindow.CommandType) { case "LinuxSSH": OctopusLib.LinuxSSHCommand linuxCommand = new OctopusLib.LinuxSSHCommand() { Sequence = sequence, CommandType = OctopusLib.RunCommandType.LinuxSSH, IsEnabled = true, TimeOutSeconds = 30, RetryTimes = 1, RetryIntervalSeconds = 5 }; selectedAction.ActionCommands.Add(linuxCommand); this.SelectedCommandRow = linuxCommand; break; case "Copy": OctopusLib.CopyCommand copyCommand = new OctopusLib.CopyCommand() { Sequence = sequence, CommandType = OctopusLib.RunCommandType.Copy, CopyDirection = OctopusLib.CopyCommand.Direction.LocalToRemote, IsEnabled = true, IsForce = true, RetryTimes = 1, RetryIntervalSeconds = 5 }; selectedAction.ActionCommands.Add(copyCommand); this.SelectedCommandRow = copyCommand; break; case "Remote": OctopusLib.RemoteCommand remoteCommand = new OctopusLib.RemoteCommand() { Sequence = sequence, CommandType = OctopusLib.RunCommandType.Remote, IsEnabled = true, TimeOutSeconds = 120, ExpectedResult = "0", IsRunAsSystemAccount = true, RetryTimes = 1, RetryIntervalSeconds = 5, }; selectedAction.ActionCommands.Add(remoteCommand); this.SelectedCommandRow = remoteCommand; break; case "Local": OctopusLib.LocalCommand localCommand = new OctopusLib.LocalCommand() { Sequence = sequence, CommandType = OctopusLib.RunCommandType.Local, IsEnabled = true, TimeOutSeconds = 120, ExpectedResult = "0", RetryTimes = 1, RetryIntervalSeconds = 5 }; selectedAction.ActionCommands.Add(localCommand); this.SelectedCommandRow = localCommand; break; } IsModified = true; Message = "New action command be added."; } } }