// Virtual event handlers should be called in addition if overriden. // Send an update packet protected virtual void OverlaySettings_VariableUpdated(OverlayVariableBaseModel ov) { if (Connection != null && EncryptedStream != null) { Dictionary <string, object> updateParams = new Dictionary <string, object>(); updateParams["variableName"] = ov.Name; updateParams["variableValue"] = ov.StringValue; try { UpdateVariableCommand.Instance.SendCommand(EncryptedStream, updateParams); } catch (ObjectDisposedException) { } catch (InvalidOperationException) { } } }
private void OverlayVariable_VariableUpdated(OverlayVariableBaseModel sender) { // Call update variables on each overlay Application.Current.Dispatcher.Invoke(new Action(delegate() { foreach (OverlayWindow o in overlayList) { ((OverlayWindowModel)o.DataContext).UpdateVariables(variableDictionary); } }) ); if (VariableUpdated != null) { VariableUpdated(sender); } }
private void FromXML(FileInfo file) { XmlDocument xDoc = new XmlDocument(); xDoc.Load(file.FullName); XmlNode osNode = xDoc.SelectSingleNode("/OverlaySettings"); if (osNode == null) { throw new OverlayLoadingException(OverlayLoadingException.Reason.InvalidXMLFormat); } // Process groups variableGroups.Clear(); XmlNodeList glNode = osNode.SelectNodes("Groups/Group"); if (glNode != null) { foreach (XmlNode gNode in glNode) { string groupName = gNode.Attributes.GetNamedItem("name").Value; string groupLabel = gNode.Attributes.GetNamedItem("label").Value; variableGroups.Add(groupName, new OverlayVariableGroup() { GroupName = groupName, GroupLabel = groupLabel }); } } variableGroups.Add("", new OverlayVariableGroup() { GroupName = "", GroupLabel = "" }); // Process variables variableDictionary.Clear(); XmlNode vlNode = osNode.SelectSingleNode("Variables"); if (vlNode != null) { try { variableDictionary = OverlayVariableBaseModel.ProcessVariables(vlNode, diskLocation.Directory); } catch (VariableParseException ex) { MessageBox.Show(ex.Message); throw new OverlayLoadingException(OverlayLoadingException.Reason.VariableProcessing); } } // Add VariableUpdated handler to each variable's Updated event foreach (OverlayVariableBaseModel ov in variableDictionary.Values) { ov.VariableUpdated += new VariableUpdatedHandler(OverlayVariable_VariableUpdated); } // Let everyone know the overlay controls have changed RaisePropertyChanged("OverlayControls"); // Process overlays XmlNodeList oNodes = osNode.SelectNodes("Overlays/Overlay"); if (oNodes != null) { foreach (XmlNode oNode in oNodes) { OverlayWindow o = new OverlayWindow(); try { ((OverlayWindowModel)o.DataContext).FromXML(oNode); } catch (OverlayCreationException ex) { MessageBox.Show(ex.Message); throw new OverlayLoadingException(OverlayLoadingException.Reason.OverlayCreation); } ((OverlayWindowModel)o.DataContext).UpdateVariables(variableDictionary); overlayList.Add(o); } } }