public void UpdateAsync() { SendFunction("", true, x => { try { var e = (DownloadStringCompletedEventArgs)x; if (e.Error != null) { OnStateSynced?.Invoke(this, new StateSyncedEventArgs() { Successfully = false }); return; } if (e.UserState == null) { return; } IsInitializing = true; _logger.Debug("Updating vMix state."); var _temp = Create(e.Result); if (_temp == null) { _logger.Debug("vMix is offline"); _logger.Debug("Firing \"updated\" event."); IsInitializing = false; OnStateSynced?.Invoke(this, new StateSyncedEventArgs() { Successfully = false }); } _logger.Debug("Calculating difference."); Diff(this, _temp); _logger.Debug("Updating inputs."); if (Inputs == null) { Inputs = new List <Input>(); } if (Overlays == null) { Overlays = new List <Overlay>(); } if (Audio == null) { Audio = new List <Master>(); } if (Transitions == null) { Transitions = new List <Transition>(); } Inputs.Clear(); foreach (var item in _temp.Inputs) { Inputs.Add(item); } Overlays.Clear(); foreach (var item in _temp.Overlays) { Overlays.Add(item); } Audio.Clear(); foreach (var item in _temp.Audio) { Audio.Add(item); } Transitions.Clear(); foreach (var item in _temp.Transitions) { Transitions.Add(item); } Mixes.Clear(); foreach (var item in _temp.Mixes) { Mixes.Add(item); } if (_currentStateText != _temp._currentStateText) { _currentStateText = _temp._currentStateText; } _logger.Debug("Firing \"updated\" event."); IsInitializing = false; OnStateSynced?.Invoke(this, new StateSyncedEventArgs() { Successfully = true, OldInputs = null, NewInputs = null }); return; } catch (Exception e) { IsInitializing = false; _logger.Error(e, "Exception at UpdateAsync"); } }); }
public bool Update() { try { IsInitializing = true; _logger.Debug("Updating vMix state."); var _temp = Create(); if (_temp == null) { _logger.Debug("vMix is offline"); _logger.Debug("Firing \"updated\" event."); OnStateSynced?.Invoke(this, new StateSyncedEventArgs() { Successfully = false }); IsInitializing = false; return(false); } _logger.Debug("Calculating difference."); Diff(this, _temp); _logger.Debug("Updating inputs."); Inputs.Clear(); foreach (var item in _temp.Inputs) { Inputs.Add(item); } Overlays.Clear(); foreach (var item in _temp.Overlays) { Overlays.Add(item); } Audio.Clear(); foreach (var item in _temp.Audio) { Audio.Add(item); } Transitions.Clear(); foreach (var item in _temp.Transitions) { Transitions.Add(item); } Mixes.Clear(); foreach (var item in _temp.Mixes) { Mixes.Add(item); } //UpdateChangedInputs(_currentStateText, _temp._currentStateText); if (_currentStateText != _temp._currentStateText) { _currentStateText = _temp._currentStateText; } _logger.Debug("Firing \"updated\" event."); OnStateSynced?.Invoke(this, new StateSyncedEventArgs() { Successfully = true, OldInputs = null, NewInputs = null }); IsInitializing = false; return(true); } catch (Exception e) { IsInitializing = false; _logger.Error(e, "Exception at Update"); return(false); } }