public void InsertTaskAction(OctopusLib.Task selectedTask) { if (selectedTask != null) { int sequence = selectedTask.TaskActionCollection.Count + 1; TaskActionSelect rasWindow = new TaskActionSelect() { Title = "Task Action 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, }; rasWindow.BindingAvailableActionList(); rasWindow.ShowDialog(); if (rasWindow.SelectedTaskAction != null) { OctopusLib.TaskAction selectedTaskAction = rasWindow.SelectedTaskAction; selectedTaskAction.Sequence = sequence; this.SelectedTaskActionRow = selectedTaskAction; selectedTask.TaskActionCollection.Add(selectedTaskAction); selectedTask.TaskActionCollection.ItemPropertyChanged += PropertyChangedHandler; IsModified = true; Message = "New task action be added."; } } }
private void btnOK_Click(object sender, RoutedEventArgs e) { foreach (OctopusLib.Action action in lbAction.SelectedItems) { SelectedTaskAction = new TaskAction() { Name = action.Name, IsEnabled = true, IsFixed = false }; break; } this.Close(); }
public void MoveUpTaskAction(OctopusLib.Task selectedTask, object obj) { if (selectedTask != null) { var collection = ((IList)obj).Cast <OctopusLib.TaskAction>(); OctopusLib.TaskAction selectedTaskAction = new List <OctopusLib.TaskAction>(collection)[0]; int targetIndex = selectedTaskAction.Sequence - 1; OctopusLib.TaskAction targetTaskAction = selectedTask.TaskActionCollection.Where(o => o.Sequence == targetIndex).Single() as OctopusLib.TaskAction; targetTaskAction.Sequence = targetIndex + 1; selectedTaskAction.Sequence = targetIndex; selectedTask.TaskActionCollection.Sort(o => o.Sequence); IsModified = true; } }
public void Load() { try { if (!System.IO.File.Exists(_configfile)) { throw new Exception(string.Format("The config file {0} is not exists.", _configfile)); } XmlDocument doc = new XmlDocument(); doc.Load(_configfile); // Get Parameter list foreach (XmlNode paramNode in doc.SelectNodes("Topology/Parameters/Parameter")) { bool isencrypted = paramNode.Attributes["IsEncrypted"] == null ? false : Convert.ToBoolean(paramNode.Attributes["IsEncrypted"].Value); string value = string.Empty; if (isencrypted) { try { value = Encryption.Decrypt(paramNode.Attributes["Value"].Value.Trim(), _machineId); } catch { } } else { value = paramNode.Attributes["Value"].Value.Trim(); } ParameterCollection.Add(new Parameter() { Name = paramNode.Attributes["Name"].Value.Trim(), Value = value, IsEncrypted = isencrypted, MachineID = _machineId, }); } // Get machine list foreach (XmlNode machineNode in doc.SelectNodes("Topology/Machines/Machine")) { if (Convert.ToBoolean(machineNode.Attributes["IsLinux"].Value)) { MachineCollection.Add(new OctopusLib.LinuxMachine() { Name = machineNode.Attributes["Name"].Value, IP = machineNode.Attributes["IP"].Value, Username = machineNode.Attributes["Username"].Value, Password = machineNode.Attributes["Password"].Value, Domain = machineNode.Attributes["Domain"].Value, Architecture = Convert.ToInt32(machineNode.Attributes["Architecture"].Value), IsLinux = true, }); } else { MachineCollection.Add(new OctopusLib.WindowsMachine() { Name = machineNode.Attributes["Name"].Value, IP = machineNode.Attributes["IP"].Value, Username = machineNode.Attributes["Username"].Value, Password = machineNode.Attributes["Password"].Value, Domain = machineNode.Attributes["Domain"].Value, Architecture = Convert.ToInt32(machineNode.Attributes["Architecture"].Value), IsLinux = false, }); } } // get Deployment action list foreach (XmlNode actionNode in doc.SelectNodes("Topology/Actions/Action")) { OctopusLib.Action action = new OctopusLib.Action(); action.Name = actionNode.Attributes["Name"].Value; action.ActionCommands = new ObservableCollectionEx <Command>(); foreach (XmlNode cmdNode in actionNode.SelectNodes("Command")) { string cmdType = cmdNode.Attributes["Type"] == null ? "Execute" : cmdNode.Attributes["Type"].Value; int seq = action.ActionCommands.Count + 1; switch (cmdType.ToLower()) { case "copy": action.ActionCommands.Add(new OctopusLib.CopyCommand() { CommandText = string.Empty, CommandType = OctopusLib.RunCommandType.Copy, CopyDirection = cmdNode.Attributes["Direction"].Value.Equals("LocalToRemote", StringComparison.InvariantCultureIgnoreCase) ? OctopusLib.CopyCommand.Direction.LocalToRemote : OctopusLib.CopyCommand.Direction.RemoteToLocal, CopySourceFiles = cmdNode.Attributes["SourceFiles"] == null ? string.Empty : cmdNode.Attributes["SourceFiles"].Value, CopySourceDir = cmdNode.Attributes["SourceDir"] == null ? string.Empty : cmdNode.Attributes["SourceDir"].Value, CopyTargetDir = cmdNode.Attributes["TargetDir"].Value, IsEnabled = Convert.ToBoolean(cmdNode.Attributes["IsEnabled"].Value), IsForce = Convert.ToBoolean(cmdNode.Attributes["Force"].Value), Try = Convert.ToBoolean(cmdNode.Attributes["Try"].Value), Status = OctopusLib.Status.NotRun, Sequence = seq, RetryTimes = Convert.ToInt32(cmdNode.Attributes["RetryTimes"].Value), RetryIntervalSeconds = Convert.ToInt32(cmdNode.Attributes["RetryIntervalSeconds"].Value), }); break; case "linuxssh": action.ActionCommands.Add(new OctopusLib.LinuxSSHCommand() { CommandText = System.Net.WebUtility.HtmlDecode(cmdNode.InnerText), CommandType = OctopusLib.RunCommandType.LinuxSSH, IsRebootRequired = cmdNode.Attributes["Reboot"] == null ? false : Convert.ToBoolean(cmdNode.Attributes["Reboot"].Value), ExpectedPrompt = cmdNode.Attributes["ExpectedPrompt"] == null ? string.Empty : cmdNode.Attributes["ExpectedPrompt"].Value, ExpectedResult = cmdNode.Attributes["ExpectedResult"] == null ? string.Empty : cmdNode.Attributes["ExpectedResult"].Value, IsEnabled = Convert.ToBoolean(cmdNode.Attributes["IsEnabled"].Value), Try = Convert.ToBoolean(cmdNode.Attributes["Try"].Value), Status = OctopusLib.Status.NotRun, Sequence = seq, RetryTimes = Convert.ToInt32(cmdNode.Attributes["RetryTimes"].Value), RetryIntervalSeconds = Convert.ToInt32(cmdNode.Attributes["RetryIntervalSeconds"].Value), SshType = (SSHType)Enum.Parse(typeof(SSHType), cmdNode.Attributes["SSHType"].Value), TimeOutSeconds = cmdNode.Attributes["TimeOutSeconds"] == null ? 0 : Convert.ToInt32(cmdNode.Attributes["TimeOutSeconds"].Value), }); break; case "local": action.ActionCommands.Add(new OctopusLib.LocalCommand() { CommandText = System.Net.WebUtility.HtmlDecode(cmdNode.InnerText), CommandType = OctopusLib.RunCommandType.Local, Architecture = Convert.ToInt32(cmdNode.Attributes["Architecture"].Value), IsEnabled = Convert.ToBoolean(cmdNode.Attributes["IsEnabled"].Value), ExpectedResult = cmdNode.Attributes["ExpectedResult"] == null ? string.Empty : cmdNode.Attributes["ExpectedResult"].Value, Status = OctopusLib.Status.NotRun, Sequence = seq, Try = Convert.ToBoolean(cmdNode.Attributes["Try"].Value), TimeOutSeconds = cmdNode.Attributes["TimeOutSeconds"] == null ? 0 : Convert.ToInt32(cmdNode.Attributes["TimeOutSeconds"].Value), RetryTimes = Convert.ToInt32(cmdNode.Attributes["RetryTimes"].Value), RetryIntervalSeconds = Convert.ToInt32(cmdNode.Attributes["RetryIntervalSeconds"].Value), OutputParameter = cmdNode.Attributes["OutputParameter"] == null ? string.Empty : cmdNode.Attributes["OutputParameter"].Value, IsSystemCommand = cmdNode.Attributes["IsSystemCommand"] == null ? false : Convert.ToBoolean(cmdNode.Attributes["IsSystemCommand"].Value), }); break; case "remote": default: action.ActionCommands.Add(new OctopusLib.RemoteCommand() { CommandText = System.Net.WebUtility.HtmlDecode(cmdNode.InnerText), CommandType = OctopusLib.RunCommandType.Remote, Architecture = Convert.ToInt32(cmdNode.Attributes["Architecture"].Value), IsRebootRequired = Convert.ToBoolean(cmdNode.Attributes["Reboot"].Value), IsUIInteractive = Convert.ToBoolean(cmdNode.Attributes["Interactive"].Value), IsEnabled = Convert.ToBoolean(cmdNode.Attributes["IsEnabled"].Value), ExpectedResult = cmdNode.Attributes["ExpectedResult"] == null ? string.Empty : cmdNode.Attributes["ExpectedResult"].Value, IsNotLoadProfile = Convert.ToBoolean(cmdNode.Attributes["NotLoadProfile"].Value), IsRunAsSystemAccount = Convert.ToBoolean(cmdNode.Attributes["RunAsSystemAccount"].Value), IsRunAsLimittedUser = Convert.ToBoolean(cmdNode.Attributes["RunAsLimittedUser"].Value), IsNotWaitForTerminate = cmdNode.Attributes["Terminate"] == null ? false : Convert.ToBoolean(cmdNode.Attributes["Terminate"].Value), WorkingDirectory = cmdNode.Attributes["WorkingDirectory"] == null ? string.Empty : cmdNode.Attributes["WorkingDirectory"].Value, Status = OctopusLib.Status.NotRun, Sequence = seq, Try = Convert.ToBoolean(cmdNode.Attributes["Try"].Value), TimeOutSeconds = cmdNode.Attributes["TimeOutSeconds"] == null ? 0 : Convert.ToInt32(cmdNode.Attributes["TimeOutSeconds"].Value), RemoteRunAsUsername = string.IsNullOrEmpty(cmdNode.Attributes["RemoteRunAsUsername"].Value) ? string.Empty : cmdNode.Attributes["RemoteRunAsUsername"].Value, RemoteRunAsPassword = string.IsNullOrEmpty(cmdNode.Attributes["RemoteRunAsPassword"].Value) ? string.Empty : cmdNode.Attributes["RemoteRunAsPassword"].Value, RetryTimes = Convert.ToInt32(cmdNode.Attributes["RetryTimes"].Value), RetryIntervalSeconds = Convert.ToInt32(cmdNode.Attributes["RetryIntervalSeconds"].Value), OutputParameter = cmdNode.Attributes["OutputParameter"] == null ? string.Empty : cmdNode.Attributes["OutputParameter"].Value, }); break; } } ActionCollection.Add(action); } //get Deployment task list foreach (XmlNode runNode in doc.SelectNodes("Topology/Tasks/Task")) { OctopusLib.Task task = new OctopusLib.Task(); task.Name = runNode.Attributes["Name"].Value; task.IsEnabled = Convert.ToBoolean(runNode.Attributes["IsEnabled"].Value); task.Sequence = runNode.Attributes["Sequence"] == null ? 0 : Convert.ToInt32(runNode.Attributes["Sequence"].Value); task.Machines = new ObservableCollectionEx <OctopusLib.Machine>(); foreach (string machineName in runNode.Attributes["Machine"].Value.Split(new char[] { ',', ';', '|' })) { if (MachineCollection.Where(o => o.Name.Equals(machineName, StringComparison.InvariantCultureIgnoreCase)).Count() == 1) { task.Machines.Add(MachineCollection.Where(o => o.Name.Equals(machineName, StringComparison.InvariantCultureIgnoreCase)).Single() as OctopusLib.Machine); } } task.TaskActionCollection = new ObservableCollectionEx <OctopusLib.TaskAction>(); foreach (XmlNode actionNode in runNode.SelectNodes("TaskAction")) { int seq = task.TaskActionCollection.Count + 1; if (ActionCollection.Where(o => o.Name.Equals(actionNode.InnerText.Trim(), StringComparison.InvariantCultureIgnoreCase)).Count() == 1) { OctopusLib.TaskAction taskAction = new TaskAction() { IsEnabled = Convert.ToBoolean(actionNode.Attributes["IsEnabled"].Value), IsFixed = Convert.ToBoolean(actionNode.Attributes["Fixed"].Value), Machine = actionNode.Attributes["Machine"] != null?MachineCollection.Where(o => o.Name.Equals(actionNode.Attributes["Machine"].Value, StringComparison.InvariantCultureIgnoreCase)).Single() as OctopusLib.Machine : null, Sequence = seq, Name = actionNode.InnerText.Trim(), }; task.TaskActionCollection.Add(taskAction); } } TaskCollection.Add(task); } } catch (Exception ex) { throw new Exception(ex.Message); } }