Esempio n. 1
0
        protected void DoFunctionList(HproseMethods methods)
        {
#if !(dotNET10 || dotNET11 || dotNETCF10)
            List <string> names = new List <string>(GlobalMethods.AllNames);
#else
            ArrayList names = new ArrayList(GlobalMethods.AllNames);
#endif
            if (methods != null)
            {
                names.AddRange(methods.AllNames);
            }
            Stream ostream = OutputStream;
            if (filter != null)
            {
                ostream = filter.OutputFilter(ostream);
            }
            HproseWriter writer = new HproseWriter(ostream, mode);
            ostream.WriteByte(HproseTags.TagFunctions);
#if !(dotNET10 || dotNET11 || dotNETCF10)
            writer.WriteList((IList <string>)names);
#else
            writer.WriteList((IList)names);
#endif
            ostream.WriteByte(HproseTags.TagEnd);
            ostream.Flush();
        }
Esempio n. 2
0
        private MemoryStream DoOutput(string functionName, object[] arguments, bool byRef, bool simple, HproseClientContext context)
        {
            MemoryStream outData = new MemoryStream();

#if !dotNETMF
            HproseWriter writer = new HproseWriter(outData, mode, simple);
#else
            HproseWriter writer = new HproseWriter(outData, simple);
#endif
            outData.WriteByte(HproseTags.TagCall);
            writer.WriteString(functionName);
            if ((arguments != null) && (arguments.Length > 0 || byRef))
            {
                writer.Reset();
                writer.WriteArray(arguments);
                if (byRef)
                {
                    writer.WriteBoolean(true);
                }
            }
            outData.WriteByte(HproseTags.TagEnd);
            outData.Position = 0;
            for (int i = 0, n = filters.Count; i < n; ++i)
            {
#if (dotNET10 || dotNET11 || dotNETCF10 || dotNETMF)
                IHproseFilter filter = (IHproseFilter)filters[i];
                outData = filter.OutputFilter(outData, context);
#else
                outData = filters[i].OutputFilter(outData, context);
#endif
                outData.Position = 0;
            }
            return(outData);
        }
Esempio n. 3
0
        public static MemoryStream Serialize(object obj, HproseMode mode)
        {
            MemoryStream stream = new MemoryStream();
            HproseWriter writer = new HproseWriter(stream, mode);

            writer.Serialize(obj);
            return(stream);
        }
Esempio n. 4
0
        protected void SendError(string error)
        {
            if (OnSendError != null)
            {
                OnSendError(error);
            }
            Stream       ostream = OutputStream;
            HproseWriter writer  = new HproseWriter(ostream, mode);

            ostream.WriteByte(HproseTags.TagError);
            writer.WriteString(error, false);
            ostream.WriteByte(HproseTags.TagEnd);
            ostream.Flush();
        }
Esempio n. 5
0
        protected MemoryStream SendError(Exception e, object context)
        {
            if (OnSendError != null)
            {
                OnSendError(e, context);
            }
            string       error  = debugEnabled ? e.ToString(): e.Message;
            MemoryStream data   = new MemoryStream(4096);
            HproseWriter writer = new HproseWriter(data, mode, true);

            data.WriteByte(HproseTags.TagError);
            writer.WriteString(error);
            data.WriteByte(HproseTags.TagEnd);
            return(ResponseEnd(data, context));
        }
Esempio n. 6
0
        protected void DoFunctionList(HproseMethods methods)
        {
            ArrayList names = new ArrayList(GlobalMethods.AllNames);

            if (methods != null)
            {
                names.AddRange(methods.AllNames);
            }
            Stream       ostream = OutputStream;
            HproseWriter writer  = new HproseWriter(ostream, mode);

            ostream.WriteByte(HproseTags.TagFunctions);
            writer.WriteList(names, false);
            ostream.WriteByte(HproseTags.TagEnd);
            ostream.Flush();
        }
Esempio n. 7
0
        private void DoOutput(string functionName, object[] arguments, bool byRef, Stream ostream)
        {
            HproseWriter hproseWriter = new HproseWriter(ostream, mode);

            ostream.WriteByte(HproseTags.TagCall);
            hproseWriter.WriteString(functionName, false);
            if ((arguments != null) && (arguments.Length > 0 || byRef))
            {
                hproseWriter.Reset();
                hproseWriter.WriteArray(arguments, false);
                if (byRef)
                {
                    hproseWriter.WriteBoolean(true);
                }
            }
            ostream.WriteByte(HproseTags.TagEnd);
        }
Esempio n. 8
0
        protected MemoryStream DoFunctionList(HproseMethods methods, HproseContext context)
        {
#if dotNETMF
            ArrayList names = new ArrayList();
            foreach (object name in GlobalMethods.AllNames)
            {
                names.Add(name);
            }
#elif !(dotNET10 || dotNET11 || dotNETCF10)
            List <string> names = new List <string>(GlobalMethods.AllNames);
#else
            ArrayList names = new ArrayList(GlobalMethods.AllNames);
#endif
            if (methods != null)
            {
#if dotNETMF
                foreach (object name in methods.AllNames)
                {
                    names.Add(name);
                }
#else
                names.AddRange(methods.AllNames);
#endif
            }
#if !dotNETMF
            MemoryStream data   = new MemoryStream(4096);
            HproseWriter writer = new HproseWriter(data, mode, true);
#else
            MemoryStream data   = new MemoryStream();
            HproseWriter writer = new HproseWriter(data, true);
#endif
            data.WriteByte(HproseTags.TagFunctions);
#if !(dotNET10 || dotNET11 || dotNETCF10 || dotNETMF)
            writer.WriteList((IList <string>)names);
#else
            writer.WriteList((IList)names);
#endif
            data.WriteByte(HproseTags.TagEnd);
            return(ResponseEnd(data, context));
        }
 public void SerializeFields(object value, HproseWriter writer)
 {
     serializeFieldsDelegate(value, writer);
 }
Esempio n. 10
0
        public static void Serialize(object obj, Stream stream, HproseMode mode)
        {
            HproseWriter writer = new HproseWriter(stream, mode);

            writer.Serialize(obj);
        }
Esempio n. 11
0
        protected MemoryStream DoInvoke(MemoryStream istream, HproseMethods methods, object context)
        {
            HproseReader reader = new HproseReader(istream, mode);
            MemoryStream data   = new MemoryStream(4096);
            int          tag;

            do
            {
                reader.Reset();
                string       name         = reader.ReadString();
                HproseMethod remoteMethod = null;
                int          count        = 0;
                object[]     args         = null;
                object[]     arguments    = null;
                bool         byRef        = false;
                tag = reader.CheckTags((char)HproseTags.TagList + "" +
                                       (char)HproseTags.TagEnd + "" +
                                       (char)HproseTags.TagCall);
                if (tag == HproseTags.TagList)
                {
                    reader.Reset();
                    count = reader.ReadInt(HproseTags.TagOpenbrace);
                    if (methods != null)
                    {
                        remoteMethod = methods.GetMethod(name, count);
                    }
                    if (remoteMethod == null)
                    {
                        remoteMethod = GlobalMethods.GetMethod(name, count);
                    }
                    if (remoteMethod == null)
                    {
                        arguments = reader.ReadArray(count);
                    }
                    else
                    {
                        arguments = new object[count];
                        reader.ReadArray(remoteMethod.paramTypes, arguments, count);
                    }
                    tag = reader.CheckTags((char)HproseTags.TagTrue + "" +
                                           (char)HproseTags.TagEnd + "" +
                                           (char)HproseTags.TagCall);
                    if (tag == HproseTags.TagTrue)
                    {
                        byRef = true;
                        tag   = reader.CheckTags((char)HproseTags.TagEnd + "" +
                                                 (char)HproseTags.TagCall);
                    }
                }
                else
                {
                    if (methods != null)
                    {
                        remoteMethod = methods.GetMethod(name, 0);
                    }
                    if (remoteMethod == null)
                    {
                        remoteMethod = GlobalMethods.GetMethod(name, 0);
                    }
                    arguments = new object[0];
                }
                if (OnBeforeInvoke != null)
                {
                    OnBeforeInvoke(name, arguments, byRef, context);
                }
                if (remoteMethod == null)
                {
                    args = arguments;
                }
                else
                {
                    args = FixArguments(remoteMethod.paramTypes, arguments, count, context);
                }
                object result;
                if (remoteMethod == null)
                {
                    if (methods != null)
                    {
                        remoteMethod = methods.GetMethod("*", 2);
                    }
                    if (remoteMethod == null)
                    {
                        remoteMethod = GlobalMethods.GetMethod("*", 2);
                    }
                    if (remoteMethod == null)
                    {
                        throw new MissingMethodException("Can't find this method " + name);
                    }
                    result = remoteMethod.method.Invoke(remoteMethod.obj, new object[] { name, args });
                }
                else
                {
                    result = remoteMethod.method.Invoke(remoteMethod.obj, args);
                }
                if (byRef)
                {
                    Array.Copy(args, 0, arguments, 0, count);
                }
                if (OnAfterInvoke != null)
                {
                    OnAfterInvoke(name, arguments, byRef, result, context);
                }
                if (remoteMethod.mode == HproseResultMode.RawWithEndTag)
                {
                    data.Write((byte[])result, 0, ((byte[])result).Length);
                    return(ResponseEnd(data, context));
                }
                else if (remoteMethod.mode == HproseResultMode.Raw)
                {
                    data.Write((byte[])result, 0, ((byte[])result).Length);
                }
                else
                {
                    data.WriteByte(HproseTags.TagResult);
                    bool         simple = remoteMethod.simple;
                    HproseWriter writer = new HproseWriter(data, mode, simple);
                    if (remoteMethod.mode == HproseResultMode.Serialized)
                    {
                        data.Write((byte[])result, 0, ((byte[])result).Length);
                    }
                    else
                    {
                        writer.Serialize(result);
                    }
                    if (byRef)
                    {
                        data.WriteByte(HproseTags.TagArgument);
                        writer.Reset();
                        writer.WriteArray(arguments);
                    }
                }
            } while (tag == HproseTags.TagCall);
            data.WriteByte(HproseTags.TagEnd);
            return(ResponseEnd(data, context));
        }
Esempio n. 12
0
 public void WriteIList(HproseWriter writer, object list, bool checkRef)
 {
     writer.WriteIList <T>((IList <T>)list, checkRef);
 }
Esempio n. 13
0
 public void WriteIMap(HproseWriter writer, object map, bool checkRef)
 {
     writer.WriteIMap <TKey, TValue>((IDictionary <TKey, TValue>)map, checkRef);
 }
Esempio n. 14
0
 public void WriteICollection(HproseWriter writer, object collection, bool checkRef)
 {
     writer.WriteICollection <T>((ICollection <T>)collection, checkRef);
 }
Esempio n. 15
0
 public void SerializeProperties(object value, HproseWriter writer)
 {
     serializePropertiesDelegate(value, writer);
 }
Esempio n. 16
0
 public void SerializeMembers(object value, HproseWriter writer)
 {
     serializeMembersDelegate(value, writer);
 }
Esempio n. 17
0
        protected void DoInvoke(HproseMethods methods)
        {
            Stream       istream = InputStream;
            HproseReader reader  = new HproseReader(istream, mode);
            Stream       ostream = OutputStream;
            HproseWriter writer  = new HproseWriter(ostream, mode);
            int          tag;

            do
            {
                reader.Reset();
                string       name         = ((string)reader.ReadString());
                HproseMethod remoteMethod = null;
                int          count        = 0;
                object[]     args         = null;
                object[]     arguments    = null;
                bool         byRef        = false;
                tag = reader.CheckTags((char)HproseTags.TagList + "" +
                                       (char)HproseTags.TagEnd + "" +
                                       (char)HproseTags.TagCall);
                if (tag == HproseTags.TagList)
                {
                    reader.Reset();
                    count = reader.ReadInt(HproseTags.TagOpenbrace);
                    if (methods != null)
                    {
                        remoteMethod = methods.GetMethod(name, count);
                    }
                    if (remoteMethod == null)
                    {
                        remoteMethod = GlobalMethods.GetMethod(name, count);
                    }
                    if (remoteMethod == null)
                    {
                        arguments = reader.ReadArray(count);
                    }
                    else
                    {
                        arguments = new object[count];
                        reader.ReadArray(remoteMethod.paramTypes, arguments, count);
                    }
                    reader.CheckTag(HproseTags.TagClosebrace);
                    tag = reader.CheckTags((char)HproseTags.TagTrue + "" +
                                           (char)HproseTags.TagEnd + "" +
                                           (char)HproseTags.TagCall);
                    if (tag == HproseTags.TagTrue)
                    {
                        byRef = true;
                        tag   = reader.CheckTags((char)HproseTags.TagEnd + "" +
                                                 (char)HproseTags.TagCall);
                    }
                }
                else
                {
                    if (methods != null)
                    {
                        remoteMethod = methods.GetMethod(name, 0);
                    }
                    if (remoteMethod == null)
                    {
                        remoteMethod = GlobalMethods.GetMethod(name, 0);
                    }
                    arguments = new object[0];
                }
                if (OnBeforeInvoke != null)
                {
                    OnBeforeInvoke(name, arguments, byRef);
                }
                if (remoteMethod == null)
                {
                    args = arguments;
                }
                else
                {
                    args = FixArguments(remoteMethod.paramTypes, arguments, count);
                }
                object result;
                if (remoteMethod == null)
                {
                    if (methods != null)
                    {
                        remoteMethod = methods.GetMethod("*", 2);
                    }
                    if (remoteMethod == null)
                    {
                        remoteMethod = GlobalMethods.GetMethod("*", 2);
                    }
                    if (remoteMethod == null)
                    {
                        throw new MissingMethodException("Can't find this method " + name);
                    }
                    result = remoteMethod.method.Invoke(remoteMethod.obj, new object[] { name, args });
                }
                else
                {
                    result = remoteMethod.method.Invoke(remoteMethod.obj, args);
                }
                if (byRef)
                {
                    Array.Copy(args, 0, arguments, 0, count);
                }
                if (OnAfterInvoke != null)
                {
                    OnAfterInvoke(name, arguments, byRef, result);
                }
                if (remoteMethod.mode == HproseResultMode.RawWithEndTag)
                {
                    ostream.Write((byte[])result, 0, ((byte[])result).Length);
                    ostream.Flush();
                    return;
                }
                else if (remoteMethod.mode == HproseResultMode.Raw)
                {
                    ostream.Write((byte[])result, 0, ((byte[])result).Length);
                }
                else
                {
                    ostream.WriteByte(HproseTags.TagResult);
                    if (remoteMethod.mode == HproseResultMode.Serialized)
                    {
                        ostream.Write((byte[])result, 0, ((byte[])result).Length);
                    }
                    else
                    {
                        writer.Reset();
                        writer.Serialize(result);
                    }
                    if (byRef)
                    {
                        ostream.WriteByte(HproseTags.TagArgument);
                        writer.Reset();
                        writer.WriteArray(arguments, false);
                    }
                }
            } while (tag == HproseTags.TagCall);
            ostream.WriteByte(HproseTags.TagEnd);
            ostream.Flush();
        }