Пример #1
0
 public override void addClient(CallbackReceiverPrx client, Ice.Current current)
 {
     lock (this)
     {
         Console.Out.WriteLine("adding client `" + Ice.Util.identityToString(client.ice_getIdentity()) + "'");
         _clients.Add((CallbackReceiverPrx)client.ice_fixed(current.con));
     }
 }
Пример #2
0
 private void removeClient(CallbackReceiverPrx c, Exception ex)
 {
     Console.Error.WriteLine("removing client `" + Ice.Util.identityToString(c.ice_getIdentity()) + "':\n" + ex);
     lock (this)
     {
         _clients.Remove(c);
     }
 }
Пример #3
0
        public override int runWithSession(string[] args)
        {
            if (args.Length > 0)
            {
                Console.Error.WriteLine(appName() + ": too many arguments");
                return(1);
            }

            Ice.Identity callbackReceiverIdent     = createCallbackIdentity("callbackReceiver");
            Ice.Identity callbackReceiverFakeIdent = new Ice.Identity("fake", "callbackReceiver");

            Ice.ObjectPrx @base       = communicator().propertyToProxy("Callback.Proxy");
            CallbackPrx   twoway      = CallbackPrxHelper.checkedCast(@base);
            CallbackPrx   oneway      = CallbackPrxHelper.uncheckedCast(twoway.ice_oneway());
            CallbackPrx   batchOneway = CallbackPrxHelper.uncheckedCast(twoway.ice_batchOneway());

            objectAdapter().add(new CallbackReceiverI(), callbackReceiverFakeIdent);

            CallbackReceiverPrx twowayR = CallbackReceiverPrxHelper.uncheckedCast(
                objectAdapter().add(new CallbackReceiverI(), callbackReceiverIdent));

            CallbackReceiverPrx onewayR = CallbackReceiverPrxHelper.uncheckedCast(twowayR.ice_oneway());

            menu();

            string line      = null;
            string @override = null;
            bool   fake      = false;

            do
            {
                Console.Write("==> ");
                Console.Out.Flush();
                line = Console.In.ReadLine();
                if (line == null)
                {
                    break;
                }
                if (line.Equals("t"))
                {
                    Dictionary <string, string> context = new Dictionary <string, string>();
                    context["_fwd"] = "t";
                    if (@override != null)
                    {
                        context["_ovrd"] = @override;
                    }
                    twoway.initiateCallback(twowayR, context);
                }
                else if (line.Equals("o"))
                {
                    Dictionary <string, string> context = new Dictionary <string, string>();
                    context["_fwd"] = "o";
                    if (@override != null)
                    {
                        context["_ovrd"] = @override;
                    }
                    oneway.initiateCallback(onewayR, context);
                }
                else if (line.Equals("O"))
                {
                    Dictionary <string, string> context = new Dictionary <string, string>();
                    context["_fwd"] = "O";
                    if (@override != null)
                    {
                        context["_ovrd"] = @override;
                    }
                    batchOneway.initiateCallback(onewayR, context);
                }
                else if (line.Equals("f"))
                {
                    batchOneway.ice_flushBatchRequests();
                }
                else if (line.Equals("v"))
                {
                    if (@override == null)
                    {
                        @override = "some_value";
                        Console.WriteLine("override context field is now `" + @override + "'");
                    }
                    else
                    {
                        @override = null;
                        Console.WriteLine("override context field is empty");
                    }
                }
                else if (line.Equals("F"))
                {
                    fake = !fake;

                    if (fake)
                    {
                        twowayR = CallbackReceiverPrxHelper.uncheckedCast(
                            twowayR.ice_identity(callbackReceiverFakeIdent));
                        onewayR = CallbackReceiverPrxHelper.uncheckedCast(
                            onewayR.ice_identity(callbackReceiverFakeIdent));
                    }
                    else
                    {
                        twowayR = CallbackReceiverPrxHelper.uncheckedCast(
                            twowayR.ice_identity(callbackReceiverIdent));
                        onewayR = CallbackReceiverPrxHelper.uncheckedCast(
                            onewayR.ice_identity(callbackReceiverIdent));
                    }

                    Console.WriteLine("callback receiver identity: " +
                                      Ice.Util.identityToString(twowayR.ice_getIdentity()));
                }
                else if (line.Equals("s"))
                {
                    twoway.shutdown();
                }
                else if (line.Equals("r"))
                {
                    restart();
                }
                else if (line.Equals("x"))
                {
                    // Nothing to do
                }
                else if (line.Equals("?"))
                {
                    menu();
                }
                else
                {
                    Console.WriteLine("unknown command `" + line + "'");
                    menu();
                }
            }while(!line.Equals("x"));

            return(0);
        }
Пример #4
0
    private static int run(Ice.Communicator communicator)
    {
        var router = Glacier2.RouterPrxHelper.checkedCast(communicator.getDefaultRouter());

        Glacier2.SessionPrx session;
        while (true)
        {
            Console.WriteLine("This demo accepts any user-id / password combination.");

            string id;
            string pw;
            try
            {
                Console.Write("user id: ");
                Console.Out.Flush();
                id = Console.In.ReadLine();
                if (id == null)
                {
                    throw new Ice.CommunicatorDestroyedException();
                }
                id = id.Trim();

                Console.Write("password: "******"permission denied:\n" + ex.reason);
            }
            catch (Glacier2.CannotCreateSessionException ex)
            {
                Console.WriteLine("cannot create session:\n" + ex.reason);
            }
        }

        int acmTimeout = router.getACMTimeout();

        Ice.Connection connection = router.ice_getCachedConnection();
        Debug.Assert(connection != null);
        connection.setACM(acmTimeout, Ice.Util.None, Ice.ACMHeartbeat.HeartbeatAlways);
        connection.setCloseCallback(_ => Console.WriteLine("The Glacier2 session has been destroyed."));

        Ice.Identity callbackReceiverIdent     = new Ice.Identity("callbackReceiver", router.getCategoryForClient());
        Ice.Identity callbackReceiverFakeIdent = new Ice.Identity("fake", "callbackReceiver");

        Ice.ObjectPrx @base       = communicator.propertyToProxy("Callback.Proxy");
        CallbackPrx   twoway      = CallbackPrxHelper.checkedCast(@base);
        CallbackPrx   oneway      = CallbackPrxHelper.uncheckedCast(twoway.ice_oneway());
        CallbackPrx   batchOneway = CallbackPrxHelper.uncheckedCast(twoway.ice_batchOneway());

        var adapter = communicator.createObjectAdapterWithRouter("", router);

        adapter.add(new CallbackReceiverI(), callbackReceiverFakeIdent);

        CallbackReceiverPrx twowayR = CallbackReceiverPrxHelper.uncheckedCast(
            adapter.add(new CallbackReceiverI(), callbackReceiverIdent));

        adapter.activate();
        CallbackReceiverPrx onewayR = CallbackReceiverPrxHelper.uncheckedCast(twowayR.ice_oneway());

        menu();

        string line      = null;
        string @override = null;
        bool   fake      = false;

        do
        {
            Console.Write("==> ");
            Console.Out.Flush();
            line = Console.In.ReadLine();
            if (line == null)
            {
                break;
            }
            if (line.Equals("t"))
            {
                Dictionary <string, string> context = new Dictionary <string, string>();
                context["_fwd"] = "t";
                if (@override != null)
                {
                    context["_ovrd"] = @override;
                }
                twoway.initiateCallback(twowayR, context);
            }
            else if (line.Equals("o"))
            {
                Dictionary <string, string> context = new Dictionary <string, string>();
                context["_fwd"] = "o";
                if (@override != null)
                {
                    context["_ovrd"] = @override;
                }
                oneway.initiateCallback(onewayR, context);
            }
            else if (line.Equals("O"))
            {
                Dictionary <string, string> context = new Dictionary <string, string>();
                context["_fwd"] = "O";
                if (@override != null)
                {
                    context["_ovrd"] = @override;
                }
                batchOneway.initiateCallback(onewayR, context);
            }
            else if (line.Equals("f"))
            {
                batchOneway.ice_flushBatchRequests();
            }
            else if (line.Equals("v"))
            {
                if (@override == null)
                {
                    @override = "some_value";
                    Console.WriteLine("override context field is now `" + @override + "'");
                }
                else
                {
                    @override = null;
                    Console.WriteLine("override context field is empty");
                }
            }
            else if (line.Equals("F"))
            {
                fake = !fake;

                if (fake)
                {
                    twowayR = CallbackReceiverPrxHelper.uncheckedCast(
                        twowayR.ice_identity(callbackReceiverFakeIdent));
                    onewayR = CallbackReceiverPrxHelper.uncheckedCast(
                        onewayR.ice_identity(callbackReceiverFakeIdent));
                }
                else
                {
                    twowayR = CallbackReceiverPrxHelper.uncheckedCast(
                        twowayR.ice_identity(callbackReceiverIdent));
                    onewayR = CallbackReceiverPrxHelper.uncheckedCast(
                        onewayR.ice_identity(callbackReceiverIdent));
                }

                Console.WriteLine("callback receiver identity: " +
                                  Ice.Util.identityToString(twowayR.ice_getIdentity()));
            }
            else if (line.Equals("s"))
            {
                twoway.shutdown();
            }
            else if (line.Equals("x"))
            {
                // Nothing to do
            }
            else if (line.Equals("?"))
            {
                menu();
            }
            else
            {
                Console.WriteLine("unknown command `" + line + "'");
                menu();
            }
        }while(!line.Equals("x"));

        return(0);
    }
Пример #5
0
    private static int run(Ice.Communicator communicator)
    {
        var router = Glacier2.RouterPrxHelper.checkedCast(communicator.getDefaultRouter());

        Glacier2.SessionPrx session;
        //
        // Loop until we have successfully create a session.
        //
        while (true)
        {
            //
            // Prompt the user for the credentials to create the session.
            //
            Console.WriteLine("This demo accepts any user-id / password combination.");

            string id;
            string pw;
            try
            {
                Console.Write("user id: ");
                Console.Out.Flush();
                id = Console.In.ReadLine();
                if (id == null)
                {
                    throw new Ice.CommunicatorDestroyedException();
                }
                id = id.Trim();

                Console.Write("password: "******"permission denied:\n" + ex.reason);
            }
            catch (Glacier2.CannotCreateSessionException ex)
            {
                Console.WriteLine("cannot create session:\n" + ex.reason);
            }
        }

        int acmTimeout = router.getACMTimeout();

        Ice.Connection connection = router.ice_getCachedConnection();
        Debug.Assert(connection != null);
        connection.setACM(acmTimeout, Ice.Util.None, Ice.ACMHeartbeat.HeartbeatAlways);
        connection.setCloseCallback(_ => Console.WriteLine("The Glacier2 session has been destroyed."));

        //
        // The Glacier2 router routes bidirectional calls to objects in the client only
        // when these objects have the correct Glacier2-issued category. The purpose of
        // the callbackReceiverFakeIdent is to demonstrate this.
        //
        // The Identity name is not checked by the server any value can be used.
        //
        Ice.Identity callbackReceiverIdent =
            new Ice.Identity(System.Guid.NewGuid().ToString(), router.getCategoryForClient());
        Ice.Identity callbackReceiverFakeIdent =
            new Ice.Identity(System.Guid.NewGuid().ToString(), "fake");

        Ice.ObjectPrx @base       = communicator.propertyToProxy("Callback.Proxy");
        CallbackPrx   twoway      = CallbackPrxHelper.checkedCast(@base);
        CallbackPrx   oneway      = CallbackPrxHelper.uncheckedCast(twoway.ice_oneway());
        CallbackPrx   batchOneway = CallbackPrxHelper.uncheckedCast(twoway.ice_batchOneway());

        var adapter = communicator.createObjectAdapterWithRouter("", router);

        //
        // Callback will never be called for a fake identity.
        //
        adapter.add(new CallbackReceiverI(), callbackReceiverFakeIdent);

        CallbackReceiverPrx twowayR = CallbackReceiverPrxHelper.uncheckedCast(
            adapter.add(new CallbackReceiverI(), callbackReceiverIdent));

        adapter.activate();
        CallbackReceiverPrx onewayR = CallbackReceiverPrxHelper.uncheckedCast(twowayR.ice_oneway());

        menu();

        //
        // Client REPL
        //
        string line      = null;
        string @override = null;
        bool   fake      = false;

        do
        {
            Console.Write("==> ");
            Console.Out.Flush();
            line = Console.In.ReadLine();
            if (line == null)
            {
                break;
            }
            if (line.Equals("t"))
            {
                twoway.initiateCallback(twowayR);
            }
            else if (line.Equals("o"))
            {
                Dictionary <string, string> context = new Dictionary <string, string>();
                if (@override != null)
                {
                    context["_ovrd"] = @override;
                }
                oneway.initiateCallback(onewayR, context);
            }
            else if (line.Equals("O"))
            {
                Dictionary <string, string> context = new Dictionary <string, string>();
                context["_fwd"] = "O";
                if (@override != null)
                {
                    context["_ovrd"] = @override;
                }
                batchOneway.initiateCallback(onewayR, context);
            }
            else if (line.Equals("f"))
            {
                batchOneway.ice_flushBatchRequests();
            }
            else if (line.Equals("v"))
            {
                if (@override == null)
                {
                    @override = "some_value";
                    Console.WriteLine("override context field is now `" + @override + "'");
                }
                else
                {
                    @override = null;
                    Console.WriteLine("override context field is empty");
                }
            }
            else if (line.Equals("F"))
            {
                fake = !fake;

                if (fake)
                {
                    twowayR = CallbackReceiverPrxHelper.uncheckedCast(
                        twowayR.ice_identity(callbackReceiverFakeIdent));
                    onewayR = CallbackReceiverPrxHelper.uncheckedCast(
                        onewayR.ice_identity(callbackReceiverFakeIdent));
                }
                else
                {
                    twowayR = CallbackReceiverPrxHelper.uncheckedCast(
                        twowayR.ice_identity(callbackReceiverIdent));
                    onewayR = CallbackReceiverPrxHelper.uncheckedCast(
                        onewayR.ice_identity(callbackReceiverIdent));
                }

                Console.WriteLine("callback receiver identity: " +
                                  Ice.Util.identityToString(twowayR.ice_getIdentity()));
            }
            else if (line.Equals("s"))
            {
                twoway.shutdown();
            }
            else if (line.Equals("x"))
            {
                // Nothing to do
            }
            else if (line.Equals("?"))
            {
                menu();
            }
            else
            {
                Console.WriteLine("unknown command `" + line + "'");
                menu();
            }
        }while(!line.Equals("x"));

        return(0);
    }