示例#1
0
        public GroupService(Config config, LightService lightService)
        {
            if (config is null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            if (lightService is null)
            {
                throw new ArgumentNullException(nameof(lightService));
            }

            this.lightService = lightService;
            this.nameToGroup  = new Dictionary <string, Group>();
            this.groupValues  = new Dictionary <Group, int>();
            this.groupToLamps = new Dictionary <Group, IEnumerable <string> >();

            foreach (var group in config.Groups)
            {
                nameToGroup[group.Name] = group;
                groupValues[group]      = group.Percentage;
                foreach (var lamp in group.Lamps)
                {
                    if (lightService.IsNameExisting(lamp))
                    {
                        lightService.UpdateFactor(lamp, group.Percentage / 100d, 1);
                    }
                }
            }

            foreach (var group in config.Groups)
            {
                groupToLamps[group] = GetLampsInGroupHelper(group.Name, new List <string>()).Distinct();
            }
        }
示例#2
0
        public void SetPercentage(Group group, int percentage)
        {
            if (group is null)
            {
                throw new ArgumentNullException(nameof(group));
            }

            if (!group.Locked)
            {
                foreach (var item in groupToLamps[group])
                {
                    lightService.UpdateFactor(item, percentage / 100d, groupValues[group] / 100d);
                }
                groupValues[group] = percentage;
                group.Percentage   = percentage;
            }
        }