Exemplo n.º 1
0
        public ConsoleSwitchOption(
            string textSwitchedOff, Func <ConsoleMenu, ConsoleSwitchOption, bool> switchOn
            , string textSwitchedOn, Func <ConsoleMenu, ConsoleSwitchOption, bool> switchOff
            , ConsoleMenu childMenu = null
            , Func <ConsoleMenu, ConsoleSwitchOption, bool> switched = null
            , Func <ConsoleMenu, ConsoleOption, bool> enabled        = null
            , Func <ConsoleMenu, ConsoleOption, string> display      = null
            , string shortcut = null
            )
            : base(textSwitchedOff, null, childMenu, enabled, display, null, shortcut)
        {
            Action = (m, o) =>
            {
                ConsoleSwitchOption to = o as ConsoleSwitchOption;

                if (IsSwitchedOn)
                {
                    IsSwitchedOn = !switchOff(m, to);
                }
                else
                {
                    IsSwitchedOn = switchOn(m, to);
                }

                if (switched != null)
                {
                    if (switched(m, to))
                    {
                    }
                }

                Text = IsSwitchedOn? textSwitchedOn : textSwitchedOff;
            };
        }
Exemplo n.º 2
0
 public ConsoleOption(string text
                      , ConsoleMenu childMenu
                      , Func <ConsoleMenu, ConsoleOption, bool> enabled   = null
                      , Func <ConsoleMenu, ConsoleOption, string> display = null
                      , Func <ConsoleMenu, ConsoleOption, bool> selected  = null
                      , string shortcut = null
                      )
     : this(text, null, childMenu, enabled, display, selected, shortcut)
 {
 }
Exemplo n.º 3
0
        /// <summary>
        /// This method can be called by an external process to update the info messages displayed in the menu.
        /// </summary>
        /// <param name="message">The info message</param>
        /// <param name="refresh">The refresh option flag.</param>
        /// <param name="type">The log type.</param>
        public static ConsoleMenu AddOption(this ConsoleMenu menu, string text
                                            , Action <ConsoleMenu, ConsoleOption> action
                                            , ConsoleMenu childMenu = null
                                            , Func <ConsoleMenu, ConsoleOption, bool> enabled   = null
                                            , Func <ConsoleMenu, ConsoleOption, string> display = null
                                            , Func <ConsoleMenu, ConsoleOption, bool> selected  = null
                                            , string shortcut = null)
        {
            menu.Context.Options.Add(new Xigadee.ConsoleOption(text, action, childMenu, enabled, display, selected, shortcut));

            return(menu);
        }
        /// <summary>
        /// This method adds an override setting and clears the cache.
        /// </summary>
        /// <typeparam name="P">The pipeline type.</typeparam>
        /// <param name="pipeline">The pipeline.</param>
        /// <param name="title">The alternate title.</param>
        /// <returns>Returns the pipeline.</returns>
        public static P StartWithConsole <P>(this P pipeline, string title = null)
            where P : IPipeline
        {
            var ms = pipeline.ToMicroservice();

            var mainMenu = new ConsoleMenu(title ?? "Xigadee Microservice Test Console");

            mainMenu.AddMicroservicePipeline(pipeline);

            mainMenu.Show();

            return(pipeline);
        }
Exemplo n.º 5
0
        /// <summary>
        /// This method can be called by an external process to update the info messages displayed in the menu.
        /// </summary>
        /// <param name="menu">The menu.</param>
        /// <param name="message">The info message</param>
        /// <param name="refresh">The refresh option flag.</param>
        /// <param name="type">The log type.</param>
        public static ConsoleMenu AddInfoMessage(this ConsoleMenu menu, string message, bool refresh = false, LoggingLevel type = LoggingLevel.Info)
        {
            menu.ContextInfo.Add(new ErrorInfo()
            {
                Type = type, Message = message
            });

            if (refresh)
            {
                menu.Refresh();
            }

            return(menu);
        }
        /// <summary>
        /// This method can be called by an external process to update the info messages displayed in the menu.
        /// </summary>
        /// <param name="menu">The menu.</param>
        /// <param name="message">The info message</param>
        /// <param name="refresh">The refresh option flag.</param>
        /// <param name="type">The log type.</param>
        public static ConsoleMenu AddInfoMessage(this ConsoleMenu menu, string message, bool refresh = false, EventLogEntryType type = EventLogEntryType.Information)
        {
            menu.ContextInfo.Add(new ErrorInfo()
            {
                Type = type, Message = message
            });

            if (refresh)
            {
                menu.Refresh();
            }

            return(menu);
        }
Exemplo n.º 7
0
        /// <summary>
        /// This method can be called by an external process to update the info messages displayed in the menu.
        /// </summary>
        /// <param name="menu">The info message</param>
        /// <param name="pipeline">The refresh option flag.</param>
        /// <param name="useParentContextInfo">The log type.</param>
        public static ConsoleMenu AddMicroservicePipeline(this ConsoleMenu menu, IPipeline pipeline
                                                          , bool useParentContextInfo = true)
        {
            var ms = pipeline.ToMicroservice();

            string title = $"Microservice: {ms.Id.Name}";

            var msMenu = new ConsoleMenu(title)
            {
                ContextInfoInherit = useParentContextInfo
            };

            menu.OnClose += (m, e) =>
            {
                if (ms.Status == ServiceStatus.Running)
                {
                    pipeline.Stop();
                }
            };

            msMenu.AddOption("Start", (m, o) =>
            {
                try
                {
                    pipeline.Start();
                }
                catch (Exception ex)
                {
                    msMenu.AddInfoMessage($"{ms.Id.Name} start error: {ex.Message}", true, LoggingLevel.Error);
                }
            }
                             , enabled: (m, o) => ms.Status != ServiceStatus.Running
                             , shortcut: ms.Id.Name
                             );

            msMenu.AddOption("Stop", (m, o) => pipeline.Stop(), enabled: (m, o) => ms.Status == ServiceStatus.Running);

            //Add an option to the main menu.
            var mainMenu = menu.AddOption(new ConsoleOption(title, msMenu));

            ms.StatusChanged += (s, e) =>
            {
                mainMenu.AddInfoMessage($"{ms.Id.Name} service status changed: {e.StatusNew}", true);
            };

            return(menu);
        }
Exemplo n.º 8
0
 public ConsoleOption(string text
                      , Action <ConsoleMenu, ConsoleOption> action
                      , ConsoleMenu childMenu = null
                      , Func <ConsoleMenu, ConsoleOption, bool> enabled   = null
                      , Func <ConsoleMenu, ConsoleOption, string> display = null
                      , Func <ConsoleMenu, ConsoleOption, bool> selected  = null
                      , string shortcut = null
                      )
 {
     Action     = action;
     Menu       = childMenu;
     Text       = text;
     FnDisplay  = display;
     FnEnabled  = enabled ?? ((m, o) => true);
     FnSelected = selected;
     Shortcut   = shortcut;
 }
Exemplo n.º 9
0
        /// <summary>
        /// This method adds an override setting and clears the cache.
        /// </summary>
        /// <typeparam name="P">The pipeline type.</typeparam>
        /// <param name="pipeline">The pipeline.</param>
        /// <param name="title">The alternate title.</param>
        /// <param name="args">This is the command arguments. I will be used to parse out the shortcut parameter.</param>
        /// <param name="configureMenu">An optional action that can be used to configure additional menu items.</param>
        /// <returns>Returns the pipeline.</returns>
        public static P StartWithConsole <P>(this P pipeline, string title = null, string[] args = null, Action <ConsoleMenu> configureMenu = null)
            where P : IPipeline
        {
            var items = args?.CommandArgsParse();

            var ms = pipeline.ToMicroservice();

            var mainMenu = new ConsoleMenu(title ?? ms.Id.Description ?? "Xigadee Microservice Test Console");

            mainMenu.AddMicroservicePipeline(pipeline);

            configureMenu?.Invoke(mainMenu);

            var shortcut = (items?.ContainsKey("shortcut") ?? false)?items["shortcut"]:null;

            mainMenu.Show(shortcut: shortcut);

            return(pipeline);
        }
Exemplo n.º 10
0
        /// <summary>
        /// This method can be called by an external process to update the info messages displayed in the menu.
        /// </summary>
        /// <param name="message">The info message</param>
        /// <param name="refresh">The refresh option flag.</param>
        /// <param name="type">The log type.</param>
        public static ConsoleMenu AddOption(this ConsoleMenu menu, ConsoleOption option)
        {
            menu.Context.Options.Add(option);

            return(menu);
        }