Ejemplo n.º 1
0
 ice_invoke(byte[] inParams, out byte[] outParams, Ice.Current current)
 {
     Ice.Communicator communicator = current.adapter.getCommunicator();
     Ice.InputStream  inS          = new Ice.InputStream(communicator, inParams);
     inS.startEncapsulation();
     Ice.OutputStream outS = new Ice.OutputStream(communicator);
     outS.startEncapsulation();
     if (current.operation.Equals("opOneway"))
     {
         outParams = new byte[0];
         return(true);
     }
     else if (current.operation.Equals("opString"))
     {
         string s = inS.readString();
         outS.writeString(s);
         outS.writeString(s);
         outS.endEncapsulation();
         outParams = outS.finished();
         return(true);
     }
     else if (current.operation.Equals("opException"))
     {
         Test.MyException ex = new Test.MyException();
         outS.writeException(ex);
         outS.endEncapsulation();
         outParams = outS.finished();
         return(false);
     }
     else if (current.operation.Equals("shutdown"))
     {
         communicator.shutdown();
         outParams = null;
         return(true);
     }
     else if (current.operation.Equals("ice_isA"))
     {
         string s = inS.readString();
         if (s.Equals("::Test::MyClass"))
         {
             outS.writeBool(true);
         }
         else
         {
             outS.writeBool(false);
         }
         outS.endEncapsulation();
         outParams = outS.finished();
         return(true);
     }
     else
     {
         Ice.OperationNotExistException ex = new Ice.OperationNotExistException();
         ex.id        = current.id;
         ex.facet     = current.facet;
         ex.operation = current.operation;
         throw ex;
     }
 }
Ejemplo n.º 2
0
    public override bool ice_invoke(byte[] inParams, out byte[] outParams, Ice.Current current)
    {
        outParams = null;

        Ice.Communicator communicator = current.adapter.getCommunicator();

        Ice.InputStream inStream = null;
        if (inParams.Length > 0)
        {
            inStream = new Ice.InputStream(communicator, inParams);
            inStream.startEncapsulation();
        }

        if (current.operation.Equals("printString"))
        {
            string message = inStream.readString();
            inStream.endEncapsulation();
            Console.WriteLine("Printing string `" + message + "'");
            return(true);
        }
        else if (current.operation.Equals("printStringSequence"))
        {
            String[] seq = Demo.StringSeqHelper.read(inStream);
            inStream.endEncapsulation();
            Console.Write("Printing string sequence {");
            for (int i = 0; i < seq.Length; ++i)
            {
                if (i > 0)
                {
                    Console.Write(", ");
                }
                Console.Write("'" + seq[i] + "'");
            }
            Console.WriteLine("}");
            return(true);
        }
        else if (current.operation.Equals("printDictionary"))
        {
            Dictionary <string, string> dict = Demo.StringDictHelper.read(inStream);
            inStream.endEncapsulation();
            Console.Write("Printing dictionary {");
            bool first = true;
            foreach (KeyValuePair <string, string> e in dict)
            {
                if (!first)
                {
                    Console.Write(", ");
                }
                first = false;
                Console.Write(e.Key + "=" + e.Value);
            }
            Console.WriteLine("}");
            return(true);
        }
        else if (current.operation.Equals("printEnum"))
        {
            Demo.Color c = Demo.ColorHelper.read(inStream);
            inStream.endEncapsulation();
            Console.WriteLine("Printing enum " + c);
            return(true);
        }
        else if (current.operation.Equals("printStruct"))
        {
            Demo.Structure s = Demo.Structure.read(inStream);
            inStream.endEncapsulation();
            Console.WriteLine("Printing struct: name=" + s.name + ", value=" + s.value);
            return(true);
        }
        else if (current.operation.Equals("printStructSequence"))
        {
            Demo.Structure[] seq = Demo.StructureSeqHelper.read(inStream);
            inStream.endEncapsulation();
            Console.Write("Printing struct sequence: {");
            for (int i = 0; i < seq.Length; ++i)
            {
                if (i > 0)
                {
                    Console.Write(", ");
                }
                Console.Write(seq[i].name + "=" + seq[i].value);
            }
            Console.WriteLine("}");
            return(true);
        }
        else if (current.operation.Equals("printClass"))
        {
            ReadValueCallback cb = new ReadValueCallback();
            inStream.readValue(cb.invoke);
            inStream.readPendingValues();
            inStream.endEncapsulation();
            Demo.C c = cb.obj as Demo.C;
            Console.WriteLine("Printing class: s.name=" + c.s.name + ", s.value=" + c.s.value);
            return(true);
        }
        else if (current.operation.Equals("getValues"))
        {
            Demo.C c = new Demo.C();
            c.s       = new Demo.Structure();
            c.s.name  = "green";
            c.s.value = Demo.Color.green;
            Ice.OutputStream outStream = new Ice.OutputStream(communicator);
            outStream.startEncapsulation();
            outStream.writeValue(c);
            outStream.writeString("hello");
            outStream.writePendingValues();
            outStream.endEncapsulation();
            outParams = outStream.finished();
            return(true);
        }
        else if (current.operation.Equals("throwPrintFailure"))
        {
            Console.WriteLine("Throwing PrintFailure");
            Demo.PrintFailure ex = new Demo.PrintFailure();
            ex.reason = "paper tray empty";
            Ice.OutputStream outStream = new Ice.OutputStream(communicator);
            outStream.startEncapsulation();
            outStream.writeException(ex);
            outStream.endEncapsulation();
            outParams = outStream.finished();
            return(false);
        }
        else if (current.operation.Equals("shutdown"))
        {
            current.adapter.getCommunicator().shutdown();
            return(true);
        }
        else
        {
            Ice.OperationNotExistException ex = new Ice.OperationNotExistException();
            ex.id        = current.id;
            ex.facet     = current.facet;
            ex.operation = current.operation;
            throw ex;
        }
    }
Ejemplo n.º 3
0
        public override bool Sent() => base.SentImpl(!Proxy.IsTwoway); // done = true if it's not a two-way proxy

        public override bool Response()
        {
            Debug.Assert(Is != null);
            //
            // NOTE: this method is called from ConnectionI.parseMessage
            // with the connection locked. Therefore, it must not invoke
            // any user callbacks.
            //
            Debug.Assert(Proxy.IsTwoway); // Can only be called for twoways.

            if (ChildObserver != null)
            {
                ChildObserver.Reply(Is.Size - Protocol.headerSize - 4);
                ChildObserver.Detach();
                ChildObserver = null;
            }

            byte replyStatus;

            try
            {
                replyStatus = Is.ReadByte();

                switch (replyStatus)
                {
                case ReplyStatus.replyOK:
                    {
                        break;
                    }

                case ReplyStatus.replyUserException:
                {
                    if (Observer != null)
                    {
                        Observer.UserException();
                    }
                    break;
                }

                case ReplyStatus.replyObjectNotExist:
                case ReplyStatus.replyFacetNotExist:
                case ReplyStatus.replyOperationNotExist:
                {
                    var ident = new Ice.Identity(Is);

                    //
                    // For compatibility with the old FacetPath.
                    //
                    string[] facetPath = Is.ReadStringArray();
                    string   facet;
                    if (facetPath.Length > 0)
                    {
                        if (facetPath.Length > 1)
                        {
                            throw new Ice.MarshalException();
                        }
                        facet = facetPath[0];
                    }
                    else
                    {
                        facet = "";
                    }

                    string operation = Is.ReadString();

                    Ice.RequestFailedException ex;
                    switch (replyStatus)
                    {
                    case ReplyStatus.replyObjectNotExist:
                    {
                        ex = new Ice.ObjectNotExistException();
                        break;
                    }

                    case ReplyStatus.replyFacetNotExist:
                    {
                        ex = new Ice.FacetNotExistException();
                        break;
                    }

                    case ReplyStatus.replyOperationNotExist:
                    {
                        ex = new Ice.OperationNotExistException();
                        break;
                    }

                    default:
                    {
                        Debug.Assert(false);
                        throw new System.InvalidOperationException();
                    }
                    }

                    ex.Id        = ident;
                    ex.Facet     = facet;
                    ex.Operation = operation;
                    throw ex;
                }

                case ReplyStatus.replyUnknownException:
                case ReplyStatus.replyUnknownLocalException:
                case ReplyStatus.replyUnknownUserException:
                {
                    string unknown = Is.ReadString();

                    Ice.UnknownException ex;
                    switch (replyStatus)
                    {
                    case ReplyStatus.replyUnknownException:
                    {
                        ex = new Ice.UnknownException();
                        break;
                    }

                    case ReplyStatus.replyUnknownLocalException:
                    {
                        ex = new Ice.UnknownLocalException();
                        break;
                    }

                    case ReplyStatus.replyUnknownUserException:
                    {
                        ex = new Ice.UnknownUserException();
                        break;
                    }

                    default:
                    {
                        Debug.Assert(false);
                        throw new System.InvalidOperationException();
                    }
                    }

                    ex.Unknown = unknown;
                    throw ex;
                }

                default:
                {
                    throw new Ice.UnknownReplyStatusException();
                }
                }

                return(ResponseImpl(false, replyStatus == ReplyStatus.replyOK, true));
            }
            catch (Ice.Exception ex)
            {
                return(Exception(ex));
            }
        }