static public void DisconnectAllEventHandlers() { EventDispatcherList <T> handlers = EventDispatcher <T> .GetEventHandlers(); foreach (EventDispatcher <T> dispatcher in handlers) { dispatcher.DisconnectFromEventHandler(); } }
/// <summary> /// This method retrieves events based on the provided provisioning action type. /// </summary> protected EventDispatcherList GetEventsByActionCode(String actionCode) { using (var eventClient = new SelcommWSsvc.SelcommWSAll.EventClient(Singtel.Helpers.Helpers.GetSelcommWsEndpointName())) { var eventDispatcherList = new EventDispatcherList(); if (!string.IsNullOrWhiteSpace(actionCode)) { //load the event type/code from evnt_dispatcher table based on the service id eventDispatcherList = eventClient.EventDispatcherList(ClientSessionWS.SessionKey, actionCode, true); } return(eventDispatcherList); } }
} /* GetEventHandlers() */ static public void DisconnectEventHandler(String _oid) { if (String.IsNullOrWhiteSpace(_oid)) { return; } EventDispatcherList <T> handlers = EventDispatcher <T> .GetEventHandlers(); foreach (EventDispatcher <T> dispatcher in handlers.FindAll(x => x._OID == _oid)) { dispatcher.DisconnectFromEventHandler(); } }
} /* DisconnectFromEventHandler() */ static public EventDispatcherList <T> GetEventHandlers() { EventDispatcherList <T> retval = new EventDispatcherList <T>(); String uri = String.Format("http://{0}:{1}/default/eventhandlers?appid={2}", RestSettings.Instance.ServerIP, RestSettings.Instance.ServerPort, RestSettings.Instance.AppID); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri); request.Method = "GET"; request.ProtocolVersion = HttpVersion.Version11; try { LoggingSingleton.Instance.Message(LogType.Library, LogLevel.Debug2, "EventDispatcher::GetEventHandlers : Sent GET {0}", uri); /// This waits for a response from the far end... /// using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) { using (StreamReader stream = new StreamReader(response.GetResponseStream())) { /// Read the result from the far end... /// String result = stream.ReadToEnd(); LoggingSingleton.Instance.Message(LogType.Library, LogLevel.Debug2, "EventDispatcher::GetEventHandlers : Received {0:D} {1}", response.StatusCode, response.StatusDescription); LoggingSingleton.Instance.Message(LogType.Library, LogLevel.Debug3, "EventDispatcher::GetEventHandlers : {0}", result); RESTapi.web_service evresponse = RestHelpers.XMLToRESTapi(result, typeof(RESTapi.web_service)) as RESTapi.web_service; if (evresponse != null) { /// We know that the actual object type is "eventhandlers_response" /// in this case so we go ahead and cast it... /// RESTapi.eventhandlers_response evhandlers = evresponse.Item as RESTapi.eventhandlers_response; if (evhandlers != null) { LoggingSingleton.Instance.Message(LogType.Library, LogLevel.Info, "EventDispatcher::GetEventHandlers : Found {0} existing event handlers", evhandlers.size); if (evhandlers.eventhandler_response != null) { foreach (RESTapi.eventhandler_response ev in evhandlers.eventhandler_response) { LoggingSingleton.Instance.Message(LogType.Library, LogLevel.Debug3, "EventDispatcher::GetEventHandlers : Event handler :\n" + " => identifier = {0}\n" + " => href = {1}\n" + " => appid = {2}\n", ev.identifier, ev.href, ev.appid); retval.Add(new EventDispatcher <T>() { _OID = ev.identifier, _EventHandlerURI = ev.href.Contains("http://") ? String.Format("{0}?appid={1}", ev.href, ev.appid) : String.Format("http://{0}:{1}{2}?appid={3}", RestSettings.Instance.ServerIP, RestSettings.Instance.ServerPort, ev.href, ev.appid), _ConnectionState = ConnectionStateEnum.Connected, }); } } } } } } } catch (WebException ex) { if (ex.Status == WebExceptionStatus.ProtocolError) { HttpWebResponse response = ex.Response as HttpWebResponse; if (response != null) { LoggingSingleton.Instance.Message(LogType.Library, LogLevel.Warning, "EventDispatcher::GetEventHandlers : Received HTTP failure response {0} {1}", (int)response.StatusCode, response.StatusDescription); } } else { LoggingSingleton.Instance.Message(LogType.Library, LogLevel.Warning, "EventDispatcher::GetEventHandlers : {0}\n{1}", ex.Message.ToString(), ex.StackTrace.ToString()); } return(retval); } catch (Exception ex) { LoggingSingleton.Instance.Message(LogType.Library, LogLevel.Warning, "EventDispatcher::GetEventHandlers : {0}\n{1}", ex.Message.ToString(), ex.StackTrace.ToString()); return(retval); } return(retval); } /* GetEventHandlers() */