Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            DebusClient client;

            try
            {
                client = new DebusClient();

                client.AsyncListener = OnReceiveMessage;
                while (true)
                {
                    string cmd = System.Console.ReadLine();
                    int    i   = cmd.IndexOf(' ');
                    if (i != -1)
                    {
                        string receiver = cmd.Substring(0, i);
                        string message  = cmd.Substring(i + 1);
                        client.SendMessageAsync(receiver, message);
                    }
                }
            }
            catch (System.TimeoutException) {
                System.Console.WriteLine("Request timed out.");
                System.Console.ReadKey(false);
            }
        }
        static void a()//Main(string[] args)
        {
            try
            {
                client = new DebusClient(); // throws TimeoutException
                client.AsyncListener = OnReceiveMessage;

                string reply;
                reply = client.SendMessage("Base\\Core", "Register MyName\\Example1"); // throws TimeoutException
                if (reply != "Registered MyName\\Example1")
                {
                    System.Console.WriteLine(reply);
                    Thread.Sleep(453543);
                    return;
                    // or check if reply == "ERROR RegistrationNameTaken"
                }

                waitingForDependencies = 0;

                reply = client.SendMessage("Base\\Core", "IsLoaded Base\\Hotkey"); // throws TimeoutException
                if (reply != "Loaded Base\\Hotkey")
                {
                    // Process.Start("Base\\Hotkey.exe")
                    waitingForDependencies++;
                }
                reply = client.SendMessage("Base\\Core", "IsLoaded AnotherDev\\AnotherDep"); // throws TimeoutException
                if (reply != "Loaded AnotherDev\\AnotherDep")
                {
                    // Process.Start("../../AnotherDev.exe");
                    waitingForDependencies++;
                }

                int timeout = 0;
                while (waitingForDependencies > 0)
                {
                    Thread.Sleep(10);
                    timeout++;
                    if (timeout > 300)
                    {
                        System.Console.WriteLine("Loading takes too long"); return;
                    }
                }

                client.SendMessageAsync("Base\\Hotkey", "Register Win F1"); // if you don't care much about result (reply will go to AsyncListener)

                reply = client.SendMessage("Base\\Core", "Ready");          // throws TimeoutException
                if (reply != "Ready MyName\\Example1")
                {
                    System.Console.WriteLine(reply);
                    Thread.Sleep(453543);
                    return;
                }
                Thread.Sleep(123456); // some random code
            }
            catch (System.TimeoutException) { /* code */ }
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            try
            {
                client = new DebusClient(); // throws TimeoutException
                client.AsyncListener = OnReceiveMessage;

                string reply;
                reply = client.SendMessage("Base\\Core", "Register MyName\\Example1"); // throws TimeoutException
                if (reply != "Registered MyName\\Example1")
                {
                    System.Console.WriteLine(reply);
                    Thread.Sleep(453543);
                    return;
                    // or check if reply == "ERROR RegistrationNameTaken"
                }

                reply = client.SendMessage("Base\\Core", "IsLoaded Base\\Hotkey"); // throws TimeoutException
                if (reply != "Loaded Base\\Hotkey")
                {
                    // Process.Start("Base\\Hotkey.exe")
                }
                reply = client.SendMessage("Base\\Core", "IsLoaded AnotherDev\\AnotherDep"); // throws TimeoutException
                if (reply != "Loaded AnotherDev\\AnotherDep")
                {
                    // Process.Start("../../AnotherDev.exe");
                }
                while (reply != "Loaded Base\\Hotkey")
                {
                    reply = client.SendMessage("Base\\Core", "IsLoaded Base\\Hotkey"); Thread.Sleep(10);
                }                                                                                                                               // throws TimeoutException
                while (reply != "Loaded AnotherDev\\AnotherDep")
                {
                    reply = client.SendMessage("Base\\Core", "IsLoaded AnotherDev\\AnotherDep"); Thread.Sleep(10);
                }                                                                                                                                                   // throws TimeoutException

                // TODO add timeout to loops above

                client.SendMessageAsync("Base\\Hotkey", "Register Win F1"); // if you don't care much about result (reply will go to AsyncListener)

                reply = client.SendMessage("Base\\Core", "Ready");          // throws TimeoutException
                if (reply != "Ready MyName\\Example1")
                {
                    System.Console.WriteLine(reply);
                    Thread.Sleep(453543);
                    return;
                }
                Thread.Sleep(123456); // some random code
            }
            catch (System.TimeoutException) { /* code */ }
        }