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);*/ }
private void PublishEvent(string ascii, double duration) { ChannelFactory <IPubSubEventAPI> factory = new ChannelFactory <IPubSubEventAPI>("IPubSubEventAPI"); try { IPubSubEventAPI client = factory.CreateChannel(); client.PublishEvent("DTMF", new Uri(ConfigurationManager.AppSettings["service_address"]), new EventData[] { new EventData { Data_ID = "TIME", Data_Val = DateTime.Now }, new EventData { Data_ID = "ASCII", Data_Val = ascii }, new EventData { Data_ID = "Duration", Data_Val = duration } }); } catch (Exception e) { Console.WriteLine("**No se pudo establecer el canal de comunicacion con el subsistema Pub-Sub de eventos**, Detalle: " + e.Message); Console.WriteLine("**Detalle de la excepcion:{0}**" + e.Message); } }
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 PublishEvent(String event_name, Uri sender_address, EventData[] data) { Console.WriteLine("***Event Published, event_identifier:{0}***", event_name); Console.WriteLine("***Publisher Service address{0}***", sender_address.ToString()); List <ReciverEndpointInfo> uris; lock (this._registrations) { uris = _registrations.SingleOrDefault(o => o.Key == event_name).Value; } Console.WriteLine("***Detected {0} subscribciones***", uris == null?0:uris.Count); if (foreward) { Action <String, Uri, EventData[]> forewardFunc = (s, u, d) => { ChannelFactory <IPubSubEventAPI> factory = new ChannelFactory <IPubSubEventAPI>("IPubSub_Foreward"); try { IPubSubEventAPI client = factory.CreateChannel(); client.PublishEvent(event_name, sender_address, data); Console.WriteLine("**Event Forewarded**"); } catch (Exception e) { Console.WriteLine("**No se pudo establecer el canal de comunicacion con el Servicio PubSub de nivel superior**"); Console.WriteLine("**Detalle de la excepcion:{0}**" + e.Message); } }; forewardFunc.BeginInvoke(event_name, sender_address, data, null, null); } if (uris != null) { foreach (ReciverEndpointInfo r in uris) { Action <String, Uri, EventData[]> notify = (s, u, d) => { ChannelFactory <IEventReciver> factory = new ChannelFactory <IEventReciver>("IEventReciver", new EndpointAddress(r.Address)); try { IEventReciver client = factory.CreateChannel(); client.ReciveEvent(s, u, d); } catch (Exception e) { Console.WriteLine("**No se pudo establecer el canal de comunicacion con el Cliente Subscrito{0}**, Detalle:{1}", r.Address, " " + e.Message); Console.WriteLine("**Detalle de la excepcion:{0}**" + e.Message); } }; notify.BeginInvoke(event_name, sender_address, data, null, r); } } else { Console.WriteLine("***No existen subscripciones para el evento***"); } }
private static void SubscribeForEvent() { ChannelFactory <IPubSubEventAPI> factory = new ChannelFactory <IPubSubEventAPI>("IPubSubEventAPI"); IPubSubEventAPI client = factory.CreateChannel(); client.SubscribeForEvent("PSC", new ReciverEndpointInfo { Address = new Uri(ConfigurationManager.AppSettings["service_address"].ToString()), Binding = "" }); factory.Close(); }
private void PublishEvent(Object result) { ChannelFactory <IPubSubEventAPI> factory = new ChannelFactory <IPubSubEventAPI>("WSHttpBinding_IPubSubEventAPI"); IPubSubEventAPI client = factory.CreateChannel(); EventData[] data = { new EventData { Data_ID = "result", Data_Val = result } }; client.PublishEvent("CalcOperationComplete", new Uri(ConfigurationManager.AppSettings["service_address"]), data); factory.Close(); }
public static void Main() { ls = new List <SensorGroupCtrl>(); SomeClass A = new SomeClass(5); EventReciverService instance = new EventReciverService(); instance.EventRecibed = A.SomeMethod; ServiceHost r_host = new ServiceHost(instance); r_host.Open(); BuildDevicesControls(); ChannelFactory <IPubSubEventAPI> factory = new ChannelFactory <IPubSubEventAPI>("IPubSubEventAPI"); IPubSubEventAPI client = factory.CreateChannel(); InitSensors(); client.SubscribeForEvent("NSTAT", new ReciverEndpointInfo { Address = new Uri(ConfigurationManager.AppSettings["service_address"]), Binding = "KAKA" }); client.SubscribeForEvent("DTMF", new ReciverEndpointInfo { Address = new Uri(ConfigurationManager.AppSettings["service_address"]), Binding = "KAKA" }); client.SubscribeForEvent("PSC", new ReciverEndpointInfo { Address = new Uri(ConfigurationManager.AppSettings["service_address"]), Binding = "KAKA" }); factory.Close(); // Create a DiscoveryEndpoint that points to the DiscoveryProxy //Uri probeEndpointAddress = new Uri("net.tcp://localhost:8001/Probe"); //DiscoveryEndpoint discoveryEndpoint = new DiscoveryEndpoint(new NetTcpBinding(), new EndpointAddress(probeEndpointAddress)); //UdpDiscoveryEndpoint discoveryEndpoint = new UdpDiscoveryEndpoint(); // DiscoveryClient discoveryClient = new DiscoveryClient(discoveryEndpoint); // Console.WriteLine("Finding IParallelPortService endpoints"); // Console.WriteLine(); try { // Find ICalculatorService endpoints //FindResponse findResponse = discoveryClient.Find(new FindCriteria(typeof(IPortServerContract))); //Console.WriteLine("Found {0} IParallelPortService endpoint(s).", findResponse.Endpoints.Count); //Console.WriteLine(); // Check to see if endpoints were found, if so then invoke the service. } catch (TargetInvocationException) { Console.WriteLine("This client was unable to connect to and query the proxy. Ensure that the proxy is up and running."); } Console.WriteLine("Press <ENTER> to exit."); Console.ReadLine(); }
void detector_EndRecording(object sender, EventArgs e) { if (wcfInstance.IsDetecting()) { ChannelFactory <IPubSubEventAPI> factory = new ChannelFactory <IPubSubEventAPI>("IPubSubEventAPI"); try { IPubSubEventAPI client = factory.CreateChannel(); client.PublishEvent("ENDOR", new Uri(ConfigurationManager.AppSettings["service_address"]), new EventData[] { new EventData { Data_ID = "Alarm", Data_Val = detecting } }); } catch (Exception excp) { Console.WriteLine("**No se pudo establecer el canal de comunicacion con el subsistema Pub-Sub de eventos**, Detalle: " + excp.Message); Console.WriteLine("**Detalle de la excepcion:{0}**" + excp.Message); } } }
private void SelfNotification(object o) { if (detecting) { ChannelFactory <IPubSubEventAPI> factory = new ChannelFactory <IPubSubEventAPI>("IPubSubEventAPI"); try { IPubSubEventAPI client = factory.CreateChannel(); client.PublishEvent("NSTAT", new Uri(ConfigurationManager.AppSettings["service_address"]), new EventData[] { new EventData { Data_ID = "DETECT", Data_Val = true } }); } catch (Exception e) { Console.WriteLine("**No se pudo establecer el canal de comunicacion con el subsistema Pub-Sub de eventos**, Evento NSTAT***"); Console.WriteLine("**Detalle de la excepcion:{0}**" + e.Message); } } }
private void PublishEvent(object inf) { if (detecting) { lock (_publish_sync) { ParallelPortInfo info = inf as ParallelPortInfo; ChannelFactory <IPubSubEventAPI> factory = new ChannelFactory <IPubSubEventAPI>("IPubSubEventAPI"); try { IPubSubEventAPI client = factory.CreateChannel(); client.PublishEvent("PSC", new Uri(ConfigurationManager.AppSettings["service_address"]), new EventData[] { new EventData { Data_ID = "TIME", Data_Val = DateTime.Now }, new EventData { Data_ID = "P378", Data_Val = info.getPortState(ParallelPortInfo.P378) }, new EventData { Data_ID = "P379", Data_Val = info.getPortState(ParallelPortInfo.P379) }, new EventData { Data_ID = "P37A", Data_Val = info.getPortState(ParallelPortInfo.P37A) } }); Console.WriteLine("***Event Publihed***" + "Event Type:" + "PSC"); Console.WriteLine("TIME:{0}", DateTime.Now); Console.WriteLine("port:{0}_value:{1}", "378", info.getPortState(ParallelPortInfo.P378)); Console.WriteLine("port:{0}_value:{1}", "379", info.getPortState(ParallelPortInfo.P379)); Console.WriteLine("port:{0}_value:{1}", "37A", info.getPortState(ParallelPortInfo.P37A)); } catch (Exception e) { Console.WriteLine("**No se pudo establecer el canal de comunicacion con el subsistema Pub-Sub de eventos***, Evento PSC***"); Console.WriteLine("**Detalle de la excepcion:{0}**" + e.Message); } } } }