Пример #1
0
        public void Reset()
        {
            if (m_Playing && World.Player != null && DragDropManager.Holding != null && DragDropManager.Holding == LiftAction.LastLift)
            {
                ClientCommunication.SendToServer(new DropRequest(DragDropManager.Holding, World.Player.Serial));
            }

            m_Wait = null;

            m_IfStatus.Clear();

            bool resync = false;

            foreach (MacroAction a in m_Actions)
            {
                if (a is WalkAction)
                {
                    resync = true;
                }
                else if (a is ForAction)
                {
                    ((ForAction)a).Count = 0;
                }
            }

            if (resync && World.Player != null)
            {
                // resync if the macro walked for us
                //ClientCommunication.SendToClient( new MoveReject( World.Player.WalkSequence, World.Player ) );
                ClientCommunication.SendToClient(new MobileIncoming(World.Player));
                ClientCommunication.SendToClient(new MobileIncoming(World.Player));
                ClientCommunication.SendToServer(new ResyncReq());
                World.Player.Resync();
            }
        }
Пример #2
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();
            }
        }
Пример #3
0
        private void PlayMacroAction(PlayableMacroAction playableMacroAction)
        {
            ControlPanel.ApplyMacroActionState(playableMacroAction.Macro.ID, playableMacroAction.MacroAction.ID, MacroActionState.Ongoing);
            if (playableMacroAction.MacroAction.Type == MacroActionType.Wait)
            {
                MacroWaitAction macroWaitAction = (MacroWaitAction)playableMacroAction.MacroAction;
                switch (macroWaitAction.WaitForEvent)
                {
                case MacroActionWaitForEvent.Timeout:
                {
                    Thread.Sleep(macroWaitAction.TimeoutMilliseconds);
                }
                break;

                case MacroActionWaitForEvent.PreviousActionsCompleted:
                {
                    List <PlayableMacroAction> previousPlayableMacroActions = new List <PlayableMacroAction>();
                    MacroPlaybackContainer     container = _macroPlaybackContainers[playableMacroAction.Macro.ID];
                    foreach (PlayableMacroAction previousPlayableMacroAction in container.PlayableMacroActions.TakeWhile(x => x.MacroAction.ID != playableMacroAction.MacroAction.ID))
                    {
                        if (previousPlayableMacroAction.MacroAction.Type == MacroActionType.Wait)
                        {
                            previousPlayableMacroActions.Clear();
                        }
                        else
                        {
                            previousPlayableMacroActions.Add(previousPlayableMacroAction);
                        }
                    }
                    WaitWhileOngoing(previousPlayableMacroActions);
                }
                break;
                }
                ControlPanel.ApplyMacroActionState(playableMacroAction.Macro.ID, playableMacroAction.MacroAction.ID, MacroActionState.Success);
            }
            else
            {
                bool actionSuccess = ControlPanel.TakeAction(playableMacroAction.Action);
                lock (_macroPlaybackContainers)
                {
                    playableMacroAction.MacroActionState = !actionSuccess
                                                ? MacroActionState.Failure
                                                : playableMacroAction.MacroAction.Type == MacroActionType.Start || playableMacroAction.MacroAction.Type == MacroActionType.Stop || playableMacroAction.MacroAction.Type == MacroActionType.Restart
                                                        ? MacroActionState.Success
                                                        : MacroActionState.Ongoing;
                }
                ControlPanel.ApplyMacroActionState(playableMacroAction.Macro.ID, playableMacroAction.MacroAction.ID, playableMacroAction.MacroActionState);
            }
        }
Пример #4
0
        public void Reset()
        {
            if (m_Playing && World.Player != null && DragDropManager.Holding != null &&
                DragDropManager.Holding == LiftAction.LastLift)
                Client.Instance.SendToServer(new DropRequest(DragDropManager.Holding, World.Player.Serial));

            m_Wait = null;

            m_IfStatus.Clear();

            foreach (MacroAction a in m_Actions)
            {
                if (a is ForAction)
                    ((ForAction) a).Count = 0;
            }
        }
Пример #5
0
        // returns true if the were waiting for this action
        public bool Action(MacroAction action)
        {
            if (m_Recording)
            {
                action.Parent = this;
                m_Actions.Insert(m_CurrentAction, action);
                if (m_ListBox != null)
                    m_ListBox.SafeAction(s => s.Items.Insert(m_CurrentAction, action));
                m_CurrentAction++;

                return false;
            }
            else if (m_Playing && m_Wait != null && m_Wait.CheckMatch(action))
            {
                m_Wait = null;
                ExecNext();
                return true;
            }

            return false;
        }
        private void MacroDistributionActionItem_Load(object sender, EventArgs e)
        {
            if (ActionBundle == null)
            {
                throw new InvalidOperationException();
            }

            if (ActionBundle.Actions.Any())
            {
                MacroWaitAction macroAction = (MacroWaitAction)ActionBundle.Actions[0];
                _selectedWaitForEvent = macroAction.WaitForEvent;
                TimeoutMilliseconds   = macroAction.TimeoutMilliseconds;
            }
            else
            {
                SelectedWaitForEvent = null;
                TimeoutMilliseconds  = 0;
            }

            discardNumericUpDownValueChangedEvents = true;
            UpdateLinkLabelWaitForEvent();
            discardNumericUpDownValueChangedEvents = false;
        }
Пример #7
0
        //return true to continue the macro, false to stop (macro's over)
        public bool ExecNext()
        {
            try
            {
                if (!m_Playing)
                {
                    return(false);
                }

                if (m_Wait != null)
                {
                    TimeSpan waitLen = DateTime.UtcNow - m_Wait.StartTime;
                    if (!(m_Wait is PauseAction) && waitLen >= m_Wait.Timeout)
                    {
                        if (Loop)
                        {
                            if (Engine.MainWindow.WaitDisplay != null)
                            {
                                Engine.MainWindow.WaitDisplay.SafeAction(s => s.Text = string.Empty);
                            }
                            m_CurrentAction = -1;
                            m_IfStatus.Clear();
                            PauseB4Loop.Perform();
                            PauseB4Loop.Parent = this;
                            m_Wait             = PauseB4Loop;
                            return(true);
                        }
                        else
                        {
                            Stop();
                            return(false);
                        }
                    }
                    else
                    {
                        if (!m_Wait.PerformWait())
                        {
                            m_Wait = null; // done waiting
                            if (Engine.MainWindow.WaitDisplay != null)
                            {
                                Engine.MainWindow.WaitDisplay.SafeAction(s => s.Text = string.Empty);
                            }
                        }
                        else
                        {
                            if (waitLen >= TimeSpan.FromSeconds(4.0) && Engine.MainWindow.WaitDisplay != null)
                            {
                                StringBuilder sb = new StringBuilder(Language.GetString(LocString.WaitingTimeout));

                                sb.AppendLine("\n");

                                int s = (int)(m_Wait.Timeout - waitLen).TotalSeconds;
                                int m = 0;

                                if (s > 60)
                                {
                                    m  = s / 60;
                                    s %= 60;
                                    if (m > 60)
                                    {
                                        sb.AppendFormat("{0}:", m / 60);
                                        m %= 60;
                                    }
                                }

                                sb.AppendFormat("{0:00}:{1:00}", m, s);

                                Engine.MainWindow.WaitDisplay.SafeAction(w => w.Text = sb.ToString());
                            }

                            return(true); // keep waiting
                        }
                    }
                }

                m_CurrentAction++;
                //MacroManager.ActionUpdate( this, m_CurrentAction );
                if (m_ListBox != null)
                {
                    if (m_CurrentAction < m_ListBox.Items.Count)
                    {
                        m_ListBox.SafeAction(s => s.SelectedIndex = m_CurrentAction);
                    }
                    else
                    {
                        m_ListBox.SafeAction(s => s.SelectedIndex = -1);
                    }
                }

                if (m_CurrentAction >= 0 && m_CurrentAction < m_Actions.Count)
                {
                    MacroAction action = (MacroAction)m_Actions[m_CurrentAction];

                    if (action is IfAction)
                    {
                        bool val = ((IfAction)action).Evaluate();
                        m_IfStatus.Push(val);

                        if (!val)
                        {
                            // false so skip to an else or an endif
                            int ifcount = 0;
                            while (m_CurrentAction + 1 < m_Actions.Count)
                            {
                                if (m_Actions[m_CurrentAction + 1] is IfAction)
                                {
                                    ifcount++;
                                }
                                else if (m_Actions[m_CurrentAction + 1] is ElseAction && ifcount <= 0)
                                {
                                    break;
                                }
                                else if (m_Actions[m_CurrentAction + 1] is EndIfAction)
                                {
                                    if (ifcount <= 0)
                                    {
                                        break;
                                    }
                                    else
                                    {
                                        ifcount--;
                                    }
                                }

                                m_CurrentAction++;
                            }
                        }
                    }
                    else if (action is ElseAction && m_IfStatus.Count > 0)
                    {
                        bool val = (bool)m_IfStatus.Peek();
                        if (val)
                        {
                            // the if was true, so skip to an endif
                            int ifcount = 0;
                            while (m_CurrentAction + 1 < m_Actions.Count)
                            {
                                if (m_Actions[m_CurrentAction + 1] is IfAction)
                                {
                                    ifcount++;
                                }
                                else if (m_Actions[m_CurrentAction + 1] is EndIfAction)
                                {
                                    if (ifcount <= 0)
                                    {
                                        break;
                                    }
                                    else
                                    {
                                        ifcount--;
                                    }
                                }

                                m_CurrentAction++;
                            }
                        }
                    }
                    else if (action is EndIfAction && m_IfStatus.Count > 0)
                    {
                        m_IfStatus.Pop();
                    }
                    else if (action is ForAction)
                    {
                        ForAction fa = (ForAction)action;
                        fa.Count++;

                        if (fa.Count > fa.Max)
                        {
                            fa.Count = 0;

                            int forcount = 0;
                            m_CurrentAction++;
                            while (m_CurrentAction < m_Actions.Count)
                            {
                                if (m_Actions[m_CurrentAction] is ForAction)
                                {
                                    forcount++;
                                }
                                else if (m_Actions[m_CurrentAction] is EndForAction)
                                {
                                    if (forcount <= 0)
                                    {
                                        break;
                                    }
                                    else
                                    {
                                        forcount--;
                                    }
                                }

                                m_CurrentAction++;
                            }

                            if (m_CurrentAction < m_Actions.Count)
                            {
                                action = (MacroAction)m_Actions[m_CurrentAction];
                            }
                        }
                    }
                    else if (action is EndForAction && Client.Instance.AllowBit(FeatureBit.LoopingMacros))
                    {
                        int ca       = m_CurrentAction - 1;
                        int forcount = 0;

                        while (ca >= 0)
                        {
                            if (m_Actions[ca] is EndForAction)
                            {
                                forcount--;
                            }
                            else if (m_Actions[ca] is ForAction)
                            {
                                if (forcount >= 0)
                                {
                                    break;
                                }
                                else
                                {
                                    forcount++;
                                }
                            }

                            ca--;
                        }

                        if (ca >= 0 && m_Actions[ca] is ForAction)
                        {
                            m_CurrentAction = ca - 1;
                        }
                    }
                    else if (action is WhileAction && Client.Instance.AllowBit(FeatureBit.LoopingMacros))
                    {
                        bool val = ((WhileAction)action).Evaluate();

                        if (!val)
                        {
                            // false so skip to the endwhile
                            int whilecount = 0;
                            while (m_CurrentAction + 1 < m_Actions.Count)
                            {
                                if (m_Actions[m_CurrentAction + 1] is WhileAction)
                                {
                                    whilecount++;
                                }
                                else if (m_Actions[m_CurrentAction + 1] is EndWhileAction)
                                {
                                    if (whilecount <= 0)
                                    {
                                        // Skip over the end while
                                        m_CurrentAction++;
                                        break;
                                    }

                                    whilecount--;
                                }

                                m_CurrentAction++;
                            }
                        }
                    }
                    else if (action is EndWhileAction && Client.Instance.AllowBit(FeatureBit.LoopingMacros))
                    {
                        int ca         = m_CurrentAction - 1;
                        int whilecount = 0;

                        while (ca >= 0)
                        {
                            if (m_Actions[ca] is EndWhileAction)
                            {
                                whilecount--;
                            }
                            else if (m_Actions[ca] is WhileAction)
                            {
                                if (whilecount >= 0)
                                {
                                    break;
                                }
                                else
                                {
                                    whilecount++;
                                }
                            }

                            ca--;
                        }

                        if (ca >= 0 && m_Actions[ca] is WhileAction)
                        {
                            m_CurrentAction = ca - 1;
                        }
                    }
                    else if (action is DoWhileAction && Client.Instance.AllowBit(FeatureBit.LoopingMacros))
                    {
                        bool val = ((DoWhileAction)action).Evaluate();

                        if (val)
                        {
                            int ca           = m_CurrentAction - 1;
                            int dowhilecount = 0;

                            while (ca >= 0)
                            {
                                if (m_Actions[ca] is DoWhileAction)
                                {
                                    dowhilecount--;
                                }
                                else if (m_Actions[ca] is StartDoWhileAction)
                                {
                                    if (dowhilecount >= 0)
                                    {
                                        break;
                                    }
                                    else
                                    {
                                        dowhilecount++;
                                    }
                                }

                                ca--;
                            }

                            if (ca >= 0 && m_Actions[ca] is StartDoWhileAction)
                            {
                                m_CurrentAction = ca - 1;
                            }
                        }
                    }

                    bool isWait = action is MacroWaitAction;
                    if (!action.Perform() && isWait)
                    {
                        m_Wait           = (MacroWaitAction)action;
                        m_Wait.StartTime = DateTime.UtcNow;
                    }
                    else if (NextIsInstantWait() && !isWait)
                    {
                        return(ExecNext());
                    }
                }
                else
                {
                    if (Engine.MainWindow.WaitDisplay != null)
                    {
                        Engine.MainWindow.WaitDisplay.SafeAction(s => s.Text = string.Empty);
                    }

                    if (Loop)
                    {
                        m_CurrentAction = -1;

                        Reset();

                        PauseB4Loop.Perform();
                        PauseB4Loop.Parent = this;
                        m_Wait             = PauseB4Loop;
                    }
                    else
                    {
                        Stop();
                        return(false);
                    }
                }
            }
            catch (Exception e)
            {
                new MessageDialog("Macro Exception", true, e.ToString()).Show();
                return(false);
            }

            return(true);
        }
Пример #8
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();
        }
Пример #9
0
        public static void SaveClientSettings(ClientSettingsType clientSettingsType)
        {
            RegistryKey key = _registryHive.CreateSubKey(APPLICATION_REGISTRY_KEY);

            if (key == null)
            {
                return;
            }
            switch (clientSettingsType)
            {
            case ClientSettingsType.Machines:
                RegistryKey machinesKey = key.CreateSubKey("Machines");
                if (machinesKey != null)
                {
                    foreach (string subKeyName in machinesKey.GetSubKeyNames().Where(subKeyName => subKeyName.StartsWith("Machine ")))
                    {
                        machinesKey.DeleteSubKeyTree(subKeyName);
                    }
                    for (int i = 0; i < Settings.Client.Machines.Count; i++)
                    {
                        RegistryKey machineKey = machinesKey.CreateSubKey($"Machine {i.ToString("00")}");
                        if (machineKey == null)
                        {
                            continue;
                        }
                        machineKey.SetValue("Host Name", Settings.Client.Machines[i].HostName);
                        machineKey.Close();
                    }
                    machinesKey.Close();
                }
                break;

            case ClientSettingsType.Macros:
                RegistryKey macrosKey = key.CreateSubKey("Macros");
                if (macrosKey != null)
                {
                    foreach (string subKeyName in macrosKey.GetSubKeyNames())
                    {
                        macrosKey.DeleteSubKeyTree(subKeyName);
                    }
                    foreach (Macro macro in Settings.Client.Macros)
                    {
                        RegistryKey macroKey = macrosKey.CreateSubKey(macro.ID.ToString());
                        if (macroKey == null)
                        {
                            continue;
                        }
                        macroKey.SetValue("Name", macro.Name);
                        for (int i = 0; i < macro.ActionBundles.Count; i++)
                        {
                            MacroActionBundle actionBundle = macro.ActionBundles[i];
                            RegistryKey       bundleKey    = macroKey.CreateSubKey($"Action Bundle {i.ToString("00")}");
                            if (bundleKey == null)
                            {
                                continue;
                            }
                            bundleKey.SetValue("Action Type", actionBundle.Type.ToString());
                            for (int j = 0; j < actionBundle.Actions.Count; j++)
                            {
                                RegistryKey actionKey = bundleKey.CreateSubKey($"Action {j.ToString("00")}");
                                if (actionKey == null)
                                {
                                    continue;
                                }
                                actionKey.SetValue("ID", actionBundle.Actions[j].ID.ToString());
                                if (actionBundle.Actions[j] is MacroProcessAction)
                                {
                                    MacroProcessAction macroProcessAction = (MacroProcessAction)actionBundle.Actions[j];
                                    actionKey.SetValue("Machine ID", macroProcessAction.MachineID);
                                    actionKey.SetValue("Group ID", macroProcessAction.GroupID);
                                    actionKey.SetValue("Application ID", macroProcessAction.ApplicationID);
                                }
                                else if (actionBundle.Actions[j] is MacroDistributionAction)
                                {
                                    MacroDistributionAction macroDistributionAction = (MacroDistributionAction)actionBundle.Actions[j];
                                    actionKey.SetValue("Source Machine ID", macroDistributionAction.SourceMachineID);
                                    actionKey.SetValue("Group ID", macroDistributionAction.GroupID);
                                    actionKey.SetValue("Application ID", macroDistributionAction.ApplicationID);
                                    actionKey.SetValue("Destination Machine ID", macroDistributionAction.DestinationMachineID);
                                }
                                else if (actionBundle.Actions[j] is MacroWaitAction)
                                {
                                    MacroWaitAction macroWaitAction = (MacroWaitAction)actionBundle.Actions[j];
                                    if (macroWaitAction.IsValid)
                                    {
                                        actionKey.SetValue("Wait For Event", macroWaitAction.WaitForEvent.ToString());
                                        if (macroWaitAction.WaitForEvent == MacroActionWaitForEvent.Timeout)
                                        {
                                            actionKey.SetValue("Timeout Milliseconds", macroWaitAction.TimeoutMilliseconds.ToString(CultureInfo.InvariantCulture));
                                        }
                                    }
                                }
                                actionKey.Close();
                            }
                            bundleKey.Close();
                        }
                        macroKey.Close();
                    }
                    macrosKey.Close();
                }
                break;

            case ClientSettingsType.Options:
                RegistryKey optionsKey = key.CreateSubKey("Options");
                if (optionsKey != null)
                {
                    optionsKey.SetValue("Start With Windows", Settings.Client.StartWithWindows.ToString());
                    optionsKey.SetValue("User Owns Control Panel", Settings.Client.UserOwnsControlPanel.ToString());
                    optionsKey.SetValue("Keep Control Panel Top Most", Settings.Client.KeepControlPanelTopMost.ToString());
                    optionsKey.SetValue("Log Type Min Level", Settings.Client.LogTypeMinLevel.ToString());
                    optionsKey.Close();
                }
                break;

            case ClientSettingsType.States:
                RegistryKey statesKey = key.CreateSubKey("States");
                if (statesKey != null)
                {
                    statesKey.SetValue("CFG Selected Host Name", Settings.Client.CFG_SelectedHostName);
                    statesKey.SetValue("CFG Selected Configuration Section", Settings.Client.CFG_SelectedConfigurationSection);
                    statesKey.SetValue("CP Selected Tab", Settings.Client.CP_SelectedTab);
                    statesKey.SetValue("P Selected Grouping", Settings.Client.P_SelectedGrouping);
                    statesKey.SetValue("P Selected Filter Machine", Settings.Client.P_SelectedFilterMachine);
                    statesKey.SetValue("P Selected Filter Group", Settings.Client.P_SelectedFilterGroup);
                    statesKey.SetValue("P Selected Filter Application", Settings.Client.P_SelectedFilterApplication);
                    RegistryKey checkedNodesKey = statesKey.CreateSubKey("P Checked Nodes");
                    if (checkedNodesKey != null)
                    {
                        foreach (string valueName in checkedNodesKey.GetValueNames().Where(valueName => valueName.StartsWith("Node ")))
                        {
                            checkedNodesKey.DeleteValue(valueName);
                        }
                        for (int i = 0; i < Settings.Client.P_CheckedNodes.Count; i++)
                        {
                            checkedNodesKey.SetValue($"Node {i.ToString("00")}", Settings.Client.P_CheckedNodes[i].ToString());
                        }
                        checkedNodesKey.Close();
                    }
                    RegistryKey collapsedNodesKey = statesKey.CreateSubKey("P Collapsed Nodes");
                    if (collapsedNodesKey != null)
                    {
                        foreach (ProcessGrouping grouping in Enum.GetValues(typeof(ProcessGrouping)))
                        {
                            RegistryKey groupingKey = collapsedNodesKey.CreateSubKey(grouping.ToString());
                            if (groupingKey != null)
                            {
                                foreach (string valueName in groupingKey.GetValueNames().Where(valueName => valueName.StartsWith("Node ")))
                                {
                                    groupingKey.DeleteValue(valueName);
                                }
                                for (int i = 0; i < Settings.Client.P_CollapsedNodes[grouping].Count; i++)
                                {
                                    groupingKey.SetValue($"Node {i.ToString("00")}", Settings.Client.P_CollapsedNodes[grouping][i].ToString());
                                }
                                groupingKey.Close();
                            }
                        }
                        collapsedNodesKey.Close();
                    }
                    statesKey.SetValue("D Selected Grouping", Settings.Client.D_SelectedGrouping);
                    statesKey.SetValue("D Selected Filter Source Machine", Settings.Client.D_SelectedFilterSourceMachine);
                    statesKey.SetValue("D Selected Filter Group", Settings.Client.D_SelectedFilterGroup);
                    statesKey.SetValue("D Selected Filter Application", Settings.Client.D_SelectedFilterApplication);
                    statesKey.SetValue("D Selected Filter Destination Machine", Settings.Client.D_SelectedFilterDestinationMachine);
                    checkedNodesKey = statesKey.CreateSubKey("D Checked Nodes");
                    if (checkedNodesKey != null)
                    {
                        foreach (string valueName in checkedNodesKey.GetValueNames().Where(valueName => valueName.StartsWith("Node ")))
                        {
                            checkedNodesKey.DeleteValue(valueName);
                        }
                        for (int i = 0; i < Settings.Client.D_CheckedNodes.Count; i++)
                        {
                            checkedNodesKey.SetValue($"Node {i.ToString("00")}", Settings.Client.D_CheckedNodes[i].ToString());
                        }
                        checkedNodesKey.Close();
                    }
                    collapsedNodesKey = statesKey.CreateSubKey("D Collapsed Nodes");
                    if (collapsedNodesKey != null)
                    {
                        foreach (DistributionGrouping grouping in Enum.GetValues(typeof(DistributionGrouping)))
                        {
                            RegistryKey groupingKey = collapsedNodesKey.CreateSubKey(grouping.ToString());
                            if (groupingKey != null)
                            {
                                foreach (string valueName in groupingKey.GetValueNames().Where(valueName => valueName.StartsWith("Node ")))
                                {
                                    groupingKey.DeleteValue(valueName);
                                }
                                for (int i = 0; i < Settings.Client.D_CollapsedNodes[grouping].Count; i++)
                                {
                                    groupingKey.SetValue($"Node {i.ToString("00")}", Settings.Client.D_CollapsedNodes[grouping][i].ToString());
                                }
                                groupingKey.Close();
                            }
                        }
                        collapsedNodesKey.Close();
                    }
                    checkedNodesKey = statesKey.CreateSubKey("M Checked Nodes");
                    if (checkedNodesKey != null)
                    {
                        foreach (string valueName in checkedNodesKey.GetValueNames().Where(valueName => valueName.StartsWith("Node ")))
                        {
                            checkedNodesKey.DeleteValue(valueName);
                        }
                        for (int i = 0; i < Settings.Client.M_CheckedNodes.Count; i++)
                        {
                            checkedNodesKey.SetValue($"Node {i.ToString("00")}", Settings.Client.M_CheckedNodes[i].ToString());
                        }
                        checkedNodesKey.Close();
                    }
                    collapsedNodesKey = statesKey.CreateSubKey("M Collapsed Nodes");
                    if (collapsedNodesKey != null)
                    {
                        foreach (string valueName in collapsedNodesKey.GetValueNames().Where(valueName => valueName.StartsWith("Node ")))
                        {
                            collapsedNodesKey.DeleteValue(valueName);
                        }
                        for (int i = 0; i < Settings.Client.M_CollapsedNodes.Count; i++)
                        {
                            collapsedNodesKey.SetValue($"Node {i.ToString("00")}", Settings.Client.M_CollapsedNodes[i].ToString());
                        }
                        collapsedNodesKey.Close();
                    }
                    statesKey.Close();
                }
                break;
            }
            key.Close();
        }