コード例 #1
0
        private void ChangeDetected(object sender, ChangeDetectedEventArgs e)
        {
            try
            {
                var module = mc.GetModule(e.ModuleName);
                if (module == null)
                {
                    module = UpsertModule(e.ModuleIp);
                }

                if (!module.IsLocal && !module.Module.Ip.Equals(e.ModuleIp))
                {
                    module.UpdateIp(e.ModuleIp);
                }
                switch (e.Type)
                {
                case ChangeType.ModuleAddress:
                    mc.UpdateIp(e.ModuleName, e.ModuleIp);
                    break;

                case ChangeType.ModuleSettings:
                    module.UpdatePresetsFromRemoteAsync();
                    break;

                case ChangeType.PresetUpserted:
                    var preset = module.DownloadPreset(e.PresetName);
                    lc.SavePreset(preset);
                    break;

                case ChangeType.PresetDeleted:
                    lc.DeletePreset(e.PresetName);
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
            catch (Exception exception)
            {
                logger.Warning(exception, "Change parser crashed");
                throw;
            }
        }
コード例 #2
0
ファイル: PresetController.cs プロジェクト: Zyklop/PiHome
 public ActionResult Save([FromBody] PresetViewModel collection)
 {
     try
     {
         ledController.SavePreset(collection.Name, collection.LedValues);
         return(RedirectToAction(nameof(Index)));
     }
     catch
     {
         return(RedirectToAction("Error", "Home"));
     }
 }