コード例 #1
0
        private static string GetActionName(IMacroAction macroAction)
        {
            Group       group       = null;
            Application application = null;

            switch (macroAction.Type)
            {
            case MacroActionType.Start:
            case MacroActionType.Stop:
            case MacroActionType.Restart:
                MacroProcessAction macroProcessAction = (MacroProcessAction)macroAction;
                Machine            machine            = Settings.Client.Machines.FirstOrDefault(x => x.ID == macroProcessAction.MachineID);
                if (machine != null && ConnectionStore.ConnectionCreated(machine))
                {
                    group       = ConnectionStore.Connections[machine].Configuration.Groups.FirstOrDefault(x => x.ID == macroProcessAction.GroupID);
                    application = ConnectionStore.Connections[machine].Configuration.Applications.FirstOrDefault(x => x.ID == macroProcessAction.ApplicationID);
                }
                return(machine == null || group == null || application == null
                                                ? null
                                                : $"{group.Name} / {application.Name}");

            case MacroActionType.Distribute:
                MacroDistributionAction macroDistributionAction = (MacroDistributionAction)macroAction;
                Machine destinationMachine = Settings.Client.Machines.FirstOrDefault(x => x.ID == macroDistributionAction.DestinationMachineID);
                if (destinationMachine == null || !ConnectionStore.ConnectionCreated(destinationMachine))
                {
                    return(null);
                }
                Machine sourceMachine = Settings.Client.Machines.FirstOrDefault(x => x.ID == macroDistributionAction.SourceMachineID);
                if (sourceMachine != null && ConnectionStore.ConnectionCreated(sourceMachine))
                {
                    group       = ConnectionStore.Connections[sourceMachine].Configuration.Groups.FirstOrDefault(x => x.ID == macroDistributionAction.GroupID);
                    application = ConnectionStore.Connections[sourceMachine].Configuration.Applications.FirstOrDefault(x => x.ID == macroDistributionAction.ApplicationID);
                }
                return(sourceMachine == null || group == null || application == null
                                                ? null
                                                : $"{sourceMachine.HostName} / {group.Name} / {application.Name}");

            case MacroActionType.Wait:
                MacroWaitAction macroWaitAction = (MacroWaitAction)macroAction;
                if (!macroWaitAction.IsValid)
                {
                    throw new InvalidOperationException();
                }
                switch (macroWaitAction.WaitForEvent)
                {
                case MacroActionWaitForEvent.Timeout:
                    return($"{macroWaitAction.Type} for timeout, {macroWaitAction.TimeoutMilliseconds} ms");

                case MacroActionWaitForEvent.PreviousActionsCompleted:
                    return($"{macroWaitAction.Type} for previous actions completed");

                default:
                    throw new InvalidOperationException();
                }

            default:
                throw new InvalidOperationException();
            }
        }
コード例 #2
0
 public PlayableMacroAction(Macro macro, IMacroAction macroAction, IAction action = null)
 {
     Macro            = macro;
     MacroAction      = macroAction;
     Action           = action;
     MacroActionState = MacroActionState.Unknown;
 }
コード例 #3
0
 public MacroActionNode(IMacroAction macroAction, Guid macroID)
 {
     InitializeComponent();
     MacroAction = macroAction;
     _id         = MakeID(macroID, macroAction.ID);
     _state      = MacroActionState.Unknown;
     _actionName = GetActionName(MacroAction);
     //BackColor = Color.FromArgb(255, 192, 128);
 }
コード例 #4
0
        private static IAction CreateAction(IMacroAction macroAction)
        {
            switch (macroAction.Type)
            {
            case MacroActionType.Start:
            case MacroActionType.Stop:
            case MacroActionType.Restart:
            {
                MacroProcessAction macroProcessAction = (MacroProcessAction)macroAction;
                Machine            machine            = Settings.Client.Machines.FirstOrDefault(x => x.ID == macroProcessAction.MachineID);
                if (machine != null && ConnectionStore.ConnectionCreated(machine))
                {
                    Group       group       = ConnectionStore.Connections[machine].Configuration.Groups.FirstOrDefault(x => x.ID == macroProcessAction.GroupID);
                    Application application = ConnectionStore.Connections[machine].Configuration.Applications.FirstOrDefault(x => x.ID == macroProcessAction.ApplicationID);
                    return(new ProcessAction(Convert(macroAction.Type), machine, @group, application));
                }
                return(null);
            }

            case MacroActionType.Distribute:
            {
                MacroDistributionAction macroDistributionAction = (MacroDistributionAction)macroAction;
                Machine sourceMachine      = Settings.Client.Machines.FirstOrDefault(x => x.ID == macroDistributionAction.SourceMachineID);
                Machine destinationMachine = Settings.Client.Machines.FirstOrDefault(x => x.ID == macroDistributionAction.DestinationMachineID);
                if (sourceMachine != null && ConnectionStore.ConnectionCreated(sourceMachine))
                {
                    Group       group       = ConnectionStore.Connections[sourceMachine].Configuration.Groups.FirstOrDefault(x => x.ID == macroDistributionAction.GroupID);
                    Application application = ConnectionStore.Connections[sourceMachine].Configuration.Applications.FirstOrDefault(x => x.ID == macroDistributionAction.ApplicationID);
                    return(new DistributionAction(Convert(macroAction.Type), sourceMachine, group, application, destinationMachine));
                }
                return(null);
            }

            default:
                return(null);
            }
        }
コード例 #5
0
 /// <summary>
 /// Instantiates a new instance of the <see cref="MacroActionValidationResult"/> class
 /// </summary>
 /// <param name="action"></param>
 /// <param name="valid"></param>
 /// <param name="childResult"></param>
 public MacroActionValidationResult(IMacroAction action, bool valid, IMacroValidationResult childResult = null)
 {
     this._action = action;
     this._valid = valid;
     this._childResult = childResult;
 }
コード例 #6
0
ファイル: MacroRoutineExecutor.cs プロジェクト: zmsl/Ennerbot
 /// <summary>
 /// Fires the action ended event
 /// </summary>
 /// <param name="context"></param>
 /// <param name="action"></param>
 protected virtual void MacroRoutine_OnActionEnded(IExecutionContext context, IMacroAction action)
 {
     var handler = OnActionEnded;
     if (handler != null) handler(this, context, action);
 }
コード例 #7
0
 public MacroAction(ActionType type, IMacroAction action) : this(type)
 {
     Actions.Add(action);
 }
コード例 #8
0
        private void DoneBtn_Click(object sender, RoutedEventArgs e)
        {
            if (CheckForEmtpyTextbox(nameTb))
            {
                return;
            }
            if (CheckForEmtpyTextbox(hotkeyTb))
            {
                return;
            }

            if (launchProcRb.IsChecked.Value)
            {
                if (CheckForEmtpyTextbox(lp_procPathTb))
                {
                    return;
                }
            }
            else if (sendKeysRb.IsChecked.Value)
            {
                if (CheckForEmtpyTextbox(sK_KeystrokeTb))
                {
                    return;
                }
            }
            else if (sendKeycodeRb.IsChecked.Value)
            {
                if (CheckForEmtpyTextbox(sKc_KeycodeTb))
                {
                    return;
                }
            }
            else if (sendHttpRequestRb.IsChecked.Value)
            {
                if (CheckForEmtpyTextbox(sHr_URLTb))
                {
                    return;
                }
            }

            IMacroAction action = null;

            if (launchProcRb.IsChecked.Value)
            {
                action = new LaunchProcessMacro(nameTb.Text, lp_procPathTb.Text, lp_procArgsTb.Text, lp_procStartPathTb.Text, lp_adminTBtn.IsChecked.Value);
            }
            else if (sendKeysRb.IsChecked.Value)
            {
                action = new SendKeysMacro(nameTb.Text, sK_KeystrokeTb.Text);
            }
            else if (sendKeycodeRb.IsChecked.Value)
            {
                action = new SendKeycodeMacro(nameTb.Text, int.Parse(sKc_KeycodeTb.Text));
            }
            else if (sendHttpRequestRb.IsChecked.Value)
            {
                action = new HttpRequestMacro(nameTb.Text, sHr_URLTb.Text, sHr_MethodTb.IsChecked.Value ? HttpRequestMacro.RequestMethod.POST : HttpRequestMacro.RequestMethod.GET, sHr_clipboardCb.IsChecked.Value);
            }
            MacroItem item = new MacroItem((Key)Enum.Parse(typeof(Key), hotkeyTb.Text), action);

            if (IsEditWindow)
            {
                Variables.Macros[Variables.Macros.IndexOf(Macro)] = item;
            }
            else
            {
                Variables.Macros.Add(item);
            }
            ConfigManager.StoreObject(Variables.Macros, Constants.MacrosPath);
            this.Close();
        }
コード例 #9
0
 public MacroItem(Key hotkey, IMacroAction action)
 {
     Hotkey = hotkey;
     Action = action;
 }
コード例 #10
0
        public static void LoadClientSettings(ClientSettingsType clientSettingsType)
        {
            RegistryKey key = _registryHive.OpenSubKey(APPLICATION_REGISTRY_KEY, false);

            if (key == null)
            {
                return;
            }
            switch (clientSettingsType)
            {
            case ClientSettingsType.Machines:
                Settings.Client.Machines.Clear();
                RegistryKey machinesKey = key.OpenSubKey("Machines", false);
                if (machinesKey != null)
                {
                    RegistryKey machineKey = machinesKey.OpenSubKey("Machine " + Settings.Client.Machines.Count.ToString("00"), false);
                    while (machineKey != null)
                    {
                        string hostName = (string)machineKey.GetValue("Host Name", "<unknown>");
                        Settings.Client.Machines.Add(new Machine(hostName));
                        machineKey.Close();
                        machineKey = machinesKey.OpenSubKey("Machine " + Settings.Client.Machines.Count.ToString("00"), false);
                    }
                    machinesKey.Close();
                }
                break;

            case ClientSettingsType.Macros:
                Settings.Client.Macros.Clear();
                RegistryKey macrosKey = key.OpenSubKey("Macros", false);
                if (macrosKey != null)
                {
                    foreach (string macroID in macrosKey.GetSubKeyNames())
                    {
                        RegistryKey macroKey = macrosKey.OpenSubKey(macroID, false);
                        if (macroKey == null)
                        {
                            continue;
                        }
                        string name  = (string)macroKey.GetValue("Name", "<unknown>");
                        Macro  macro = new Macro(Guid.Parse(macroID), name);
                        try
                        {
                            RegistryKey bundleKey = macroKey.OpenSubKey("Action Bundle " + macro.ActionBundles.Count.ToString("00"), false);
                            while (bundleKey != null)
                            {
                                string actionTypeStr = (string)bundleKey.GetValue("Action Type");
                                if (actionTypeStr == null)
                                {
                                    break;
                                }
                                MacroActionType   actionType   = (MacroActionType)Enum.Parse(typeof(MacroActionType), actionTypeStr);
                                MacroActionBundle actionBundle = new MacroActionBundle(actionType);
                                RegistryKey       actionKey    = bundleKey.OpenSubKey("Action " + actionBundle.Actions.Count.ToString("00"), false);
                                while (actionKey != null)
                                {
                                    IMacroAction action = null;
                                    string       id     = (string)actionKey.GetValue("ID");
                                    if (id == null)
                                    {
                                        break;
                                    }
                                    switch (actionType)
                                    {
                                    case MacroActionType.Start:
                                    case MacroActionType.Stop:
                                    case MacroActionType.Restart:
                                        string processMachineID     = (string)actionKey.GetValue("Machine ID", Guid.Empty.ToString());
                                        string processGroupID       = (string)actionKey.GetValue("Group ID", Guid.Empty.ToString());
                                        string processApplicationID = (string)actionKey.GetValue("Application ID", Guid.Empty.ToString());
                                        action = new MacroProcessAction(Guid.Parse(id), actionType, Guid.Parse(processMachineID),
                                                                        Guid.Parse(processGroupID), Guid.Parse(processApplicationID));
                                        break;

                                    case MacroActionType.Distribute:
                                        string distributionSourceMachineID      = (string)actionKey.GetValue("Source Machine ID", Guid.Empty.ToString());
                                        string distributionGroupID              = (string)actionKey.GetValue("Group ID", Guid.Empty.ToString());
                                        string distributionApplicationID        = (string)actionKey.GetValue("Application ID", Guid.Empty.ToString());
                                        string distributionDestinationMachineID = (string)actionKey.GetValue("Destination Machine ID", Guid.Empty.ToString());
                                        action = new MacroDistributionAction(Guid.Parse(id), actionType, Guid.Parse(distributionSourceMachineID),
                                                                             Guid.Parse(distributionGroupID), Guid.Parse(distributionApplicationID), Guid.Parse(distributionDestinationMachineID));
                                        break;

                                    case MacroActionType.Wait:
                                        string waitForEvent        = (string)actionKey.GetValue("Wait For Event");
                                        string timeoutMilliseconds = (string)actionKey.GetValue("Timeout Milliseconds", "0");
                                        action = new MacroWaitAction(Guid.Parse(id), actionType,
                                                                     (MacroActionWaitForEvent)Enum.Parse(typeof(MacroActionWaitForEvent), waitForEvent),
                                                                     int.Parse(timeoutMilliseconds));
                                        break;
                                    }
                                    if (action == null)
                                    {
                                        break;
                                    }
                                    actionBundle.Actions.Add(action);
                                    actionKey.Close();
                                    actionKey = bundleKey.OpenSubKey("Action " + actionBundle.Actions.Count.ToString("00"), false);
                                }
                                macro.ActionBundles.Add(actionBundle);
                                bundleKey.Close();
                                bundleKey = macroKey.OpenSubKey("Action Bundle " + macro.ActionBundles.Count.ToString("00"), false);
                            }
                        }
                        catch
                        {
                            continue;
                        }
                        Settings.Client.Macros.Add(macro);
                        macroKey.Close();
                    }
                    macrosKey.Close();
                }
                break;

            case ClientSettingsType.Options:
                RegistryKey optionsKey = key.OpenSubKey("Options", false);
                if (optionsKey != null)
                {
                    Settings.Client.StartWithWindows        = bool.Parse((string)optionsKey.GetValue("Start With Windows", Settings.Client.Defaults.START_WITH_WINDOWS));
                    Settings.Client.UserOwnsControlPanel    = bool.Parse((string)optionsKey.GetValue("User Owns Control Panel", Settings.Client.Defaults.USER_OWNS_CONTROL_PANEL));
                    Settings.Client.KeepControlPanelTopMost = bool.Parse((string)optionsKey.GetValue("Keep Control Panel Top Most", Settings.Client.Defaults.KEEP_CONTROL_PANEL_TOP_MOST));
                    Settings.Client.LogTypeMinLevel         = (LogType)Enum.Parse(typeof(LogType), (string)optionsKey.GetValue("Log Type Min Level", Settings.Client.Defaults.LOG_TYPE_MIN_LEVEL));
                    optionsKey.Close();
                }
                break;

            case ClientSettingsType.States:
                RegistryKey statesKey = key.OpenSubKey("States", false);
                if (statesKey != null)
                {
                    Settings.Client.CFG_SelectedHostName             = (string)statesKey.GetValue("CFG Selected Host Name", Settings.Client.Defaults.SELECTED_HOST_NAME);
                    Settings.Client.CFG_SelectedConfigurationSection = (string)statesKey.GetValue("CFG Selected Configuration Section", Settings.Client.Defaults.SELECTED_CONFIGURATION_SECTION);
                    Settings.Client.CP_SelectedTab              = (string)statesKey.GetValue("CP Selected Tab", Settings.Client.Defaults.SELECTED_TAB);
                    Settings.Client.P_SelectedGrouping          = (string)statesKey.GetValue("P Selected Grouping", Settings.Client.Defaults.SELECTED_PROCESS_GROUPING);
                    Settings.Client.P_SelectedFilterMachine     = (string)statesKey.GetValue("P Selected Filter Machine", Settings.Client.Defaults.SELECTED_PROCESS_FILTER_MACHINE);
                    Settings.Client.P_SelectedFilterGroup       = (string)statesKey.GetValue("P Selected Filter Group", Settings.Client.Defaults.SELECTED_PROCESS_FILTER_GROUP);
                    Settings.Client.P_SelectedFilterApplication = (string)statesKey.GetValue("P Selected Filter Application", Settings.Client.Defaults.SELECTED_PROCESS_FILTER_APPLICATION);
                    Settings.Client.P_CheckedNodes.Clear();
                    RegistryKey checkedNodesKey = statesKey.OpenSubKey("P Checked Nodes", false);
                    if (checkedNodesKey != null)
                    {
                        string nodeID = (string)checkedNodesKey.GetValue("Node " + Settings.Client.P_CheckedNodes.Count.ToString("00"));
                        while (nodeID != null)
                        {
                            Settings.Client.P_CheckedNodes.Add(new Guid(nodeID));
                            nodeID = (string)checkedNodesKey.GetValue("Node " + Settings.Client.P_CheckedNodes.Count.ToString("00"));
                        }
                        checkedNodesKey.Close();
                    }
                    Enum.GetValues(typeof(ProcessGrouping)).Cast <ProcessGrouping>().ToList().ForEach(grouping => Settings.Client.P_CollapsedNodes[grouping].Clear());
                    RegistryKey collapsedNodesKey = statesKey.OpenSubKey("P Collapsed Nodes", false);
                    if (collapsedNodesKey != null)
                    {
                        foreach (ProcessGrouping grouping in Enum.GetValues(typeof(ProcessGrouping)))
                        {
                            RegistryKey groupingKey = collapsedNodesKey.OpenSubKey(grouping.ToString(), false);
                            if (groupingKey != null)
                            {
                                string nodeID = (string)groupingKey.GetValue("Node " + Settings.Client.P_CollapsedNodes[grouping].Count.ToString("00"));
                                while (nodeID != null)
                                {
                                    Settings.Client.P_CollapsedNodes[grouping].Add(new Guid(nodeID));
                                    nodeID = (string)groupingKey.GetValue("Node " + Settings.Client.P_CollapsedNodes[grouping].Count.ToString("00"));
                                }
                                groupingKey.Close();
                            }
                        }
                        collapsedNodesKey.Close();
                    }
                    Settings.Client.D_SelectedGrouping                 = (string)statesKey.GetValue("D Selected Grouping", Settings.Client.Defaults.SELECTED_DISTRIBUTION_GROUPING);
                    Settings.Client.D_SelectedFilterSourceMachine      = (string)statesKey.GetValue("D Selected Filter Source Machine", Settings.Client.Defaults.SELECTED_DISTRIBUTION_FILTER_SOURCE_MACHINE);
                    Settings.Client.D_SelectedFilterGroup              = (string)statesKey.GetValue("D Selected Filter Group", Settings.Client.Defaults.SELECTED_DISTRIBUTION_FILTER_GROUP);
                    Settings.Client.D_SelectedFilterApplication        = (string)statesKey.GetValue("D Selected Filter Application", Settings.Client.Defaults.SELECTED_DISTRIBUTION_FILTER_APPLICATION);
                    Settings.Client.D_SelectedFilterDestinationMachine = (string)statesKey.GetValue("D Selected Filter Destination Machine", Settings.Client.Defaults.SELECTED_DISTRIBUTION_FILTER_DESTINATION_MACHINE);
                    Settings.Client.D_CheckedNodes.Clear();
                    checkedNodesKey = statesKey.OpenSubKey("D Checked Nodes", false);
                    if (checkedNodesKey != null)
                    {
                        string nodeID = (string)checkedNodesKey.GetValue("Node " + Settings.Client.D_CheckedNodes.Count.ToString("00"));
                        while (nodeID != null)
                        {
                            Settings.Client.D_CheckedNodes.Add(new Guid(nodeID));
                            nodeID = (string)checkedNodesKey.GetValue("Node " + Settings.Client.D_CheckedNodes.Count.ToString("00"));
                        }
                        checkedNodesKey.Close();
                    }
                    Enum.GetValues(typeof(DistributionGrouping)).Cast <DistributionGrouping>().ToList().ForEach(grouping => Settings.Client.D_CollapsedNodes[grouping].Clear());
                    collapsedNodesKey = statesKey.OpenSubKey("D Collapsed Nodes", false);
                    if (collapsedNodesKey != null)
                    {
                        foreach (DistributionGrouping grouping in Enum.GetValues(typeof(DistributionGrouping)))
                        {
                            RegistryKey groupingKey = collapsedNodesKey.OpenSubKey(grouping.ToString(), false);
                            if (groupingKey != null)
                            {
                                string nodeID = (string)groupingKey.GetValue("Node " + Settings.Client.D_CollapsedNodes[grouping].Count.ToString("00"));
                                while (nodeID != null)
                                {
                                    Settings.Client.D_CollapsedNodes[grouping].Add(new Guid(nodeID));
                                    nodeID = (string)groupingKey.GetValue("Node " + Settings.Client.D_CollapsedNodes[grouping].Count.ToString("00"));
                                }
                                groupingKey.Close();
                            }
                        }
                        collapsedNodesKey.Close();
                    }
                    Settings.Client.M_CheckedNodes.Clear();
                    checkedNodesKey = statesKey.OpenSubKey("M Checked Nodes", false);
                    if (checkedNodesKey != null)
                    {
                        string nodeID = (string)checkedNodesKey.GetValue("Node " + Settings.Client.M_CheckedNodes.Count.ToString("00"));
                        while (nodeID != null)
                        {
                            Settings.Client.M_CheckedNodes.Add(new Guid(nodeID));
                            nodeID = (string)checkedNodesKey.GetValue("Node " + Settings.Client.M_CheckedNodes.Count.ToString("00"));
                        }
                        checkedNodesKey.Close();
                    }
                    Settings.Client.M_CollapsedNodes.Clear();
                    collapsedNodesKey = statesKey.OpenSubKey("M Collapsed Nodes", false);
                    if (collapsedNodesKey != null)
                    {
                        string nodeID = (string)collapsedNodesKey.GetValue("Node " + Settings.Client.M_CollapsedNodes.Count.ToString("00"));
                        while (nodeID != null)
                        {
                            Settings.Client.M_CollapsedNodes.Add(new Guid(nodeID));
                            nodeID = (string)collapsedNodesKey.GetValue("Node " + Settings.Client.M_CollapsedNodes.Count.ToString("00"));
                        }
                        collapsedNodesKey.Close();
                    }
                    statesKey.Close();
                }
                break;
            }
            key.Close();
        }
コード例 #11
0
ファイル: MacroManager.cs プロジェクト: zmsl/Ennerbot
 /// <summary>
 /// Handles actions starting
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="context"></param>
 /// <param name="action"></param>
 private void MacroExecution_OnActionStarted(IMacroRoutineExecutor sender, IExecutionContext context, IMacroAction action)
 {
 }