/// <summary> /// Retruns a proxy object to the monitor and control service. /// </summary> /// <returns>Proxy Object to Monitor & Control service.</returns> private MonitorAndControlClient getMCProxy() { MonitorAndControlClient mcProxy = null; IMonitorAndControlCallback serverCallback = new ServcieManagerCallback(); mcProxy = new MonitorAndControlClient(new InstanceContext(serverCallback)); // Connect to the discovered service endpoint mcProxy.Endpoint.Address = monitorControlServiceHostAddress; return(mcProxy); }
private MonitorAndControlClient CreateMCClient(EndpointAddress endPointAddress, string clientIpOrName) { MonitorAndControlClient mcIfc = null; IMonitorAndControlCallback serverCallback = this; mcIfc = new MonitorAndControlClient(new InstanceContext(serverCallback)); // Connect to the defined service endpoint mcIfc.Endpoint.Address = endPointAddress; (mcIfc as MonitorAndControlClient).SetClientBaseAddress(clientIpOrName); _log.Trace(m => m("Invoking discovered M&C service at {0}", endPointAddress)); return(mcIfc); }
private void InitializeMonitorAndControlProxy() { try { IMonitorAndControlCallback serverCallback = this; _monitorAndControlProxy = new MonitorAndControlClient(new InstanceContext(serverCallback)); _monitorAndControlProxy.SetClientBaseAddress(); _monitorAndControlProxy.Connect(); } catch (Exception) { _monitorAndControlProxy.Abort(); } }
/// <summary> /// Change the volume of a specified zone. /// </summary> /// <param name="zoneId">Zone id</param> /// <param name="adjVolume">Delta Volume</param> /// <returns>Zone state, after the command has been performed.</returns> private ZoneState AdjustVolume(Address zoneId, int adjVolume) { MonitorAndControlClient mcProxy = getMCProxy(); mcProxy.Connect(); ZoneState zoneState = mcProxy.GetZoneState(zoneId); zoneState.Volume = zoneState.Volume + adjVolume; mcProxy.SetZoneState(zoneId, zoneState); zoneState = mcProxy.GetZoneState(zoneId); mcProxy.Disconnect(); return(zoneState); }
/// <summary> /// Changes the source of a specified zone. /// </summary> /// <param name="zoneId">Zone id, to specify zone</param> /// <param name="sourceId">Source id, tp specify source</param> /// <returns>Zone state, after the command has been performed.</returns> public ZoneState SwitchSource(Address zoneId, Address sourceId) { MonitorAndControlClient mcProxy = getMCProxy(); mcProxy.Connect(); ZoneState zoneState = mcProxy.GetZoneState(zoneId); zoneState.Source = sourceId; mcProxy.SetZoneState(zoneId, zoneState); zoneState = mcProxy.GetZoneState(zoneId); mcProxy.Disconnect(); return(zoneState); }
/// <summary> /// Switches a zone, specified by its zone id, either on or off (depending on its current state). /// </summary> /// <param name="zoneId">Zone Id</param> /// <returns>Zone state, after the switch command has been performed.</returns> public ZoneState SwitchZone(Address zoneId) { MonitorAndControlClient mcProxy = getMCProxy(); mcProxy.Connect(); ZoneState zoneState = mcProxy.GetZoneState(zoneId); zoneState.PowerStatus = !zoneState.PowerStatus; mcProxy.SetZoneState(zoneId, zoneState); zoneState = mcProxy.GetZoneState(zoneId); mcProxy.Disconnect(); return(zoneState); }
/// <summary> /// Create client for configuration service. Either use discovered service or configuration read from /// configuration file. /// </summary> /// <returns>Client to configure service.</returns> private MonitorAndControlClient CreateMCClient(string clientIpOrName) { MonitorAndControlClient mcIfc = null; IMonitorAndControlCallback serverCallback = this; if (ServiceProxy.ServiceDiscovery.isServiceDiscovered(serviceName)) { mcIfc = new MonitorAndControlClient(new InstanceContext(serverCallback)); // Connect to the discovered service endpoint EndpointAddress addr = ServiceProxy.ServiceDiscovery.EndpointAddress(serviceName, ServiceProxy.ServiceDiscovery.SelectedServer); mcIfc.Endpoint.Address = addr; (mcIfc as MonitorAndControlClient).SetClientBaseAddress(clientIpOrName); _log.Trace(m => m("Invoking discovered M&C service at {0}", addr)); } else { mcIfc = new MonitorAndControlClient(new InstanceContext(serverCallback), "WSDualHttpBinding_IMonitorAndControl", ServiceProxy.buildEndpointAddress("WSDualHttpBinding_IMonitorAndControl")); (mcIfc as MonitorAndControlClient).SetClientBaseAddress(clientIpOrName); _log.Trace(m => m("Invoking configured M&C service at {0}", ServiceProxy.buildEndpointAddress("WSDualHttpBinding_IMonitorAndControl"))); } return(mcIfc); }
/// <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); }