protected void listSources_SelectedIndexChanged(object sender, EventArgs e) { _log.Trace(m => m("[{0}] Drop-down list of sources selected (listSources_SelectedIndexChanged). Selected Source = {1}", _zoneId.ToString(), listSources.Text)); ZoneState zoneState = _serviceManager.SwitchSource(_zoneId, _serviceManager.GetSource(listSources.Text).Id); setZoneState(zoneState); _log.Trace(m => m("[{0}] New Zone State = {1}", _zoneId.ToString(), zoneState.ToString())); }
private void setZoneState(ZoneState zoneState) { _log.Trace(m => m("[{0}] Update zone state. New Zone State = {1}", _zoneId.ToString(), zoneState.ToString())); btnPower.Text = (zoneState.PowerStatus ? "Off" : "On"); lblVolume.Text = zoneState.Volume.ToString(); labelSource.Text = _serviceManager.GetSource(zoneState.Source).Name; // Set Tooltip with full zone state information. labelZoneName.ToolTip = zoneState.ToString(); }
/// <summary> /// Get zone status; connects to the end point address and reads the zone status. /// </summary> /// <param name="endPointAddress">Server end point address.</param> /// <param name="adr">Zone Address to get the status.</param> private static void GetZoneState(EndpointAddress endPointAddress, Address adr) { Console.WriteLine(">>> Setup M&C server ..."); ILog _log = LogManager.GetCurrentClassLogger(); IMonitorAndControl pipeProxy = null; IMonitorAndControlNotification serverCallback = new ServerCallback(); try { //var binding = new WSDualHttpBinding(WSDualHttpSecurityMode.None); var binding = new WSDualHttpBinding("WSDualHttpBinding_IMonitorAndControl"); int port = FindPort(); //binding.ClientBaseAddress = new Uri("http://" + machineIpOrName + ":" + port + "/"); //binding.ClientBaseAddress = new Uri("http://" + "192.168.1.115" + ":" + port + "/"); binding.ClientBaseAddress = new Uri("http://" + NetworkHelper.getHostName() + ":" + port + "/"); /*note the "DuplexChannelFactory". This is necessary for Callbacks. * A regular "ChannelFactory" won't work with callbacks.*/ DuplexChannelFactory <IMonitorAndControl> pipeFactory = new DuplexChannelFactory <IMonitorAndControl>( new InstanceContext(serverCallback), binding /*new NetTcpBinding()*/, endPointAddress /*new EndpointAddress("net.tcp://localhost:8000/ISubscribe")*/); try { Console.WriteLine(">>> creating channel to {0} with callback address {1}", endPointAddress.Uri.ToString(), binding.ClientBaseAddress.ToString()); //Open the channel to the server pipeProxy = pipeFactory.CreateChannel(); pipeProxy.Connect(); // Get zone status ZoneState state = pipeProxy.GetZoneState(adr); Console.WriteLine(">>> zone state: {0}", state.ToString()); } catch (Exception e) { Console.WriteLine("GetZoneState - Exception: {0}", e.Message); _log.Fatal(m => m("GetZoneState - Exception: {0}", e.Message)); } } catch (FaultException <ArgumentException> exc) { Console.WriteLine("GetZoneState - FaultException: {0}", exc); _log.Fatal(m => m("GetZoneState - FaultException: {0}", exc)); } catch (Exception exc) { Console.WriteLine("GetZoneState - Exception: {0}", exc); _log.Fatal(m => m("GetZoneState - Exception: {0}", exc)); } }
/// <summary> /// Private method to notify the subscribers about changes in the zone state. /// </summary> /// <param name="zoneId">Zone Id, of the changed zone. One-Based enumeration.</param> /// <param name="oldZoneState">Old Zone State.</param> /// <param name="newZoneState">New Zone State.</param> private void notifyZoneStateSubscribers(ENuvoEssentiaZones zoneId, ZoneState oldZoneState, ZoneState newZoneState) { _log.Trace(m => m("Zone State with zoneId='{0}' has changed, notify the subscribers. oldState='{1}' newState='{2}'.", zoneId.ToString(), oldZoneState.ToString(), newZoneState.ToString())); if (onZoneUpdated != null) { if (oldZoneState != newZoneState) { onZoneUpdated(this, new ZoneStateEventArgs(zoneId, oldZoneState, newZoneState)); } } }
/// <summary> /// Returns string represantitive of this object. /// </summary> /// <returns>String, representing this object.</returns> public override string ToString() { return(String.Format("[ZoneState={0}]", _zoneState.ToString())); }
/// <summary> /// Notifies all subscribed clients for zone state changes. /// </summary> /// <param name="zoneId">The associated zone id.</param> /// <param name="zoneState">The zone state.</param> private void NotifySubscribers(Address zoneId, ZoneState zoneState) { _log.Trace(m => m(String.Format("M&C: TryNotifySubscribers, Address={0}, Command={1}", zoneId.ToString(), zoneState.ToString()))); if (_zoneSubscriptions.Contains(zoneId) && _subscriber != null) { _log.Trace(m => m(String.Format("M&C: NotifySubscribers, Address={0}, Command={1}", zoneId.ToString(), zoneState.ToString()))); _subscriber.OnZoneStateChanged(zoneId, zoneState); } }
/// <summary> /// <see cref="IMonitorAndControl"/> /// </summary> /// <param name="zoneId"></param> /// <returns></returns> public ZoneState GetZoneState(Address zoneId) { ZoneState currentZoneState = _zoneServer.GetZoneState(zoneId); _log.Trace(m => m(String.Format("M&C: GetZoneState: Address={0}, State={1}", zoneId.ToString(), currentZoneState.ToString()))); return(currentZoneState); }
/// <summary> /// <see cref=">IMonitorAndControl"/> /// </summary> /// <param name="zoneId"></param> /// <param name="stateCommand"></param> public void SetZoneState(Address zoneId, ZoneState stateCommand) { _log.Trace(m => m(String.Format("M&C: SetZoneState: Address={0}, Command={1}", zoneId.ToString(), stateCommand.ToString()))); _zoneServer.SetZoneState(zoneId, stateCommand); }
/// <summary> /// <see cref="IZoneController"/> /// </summary> public void NotifySubscribedClients() { if (_zoneNotification != null) { _log.Trace(m => m(String.Format("ZC.NotifySubscribers: Address={0}, Command={1}", _zoneId.ToString(), _zoneState.ToString()))); _zoneNotification(this, new ZoneStateEventArgs(_zoneState)); } }
/// <summary> /// <see cref="IZoneController"/> /// </summary> /// <param name="zoneState"></param> public void SetZoneState(ZoneState zoneState) { lock (this) { _log.Trace(m => m(String.Format("ZC.SetZoneState: Address={0}, Command={1}", _zoneId.ToString(), zoneState.ToString()))); _protocolDriver.SetZoneState(_zoneId, zoneState); _zoneState = new ZoneState(zoneState); _zoneState.CommandUnacknowledged = true; } NotifySubscribedClients(); }
/// <summary> /// Returns the current zone state for a zone, specified by Zone Id. /// </summary> /// <param name="zoneId">Zone Id</param> /// <returns>Zone State.</returns> public ZoneState GetZoneState(Address zoneId) { MonitorAndControlClient mcProxy = getMCProxy(); mcProxy.Connect(); ZoneState zoneState = mcProxy.GetZoneState(zoneId); _log.Trace(m => m("Read zone status for zone with id {0}. Zone State = [{1}]", zoneId.ToString(), zoneState.ToString())); mcProxy.Disconnect(); // Tweak: If a source is not configured, it needs to be added programmatically to the list, because it is still possible to select this source on the keypad. // If such an unconfigured source has been selected an error occurs, becuase the source is unkown! // ToDo: Implement this tweak on server side SourceGraphic source = GetSource(zoneState.Source); if (source.isEmpty()) { _sources.Add(new SourceGraphic(zoneState.Source, String.Format("[{0}]", zoneState.Source), "n/a", "n/a")); _log.Trace(m => m("SOURCE added with id {0}.", zoneState.Source)); } return(zoneState); }
public void OnZoneStateChanged(Address zoneId, ZoneState zoneState) { _log.Trace(m => m("Notification from server zone with id={0} has changed. New state is {1}", zoneId.ToString(), zoneState.ToString())); }
public void OnZoneStateChanged(Address zoneId, ZoneState zoneState) { Console.WriteLine("+++ Notification from server zone: zoneId={0} / zoneState={1}", zoneId.ToString(), zoneState.ToString()); }
protected void btnVolUp_Click(object sender, EventArgs e) { ZoneState zoneState = _serviceManager.VolumeUp(_zoneId); setZoneState(zoneState); _log.Trace(m => m("[{0}] Volume UP button clicked (btnVolUp_Click). New Zone State = {1}", _zoneId.ToString(), zoneState.ToString())); }
protected void btnPower_Click(object sender, EventArgs e) { ZoneState zoneState = _serviceManager.SwitchZone(_zoneId); setZoneState(zoneState); _log.Trace(m => m("[{0}] Power button clicked (btnPower_Click). New Zone State = {1}", _zoneId.ToString(), zoneState.ToString())); }