Ejemplo n.º 1
0
 public void EqualsTest()
 {
     string name = "name";
     string hostname = "hostname";
     ushort port = 8080;
     string type = "type";
     Dictionary<string, string> TXTRecord = new Dictionary<string, string>() { { "key", "value" } };
     SDService service = new SDService(name, hostname, port, type, TXTRecord);
     SDService other = new SDService(name, hostname, port, type, TXTRecord);
     Assert.IsTrue(service.Equals(other));
     Assert.IsTrue(service.GetHashCode() == other.GetHashCode());
 }
Ejemplo n.º 2
0
 protected virtual void OnServiceLost(SDService service)
 {
     if (ServiceLost != null)
     {
         ServiceLost(service);
     }
 }
Ejemplo n.º 3
0
 protected virtual void OnServiceFound(SDService service, bool ownService)
 {
     if (ServiceFound != null)
     {
         ServiceFound(service, ownService);
     }
 }
Ejemplo n.º 4
0
 protected void NetServiceDidResolveAddress(NetService sender)
 {
     logger.TraceEvent(TraceEventType.Information, 0, String.Format("{0}: didResolveAddress", sender));
     SDService service = new SDService(sender.Name, sender.HostName, (ushort) sender.Port, sender.Type, null);
     bool ownService = false;
     foreach (NetService netService in this.netServices.Values)
     {
         if (netService.Name.Equals(sender.Name))
         {
             ownService = true;
             break;
         }
     }
     OnServiceFound(service, ownService);
 }
Ejemplo n.º 5
0
 protected void NetServiceBrowserDidRemoveService(NetServiceBrowser aNetServiceBrowser, NetService netService, bool moreComing)
 {
     logger.TraceEvent(TraceEventType.Verbose, 0, String.Format("{0}: didRemoveService: {1}", aNetServiceBrowser, netService));
     SDService service = new SDService(netService.Name, netService.HostName, (ushort)netService.Port, netService.Type, null);
     OnServiceLost(service);
 }
Ejemplo n.º 6
0
 public void ToStringTest()
 {
     string name = "name";
     string hostname = "hostname";
     ushort port = 8080;
     string type = "type";
     Dictionary<string, string> TXTRecord = new Dictionary<string, string>() { { "key", "value" } };
     SDService service = new SDService(name, hostname, port, type, TXTRecord);
     Assert.IsNotNull(service.ToString());
 }
Ejemplo n.º 7
0
 public void SDServiceConstructorTest()
 {
     string name = "name";
     string hostname = "hostname";
     ushort port = 8080;
     string type = "type";
     Dictionary<string, string> TXTRecord = new Dictionary<string, string>() { {"key", "value"} };
     SDService service = new SDService(name, hostname, port, type, TXTRecord);
     Assert.AreEqual(name, service.Name);
     Assert.AreEqual(hostname, service.Hostname);
     Assert.AreEqual(port, service.Port);
     Assert.AreEqual(type, service.Type);
     Assert.AreEqual(TXTRecord, service.TXTRecord);
 }
Ejemplo n.º 8
0
 public void EqualsWithNullTest()
 {
     string name = "name";
     string hostname = "hostname";
     ushort port = 8080;
     string type = "type";
     Dictionary<string, string> TXTRecord = new Dictionary<string, string>() { { "key", "value" } };
     SDService service = new SDService(name, hostname, port, type, TXTRecord);
     Assert.IsFalse(service.Equals(null));
 }
Ejemplo n.º 9
0
 private void OnServiceLost(SDService service)
 {
     IADevice device = new IADevice(service.Name, service.Hostname, service.Port, null);
     this.devices.Remove(device);
     OnDeviceLost(device);
 }
Ejemplo n.º 10
0
 private void OnServiceFound(SDService service, bool ownService)
 {
     if (ownService)
     {
         IADevice device = new IADevice(service.Name, service.Hostname, service.Port, this.SupportedRoutes);
         this.OwnDevice = device;
         OnDeviceFound(device, true);
     }
     else
     {
         IADevice device = new IADevice(service.Name, service.Hostname, service.Port, null);
         IARequest request = new IARequest(IARoute.Get("/routes"));
         SendRequest(request, device, delegate(IAResponse response, Exception error)
         {
             if (error == null)
             {
                 if (response.StatusCode == 200)
                 {
                     List<IARoute> supportedRoutes = response.BodyAs<IARoute>();
                     IADevice deviceWithRoutes = new IADevice(service.Name, service.Hostname, service.Port, new HashSet<IARoute>(supportedRoutes));
                     this.devices.Add(deviceWithRoutes);
                     OnDeviceFound(deviceWithRoutes, false);
                 }
                 else
                 {
                     Console.WriteLine(String.Format("An error ocurred trying to request routes from {0}", device));
                 }
             }
             else
             {
                 Console.WriteLine(String.Format("An error ocurred: {0}", error));
             }
         });
     }
 }