Beispiel #1
0
 /// <summary>实例化</summary>
 /// <param name="value">对象</param>
 /// <param name="type">对象类型</param>
 /// <param name="member">成员</param>
 /// <param name="index">成员序号</param>
 /// <param name="callback"></param>
 public ReadMemberEventArgs(Object value, Type type, IObjectMemberInfo member, Int32 index, ReadObjectCallback callback)
     : base(index, callback)
 {
     Value = value;
     Type = type;
     Member = member;
 }
Beispiel #2
0
        /// <summary>尝试读取引用对象</summary>
        /// <param name="type">要读取的对象类型</param>
        /// <param name="value">要读取的对象</param>
        /// <param name="callback">处理成员的方法</param>
        /// <returns>是否读取成功</returns>
        protected override bool ReadRefObject(Type type, ref object value, ReadObjectCallback callback)
        {
            Boolean isElement = Reader.NodeType == XmlNodeType.Element;
            Boolean isAtt     = Settings.MemberAsAttribute && XmlWriterX.IsAttributeType(type);

            if (isElement && !isAtt)
            {
                if (SkipEmpty())
                {
                    return(true);
                }
                if (Reader.MoveToAttribute("Lengths"))
                {
                    WriteLog("ReadLengths");
                    Lengths = ReadString();
                    if (Reader.NodeType == XmlNodeType.Attribute)
                    {
                        Reader.MoveToElement();
                    }
                }
                Reader.ReadStartElement();
            }

            Boolean b = base.ReadRefObject(type, ref value, callback);

            if (isElement && !isAtt && Reader.NodeType == XmlNodeType.EndElement)
            {
                Reader.ReadEndElement();
            }

            return(b);
        }
 /// <summary>
 /// 实例化
 /// </summary>
 /// <param name="value">对象</param>
 /// <param name="keyType">键类型</param>
 /// <param name="valueType">值类型</param>
 /// <param name="index"></param>
 /// <param name="callback"></param>
 public ReadDictionaryEventArgs(DictionaryEntry value, Type keyType,Type valueType, Int32 index, ReadObjectCallback callback)
     : base(index, callback)
 {
     Value = value;
     KeyType = keyType;
     ValueType = valueType;
 }
Beispiel #4
0
        /// <summary>尝试读取字典类型对象</summary>
        /// <param name="type">类型</param>
        /// <param name="value">对象</param>
        /// <param name="callback">处理成员的方法</param>
        /// <returns>是否读取成功</returns>
        public override bool ReadDictionary(Type type, ref object value, ReadObjectCallback callback)
        {
            if (SkipEmpty())
            {
                return(true);
            }

            return(base.ReadDictionary(type, ref value, callback));
        }
Beispiel #5
0
        /// <summary>读取实现了可序列化接口的对象</summary>
        /// <param name="type">要读取的对象类型</param>
        /// <param name="value">要读取的对象</param>
        /// <param name="callback">处理成员的方法</param>
        /// <returns>是否读取成功</returns>
        public override bool ReadSerializable(Type type, ref object value, ReadObjectCallback callback)
        {
            if (!typeof(IXmlSerializable).IsAssignableFrom(type))
            {
                return(base.ReadSerializable(type, ref value, callback));
            }

            if (value == null)
            {
                value = type.CreateInstance();
            }
            ((IXmlSerializable)value).ReadXml(Reader);
            return(true);
        }
Beispiel #6
0
        /// <summary>尝试读取引用对象</summary>
        /// <param name="type">要读取的对象类型</param>
        /// <param name="value">要读取的对象</param>
        /// <param name="callback">处理成员的方法</param>
        /// <returns>是否读取成功</returns>
        protected override bool ReadRefObject(Type type, ref object value, ReadObjectCallback callback)
        {
            if (value != null)
            {
                type = value.GetType();
            }
            // ReadType必须增加深度,否则写对象引用时将会受到影响,顶级对象不写对象引用
            if (!Settings.IgnoreType)
            {
                type = ReadType();
            }

            return(base.ReadRefObject(type, ref value, callback));
        }
Beispiel #7
0
        /// <summary>尝试读取枚举</summary>
        /// <remarks>重点和难点在于如果得知枚举元素类型,这里假设所有元素类型一致,否则实在无法处理</remarks>
        /// <param name="type">要读取的对象类型</param>
        /// <param name="value">要读取的对象</param>
        /// <param name="callback">处理成员的方法</param>
        /// <returns>是否读取成功</returns>
        public override bool ReadEnumerable(Type type, ref object value, ReadObjectCallback callback)
        {
            Type t = type.GetElementType();

            #region 锯齿二维数组处理
            Int32 length = 1;
            while (typeof(IEnumerable).IsAssignableFrom(t))
            {
                length++;
                t = t.GetElementType();
            }

            if (length > 1)
            {
                Array array = type.CreateInstance(length) as Array;
                t = type.GetElementType();
                for (int j = 0; j < length - 1; j++)
                {
                    //开始循环之前已赋值,所以第一次循环时跳过
                    if (j > 0)
                    {
                        t = t.GetElementType();
                    }

                    for (int i = 0; i < array.Length; i++)
                    {
                        if (value != null)
                        {
                            value = null;
                        }
                        if (base.ReadEnumerable(t, ref value, callback) && value != null)
                        {
                            array.SetValue(value, i);
                        }
                    }
                }
                if (array != null && array.Length > 0)
                {
                    value = array;
                }
                return(true);
            }
            #endregion

            return(base.ReadEnumerable(type, ref value, callback));
        }
Beispiel #8
0
 /// <summary>读取未知对象(其它所有方法都无法识别的对象),采用BinaryFormatter或者XmlSerialization</summary>
 /// <param name="type">要读取的对象类型</param>
 /// <param name="value">要读取的对象</param>
 /// <param name="callback">处理成员的方法</param>
 /// <returns>是否读取成功</returns>
 public override bool ReadUnKnown(Type type, ref object value, ReadObjectCallback callback)
 {
     try
     {
         WriteLog("XmlSerializer", type.Name);
         XmlSerializer serializer = new XmlSerializer(type);
         String        str        = Reader.ReadString();
         if (!String.IsNullOrEmpty(str))
         {
             MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(str));
             value = serializer.Deserialize(ms);
         }
         return(true);
     }
     catch
     {
         //只能处理公共类型,Type因其保护级别而不可访问。
     }
     return(base.ReadUnKnown(type, ref value, callback));
 }
Beispiel #9
0
        /// <summary>尝试读取目标对象指定成员的值,通过委托方法递归处理成员</summary>
        /// <param name="type">要读取的对象类型</param>
        /// <param name="value">要读取的对象</param>
        /// <param name="callback">处理成员的方法</param>
        /// <returns>是否读取成功</returns>
        protected override bool OnReadObject(Type type, ref object value, ReadObjectCallback callback)
        {
            if (Depth > 1)
            {
                return(base.OnReadObject(type, ref value, callback));
            }

            while (Reader.NodeType != XmlNodeType.Element)
            {
                if (!Reader.Read())
                {
                    return(false);
                }
            }
            if (String.IsNullOrEmpty(RootName))
            {
                RootName = Reader.Name;
            }

            return(base.OnReadObject(type, ref value, callback));
        }
Beispiel #10
0
        /// <summary>读取枚举项</summary>
        /// <param name="type">类型</param>
        /// <param name="value">数值</param>
        /// <param name="index">元素序号</param>
        /// <param name="callback">处理元素的方法</param>
        /// <returns></returns>
        protected override bool ReadItem(Type type, ref object value, Int32 index, ReadObjectCallback callback)
        {
            String name = type.GetCustomAttributeValue <XmlRootAttribute, String>(true);

            if (String.IsNullOrEmpty(name) && type != null)
            {
                name = type.Name;
            }

            if (Reader.NodeType == XmlNodeType.EndElement || Reader.Name != name)
            {
                return(false);
            }

            Boolean rs = base.ReadItem(type, ref value, index, callback);

            if (Reader.NodeType == XmlNodeType.EndElement)
            {
                Reader.ReadEndElement();
            }

            return(rs);
        }
Beispiel #11
0
 /// <summary>实例化</summary>
 /// <param name="callback"></param>
 public ReaderEventArgs(ReadObjectCallback callback)
 {
     Callback = callback;
 }
Beispiel #12
0
 internal abstract void readObject(ReadObjectCallback cb);
Beispiel #13
0
            protected void addPatchEntry(int index, ReadObjectCallback cb)
            {
                Debug.Assert(index > 0);

                //
                // Check if already un-marshalled the object. If that's the case,
                // just patch the object smart pointer and we're done.
                //
                Ice.Object obj;
                if(_unmarshaledMap.TryGetValue(index, out obj))
                {
                    cb(obj);
                    return;
                }

                if(_patchMap == null)
                {
                    _patchMap = new Dictionary<int, LinkedList<ReadObjectCallback>>();
                }

                //
                // Add patch entry if the object isn't un-marshalled yet,
                // the smart pointer will be patched when the instance is
                // un-marshalled.
                //
                LinkedList<ReadObjectCallback> l;
                if(!_patchMap.TryGetValue(index, out l))
                {
                    //
                    // We have no outstanding instances to be patched for this
                    // index, so make a new entry in the patch map.
                    //
                    l = new LinkedList<ReadObjectCallback>();
                    _patchMap.Add(index, l);
                }

                //
                // Append a patch entry for this instance.
                //
                l.AddLast(cb);
            }
Beispiel #14
0
        /// <summary>读取字典项</summary>
        /// <param name="keyType">键类型</param>
        /// <param name="valueType">值类型</param>
        /// <param name="value">字典项</param>
        /// <param name="index">元素序号</param>
        /// <param name="callback">处理成员的方法</param>
        /// <returns>是否读取成功</returns>
        protected override bool ReadDictionaryEntry(Type keyType, Type valueType, ref DictionaryEntry value, Int32 index, ReadObjectCallback callback)
        {
            if (Reader.NodeType == XmlNodeType.EndElement)
            {
                return(false);
            }

            Object key = null;
            Object val = null;

            // <Item>
            Reader.ReadStartElement();

            // <Key>
            Reader.ReadStartElement();
            if (!ReadObject(keyType, ref key))
            {
                return(false);
            }
            // </Key>
            if (Reader.NodeType == XmlNodeType.EndElement)
            {
                Reader.ReadEndElement();
            }

            // <Value>
            if (!ReadObject(valueType, ref val))
            {
                return(false);
            }
            // </Value>

            value.Key   = key;
            value.Value = val;

            // </Item>
            if (Reader.NodeType == XmlNodeType.EndElement)
            {
                Reader.ReadEndElement();
            }

            return(true);
        }
Beispiel #15
0
 /// <summary>
 /// Extracts the index of an optional Slice value from the stream.
 /// </summary>
 /// <param name="tag">The numeric tag associated with the value.</param>
 /// <param name="cb">The callback to notify the application when the extracted instance is available (if any).
 /// The stream extracts Slice values in stages. The Ice run time invokes the delegate when the
 /// corresponding instance has been fully unmarshaled.</param>
 public void readObject(int tag, ReadObjectCallback cb)
 {
     if(readOptional(tag, Ice.OptionalFormat.Class))
     {
         readObject(cb);
     }
 }
Beispiel #16
0
            internal override void readObject(ReadObjectCallback cb)
            {
                Debug.Assert(cb != null);

                //
                // Object references are encoded as a negative integer in 1.0.
                //
                int index = _stream.readInt();
                if(index > 0)
                {
                    throw new Ice.MarshalException("invalid object id");
                }
                index = -index;

                if(index == 0)
                {
                    cb(null);
                }
                else
                {
                    addPatchEntry(index, cb);
                }
            }
 /// <summary>
 /// 实例化
 /// </summary>
 /// <param name="value">对象</param>
 /// <param name="type">对象类型</param>
 /// <param name="callback"></param>
 public ReadObjectEventArgs(Object value, Type type, ReadObjectCallback callback)
     : base(callback)
 {
     Value = value;
     Type = type;
 }
Beispiel #18
0
 /// <summary>
 /// 实例化
 /// </summary>
 /// <param name="callback"></param>
 public ReaderEventArgs(ReadObjectCallback callback)
 {
     Callback = callback;
 }
Beispiel #19
0
 public void readObject(ReadObjectCallback cb)
 {
     _is.readObject(new Patcher <Ice.Object>(cb));
 }
Beispiel #20
0
 internal override void readObject(ReadObjectCallback cb)
 {
     int index = _stream.readSize();
     if(index < 0)
     {
         throw new Ice.MarshalException("invalid object id");
     }
     else if(index == 0)
     {
         if(cb != null)
         {
             cb(null);
         }
     }
     else if(_current != null && (_current.sliceFlags & Protocol.FLAG_HAS_INDIRECTION_TABLE) != 0)
     {
         //
         // When reading an object within a slice and there's an
         // indirect object table, always read an indirect reference
         // that points to an object from the indirect object table
         // marshaled at the end of the Slice.
         //
         // Maintain a list of indirect references. Note that the
         // indirect index starts at 1, so we decrement it by one to
         // derive an index into the indirection table that we'll read
         // at the end of the slice.
         //
         if(cb != null)
         {
             if(_current.indirectPatchList == null)
             {
                 _current.indirectPatchList = new Stack<IndirectPatchEntry>();
             }
             IndirectPatchEntry e = new IndirectPatchEntry();
             e.index = index - 1;
             e.patcher = cb;
             _current.indirectPatchList.Push(e);
         }
     }
     else
     {
         readInstance(index, cb);
     }
 }
Beispiel #21
0
            private int readInstance(int index, ReadObjectCallback cb)
            {
                Debug.Assert(index > 0);

                if(index > 1)
                {
                    if(cb != null)
                    {
                        addPatchEntry(index, cb);
                    }
                    return index;
                }

                push(SliceType.ObjectSlice);

                //
                // Get the object ID before we start reading slices. If some
                // slices are skiped, the indirect object table are still read and
                // might read other objects.
                //
                index = ++_objectIdIndex;

                //
                // Read the first slice header.
                //
                startSlice();
                string mostDerivedId = _current.typeId;
                Ice.Object v = null;
                while(true)
                {
                    bool updateCache = false;

                    if(_current.compactId >= 0)
                    {
                        updateCache = true;

                        //
                        // Translate a compact (numeric) type ID into a class.
                        //
                        if(_compactIdCache == null)
                        {
                            _compactIdCache = new Dictionary<int, Type>(); // Lazy initialization.
                        }
                        else
                        {
                            //
                            // Check the cache to see if we've already translated the compact type ID into a class.
                            //
                            Type cls = null;
                            _compactIdCache.TryGetValue(_current.compactId, out cls);
                            if(cls != null)
                            {
                                try
                                {
                                    Debug.Assert(!cls.IsAbstract && !cls.IsInterface);
                                    v = (Ice.Object)IceInternal.AssemblyUtil.createInstance(cls);
                                    updateCache = false;
                                }
                                catch(Exception ex)
                                {
                                    throw new NoValueFactoryException("no value factory", "compact ID " +
                                                                      _current.compactId, ex);
                                }
                            }
                        }

                        //
                        // If we haven't already cached a class for the compact ID, then try to translate the
                        // compact ID into a type ID.
                        //
                        if(v == null)
                        {
                            _current.typeId = "";
                            if(_compactIdResolver != null)
                            {
                                try
                                {
                                    _current.typeId = _compactIdResolver(_current.compactId);
                                }
                                catch(Ice.LocalException)
                                {
                                    throw;
                                }
                                catch(System.Exception ex)
                                {
                                    throw new Ice.MarshalException("exception in CompactIdResolver for ID " +
                                                                   _current.compactId, ex);
                                }
                            }

                            if(_current.typeId.Length == 0)
                            {
                                _current.typeId = _stream.instance().resolveCompactId(_current.compactId);
                            }
                        }
                    }

                    if(v == null && _current.typeId.Length > 0)
                    {
                        v = newInstance(_current.typeId);
                    }

                    if(v != null)
                    {
                        if(updateCache)
                        {
                            Debug.Assert(_current.compactId >= 0);
                            _compactIdCache.Add(_current.compactId, v.GetType());
                        }

                        //
                        // We have an instance, get out of this loop.
                        //
                        break;
                    }

                    //
                    // If object slicing is disabled, stop un-marshalling.
                    //
                    if(!_sliceObjects)
                    {
                        throw new NoValueFactoryException("no value factory found and object slicing is disabled",
                                                          _current.typeId);
                    }

                    //
                    // Slice off what we don't understand.
                    //
                    skipSlice();

                    //
                    // If this is the last slice, keep the object as an opaque
                    // UnknownSlicedData object.
                    //
                    if((_current.sliceFlags & Protocol.FLAG_IS_LAST_SLICE) != 0)
                    {
                        //
                        // Provide a factory with an opportunity to supply the object.
                        // We pass the "::Ice::Object" ID to indicate that this is the
                        // last chance to preserve the object.
                        //
                        v = newInstance(Ice.ObjectImpl.ice_staticId());
                        if(v == null)
                        {
                            v = new Ice.UnknownSlicedObject(mostDerivedId);
                        }

                        break;
                    }

                    startSlice(); // Read next Slice header for next iteration.
                }

                //
                // Un-marshal the object
                //
                unmarshal(index, v);

                if(_current == null && _patchMap != null && _patchMap.Count > 0)
                {
                    //
                    // If any entries remain in the patch map, the sender has sent an index for an object, but failed
                    // to supply the object.
                    //
                    throw new Ice.MarshalException("index for class received, but no instance");
                }

                if(cb != null)
                {
                    cb(v);
                }
                return index;
            }
Beispiel #22
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.Color)inStream.readEnum((int)Demo.Color.blue);
            inStream.endEncapsulation();
            Console.WriteLine("Printing enum " + c);
            return(true);
        }
        else if (current.operation.Equals("printStruct"))
        {
            Demo.Structure s = new Demo.Structure();
            s.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"))
        {
            ReadObjectCallback cb = new ReadObjectCallback();
            inStream.readObject(cb.invoke);
            inStream.readPendingObjects();
            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.writeObject(c);
            outStream.writeString("hello");
            outStream.writePendingObjects();
            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;
        }
    }
Beispiel #23
0
 /// <summary>实例化</summary>
 /// <param name="index">成员序号</param>
 /// <param name="callback"></param>
 public ReadIndexEventArgs(Int32 index, ReadObjectCallback callback)
     : base(callback)
 {
     Index = index;
 }
Beispiel #24
0
        /// <summary>读取对象成员</summary>
        /// <param name="type">要读取的对象类型</param>
        /// <param name="value">要读取的对象</param>
        /// <param name="member">成员</param>
        /// <param name="index">成员索引</param>
        /// <param name="callback">处理成员的方法</param>
        /// <returns>是否读取成功</returns>
        protected override bool OnReadMember(Type type, ref object value, IObjectMemberInfo member, Int32 index, ReadObjectCallback callback)
        {
            Boolean isAtt = Settings.MemberAsAttribute && XmlWriterX.IsAttributeType(member.Type);

            if (isAtt)
            {
                Reader.MoveToAttribute(member.Name);
            }

            return(base.OnReadMember(type, ref value, member, index, callback));
        }
Beispiel #25
0
 /// <summary>实例化</summary>
 /// <param name="value">对象</param>
 /// <param name="type">对象类型</param>
 /// <param name="index">序号</param>
 /// <param name="callback"></param>
 public ReadItemEventArgs(Object value, Type type, Int32 index, ReadObjectCallback callback)
     : base(index, callback)
 {
     Value = value;
     Type  = type;
 }
Beispiel #26
0
 public Patcher(ReadObjectCallback cb) : base("unknown")
 {
     _cb = cb;
 }
Beispiel #27
0
 /// <summary>实例化</summary>
 /// <param name="value">对象</param>
 /// <param name="type">对象类型</param>
 /// <param name="callback"></param>
 public ReadObjectEventArgs(Object value, Type type, ReadObjectCallback callback)
     : base(callback)
 {
     Value = value;
     Type  = type;
 }
Beispiel #28
0
 /// <summary>实例化</summary>
 /// <param name="value">对象</param>
 /// <param name="type">对象类型</param>
 /// <param name="index">序号</param>
 /// <param name="callback"></param>
 public ReadItemEventArgs(Object value, Type type, Int32 index, ReadObjectCallback callback)
     : base(index, callback)
 {
     Value = value;
     Type = type;
 }
Beispiel #29
0
        public override int run(string[] args)
        {
            if (args.Length > 0)
            {
                Console.Error.WriteLine(appName() + ": too many arguments");
                return(1);
            }

            Ice.ObjectPrx obj = communicator().propertyToProxy("Printer.Proxy");

            menu();

            string line = null;

            do
            {
                try
                {
                    Console.Write("==> ");
                    Console.Out.Flush();
                    line = Console.In.ReadLine();
                    if (line == null)
                    {
                        break;
                    }

                    byte[] outParams;

                    if (line.Equals("1"))
                    {
                        //
                        // Marshal the in parameter.
                        //
                        Ice.OutputStream outStream = new Ice.OutputStream(communicator());
                        outStream.startEncapsulation();
                        outStream.writeString("The streaming API works!");
                        outStream.endEncapsulation();

                        //
                        // Invoke operation.
                        //
                        if (!obj.ice_invoke("printString", Ice.OperationMode.Normal, outStream.finished(),
                                            out outParams))
                        {
                            Console.Error.WriteLine("Unknown user exception");
                        }
                    }
                    else if (line.Equals("2"))
                    {
                        //
                        // Marshal the in parameter.
                        //
                        Ice.OutputStream outStream = new Ice.OutputStream(communicator());
                        outStream.startEncapsulation();
                        string[] arr = { "The", "streaming", "API", "works!" };
                        Demo.StringSeqHelper.write(outStream, arr);
                        outStream.endEncapsulation();

                        //
                        // Invoke operation.
                        //
                        if (!obj.ice_invoke("printStringSequence", Ice.OperationMode.Normal, outStream.finished(),
                                            out outParams))
                        {
                            Console.Error.WriteLine("Unknown user exception");
                        }
                    }
                    else if (line.Equals("3"))
                    {
                        //
                        // Marshal the in parameter.
                        //
                        Ice.OutputStream outStream = new Ice.OutputStream(communicator());
                        outStream.startEncapsulation();
                        Dictionary <string, string> dict = new Dictionary <string, string>();
                        dict["The"] = "streaming";
                        dict["API"] = "works!";
                        Demo.StringDictHelper.write(outStream, dict);
                        outStream.endEncapsulation();

                        //
                        // Invoke operation.
                        //
                        if (!obj.ice_invoke("printDictionary", Ice.OperationMode.Normal, outStream.finished(),
                                            out outParams))
                        {
                            Console.Error.WriteLine("Unknown user exception");
                        }
                    }
                    else if (line.Equals("4"))
                    {
                        //
                        // Marshal the in parameter.
                        //
                        Ice.OutputStream outStream = new Ice.OutputStream(communicator());
                        outStream.startEncapsulation();
                        outStream.writeEnum((int)Demo.Color.green, (int)Demo.Color.blue);
                        outStream.endEncapsulation();

                        //
                        // Invoke operation.
                        //
                        if (!obj.ice_invoke("printEnum", Ice.OperationMode.Normal, outStream.finished(), out outParams))
                        {
                            Console.Error.WriteLine("Unknown user exception");
                        }
                    }
                    else if (line.Equals("5"))
                    {
                        //
                        // Marshal the in parameter.
                        //
                        Ice.OutputStream outStream = new Ice.OutputStream(communicator());
                        outStream.startEncapsulation();
                        Demo.Structure s = new Demo.Structure();
                        s.name  = "red";
                        s.value = Demo.Color.red;
                        s.write__(outStream);
                        outStream.endEncapsulation();

                        //
                        // Invoke operation.
                        //
                        if (!obj.ice_invoke("printStruct", Ice.OperationMode.Normal, outStream.finished(),
                                            out outParams))
                        {
                            Console.Error.WriteLine("Unknown user exception");
                        }
                    }
                    else if (line.Equals("6"))
                    {
                        //
                        // Marshal the in parameter.
                        //
                        Ice.OutputStream outStream = new Ice.OutputStream(communicator());
                        outStream.startEncapsulation();
                        Demo.Structure[] arr = new Demo.Structure[3];
                        arr[0]       = new Demo.Structure();
                        arr[0].name  = "red";
                        arr[0].value = Demo.Color.red;
                        arr[1]       = new Demo.Structure();
                        arr[1].name  = "green";
                        arr[1].value = Demo.Color.green;
                        arr[2]       = new Demo.Structure();
                        arr[2].name  = "blue";
                        arr[2].value = Demo.Color.blue;
                        Demo.StructureSeqHelper.write(outStream, arr);
                        outStream.endEncapsulation();

                        //
                        // Invoke operation.
                        //
                        if (!obj.ice_invoke("printStructSequence", Ice.OperationMode.Normal, outStream.finished(),
                                            out outParams))
                        {
                            Console.Error.WriteLine("Unknown user exception");
                        }
                    }
                    else if (line.Equals("7"))
                    {
                        //
                        // Marshal the in parameter.
                        //
                        Ice.OutputStream outStream = new Ice.OutputStream(communicator());
                        outStream.startEncapsulation();
                        Demo.C c = new Demo.C();
                        c.s       = new Demo.Structure();
                        c.s.name  = "blue";
                        c.s.value = Demo.Color.blue;
                        outStream.writeObject(c);
                        outStream.writePendingObjects();
                        outStream.endEncapsulation();

                        //
                        // Invoke operation.
                        //
                        if (!obj.ice_invoke("printClass", Ice.OperationMode.Normal, outStream.finished(), out outParams))
                        {
                            Console.Error.WriteLine("Unknown user exception");
                        }
                    }
                    else if (line.Equals("8"))
                    {
                        //
                        // Invoke operation.
                        //
                        if (!obj.ice_invoke("getValues", Ice.OperationMode.Normal, null, out outParams))
                        {
                            Console.Error.WriteLine("Unknown user exception");
                            continue;
                        }

                        //
                        // Unmarshal the results.
                        //
                        Ice.InputStream inStream = new Ice.InputStream(communicator(), outParams);
                        inStream.startEncapsulation();
                        ReadObjectCallback cb = new ReadObjectCallback();
                        inStream.readObject(cb.invoke);
                        String str = inStream.readString();
                        inStream.readPendingObjects();
                        Demo.C c = cb.obj as Demo.C;
                        Console.Error.WriteLine("Got string `" + str + "' and class: s.name=" + c.s.name +
                                                ", s.value=" + c.s.value);
                    }
                    else if (line.Equals("9"))
                    {
                        //
                        // Invoke operation.
                        //
                        if (obj.ice_invoke("throwPrintFailure", Ice.OperationMode.Normal, null, out outParams))
                        {
                            Console.Error.WriteLine("Expected exception");
                            continue;
                        }

                        Ice.InputStream inStream = new Ice.InputStream(communicator(), outParams);
                        inStream.startEncapsulation();
                        try
                        {
                            inStream.throwException();
                        }
                        catch (Demo.PrintFailure)
                        {
                            // Expected.
                        }
                        catch (Ice.UserException)
                        {
                            Console.Error.WriteLine("Unknown user exception");
                        }
                        inStream.endEncapsulation();
                    }
                    else if (line.Equals("s"))
                    {
                        obj.ice_invoke("shutdown", Ice.OperationMode.Normal, null, out outParams);
                    }
                    else if (line.Equals("x"))
                    {
                        // Nothing to do.
                    }
                    else if (line.Equals("?"))
                    {
                        menu();
                    }
                    else
                    {
                        Console.Error.WriteLine("unknown command `" + line + "'");
                        menu();
                    }
                }
                catch (Ice.LocalException ex)
                {
                    Console.Error.WriteLine(ex);
                }
            }while(!line.Equals("x"));

            return(0);
        }
 /// <summary>
 /// 实例化
 /// </summary>
 /// <param name="index">成员序号</param>
 /// <param name="callback"></param>
 public ReadIndexEventArgs(Int32 index, ReadObjectCallback callback)
     : base(callback)
 {
     Index = index;
 }
Beispiel #31
0
 /// <summary>实例化</summary>
 /// <param name="value">对象</param>
 /// <param name="type">对象类型</param>
 /// <param name="member">成员</param>
 /// <param name="index">成员序号</param>
 /// <param name="callback"></param>
 public ReadMemberEventArgs(Object value, Type type, IObjectMemberInfo member, Int32 index, ReadObjectCallback callback)
     : base(callback)
 {
     Value  = value;
     Type   = type;
     Member = member;
     Index  = index;
 }
Beispiel #32
0
 /// <summary>实例化</summary>
 /// <param name="value">对象</param>
 /// <param name="keyType">键类型</param>
 /// <param name="valueType">值类型</param>
 /// <param name="index"></param>
 /// <param name="callback"></param>
 public ReadDictionaryEventArgs(DictionaryEntry value, Type keyType, Type valueType, Int32 index, ReadObjectCallback callback)
     : base(index, callback)
 {
     Value     = value;
     KeyType   = keyType;
     ValueType = valueType;
 }
Beispiel #33
0
 /// <summary>
 /// Extracts the index of a Slice value from the stream.
 /// </summary>
 /// <param name="cb">The callback to notify the application when the extracted instance is available.
 /// The stream extracts Slice values in stages. The Ice run time invokes the delegate when the
 /// corresponding instance has been fully unmarshaled.</param>
 public void readObject(ReadObjectCallback cb)
 {
     initEncaps();
     _encapsStack.decoder.readObject(cb);
 }