void IniciarRecepcion() { //INICIANDO SERVICIO DE RECEPCION if (!detecting) { reciverThread = new Thread(HostReciverService); reciverThread.Start(); this.LB_status.Text = "Detección habilitada!"; this.bt_reset.Text = "Detener"; netCheker = new System.Threading.Timer(NetChekingFunc, null, 0, netChekInterval); try { ChannelFactory <IPubSubEventAPI> factory = new ChannelFactory <IPubSubEventAPI>("IPubSubEventAPI"); IPubSubEventAPI client = factory.CreateChannel(); var r = new ReciverEndpointInfo { Address = new Uri(ConfigurationManager.AppSettings["service_address"]), Binding = "KAKA" }; client.SubscribeForEvent("DTMF", r); client.SubscribeForEvent("PSC", r); client.SubscribeForEvent("NSTAT", r); client.SubscribeForEvent("ENDOR", r); } catch (Exception exc) { MessageBox.Show("Ocurrieron errores durante la subscripción para la recepcion de eventos.\nVerifique que el servicio de publicación y recepción de eventos esté iniciado.\nAlgunos sensores pueden estar desabilitados.", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } TA_logArea.Text = ""; detecting = true; ReadSensorsStatus(); } else { try { speaker.SpeakAsyncCancelAll(); } catch (Exception exc) { } ls.ForEach(s => s.Reset()); timer.Enabled = false; host.Close(); reciver.EventRecibed = null; this.bt_reset.Text = "Comenzar"; this.LB_status.Text = "Detección desabilitada!"; messages.RemoveAll(p => true); TA_logArea.Text = ""; eventDetected = false; GB_filterPanel.Visible = false; countCalls = 0; detecting = false; } /* CountDownDialog conteo = new CountDownDialog(60); * conteo.ShowInTaskbar = false; * conteo.ShowDialog(this);*/ }
public void SubscribeForEvent(String event_name, ReciverEndpointInfo listener) { lock (_registrations) { string result = _registrations.SingleOrDefault(o => o.Key == event_name).Key; if (result != null) { bool u = _registrations[result].Exists(o => o.Address == listener.Address); if (!u) { Console.WriteLine("***Subscribtion Added for {0} ", event_name); _registrations[result].Add(listener); SerializeSubscripciones(); } } else { _registrations.Add(event_name, (new List <ReciverEndpointInfo> { listener })); Console.WriteLine("***Subscribtion Added for {0} ", event_name); SerializeSubscripciones(); } } }
static void OnStart(string[] args) { try { init = new Thread(o => { ChannelFactory <IPubSubEventAPI> factory = new ChannelFactory <IPubSubEventAPI>("IPubSubEventAPI"); IPubSubEventAPI client = factory.CreateChannel(); var r = new ReciverEndpointInfo { Address = new Uri(ConfigurationSettings.AppSettings["service_address"]), Binding = "KAKA" }; client.SubscribeForEvent("PSC", r); factory.Close(); reciver = new EventReciverService(); reciver.EventRecibed = OnRecive; ServiceHost h = new ServiceHost(reciver); h.Open(); }); init.Start(); } catch (Exception exc) { } }
public void UnSubscribe(string event_name, ReciverEndpointInfo listener) { lock (_registrations) { string result = _registrations.SingleOrDefault(o => o.Key == event_name).Key; if (result != null) { bool u = _registrations[result].Exists(o => o.Address == listener.Address); if (u) { ReciverEndpointInfo r = _registrations[result].Single(o => o.Address == listener.Address); _registrations[result].Remove(r); SerializeSubscripciones(); Console.WriteLine("***Subscribtion Removed for {0} ", event_name); } } } }