internal void SendNewHostSignal()
 {
     try
     {
         var endPoint = new IPEndPoint(IPAddress.Broadcast, UdpPortNumber);
         var message = new Message { Type = MessageType.NewHost, StringContent = IpAddress };
         var bytes = SerializationHelper.ObjectToByteArray(message);
         UdpSocket.SendTo(bytes, endPoint);
         DoAzureHack();
     }
     catch (SocketException)
     {
     }
 }
 internal static void SendHostLeave()
 {
     var message = new Message { Type = MessageType.HostLeave, StringContent = IpAddress };
     var bytes = SerializationHelper.ObjectToByteArray(message);
     lock (ConnectionLock)
     {
         foreach (var client in Connections)
         {
             client.ClientSocket.Send(bytes);
             XmlRecordFile.Instance.RemoveCacheListFromRemote(client.Ip);
         }
     }
 }
 private static void DoAzureHack()
 {
     try
     {
         IPAddress ip = null;
         if (IpAddress == "10.0.0.4")
         {
             ip = IPAddress.Parse("10.0.0.5");
         }
         if (IpAddress == "10.0.0.5")
         {
             ip = IPAddress.Parse("10.0.0.4");
         }
         if (ip == null)
         {
             return;
         }
         var endPoint = new IPEndPoint(ip, UdpPortNumber);
         var message = new Message { Type = MessageType.NewHost, StringContent = IpAddress };
         var bytes = SerializationHelper.ObjectToByteArray(message);
         UdpSocket.SendTo(bytes, endPoint);
     }
     catch (SocketException)
     {
     }
 }
 private static void SendCacheList(string ipAddress)
 {
     if (ipAddress == IpAddress)
     {
         return;
     }
     var message = new Message { Type = MessageType.CacheList, ListStringContent = XmlRecordFile.Instance.GetLocalCachedItems() };
     var bytes = SerializationHelper.ObjectToByteArray(message);
     lock (Connections)
     {
         var client = Connections.First(ip => ip.Ip == ipAddress);
         client.ClientSocket.Send(bytes);
     }
 }
 private static void DealWithMessage(Message message)
 {
     switch (message.Type)
     {
         case MessageType.NewHost:
             TcpConnect(message.StringContent);
             SendCacheList(message.StringContent);
             break;
         case MessageType.HostLeave:
             RemoveHost(message.StringContent);
             XmlRecordFile.Instance.RemoveCacheListFromRemote(message.StringContent);
             break;
         case MessageType.CacheList:
             XmlRecordFile.Instance.AddToCacheListFromRemote(message.ListStringContent);
             break;
         default:
             throw new ArgumentOutOfRangeException();
     }
 }
 internal static void SendNewCacheUpdate(List<string> newElement)
 {
     var message = new Message { Type = MessageType.CacheList, ListStringContent = newElement };
     var bytes = SerializationHelper.ObjectToByteArray(message);
     lock (ConnectionLock)
     {
         foreach (var client in Connections)
         {
             client.ClientSocket.Send(bytes);
         }
     }
 }