Inheritance: IService
コード例 #1
0
 private void MergeServices(Service service)
 {
     Service rightService = services.Where(s => s.Protocol == service.Protocol && s.HostName == service.HostName).SingleOrDefault();
     if (rightService != null)
     {
         switch (service.State)
         {
             case State.Removed:
                 services.Remove(rightService);
                 if (ServiceRemoved != null)
                     ServiceRemoved(rightService);
                 break;
             case State.Added:
                 rightService.Renew(service.Ttl);
                 break;
         }
     }
     else
     {
         if (service.State == State.Added)
         {
             services.Add(service);
             if (ServiceFound != null)
                 ServiceFound(service);
         }
     }
 }
コード例 #2
0
ファイル: Service.cs プロジェクト: RoyDoron/bonjour.net
 internal static Service BuildService(HttpRequest item)
 {
     Service s = new Service();
     if (item.Headers.ContainsKey("NT"))
         s.Protocol = item.Headers["NT"];
     s.properties = item.Headers;
     s.properties.Remove("NT");
     s.Addresses.Add(new Network.Dns.EndPoint() { });
     s.Addresses[0].Addresses.Add(IPAddress.Parse(new Uri(s["LOCATION"]).Host));
     if (item.Headers.ContainsKey("NTS"))
     {
         switch (item.Headers["NTS"])
         {
             case "ssdp:alive":
                 s.State = State.Added;
                 break;
             case "ssdp:byebye":
                 s.State = State.Removed;
                 break;
         }
     }
     if (item.Headers.ContainsKey("CACHE-CONTROL"))
     {
         string cacheControl = item.Headers["CACHE-CONTROL"];
         string ttl = cacheControl.Substring(cacheControl.IndexOf("max-age=") + 8, 4);
         s.expiration = DateTime.Now.AddSeconds(int.Parse(ttl));
     }
     return s;
 }
コード例 #3
0
ファイル: Service.cs プロジェクト: RoyDoron/bonjour.net
 internal static Service BuildService(HttpResponse item)
 {
     Service s = new Service();
     if (item.Headers.ContainsKey("ST"))
         s.Protocol = item.Headers["ST"];
     if (item.Headers.ContainsKey("NT"))
         s.Protocol = item.Headers["NT"];
     s.properties = item.Headers;
     if (item.Headers.ContainsKey("LOCATION"))
     {
         s.Location = new Uri(item.Headers["LOCATION"]);
         s.properties.Remove("LOCATION");
     }
     s.properties.Remove("ST");
     s.Addresses.Add(new Network.Dns.EndPoint() { });
     if (s.Location != null)
         s.Addresses[0].Addresses.Add(IPAddress.Parse(s.Location.Host));
     if (item.Headers.ContainsKey("CACHE-CONTROL"))
     {
         string cacheControl = item.Headers["CACHE-CONTROL"];
         int startOfMaxAge = cacheControl.IndexOf("max-age=", StringComparison.InvariantCultureIgnoreCase);
         int endOfMaxAge = cacheControl.IndexOf(";", startOfMaxAge);
         if (endOfMaxAge == -1)
             endOfMaxAge = cacheControl.Length;
         string ttl = cacheControl.Substring(startOfMaxAge + 8, endOfMaxAge - (startOfMaxAge + 8));
         s.expiration = DateTime.Now.AddSeconds(int.Parse(ttl));
     }
     return s;
 }