Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="menu"></param>
        /// <param name="entry"></param>
        /// <param name="option"></param>
        /// <param name="o"></param>
        /// <returns></returns>
        static bool ReloadSettings(MenuList menu, CMenu entry, char option, object o)
        {
            ReloadSettingsType type = (ReloadSettingsType)o;

            type.SettingsFile = Input("Settings file to load", type.SettingsFile, out bool isdef);
            if (string.IsNullOrEmpty(type.SettingsFile))
            {
                CLogger.Add("No settings modified", TLog.WARNG);
                return(true);
            }
            type.Listener.Stop();
            type.Listener = new CListener();
            return(type.Listener.Start(type.SettingsFile));
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            string logFile       = null;
            string settingsFile  = null;
            string autoPurge     = null;
            string numberOfFiles = null;

            // take a list of strings (refer to PathToData) and add it to a dictionary of paths + save the value to use
            Func <string, string, string, string> CheckOption = (string arg, string option, string data) =>
            {
                try
                {
                    if ((arg.StartsWith(option, true, null)) && option.Length < arg.Length && string.IsNullOrEmpty(data))
                    {
                        return(arg.Substring(option.Length));
                    }
                    return(data);
                }
                catch (Exception) { }
                return(null);
            };

            // get start options
            foreach (string s in args)
            {
                // has the settings file been specified
                //if ((s.StartsWith(OPTION_SETTINGS_FILE_NAME, true, null)) && OPTION_SETTINGS_FILE_NAME.Length < s.Length && string.IsNullOrEmpty(settingsFile))
                //settingsFile = s.Substring(OPTION_SETTINGS_FILE_NAME.Length);

                // has the log file been specified
                //if ((s.StartsWith(OPTION_LOG_FILE_NAME, true, null)) && OPTION_LOG_FILE_NAME.Length < s.Length && string.IsNullOrEmpty(logFile))
                //	logFile = s.Substring(OPTION_LOG_FILE_NAME.Length);

                settingsFile  = CheckOption(s, OPTION_SETTINGS_FILE_NAME, settingsFile);
                logFile       = CheckOption(s, OPTION_LOG_FILE_NAME, logFile);
                numberOfFiles = CheckOption(s, OPTION_LOG_NUMBER_OF_FILES, numberOfFiles);
                autoPurge     = CheckOption(s, OPTION_LOG_AUTO_PURGE, autoPurge);
            }

            if (string.IsNullOrEmpty(settingsFile))
            {
                settingsFile = LISTENER_SETTINGS_FILE;
            }
            if (string.IsNullOrEmpty(logFile))
            {
                logFile = LISTENER_LOG_FILE;
            }
            try
            {
                CLog.AutoPurgeLogFiles = bool.Parse(autoPurge);
            }
            catch
            {
                CLog.AutoPurgeLogFiles = true;
            }
            try
            {
                CLog.NumberOfFilesToKeep = int.Parse(numberOfFiles);
            }
            catch
            {
                CLog.NumberOfFilesToKeep = 3;
            }
            CLog.LogFileName = logFile;

            CLogger.Add($"Using settings file: {settingsFile}");

            MenuList menu = new MenuList();

            menu.Add(TEST_LISTENER, new CMenu()
            {
                Text = "Test listener", Fnc = TestListener
            });
            menu.Add(TEST_LISTENER_CREATE, new CMenu()
            {
                Text = "Generate listener test file", Fnc = TestListenerCreate
            });
            menu.Add(DISPLAY_SETTINGS, new CMenu()
            {
                Text = "Display settings", Fnc = DisplaySettings
            });
            menu.Add(RELOAD_SETTINGS, new CMenu()
            {
                Text = "Reload settings", Fnc = ReloadSettings
            });
            //menu.Add(i++.ToString()[0], new CMenu() { Text = ACTIVATE_DISPLAY, Fnc = ActivityDisplay });
            menu.Add('X', new CMenu()
            {
                Text = "Exit", Fnc = Exit
            });

            // Start listener
            CListener        listener         = new CListener();
            bool             ok               = listener.Start(settingsFile);
            TestListenerType testListenerType = new TestListenerType()
            {
                FileToUse = LISTENER_TEST_FILE, Port = listener.Port, IP = listener.IP
            };

            while (ok)
            {
                CMenu entry = DisplayMenu(menu, out char option);
                if (null != entry)
                {
                    switch (option)
                    {
                    case RELOAD_SETTINGS:
                    {
                        ReloadSettingsType type = new ReloadSettingsType()
                        {
                            SettingsFile = settingsFile, Listener = listener
                        };
                        if (ok = entry.Fnc(menu, entry, option, type))
                        {
                            settingsFile = type.SettingsFile;
                            listener     = type.Listener;
                        }
                        break;
                    }

                    case TEST_LISTENER:
                    {
                        ok = entry.Fnc(menu, entry, option, testListenerType);
                        break;
                    }

                    case DISPLAY_SETTINGS:
                    {
                        ok = entry.Fnc(menu, entry, option, listener);
                        break;
                    }

                    default:
                        ok = entry.Fnc(menu, entry, option, null);
                        break;
                    }
                }
            }
            listener.Stop();
        }
Exemplo n.º 3
0
        public async Task <IResponse <IReloadSettingsCommand> > ExecuteAsync(IProfile profile, CancellationToken token, ReloadSettingsType type)
        {
            if (profile.Enigma == EnigmaType.Enigma1)
            {
                if (type == ReloadSettingsType.All)
                {
                    await base.ExecuteAsync(profile, "cgi-bin/reloadSettings", _parser, token);

                    return(await base.ExecuteAsync(profile, "cgi-bin/reloadUserBouquets", _parser, token));
                }

                if (type == ReloadSettingsType.Services)
                {
                    return(await base.ExecuteAsync(profile, "cgi-bin/reloadSettings", _parser, token));
                }

                if (type == ReloadSettingsType.Bouquets)
                {
                    return(await base.ExecuteAsync(profile, "cgi-bin/reloadUserBouquets", _parser, token));
                }

                throw new NotSupportedException("ReloadSettingsType");
            }

            return(await base.ExecuteAsync(profile, "web/servicelistreload?mode=" + (int)type, _parser, token));
        }