private void CreateProxy(string proxyName) { try { logger.Debug("Attempting to create new proxy created for " + proxyName + "."); //InstanceContext callbackContext = new InstanceContext(this); SIPMonitorPublisherProxy proxy = new SIPMonitorPublisherProxy(proxyName); m_proxies.Add(proxyName, proxy); proxy.IsAlive(); logger.Debug("Successfully connected to proxy " + proxyName + "."); /*ThreadPool.QueueUserWorkItem(delegate * { * string name = proxyName; * * try * { * proxy.IsAlive(); * // ((ICommunicationObject)proxy).Faulted += ProxyChannelFaulted; * m_proxies.Add(name, proxy); * logger.Debug("Successfully connected to proxy " + name + "."); * } * catch (Exception excp) * { * logger.Warn("Could not connect to proxy " + name + ". " + excp.Message); * Timer retryProxy = new Timer(delegate { CreateProxy(name); }, null, RETRY_FAILED_PROXY, Timeout.Infinite); * } * });*/ } catch (Exception excp) { logger.Error("Exception CreateProxy (" + proxyName + "). " + excp.Message); } }
/// <summary> /// This method is an event handler for communication fualts on a proxy channel. When a fault occurs ALL /// the available proxies will be checked for a fault and those in a faulted state will be closed and replaced. /// </summary> /// <remarks>This occurs when the channel to the SIP monitoring server that is publishing the events /// is faulted. This can occur if the SIP monitoring server is shutdown which will close the socket.</remarks> private void ProxyChannelFaulted(object sender, EventArgs e) { for (int index = 0; index < m_proxies.Count; index++) { KeyValuePair <string, SIPMonitorPublisherProxy> proxyEntry = m_proxies.ElementAt(index); SIPMonitorPublisherProxy proxy = proxyEntry.Value; if (proxy.State == CommunicationState.Faulted) { logger.Debug("Removing faulted proxy for " + proxyEntry.Key + "."); m_proxies.Remove(proxyEntry.Key); CreateProxy(proxyEntry.Key); index--; logger.Warn("MonitorProxyManager received a fault on proxy channel, comms state=" + proxy.InnerChannel.State + "."); try { proxy.Abort(); } catch (Exception abortExcp) { logger.Error("Exception ProxyChannelFaulted Abort. " + abortExcp.Message); } } } }
private void InitialiseProxies() { List <string> proxyNames = GetClientEndPointNames(); foreach (string proxyName in proxyNames) { try { SIPMonitorPublisherProxy proxy = new SIPMonitorPublisherProxy(proxyName); proxy.InnerChannel.OperationTimeout = m_proxyOperationTimeout; m_proxies.Add(proxyName, proxy); m_proxyLastTimeout.Add(proxyName, null); m_proxyTimeoutCount.Add(proxyName, 0); logger.Debug("Proxy added for " + proxyName + " on " + proxy.Endpoint.Address.ToString() + "."); //CreateProxy(proxyName); } catch (Exception excp) { logger.Error("Exception InitialiseProxies. " + excp.Message); } } }