Exemple #1
0
        public void LiveConfig_FileChanged_ChangedEventRaised()
        {
            bool success = false;
            var  config  = new LiveConfig <ConfigObject>(_file);

            config.Changed += () => success = true;

            config.Watch();

            File.WriteAllText(_file, @"{ ""Test"": ""Test"" }");

            Assert.IsTrue(success);
        }
Exemple #2
0
        public async Task LiveConfig_FileChanged_ConfigUpdated()
        {
            var tcs    = new TaskCompletionSource <bool>();
            var config = new LiveConfig <ConfigObject>(_file);

            config.Changed += () => tcs.SetResult(true);
            config.Watch();

            File.WriteAllText(_file, @"{ ""Test"": ""Test"" }");

            if (await Task.WhenAny(tcs.Task, Task.Delay(2000)) == tcs.Task)
            {
                Assert.IsTrue(config.Configuration.Test == "Test");
            }
            else
            {
                throw new Exception();
            }
        }
Exemple #3
0
        public BuildVM(IBuildRepository buildRepo, Logger.Logger logger)
        {
            if (buildRepo == null)
            {
                throw new ArgumentNullException(nameof(buildRepo));
            }
            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }

            _buildRepo = buildRepo;
            _logger    = logger;
            Items      = new ObservableCollection <BuildResult>();

            try
            {
                _liveConfig              = new LiveConfig <List <BuildConfig> >("config.json");
                _liveConfig.Changed     += initializeItems;
                _liveConfig.Unavailable += () =>
                {
                    Items.Clear();
                    _currentIndex = 0;
                };
                _liveConfig.Watch();

                var timer = new Timer();
                timer.Interval = 1000;
                timer.Elapsed += change;
                timer.Start();

                var dateTimer = new Timer();
                dateTimer.Interval = 1000;
                dateTimer.Elapsed += (s, e) => CurrentTime = DateTime.Now;
                dateTimer.Start();
            }
            catch (Exception ex)
            {
                _logger.Log(LogLevel.Info, ex);
            }
        }
Exemple #4
0
        public AggregatedConfig()
        {
            RunEnvironment    = RunEnv.ExternalEnv;
            UserCenterAddress = string.Empty;
            RtServerAddress   = string.Empty;
            ServerVersionInfo = string.Empty;

            DeviceNo  = string.Empty;
            DeviceKey = string.Empty;

            AccountAutoLogin = new LoginConfig();

            MainCamera = new VideoConfig()
            {
                Type = "主摄像头",
            };

            SecondaryCamera = new VideoConfig()
            {
                Type = "辅摄像头"
            };
            AudioConfig     = new AudioConfig();
            LocalLiveConfig = new LiveConfig()
            {
                Description = "本地推流",
                IsEnabled   = true
            };
            RemoteLiveConfig = new LiveConfig()
            {
                Description = "服务器推流",
                IsEnabled   = true
            };
            RecordConfig = new RecordConfig()
            {
                Description = "录制"
            };
        }
Exemple #5
0
 public void LiveConfig_FileDoesntExist_Throws()
 {
     var config = new LiveConfig <ConfigObject>("test");
 }
        /// <summary>
        /// Defines a Qualification Tournament.
        /// </summary>
        /// <param name="wfscore">The Worldfootball definition.</param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        private static List <BaseScore> DefineQualification(WorldFootballScore wfscore, ScoreParameter[] parameters)
        {
            int index = 0;
            List <BaseScore> scores = new List <BaseScore>();
            GenericScore     sc     = null;

            string fullname = wfscore.FullLeagueName;

            if (String.IsNullOrEmpty(wfscore.Season) == false)
            {
                fullname += "-" + wfscore.Season;
            }

            // add results scores
            sc = CreateNewScore(wfscore.Id, "results", "Results", IMG_RESULTS, "2", index++);
            string competition = ScoreCenter.GetParameter(parameters, "WF.Competition", KEY_COMPETITION);

            sc.Url   = String.Format("{0}{2}/{1}/", WF_URL, wfscore.FullLeagueName, competition);
            sc.Sizes = ScoreCenter.GetParameter(parameters, "WF.Results", SIZES_RESULTS);
            sc.AddRule(3, Operation.IsNull, "", RuleAction.MergeCells, "Header");
            sc.LiveConfig = LiveConfig.Copy(wfscore.LiveConfig, ScoreCenter.GetParameter(parameters, "WF.LiveFormat", "{2} {5} {4}"));
            sc.SetCanLive(true);
            sc.Element = "0";
            scores.Add(sc);

            // retrieve details: first element is the list of groups
            List <string> items = wfscore.Details.Split(',').ToList();

            char[] groups = items[0].ToCharArray();
            foreach (char g in groups)
            {
                // add group results
                sc       = CreateNewScore(wfscore.Id, "gr" + g, String.Format("Group {0}", Char.ToUpper(g)), "", "0", index++);
                sc.Url   = String.Format("{0}spielplan/{1}-gruppe-{2}/0/", WF_URL, fullname, g);
                sc.Sizes = ScoreCenter.GetParameter(parameters, "WF.GroupResults", SIZES_GROUP_RESULTS);
                sc.Image = String.Format(@"Groups\Group{0}", Char.ToUpper(g));
                sc.AddRule(3, Operation.IsNull, "", RuleAction.MergeCells, "Header");
                sc.AddHighlightRule(wfscore.Highlights, 0, RuleAction.FormatCell);
                scores.Add(sc);

                // add group standings
                sc         = CreateNewScore(wfscore.Id, "resgr" + g, "Standings", "", "1", index++);
                sc.Url     = String.Format("{0}spielplan/{1}-gruppe-{2}/0/", WF_URL, fullname, g);
                sc.Skip    = 1;
                sc.Headers = ScoreCenter.GetParameter(parameters, "WF.HeaderStandings", HEADERS_STANDINGS);
                sc.Sizes   = ScoreCenter.GetParameter(parameters, "WF.GroupStandings", SIZES_GROUP_STANDINGS);
                sc.Image   = String.Format(@"Groups\Table{0}", Char.ToUpper(g));
                sc.AddHighlightRule(wfscore.Highlights, 3, RuleAction.FormatLine);
                scores.Add(sc);
            }

            // add rounds
            foreach (string round in items)
            {
                if (round == items[0])
                {
                    continue;
                }
                if (round == "stadium" || round == "referee")
                {
                    continue;
                }
                sc       = CreateNewScore(wfscore.Id, round, round, IMG_RESULTS, "0", index++);
                sc.Url   = String.Format("{0}spielplan/{1}-{2}/0/", WF_URL, fullname, round);
                sc.Sizes = wfscore.TwoLegs && round != "finale"
                    ? ScoreCenter.GetParameter(parameters, "WF.QualificationLevel2", SIZES_QUALIFICATION_LEVEL2)
                    : ScoreCenter.GetParameter(parameters, "WF.QualificationLevel1", SIZES_QUALIFICATION_LEVEL1);
                sc.AddRule(3, Operation.IsNull, "", RuleAction.MergeCells, "Header");
                sc.AddRule(0, Operation.Contains, "{Rückspiel},", RuleAction.ReplaceText, "");
                scores.Add(sc);
            }

            // add details
            ScoreDetails details = GetScoreDetails(wfscore, parameters);

            details.AddTopScorerScore(scores, fullname, index++);
            details.AddAssistsScore(scores, fullname, index++);
            details.AddStadiumScore(scores, fullname, index++);
            details.AddRefereeScore(scores, fullname, index++);
            details.AddHistoryScore(scores, index++);
            details.AddTopScorerHistScore(scores, index++);

            return(scores);
        }
        public void RegisterAttributes(Plugin plugin)
        {
            Type type = plugin.GetType();

            const BindingFlags allMembers = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;

            foreach (FieldInfo field in type.GetFields(allMembers))
            {
                ConfigOption configOption = field.GetCustomAttribute <ConfigOption>();
                if (configOption != null)
                {
                    string prefix = plugin.Details.configPrefix;
                    if (prefix == null)
                    {
                        PluginManager.Manager.Logger.Error("CONFIG_MANAGER", $"{plugin} is trying to register attribute config {field.Name}, but does not have {nameof(PluginDetails.configPrefix)} in its {nameof(PluginDetails)} set.");
                        return;
                    }

                    string key = configOption.Key ?? PluginManager.ToUpperSnakeCase(field.Name);

                    if (string.IsNullOrWhiteSpace(key))
                    {
                        PluginManager.Manager.Logger.Error("CONFIG_MANAGER", $"{plugin} is trying to register attribute config {field.Name}, but it has no valid key. Is the variable all underscores with no config key overload?");
                        continue;
                    }

                    if (field.FieldType.IsGenericType && field.FieldType.GetGenericTypeDefinition() == typeof(LiveConfig <>))
                    {
                        string     realKey    = prefix + "_" + key;
                        LiveConfig liveConfig = (LiveConfig)field.GetValue(plugin);
                        if (!RegisterConfig(plugin, new ConfigSetting(realKey, liveConfig.DefaultValue, configOption.Randomized, configOption.PrimaryUser, configOption.Description)))
                        {
                            // Failed register so it should not be set.
                            field.SetValue(plugin, null);
                            continue;
                        }

                        liveConfig.ManagerInit(realKey, plugin);

                        continue;
                    }

                    if (!typeGetters.ContainsKey(field.FieldType))
                    {
                        PluginManager.Manager.Logger.Error("CONFIG_MANAGER", $"{plugin} is trying to register attribute config {field.Name}, but the type ({field.FieldType}) is not a config-allowed type.");
                        continue;
                    }

                    if (!RegisterConfig(plugin, new ConfigSetting(prefix + "_" + key, field.GetValue(plugin), configOption.Randomized, configOption.PrimaryUser, configOption.Description)))
                    {
                        // Failed register so it should not be registered to refresh every round restart.
                        PluginManager.Manager.Logger.Debug("CONFIG_MANAGER", $"Unable to register attribute config {field.Name} from {plugin}.");
                        continue;
                    }

                    if (!configFields.ContainsKey(plugin))
                    {
                        configFields.Add(plugin, new Dictionary <string, FieldInfo>());
                    }

                    configFields[plugin].Add(key, field);
                }
            }
        }