示例#1
0
        /// <summary>
        /// Performs any processing of the command data.
        /// </summary>
        /// <param name="data">The data to be processed.</param>
        /// <remarks>The supplied data is expected to be relevant to this
        /// processor (the caller should have already applied any filter
        /// to the command stream).</remarks>
        void ICmdProcessor.Process(CmdData data)
        {
            // The command names handled here need to be included
            // via the CmdFilter property

            if (data.CmdName == AddCmdLine.CmdName)
            {
                string name = data.GetValue <string>(nameof(AddCmdLine.Name));
                Names.Add(name);
            }
            else if (data.CmdName == CutCmdLine.CmdName)
            {
                string name = data.GetValue <string>(nameof(CutCmdLine.Name));
                int    nRem = Names.RemoveAll(x => x == name);

                // This is going to fail if this is getting called when we're rebuilding the model.
                // Cuts should be handled by marking the adds (to ignore them).
                // AltNames only works with the one branch
                data.Add(nameof(NameProcessor.CutCount), nRem);
            }
            else
            {
                throw new ProcessorException(this, "Unexpected command: " + data.CmdName);
            }
        }
示例#2
0
        /// <summary>
        /// Reverts any changes that were made via the last call to <see cref="Process"/>
        /// </summary>
        /// <param name="data">The data that was previously supplied to the
        /// <see cref="Process"/> method.</param>
        void ICmdProcessor.Undo(CmdData data)
        {
            if (data.CmdName == AddCmdLine.CmdName)
            {
                string name = data.GetValue <string>(nameof(AddCmdLine.Name));

                // I would expect it to be the last item in our list
                int lastIndex = Names.Count - 1;
                if (lastIndex < 0 || Names[lastIndex] != name)
                {
                    throw new ApplicationException("Not the last name added: " + name);
                }

                Names.RemoveAt(lastIndex);
            }
            else if (data.CmdName == CutCmdLine.CmdName)
            {
                string name = data.GetValue <string>(nameof(AddCmdLine.Name));
                int    nCut = data.GetValue <int>(nameof(NameProcessor.CutCount));

                for (int i = 0; i < nCut; i++)
                {
                    Names.Add(name);
                }
            }
            else
            {
                throw new ProcessorException(this, "Unexpected command: " + data.CmdName);
            }
        }
示例#3
0
        internal static string GetCommandLine(CmdData data)
        {
            Debug.Assert(data.CmdName == nameof(NameCmdLine));
            string name = data.GetValue <string>(nameof(Name));

            return($"name {name}");
        }