示例#1
0
        public ActionResult <string> AddLedEffect([FromHeader] string authorization, [FromBody] LedConfigurationDto newConfig)
        {
            var userId = _authenticationService.GetUserIdFromToken(authorization);
            var newId  = _ledService.AddEffect(userId, newConfig);

            return(Ok(newId.ToString()));
        }
示例#2
0
        public ActionResult UpdateLedEffect([FromHeader] string authorization, [FromBody] LedConfigurationDto newConfig)
        {
            var userId = _authenticationService.GetUserIdFromToken(authorization);

            _ledService.UpdateEffect(userId, newConfig);
            return(Ok());
        }
示例#3
0
        public Guid?AddEffect(string userId, LedConfigurationDto newConfig)
        {
            if (newConfig == null)
            {
                return(null);
            }
            var newId            = Guid.NewGuid();
            var existingOrdinals = _ledRepository.GetLedEffects(userId).Select(x => x.Ordinal);
            var newOrdinal       = existingOrdinals.Any() ? existingOrdinals.Max() + 1 : 1;

            _ledRepository.AddLedConfig(newId, userId, newConfig.LedEffect, newConfig.Name, newOrdinal);
            return(newId);
        }
示例#4
0
        public bool UpdateEffect(string userId, LedConfigurationDto newConfig)
        {
            if (newConfig == null)
            {
                return(false);
            }
            var id         = Guid.Parse(newConfig.Id);
            var oldEffects = _ledRepository.GetLedEffects(userId);

            if (!oldEffects.Any(x => x.Id.Equals(id)))
            {
                return(false);
            }
            _ledRepository.UpdateLedConfig(id, newConfig.LedEffect, newConfig.Name);
            return(true);
        }
示例#5
0
        public static LedEffect GetEffect(LedConfigurationDto dto, uint ledCount)
        {
            if (dto == null)
            {
                throw new ArgumentNullException(nameof(dto));
            }
            var props = dto.LedEffect.Properties;

            return(dto.LedEffect.EffectKind switch
            {
                LedEffectKind.Static => new StaticEffect(ledCount, dto.Name,
                                                         GetColorProperty(props, 1)
                                                         ),
                LedEffectKind.Pixel => new PixelEffect(ledCount, dto.Name,
                                                       GetColorProperty(props, 1),
                                                       GetColorProperty(props, 2),
                                                       GetIntProperty(props, 3),
                                                       GetIntProperty(props, 4),
                                                       GetBoolProperty(props, 5)
                                                       ),
                LedEffectKind.Stripe => new StripeEffect(ledCount, dto.Name,
                                                         GetColorProperty(props, 1),
                                                         GetColorProperty(props, 2),
                                                         GetIntProperty(props, 3),
                                                         GetBoolProperty(props, 4),
                                                         GetBoolProperty(props, 5)
                                                         ),
                LedEffectKind.Mix => new MixEffect(ledCount, dto.Name,
                                                   GetColorProperty(props, 1),
                                                   GetColorProperty(props, 2),
                                                   GetIntProperty(props, 3),
                                                   GetBoolProperty(props, 4)
                                                   ),
                LedEffectKind.Web => new WebEffect(ledCount, dto.Name,
                                                   GetStringProperty(props, 1),
                                                   GetUintProperty(props, 2)
                                                   ),
                LedEffectKind.Music => new MusicEffect(ledCount, dto.Name,
                                                       GetColorProperty(props, 1),
                                                       GetColorProperty(props, 2),
                                                       GetIntProperty(props, 3),
                                                       GetBoolProperty(props, 4),
                                                       GetBoolProperty(props, 5),
                                                       GetBoolProperty(props, 6)
                                                       ),
                _ => null,
            });
示例#6
0
        private static void StartEffectManagement(SocketService socket, uint ledCount, ArduinoSerial arduino)
        {
            mgr = new EffectManager(ledCount, arduino);
            socket.OnEffectSelected += ((sender, effectDto) =>
            {
                var effect = LedEffectBuilder.GetEffect(effectDto, mgr.LedCount);
                mgr.StartEffect(effect);

                var json = JsonSerializer.Serialize(effectDto);
                var cacheBase42 = StringUtils.Encode(json);
                var cacheEncrypted = StringUtils.Caesar(cacheBase42, 42);
                File.WriteAllText("./cache.led", cacheEncrypted, Encoding.UTF8);
            });

            if (File.Exists("./cache.led"))
            {
                var cacheEncrypted        = File.ReadAllText("./cache.led");
                var cacheLessEncrypted    = StringUtils.Caesar(cacheEncrypted, -42);
                var cacheJson             = StringUtils.Decode(cacheLessEncrypted);
                LedConfigurationDto cache = null;
                try
                {
                    cache = JsonSerializer.Deserialize <LedConfigurationDto>(cacheJson);
                }
                catch (JsonException)
                {
                    Console.Error.WriteLine("Invalid Cache File!");
                }
                if (cache != null)
                {
                    Console.WriteLine("Starting Cached Effect: " + cache.Name);
                    var effect = LedEffectBuilder.GetEffect(cache, mgr.LedCount);
                    mgr.StartEffect(effect);
                }
            }
        }
示例#7
0
 private void ReceivedEffectHandler(LedConfigurationDto effect)
 {
     OnEffectSelected?.Invoke(this, effect);
 }