Register() public method

public Register ( ) : void
return void
示例#1
1
        /// <summary>
        /// Start new broadcast service
        /// </summary>
        /// <param name="type">Type of discovery</param>
        /// <param name="nameToBroadcast">The name of the service that needs to be broadcasted</param>
        /// <param name="physicalLocation">The physical location of the service that needs to be broadcasted</param>
        /// <param name="addressToBroadcast">The address of the service that needs to be broadcasted</param>
        /// <param name="broadcastPort">The port of the broadcast service. Default=56789</param>
        public void Start(DiscoveryType type,string nameToBroadcast,string physicalLocation,string code,Uri addressToBroadcast,int broadcastPort=7892)
        {
            DiscoveryType = type;

            switch (DiscoveryType)
            {
                case DiscoveryType.WSDiscovery:
                    {
                        Ip = Net.GetIp(IPType.All);
                        Port = broadcastPort;
                        Address = "http://" + Ip + ":" + Port + "/";

                        _discoveryHost = new ServiceHost(new DiscoveyService());

                        var serviceEndpoint = _discoveryHost.AddServiceEndpoint(typeof(IDiscovery), new WebHttpBinding(), 
                                                                                Net.GetUrl(Ip, Port, ""));
                        serviceEndpoint.Behaviors.Add(new WebHttpBehavior());

                        var broadcaster = new EndpointDiscoveryBehavior();

                        broadcaster.Extensions.Add(nameToBroadcast.ToXElement<string>());
                        broadcaster.Extensions.Add(physicalLocation.ToXElement<string>());
                        broadcaster.Extensions.Add(addressToBroadcast.ToString().ToXElement<string>());
                        broadcaster.Extensions.Add(code.ToXElement<string>());

                        serviceEndpoint.Behaviors.Add(broadcaster);
                        _discoveryHost.Description.Behaviors.Add(new ServiceDiscoveryBehavior());
                        _discoveryHost.Description.Endpoints.Add(new UdpDiscoveryEndpoint());
                        _discoveryHost.Open();

                        IsRunning = true;
                    }
                    break;
                case DiscoveryType.Zeroconf:
                    {
                        var service = new RegisterService
                                          {Name = nameToBroadcast, RegType = "_am._tcp", ReplyDomain = "local.", Port = 3689};

                        // TxtRecords are optional
                        var txtRecord = new TxtRecord(){
                                                {"name", nameToBroadcast},
                                                {"addr", addressToBroadcast.ToString()},
                                                {"loc", physicalLocation},
                                                {"code", code}
                                            };
                        service.TxtRecord = txtRecord;

                        service.Register();
                    }
                    break;
            }
        }
示例#2
0
        public static void Start(short port)
        {
            service = new RegisterService
            {
                Name = Bonjour.ServiceName,
                RegType = Bonjour.ServiceType,
                // NOTE: port may have been dynamically determined by the broker
                Port = port,
                UPort = (ushort)port,
                ReplyDomain = Bonjour.ReplyDomain,
                //TxtRecord = new TxtRecord
                //{
                //    {
                //        Bonjour.IpRecord,
                //        Dns.GetHostEntry(Dns.GetHostName()).AddressList.First(ip => ip.AddressFamily == AddressFamily.InterNetwork)
                //        .ToString()
                //    },
                //    {
                //        Bonjour.PortRecord,
                //        port.ToString()
                //    }
                //}
            };

            service.Response += OnRegisterServiceResponse;
            service.Register();
        }
示例#3
0
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        /// <remarks>
        /// TODO: Need to provide a way to configure this for a given
        /// machine (so the end user can name it, etc.). Eventually it
        /// might be useful for cleaning up zombied xsp2/apache2 processes,
        /// etc.
        /// </remarks>
        static void Main()
        {
			Configuration.Initialize();

			RegisterService service = new RegisterService();
			service.Name = Configuration.ServiceName;
			service.RegType = "_http._tcp";
			service.Port = 12321;
			service.TxtRecord = new TxtRecord();
			service.TxtRecord.Add(new TxtRecordItem("servicetype", "cloverleaf"));
			service.TxtRecord.Add(new TxtRecordItem("systemtype", Environment.MachineName + ", " +
					Environment.OSVersion.ToString()));

			service.Register();

			while (true) System.Threading.Thread.Sleep(5000);
        }
示例#4
0
 public async void Start()
 {
     if (mServer != null) throw new InvalidOperationException();
     lock (knownHosts) knownHosts.Clear();
     mServer = new HttpSelfHostServer(Configure());
     var serverTask = mServer.OpenAsync();
     RegisterService rs = new RegisterService();
     rs.RegType = "_tincer._tcp";
     rs.ReplyDomain = "local.";
     rs.Name = Environment.MachineName;
     rs.Port = (short)(ushort)Arguments.Global.ListenPort;
     rs.TxtRecord = new TxtRecord();
     rs.TxtRecord.Add("NODEID", ApiHost.Id.ToByteArray());
     rs.Register();
     rs.Response += rs_Response;
     serviceRegister = rs;
     sb.ServiceAdded += sb_ServiceAdded;
     sb.ServiceRemoved += sb_ServiceRemoved;
     sb.Browse("_tincer._tcp", "local.");
     await serverTask;
     timer.Change(30000, 30000);
 }
示例#5
0
        protected virtual void RegisterService()
        {
            lock (eglock) {
                if (zc_service != null) {
                    UnregisterService ();
                }

                string auth = serverInfo.AuthenticationMethod == AuthenticationMethod.None ? "false" : "true";

                zc_service = new RegisterService ();
                zc_service.Name = serverInfo.Name;
                zc_service.RegType = ZeroconfType;
                zc_service.Port = (short)ws.BoundPort;
                zc_service.TxtRecord = new TxtRecord ();
                zc_service.TxtRecord.Add ("Password", auth);
                zc_service.TxtRecord.Add ("Machine Name", serverInfo.Name);

                AddTxtRecords (zc_service.TxtRecord);

                if (machineId != null) {
                    zc_service.TxtRecord.Add ("Machine ID", machineId);
                }

                zc_service.TxtRecord.Add ("txtvers", "1");
                zc_service.Response += OnRegisterServiceResponse;
                zc_service.Register ();
            }
        }
        private void RegisterService()
        {
            lock (eglock) {
                if (zc_service != null) {
                    UnregisterService ();
                }

                string auth = serverInfo.AuthenticationMethod == AuthenticationMethod.None ? "false" : "true";

                zc_service = new RegisterService ();
                zc_service.Name = serverInfo.Name;
                zc_service.RegType = "_dpap._tcp";
                zc_service.Port = 8770; // (short)ws.BoundPort;
                zc_service.TxtRecord = new TxtRecord ();
                zc_service.TxtRecord.Add ("Password", auth);
                zc_service.TxtRecord.Add ("Machine Name", serverInfo.Name);

                if (machineId != null) {
                    zc_service.TxtRecord.Add ("Machine ID", machineId);
                }

                zc_service.TxtRecord.Add ("txtvers", "1");
                zc_service.TxtRecord.Add ("Version", "65537");
                zc_service.ReplyDomain = "local.";
                zc_service.Response += OnRegisterServiceResponse;
                zc_service.Register ();
            }
        }
示例#7
0
    private static void RegisterService(string serviceDescription)
    {
        Match match = Regex.Match(serviceDescription, @"(_[a-z]+._tcp|udp)\s*(\d+)\s*(.*)");
        if(match.Groups.Count < 4) {
            throw new ApplicationException("Invalid service description syntax");
        }

        string type = match.Groups[1].Value.Trim();
        short port = Convert.ToInt16(match.Groups[2].Value);
        string name = match.Groups[3].Value.Trim();
        
        int txt_pos = name.IndexOf("TXT");
        string txt_data = null;
        
        if(txt_pos > 0) {
            txt_data = name.Substring(txt_pos).Trim();
            name = name.Substring(0, txt_pos).Trim();
            
            if(txt_data == String.Empty) {
                txt_data = null;
            }
        }
                
        RegisterService service = new RegisterService();
        service.Name = name;
        service.RegType = type;
        service.ReplyDomain = "local.";
        service.Port = port;

        TxtRecord record = null;
        
        if(txt_data != null) {
            Match tmatch = Regex.Match(txt_data, @"TXT\s*\[(.*)\]");

            if(tmatch.Groups.Count != 2) {
                throw new ApplicationException("Invalid TXT record definition syntax");
            }
            
            txt_data = tmatch.Groups[1].Value;
        
            foreach(string part in Regex.Split(txt_data, @"'\s*,")) {
                string expr = part.Trim();
                if(!expr.EndsWith("'")) {
                    expr += "'";
                }
                
                Match pmatch = Regex.Match(expr, @"(\w+\s*\w*)\s*=\s*['](.*)[']\s*");
                string key = pmatch.Groups[1].Value.Trim();
                string val = pmatch.Groups[2].Value.Trim();
                
                if(key == null || key == String.Empty || val == null || val == String.Empty) {
                    throw new ApplicationException("Invalid key = 'value' syntax for TXT record item");
                }
                
                if(record == null) {
                    record = new TxtRecord();
                }
                
                record.Add(key, val);
            }
        }
        
        if(record != null) {
            service.TxtRecord = record;
        }
        
        Console.WriteLine("*** Registering name = '{0}', type = '{1}', domain = '{2}'", 
            service.Name,
            service.RegType,
            service.ReplyDomain);
            
        service.Response += OnRegisterServiceResponse;
        service.Register();
    }
示例#8
0
    /// <summary>
    /// Start broadcasting service using zeroconf.
    /// </summary>
    private void RegisterZeroConf()
    {
        Debug.Log("Registering Zeroconf");
        service = new RegisterService();
        service.Name = "Openhab Kinect";
        service.RegType = "_openhab-kinect._tcp";
        service.ReplyDomain = "local.";
        service.Port = SERVER_PORT;

        service.Register();
        Debug.Log("Registered Zeroconf " + service.RegType);

        Mono.Zeroconf.ServiceBrowser browser = new Mono.Zeroconf.ServiceBrowser();
        browser.ServiceAdded += delegate (object o, Mono.Zeroconf.ServiceBrowseEventArgs args)
        {
            Debug.Log("Found Service: " + args.Service.Name);
        };
        browser.Browse("_openhab-kinect._tcp", "local");
    }
示例#9
0
        /// <summary>
        /// Publish ZeroConf, so that WaveBox may advertise itself using mDNS to capable devices
        /// </summary>
        public bool Start()
        {
            string serverUrl = ServerUtility.GetServerUrl();
            if ((object)serverUrl == null)
            {
                logger.Error("Could not start ZeroConf service, due to null ServerUrl");
                return false;
            }

            // If we're already registered, dispose of it and create a new one
            if ((object)ZeroConf != null)
            {
                this.Stop();
            }

            // Create and register the service
            try
            {
                ZeroConf = new RegisterService();
                ZeroConf.Name = Hostname;
                ZeroConf.RegType = RegType;
                ZeroConf.ReplyDomain = ReplyDomain;
                ZeroConf.Port = (short)Injection.Kernel.Get<IServerSettings>().Port;

                TxtRecord record = new TxtRecord();
                record.Add(ServerUrlKey, serverUrl);
                ZeroConf.TxtRecord = record;

                ZeroConf.Register();
            }
            catch (Exception e)
            {
                logger.Error(e);
                this.Stop();
                return false;
            }

            return true;
        }
        public void RegisterServer(P2PDictionary dict)
        {
            if (service != null)
                throw new NotImplementedException();

            service = new RegisterService();
            service.Name = "com.rhfung.P2PDictionary " + dict.Description;
            service.RegType = ZEROCONF_NAME;
            service.ReplyDomain = "local";
            service.Port = (short)((System.Net.IPEndPoint)dict.LocalEndPoint).Port;
            service.TxtRecord = new TxtRecord();
            service.TxtRecord.Add("uid", dict.LocalID.ToString());
            service.Response += new RegisterServiceEventHandler(service_Response);

            service.Register();
        }