示例#1
0
文件: Main.cs 项目: Gohla/protophase
        public static void Main(string[] args)
        {
            try {
                // Get console quit key press events.
                Console.CancelKeyPress += CancelKeyPressHandler;

                // Sleep so registry and server can start up first.
                Thread.Sleep(1000);

                // Create registry client for registry at address tcp://localhost:5555.
                using(Registry registry = new Registry())
                {
                    // Get HelloWorldResponder service, loop until it exists.
                    Service helloWorld1 = null;
                    while(helloWorld1 == null) helloWorld1 = registry.GetServiceByUID("HelloWorldResponder1");
                    Console.WriteLine("Found HelloWorldResponder1: " + helloWorld1);

                    // Get HelloWorldResponder services, loop until it exists.
                    Service helloWorldAll = null;
                    while(helloWorldAll == null) helloWorldAll = registry.GetServiceByType("HelloWorldResponder");
                    Console.WriteLine("Found HelloWorldResponders: " + helloWorldAll);

                    // Subscribe for published event.
                    helloWorld1.Published += (object obj) => Console.WriteLine("HelloWorldResponder1 published: " + obj);
                    helloWorldAll.Published += (object obj) => Console.WriteLine("HelloWorldResponders published: " + obj);

                    // Program loop
                    while(!_quit) {
                        // Call receive on the objects to receive published messages.
                        // TODO: Optionally let the library take care of this.
                        //helloWorld1.Receive();
                        //helloWorldAll.Receive();
                        registry.Update();
                        //Console.WriteLine(ApplicationInstance.Guid);

                        // RPC HelloWorld function with no parameters and print the result.
                        //Console.WriteLine("RPC call HelloWorld on HelloWorldResponder1: " + helloWorld1.Call<String>("HelloWorld"));
                        //Console.WriteLine("RPC call HelloWorld on HelloWorldResponders: " + helloWorldAll.Call<String>("HelloWorld"));
                        // RPC ReturnParam function with 3 params and print the result.
                        //Console.WriteLine("RPC call ReturnParam on HelloWorldResponder1: " + helloWorld1.Call<String>("ReturnParam", 1, 1.0f, "one"));
                        //Console.WriteLine("RPC call ReturnParam on HelloWorldResponders: " + helloWorldAll.Call<String>("ReturnParam", 1, 1.0f, "one"));

                        Thread.Sleep(100);
                    }

                    // Dispose of service objects to free sockets.
                    helloWorld1.Dispose();
                    helloWorldAll.Dispose();
                }
            } catch(Exception e) {
                Console.WriteLine(e.Message + "\n" + e.StackTrace);
                Thread.Sleep(10000);
            }
        }
示例#2
0
 public void Start()
 {
     registry = new Registry();
     if (!registry.Register(this))
     {
         Console.WriteLine("Error registering service.");
         return;
     }
     Console.WriteLine("Registered service.");
     Service rawDataPublisher = null;
     while (rawDataPublisher == null && !quit)
         rawDataPublisher = registry.GetServiceByType("RawAisDataPublisher");
     if (!quit)
         rawDataPublisher.Published += RAWAisDataRecieved;
     while (!quit)
         registry.Update();
     registry.Unregister(this);
 }
示例#3
0
 static void Main(string[] args)
 {
     registry = new Registry();
     Service rawDataPublisher = null;
     while (rawDataPublisher == null && !quit)
         rawDataPublisher = registry.GetServiceByType("RawAisDataPublisher");
     rawDataPublisher.Published += publishedEvent;
     while (!quit)
     {
         Console.Clear();
         Console.WriteLine("Total messages: " + TotalCount);
         Console.WriteLine("Total messages OK: " + OKCount);
         Console.WriteLine("Total messages Multipart: " + MultiPartCount);
         Console.WriteLine("Total messages Failed: " + FailCount);
         Console.WriteLine("");
         Console.WriteLine("Pecentage OK: " + (((double)OKCount / (double)TotalCount))*100);
         Thread.Sleep(100);
         registry.Update();
     }
 }
示例#4
0
 static void Main(string[] args)
 {
     testKML = new GoogleEarthKMLDumper();
     Console.CancelKeyPress += CancelKeyPressHandler;
     Registry registry = new Registry();
     Service aisDataPublisher = null;
     while (aisDataPublisher == null && !quit)
         aisDataPublisher = registry.GetServiceByType("AisDataPublisher");
     aisDataPublisher.Published += publishedEvent;
     int count = 0;
     while (!quit)
     {
         count++;
         if (count > 10)
         {
             count = 0;
             testKML.DumpKMLFile();
         }
         registry.Update();
         Thread.Sleep(100);
     }
 }
示例#5
0
文件: Main.cs 项目: Gohla/protophase
        public static void Main(string[] args)
        {
            // Get console quit key press events.
            Console.CancelKeyPress += CancelKeyPressHandler;

            // Create registry client for registry at address tcp://localhost:5555.
            using(Registry registry = new Registry("tcp://localhost:5555")) {
                // Register our hello world responder objects with the registry.
                HelloWorldResponder responder1 = new HelloWorldResponder(1);
                HelloWorldResponder responder2 = new HelloWorldResponder(2);
                HelloWorldResponder responder3 = new HelloWorldResponder(3);

                if(registry.Register("HelloWorldResponder1", responder1))
                    Console.WriteLine("Registered HelloWorldResponder1");
                else {
                    Console.WriteLine("Failed to register HelloWorldResponder 1");
                    return;
                }
                if(registry.Register("HelloWorldResponder2", responder2))
                    Console.WriteLine("Registered HelloWorldResponder2");
                else {
                    Console.WriteLine("Failed to register HelloWorldResponder2");
                    return;
                }
                if(registry.Register("HelloWorldResponder3", responder3))
                    Console.WriteLine("Registered HelloWorldResponder3");
                else {
                    Console.WriteLine("Failed to register HelloWorldResponder3");
                    return;
                }

                // Program loop
                while(!_quit) {
                    // Emit an event in the service.
                    responder1.SomethingHappened();
                    responder3.SomethingHappened();

                    // Receive RPC calls
                    // TODO: Optionally let the library take care of this.
                    registry.Update();

                    Thread.Sleep(100);
                }
            }
        }