public void CommunicationsUnitTest() { using (SessionServer server = new SessionServer(new IPEndPoint(IPAddress.Any, IPEndPoint.MaxPort))) { server.CommuniqueReceived += new CommuniqueReceivedEventHandler(server_CommuniqueReceived); IPHostEntry hostEntry = Dns.GetHostEntry(Dns.GetHostName()); IPEndPoint clientEndPoint = new IPEndPoint(hostEntry.AddressList[0], IPEndPoint.MaxPort); using (SessionClient client = new SessionClient(clientEndPoint)) { Communique communique = new Communique("CommunicationsUnitTest"); client.SendCommunique(communique); } } }
public override void Configure(XmlElement element) { base.Configure(element); XmlElement localCacheElement = (XmlElement) element.SelectSingleNode("localCache"); string typeName; if (localCacheElement.HasAttribute("type")) { typeName = localCacheElement.GetAttribute("type"); } else { typeName = typeof(SimpleCache).FullName; } Type type = Type.GetType(typeName); getCachedItemMethod = type.GetMethod("GetCachedItem", BindingFlags.Instance | BindingFlags.NonPublic); purgeMethod = type.GetMethod("Purge", BindingFlags.Instance | BindingFlags.NonPublic); cache = (CacheBase) type.Assembly.CreateInstance(type.FullName); cache.Configure(localCacheElement); int port; if (element.HasAttribute("port")) { port = Int32.Parse(element.GetAttribute("port")); server = new SessionServer(IPAddress.Any, port); server.CommuniqueReceived += new CommuniqueReceivedEventHandler(CommuniqueReceived); } else { throw new ConfigurationErrorsException("The port attribute is required for a distributedCache element."); } clients = new List<SessionClient>(); foreach (XmlElement serverElement in element.SelectNodes("server")) { if (serverElement.HasAttribute("port")) { SessionClient client; port = Int32.Parse(serverElement.GetAttribute("port")); if (serverElement.HasAttribute("address")) { client = new SessionClient(IPAddress.Parse(serverElement.GetAttribute("address")), port); } else if (serverElement.HasAttribute("hostName")) { client = new SessionClient(serverElement.GetAttribute("hostName"), port); } else { throw new ConfigurationErrorsException("The address or hostName attribute is required for a distributedCache server element."); } clients.Add(client); } else { throw new ConfigurationErrorsException("The port attribute is required for a distributedCache server element."); } } }
/// <summary> /// Sends an update for the specified CachedItem to all configured servers. /// </summary> /// <param name="client">The SessionClient used to send the update.</param> /// <param name="item">The CachedItem to be sent to all configured servers.</param> private void SendCommunique(SessionClient client, CachedItem item) { Communique communique = new Communique(item); client.SendCommunique(communique); }